Class: Xi::Supercollider::Stream

Inherits:
Xi::Stream show all
Includes:
OSC
Defined in:
lib/xi/supercollider/stream.rb

Constant Summary collapse

MAX_NODE_ID =
10000
DEFAULT_PARAMS =
{
  out:  0,
  amp:  1.0,
  pan:  0.0,
  vel:  127,
}

Instance Attribute Summary

Attributes inherited from Xi::Stream

#clock, #delta, #gate, #opts, #source, #state

Instance Method Summary collapse

Methods inherited from Xi::Stream

#inspect, #notify, #play, #playing?, #set, #stopped?

Constructor Details

#initialize(name, clock, server: 'localhost', port: 57110, base_node_id: 2000, **opts) ⇒ Stream

Returns a new instance of Stream.



17
18
19
20
21
22
23
# File 'lib/xi/supercollider/stream.rb', line 17

def initialize(name, clock, server: 'localhost', port: 57110, base_node_id: 2000, **opts)
  super

  @base_node_id = base_node_id
  @playing_synths = [].to_set
  at_exit { free_playing_synths }
end

Instance Method Details

#free_playing_synthsObject



34
35
36
# File 'lib/xi/supercollider/stream.rb', line 34

def free_playing_synths
  n_free(*@playing_synths.map { |so_id| node_id(so_id) })
end

#node_id(so_id) ⇒ Object



38
39
40
# File 'lib/xi/supercollider/stream.rb', line 38

def node_id(so_id)
  (@base_node_id + so_id) % MAX_NODE_ID
end

#stopObject



25
26
27
28
29
30
31
32
# File 'lib/xi/supercollider/stream.rb', line 25

def stop
  @mutex.synchronize do
    @playing_synths.each do |so_id|
      n_set(node_id(so_id), gate: 0)
    end
  end
  super
end