Class: Scruby::Bus

Inherits:
Object show all
Defined in:
lib/scruby/bus.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, rate, channels = 1, main_bus = self, hardware_out = false) ⇒ Bus

Returns a new instance of Bus.



6
7
8
# File 'lib/scruby/bus.rb', line 6

def initialize server, rate, channels = 1, main_bus = self, hardware_out = false
  @server, @rate, @channels, @main_bus, @hardware_out = server, rate, channels, main_bus, hardware_out
end

Instance Attribute Details

#channelsObject (readonly)

Returns the value of attribute channels.



4
5
6
# File 'lib/scruby/bus.rb', line 4

def channels
  @channels
end

#main_busObject (readonly)

Returns the value of attribute main_bus.



4
5
6
# File 'lib/scruby/bus.rb', line 4

def main_bus
  @main_bus
end

#rateObject (readonly)

Returns the value of attribute rate.



4
5
6
# File 'lib/scruby/bus.rb', line 4

def rate
  @rate
end

#serverObject (readonly)

Returns the value of attribute server.



4
5
6
# File 'lib/scruby/bus.rb', line 4

def server
  @server
end

Class Method Details

.audio(server, channels = 1) ⇒ Object



58
59
60
61
62
63
# File 'lib/scruby/bus.rb', line 58

def audio server, channels = 1
  buses = [new(server, :audio, channels)]
  buses.push new(server, :audio, channels, buses.first) while buses.size < channels
  server.allocate :audio_buses, buses
  buses.first
end

.control(server, channels = 1) ⇒ Object



51
52
53
54
55
56
# File 'lib/scruby/bus.rb', line 51

def control server, channels = 1
  buses = [new(server, :control, channels)]
  buses.push new(server, :control, channels, buses.first) while buses.size < channels
  server.allocate :control_buses, buses
  buses.first
end

Instance Method Details

#audio_out?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/scruby/bus.rb', line 24

def audio_out?
  index < @server.instance_variable_get(:@opts)[:audio_outputs]
end

#fill(value, channels = @channels) ⇒ Object



41
42
43
44
45
46
# File 'lib/scruby/bus.rb', line 41

def fill value, channels = @channels
  if channels > @channels
    warn "You tried to set #{ channels } values for bus #{ index } that only has #{ @channels } channels, extra values are ignored." 
  end
  @server.send '/c_fill', index, channels.min(@channels), value
end

#freeObject



14
15
16
17
# File 'lib/scruby/bus.rb', line 14

def free
  @index = nil
  @server.__send__("#{ @rate }_buses").delete(self)
end

#indexObject



10
11
12
# File 'lib/scruby/bus.rb', line 10

def index
  @index ||= @server.__send__("#{ @rate }_buses").index(self)
end

#set(*args) ⇒ Object

Messaging



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/scruby/bus.rb', line 29

def set *args
  args.flatten!
  message_args = []
  (index...channels).to_a.zip(args) do |chan, val|
    message_args.push(chan).push(val) if chan and val
  end
  if args.size > channels
    warn "You tried to set #{ args.size } values for bus #{ index } that only has #{ channels } channels, extra values are ignored." 
  end
  @server.send '/c_set', *message_args
end

#to_mapObject

Raises:



19
20
21
22
# File 'lib/scruby/bus.rb', line 19

def to_map
  raise SCError, 'Audio buses cannot be mapped' if rate == :audio
  "c#{ index }"
end