Class: Stretto::Voice

Inherits:
Array show all
Defined in:
lib/stretto/music_elements/voice.rb

Overview

Represent a channel or track, according to the MIDI specification. Each voice has an individual key signature, instrument, and for some values, different controller variables

The MIDI specification allows a pattern to have up to 16 channels, being the channel 9 the percussion 1.

Constant Summary

DEFAULT_LAYER_INDEX =
0

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Array

#sum

Constructor Details

- (Voice) initialize(index, *args)

Returns a new instance of Voice



18
19
20
21
22
# File 'lib/stretto/music_elements/voice.rb', line 18

def initialize(index, *args)
  @layers = {}
  @index = index
  super(*args)
end

Instance Attribute Details

- (Object) index (readonly)

Returns the value of attribute index



16
17
18
# File 'lib/stretto/music_elements/voice.rb', line 16

def index
  @index
end

- (Object) layers (readonly)

Returns the value of attribute layers



15
16
17
# File 'lib/stretto/music_elements/voice.rb', line 15

def layers
  @layers
end

Instance Method Details

- (Object) <<(element)

Appends an element to the voice, creating an additional layer if necessary.



32
33
34
35
36
37
38
39
40
# File 'lib/stretto/music_elements/voice.rb', line 32

def <<(element)
  if element.kind_of?(Stretto::MusicElements::LayerChange)
    @current_layer = (@layers[element.index] ||= Layer.new)
  else
    @layers[DEFAULT_LAYER_INDEX] = @current_layer = Layer.new unless @current_layer
    @current_layer << element
  end
  super(element)
end

- (Array(MusicElement)) elements

Method intended to keep consistency between array-like structures

Returns:

  • (Array(MusicElement))

    Its elements as an array



26
27
28
# File 'lib/stretto/music_elements/voice.rb', line 26

def elements
  to_a
end

- (Object) layer(index)

Accesor for the layer in the specified index



43
44
45
# File 'lib/stretto/music_elements/voice.rb', line 43

def layer(index)
  @layers[index]
end