Class: Scruby::Audio::Server
Constant Summary collapse
- @@sc_path =
'/Applications/SuperCollider/scsynth'- @@servers =
[]
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Class Method Summary collapse
-
.[](index) ⇒ Object
Return a server corresponding to the specified index of the registered servers array.
-
.[]=(index) ⇒ Object
Set a server to the specified index of the registered servers array.
-
.all ⇒ Object
Returns an array with all the registered servers.
-
.sc_path ⇒ Object
Get the scsynth path.
-
.sc_path=(path) ⇒ Object
Specify the scsynth binary path.
Instance Method Summary collapse
-
#boot ⇒ Object
Boots the local binary of the scsynth forking a process, it will rise a SCError if the scsynth binary is not found in /Applications/SuperCollider/scsynt (default Mac OS path) or given path.
-
#initialize(host = 'localhost', port = 57111) ⇒ Server
constructor
Initializes and registers a new Server instance and sets the host and port for it.
-
#send(command, *args) ⇒ Object
Sends an OSC command to the scsyth server.
-
#send_synth_def(synth_def) ⇒ Object
Encodes and sends a SynthDef to the scsynth server.
-
#stop ⇒ Object
Sends the /quit OSC signal to the scsynth server and kills the forked process if the scsynth server is running locally.
Constructor Details
#initialize(host = 'localhost', port = 57111) ⇒ Server
Initializes and registers a new Server instance and sets the host and port for it. The server is a Ruby representation of scsynth which can be a local binary or a remote
server already running. Server class keeps an array with all the instantiated servers
33 34 35 36 |
# File 'lib/scruby/audio/server.rb', line 33 def initialize( host = 'localhost', port = 57111) @host, @port = host, port @@servers << self end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
25 26 27 |
# File 'lib/scruby/audio/server.rb', line 25 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
25 26 27 |
# File 'lib/scruby/audio/server.rb', line 25 def port @port end |
Class Method Details
.[](index) ⇒ Object
Return a server corresponding to the specified index of the registered servers array
95 96 97 |
# File 'lib/scruby/audio/server.rb', line 95 def [](index) @@servers[index] end |
.[]=(index) ⇒ Object
Set a server to the specified index of the registered servers array
100 101 102 103 |
# File 'lib/scruby/audio/server.rb', line 100 def []=(index) @@servers[index] @@servers.uniq! end |
.all ⇒ Object
Returns an array with all the registered servers
90 91 92 |
# File 'lib/scruby/audio/server.rb', line 90 def all @@servers end |
.sc_path ⇒ Object
Get the scsynth path
85 86 87 |
# File 'lib/scruby/audio/server.rb', line 85 def sc_path @@sc_path end |
.sc_path=(path) ⇒ Object
Specify the scsynth binary path
80 81 82 |
# File 'lib/scruby/audio/server.rb', line 80 def sc_path=( path ) @@sc_path = path end |
Instance Method Details
#boot ⇒ Object
Boots the local binary of the scsynth forking a process, it will rise a SCError if the scsynth binary is not found in /Applications/SuperCollider/scsynt (default Mac OS path) or given path. The default path can be overriden using Server.scsynt_path=(‘path’)
41 42 43 44 45 46 47 48 |
# File 'lib/scruby/audio/server.rb', line 41 def boot raise SCError.new('Scsynth not found in the given path') unless File.exists?( @@sc_path ) Thread.new do path = @@sc_path.scan(/[^\/]+/) @server_pipe = IO.popen( "cd /#{ path[0..-2].join('/') }; ./#{ path.last } -u #{ @port }" ) loop { p Special.new(@server_pipe.gets.chomp) } end unless @server_pipe end |
#send(command, *args) ⇒ Object
Sends an OSC command to the scsyth server. E.g. server.send('/dumpOSC', 1)
60 61 62 |
# File 'lib/scruby/audio/server.rb', line 60 def send( command, *args ) return $UDP_Sender.send( command, @host, @port, *args ) end |
#send_synth_def(synth_def) ⇒ Object
Encodes and sends a SynthDef to the scsynth server
65 66 67 68 69 |
# File 'lib/scruby/audio/server.rb', line 65 def send_synth_def( synth_def ) *blob = OSC::Blob.new( synth_def.encode ), 0 = OSC::Message.new( '/d_recv', $UDP_Sender.type_tag( blob ), *blob ) ( OSC::Bundle.new( nil, ) ) end |
#stop ⇒ Object
Sends the /quit OSC signal to the scsynth server and kills the forked process if the scsynth server is running locally
52 53 54 55 56 |
# File 'lib/scruby/audio/server.rb', line 52 def stop send '/quit' Process.kill 'KILL', @server_pipe.pid if @server_pipe @server_pipe = nil end |