Class: FMOD::ChannelControl::DspChain

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(channel) ⇒ DspChain

Creates a new instance of a FMOD::ChannelControl::DspChain for the specified FMOD::ChannelControl.

Parameters:

  • channel (ChannelControl)

    The channel or channel group to create the collection wrapper for.



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.

Parameters:

Returns:

  • (Dsp|nil)

    The DSP at the specified index, or nil if index is out of range.



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.

Parameters:

Returns:

  • (Dsp)

    The given DSP instance.



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.

Parameters:

  • dsp (Dsp)

    One or more DSP instance(s).

Returns:

  • (self)


89
90
91
92
# File 'lib/fmod/channel_control.rb', line 89

def add(*dsp)
  dsp.each { |d| self[DspIndex::TAIL] = d }
  self
end

#countInteger Also known as: size, length

Retrieves the number of DSPs within the chain. This includes the built-in Effects::Fader DSP.

Returns:

  • (Integer)


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 #eachEnumerator

Overloads:

  • #each {|dsp| ... } ⇒ self

    If called with a block, passes each DSP in turn before returning self.

    Yields:

    • (dsp)

      Yields a DSP instance to the block.

    Yield Parameters:

    • dsp (Dsp)

      The DSP instance.

    Returns:

    • (self)
  • #eachEnumerator

    Returns an enumerator for the FMOD::ChannelControl::DspChain if no block is given.

    Returns:

    • (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.

Parameters:

  • dsp (Dsp)

    The DSP to retrieve the index of.

Returns:

  • (Integer)

    The index of the 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.

Parameters:

Returns:

  • (self)


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

#popDsp|nil

Removes the last element from self and returns it, or nil if the FMOD::ChannelControl::DspChain is empty.

Returns:



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.

Parameters:

  • dsp (Dsp)

    The DSP to remove.

Returns:

  • (self)


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

#shiftDsp|nil

Returns the first element of self and removes it (shifting all other elements down by one). Returns nil if the array is empty.

Returns:



117
118
119
120
121
# File 'lib/fmod/channel_control.rb', line 117

def shift
  dsp = self[DspIndex::HEAD]
  remove(dsp)
  dsp
end

#unshift(dsp) ⇒ self

Prepends objects to the front of self, moving other elements upwards.

Parameters:

  • dsp (Dsp)

    A DSP instance.

Returns:

  • (self)


98
99
100
101
# File 'lib/fmod/channel_control.rb', line 98

def unshift(dsp)
  self[DspIndex::HEAD] = dsp
  self
end