Class: SonicPi

Inherits:
Object
  • Object
show all
Defined in:
lib/sonic_pi.rb

Constant Summary collapse

RUN_COMMAND =
"/run-code"
STOP_COMMAND =
"/stop-all-jobs"
SERVER =
'localhost'
GUI_ID =
'SONIC_PI_CLI'

Instance Method Summary collapse

Constructor Details

#initialize(port = 4557) ⇒ SonicPi

Returns a new instance of SonicPi.



7
8
9
# File 'lib/sonic_pi.rb', line 7

def initialize(port=4557)
  @port=port
end

Instance Method Details

#run(command) ⇒ Object



16
17
18
# File 'lib/sonic_pi.rb', line 16

def run(command)
  send_command(RUN_COMMAND, command)
end

#stopObject



20
21
22
# File 'lib/sonic_pi.rb', line 20

def stop
  send_command(STOP_COMMAND)
end

#test_connection!Object



24
25
26
27
28
29
30
31
32
# File 'lib/sonic_pi.rb', line 24

def test_connection!
  begin
    socket = UDPSocket.new
    socket.bind(nil, @port)
    abort("ERROR: Sonic Pi is not listening on #{@port} - is it running?")
  rescue
    # everything is good
  end
end