Class: FMOD::ChannelControl::DspChain
- Inherits:
-
Object
- Object
- FMOD::ChannelControl::DspChain
- Includes:
- Enumerable
- Defined in:
- lib/fmod/channel_control.rb
Overview
Emulates an Array-type container of a FMOD::ChannelControl‘s DSP chain.
Instance Method Summary collapse
-
#[](index) ⇒ Dsp|nil
Element reference.
-
#[]=(index, dsp) ⇒ Dsp
Element assignment.
-
#add(*dsp) ⇒ self
(also: #push, #<<)
Appends or pushes the given object(s) on to the end of this DspChain.
-
#count ⇒ Integer
(also: #size, #length)
Retrieves the number of DSPs within the chain.
- #each ⇒ Object
-
#index(dsp) ⇒ Integer
Returns the index of the specified DSP.
-
#initialize(channel) ⇒ DspChain
constructor
Creates a new instance of a DspChain for the specified FMOD::ChannelControl.
-
#move(dsp, index) ⇒ self
Moves a DSP unit that exists in this DspChain to a new index.
-
#pop ⇒ Dsp|nil
Removes the last element from
self
and returns it, ornil
if the DspChain is empty. -
#remove(dsp) ⇒ self
(also: #delete)
Deletes the specified DSP from this DSP chain.
-
#shift ⇒ Dsp|nil
Returns the first element of
self
and removes it (shifting all other elements down by one). -
#unshift(dsp) ⇒ self
Prepends objects to the front of
self
, moving other elements upwards.
Constructor Details
#initialize(channel) ⇒ DspChain
Creates a new instance of a FMOD::ChannelControl::DspChain for the specified FMOD::ChannelControl.
31 32 33 34 |
# File 'lib/fmod/channel_control.rb', line 31 def initialize(channel) FMOD.type?(channel, ChannelControl) @channel = channel end |
Instance Method Details
#[](index) ⇒ Dsp|nil
Element reference. Returns the element at index.
66 67 68 69 70 71 |
# File 'lib/fmod/channel_control.rb', line 66 def [](index) return nil unless index.between?(-2, count) dsp = "\0" * Fiddle::SIZEOF_INTPTR_T FMOD.invoke(:ChannelGroup_GetDSP, @channel, index, dsp) Dsp.from_handle(dsp) end |
#[]=(index, dsp) ⇒ Dsp
Element assignment. Sets the element at the specified index.
78 79 80 81 82 |
# File 'lib/fmod/channel_control.rb', line 78 def []=(index, dsp) FMOD.type?(dsp, Dsp) FMOD.invoke(:ChannelGroup_AddDSP, @channel, index, dsp) dsp end |
#add(*dsp) ⇒ self Also known as: push, <<
Appends or pushes the given object(s) on to the end of this FMOD::ChannelControl::DspChain. This expression returns self
, so several appends may be chained together.
89 90 91 92 |
# File 'lib/fmod/channel_control.rb', line 89 def add(*dsp) dsp.each { |d| self[DspIndex::TAIL] = d } self end |
#count ⇒ Integer Also known as: size, length
Retrieves the number of DSPs within the chain. This includes the built-in Effects::Fader DSP.
40 41 42 43 44 |
# File 'lib/fmod/channel_control.rb', line 40 def count buffer = "\0" * Fiddle::SIZEOF_INT FMOD.invoke(:ChannelGroup_GetNumDSPs, @channel, buffer) buffer.unpack1('l') end |
#each {|dsp| ... } ⇒ self #each ⇒ Enumerator
55 56 57 58 59 |
# File 'lib/fmod/channel_control.rb', line 55 def each return to_enum(:each) unless block_given? (0...count).each { |i| yield self[i] } self end |
#index(dsp) ⇒ Integer
Returns the index of the specified DSP.
139 140 141 142 143 144 |
# File 'lib/fmod/channel_control.rb', line 139 def index(dsp) FMOD.type?(dsp, Dsp) buffer = "\0" * Fiddle::SIZEOF_INT FMOD.invoke(:ChannelGroup_GetDSPIndex, @channel, dsp, buffer) buffer.unpack1('l') end |
#move(dsp, index) ⇒ self
Moves a DSP unit that exists in this FMOD::ChannelControl::DspChain to a new index.
152 153 154 155 156 |
# File 'lib/fmod/channel_control.rb', line 152 def move(dsp, index) FMOD.type?(dsp, Dsp) FMOD.invoke(:ChannelGroup_SetDSPIndex, @channel, dsp, index) self end |
#pop ⇒ Dsp|nil
Removes the last element from self
and returns it, or nil
if the FMOD::ChannelControl::DspChain is empty.
107 108 109 110 111 |
# File 'lib/fmod/channel_control.rb', line 107 def pop dsp = self[DspIndex::TAIL] remove(dsp) dsp end |
#remove(dsp) ⇒ self Also known as: delete
Deletes the specified DSP from this DSP chain. This does not release ot dispose the DSP unit, only removes from this FMOD::ChannelControl::DspChain, as a DSP unit can be shared.
129 130 131 132 133 |
# File 'lib/fmod/channel_control.rb', line 129 def remove(dsp) return unless dsp.is_a?(Dsp) FMOD.invoke(:ChannelGroup_RemoveDSP, @channel, dsp) self end |