Class: Clef::Core::Voice
- Inherits:
-
Object
- Object
- Clef::Core::Voice
- Defined in:
- lib/clef/core/voice.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #add(element) ⇒ Voice
- #elements ⇒ Array<Note, Rest, Chord, Tuplet, Tempo>
-
#initialize(id: :default) ⇒ Voice
constructor
A new instance of Voice.
- #total_length ⇒ Rational
Constructor Details
#initialize(id: :default) ⇒ Voice
Returns a new instance of Voice.
11 12 13 14 |
# File 'lib/clef/core/voice.rb', line 11 def initialize(id: :default) @id = id @elements = [] end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/clef/core/voice.rb', line 8 def id @id end |
Instance Method Details
#add(element) ⇒ Voice
18 19 20 21 22 23 |
# File 'lib/clef/core/voice.rb', line 18 def add(element) raise ArgumentError, "element must be a musical element" unless musical_element?(element) @elements << element self end |
#elements ⇒ Array<Note, Rest, Chord, Tuplet, Tempo>
26 27 28 |
# File 'lib/clef/core/voice.rb', line 26 def elements @elements.dup.freeze end |
#total_length ⇒ Rational
31 32 33 |
# File 'lib/clef/core/voice.rb', line 31 def total_length @elements.reduce(Rational(0, 1)) { |memo, element| memo + element.length } end |