Class: Clef::Core::Measure
- Inherits:
-
Object
- Object
- Clef::Core::Measure
- Defined in:
- lib/clef/core/measure.rb
Instance Attribute Summary collapse
-
#clef ⇒ Object
Returns the value of attribute clef.
-
#key_signature ⇒ Object
Returns the value of attribute key_signature.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#time_signature ⇒ Object
Returns the value of attribute time_signature.
Instance Method Summary collapse
-
#initialize(number, time_signature: nil) ⇒ Measure
constructor
A new instance of Measure.
- #overflowing_voice_ids ⇒ Array<Symbol>
- #underfull_voice_ids ⇒ Array<Symbol>
- #voice(id = :default) {|Voice| ... } ⇒ Voice
- #voices ⇒ Hash<Symbol, Voice>
Constructor Details
#initialize(number, time_signature: nil) ⇒ Measure
Returns a new instance of Measure.
11 12 13 14 15 16 17 |
# File 'lib/clef/core/measure.rb', line 11 def initialize(number, time_signature: nil) raise ArgumentError, "measure number must be positive" unless number.is_a?(Integer) && number.positive? @number = number @time_signature = time_signature @voices = {} end |
Instance Attribute Details
#clef ⇒ Object
Returns the value of attribute clef.
7 8 9 |
# File 'lib/clef/core/measure.rb', line 7 def clef @clef end |
#key_signature ⇒ Object
Returns the value of attribute key_signature.
7 8 9 |
# File 'lib/clef/core/measure.rb', line 7 def key_signature @key_signature end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
6 7 8 |
# File 'lib/clef/core/measure.rb', line 6 def number @number end |
#time_signature ⇒ Object
Returns the value of attribute time_signature.
7 8 9 |
# File 'lib/clef/core/measure.rb', line 7 def time_signature @time_signature end |
Instance Method Details
#overflowing_voice_ids ⇒ Array<Symbol>
34 35 36 37 38 |
# File 'lib/clef/core/measure.rb', line 34 def overflowing_voice_ids return [] unless time_signature @voices.filter_map { |id, voice| id if voice.total_length > time_signature.measure_length } end |
#underfull_voice_ids ⇒ Array<Symbol>
41 42 43 44 45 46 47 |
# File 'lib/clef/core/measure.rb', line 41 def underfull_voice_ids return [] unless time_signature @voices.filter_map do |id, voice| id if voice.total_length.positive? && voice.total_length < time_signature.measure_length end end |
#voice(id = :default) {|Voice| ... } ⇒ Voice
22 23 24 25 26 |
# File 'lib/clef/core/measure.rb', line 22 def voice(id = :default) current = @voices[id] ||= Voice.new(id: id) yield(current) if block_given? current end |
#voices ⇒ Hash<Symbol, Voice>
29 30 31 |
# File 'lib/clef/core/measure.rb', line 29 def voices @voices.dup.freeze end |