Class: Stretto::Voice
- 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 collapse
- DEFAULT_LAYER_INDEX =
0
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#layers ⇒ Object
readonly
Returns the value of attribute layers.
Instance Method Summary collapse
-
#<<(element) ⇒ Object
Appends an element to the voice, creating an additional layer if necessary.
-
#elements ⇒ Array(MusicElement)
Method intended to keep consistency between array-like structures.
-
#initialize(index, *args) ⇒ Voice
constructor
A new instance of Voice.
-
#layer(index) ⇒ Object
Accesor for the layer in the specified
index
.
Methods inherited from Array
Constructor Details
#initialize(index, *args) ⇒ Voice
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
#index ⇒ Object (readonly)
Returns the value of attribute index.
16 17 18 |
# File 'lib/stretto/music_elements/voice.rb', line 16 def index @index end |
#layers ⇒ Object (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
#<<(element) ⇒ Object
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 |
#elements ⇒ Array(MusicElement)
Method intended to keep consistency between array-like structures
26 27 28 |
# File 'lib/stretto/music_elements/voice.rb', line 26 def elements to_a end |