Class: MIDI::Measures
- Inherits:
-
Array
- Object
- Array
- MIDI::Measures
- Defined in:
- lib/midilib/measure.rb
Overview
A specialized container for MIDI::Measure objects, which can be use to map event times to measure numbers. Please note that this object has to be remade when events are deleted/added in the sequence.
Instance Attribute Summary collapse
-
#max_time ⇒ Object
readonly
The highest event time in the sequence (at the time when the object was created).
-
#ppqd ⇒ Object
readonly
The ppqd from the sequence.
Instance Method Summary collapse
-
#initialize(max_time, ppqd) ⇒ Measures
constructor
Constructor.
-
#measure_for_event(e) ⇒ Object
Returns the MIDI::Measure object where the event is located.
-
#to_mbt(e) ⇒ Object
Returns the event’s time as a formatted MBT string (Measure:Beat:Ticks) as found in MIDI sequencers.
Constructor Details
#initialize(max_time, ppqd) ⇒ Measures
Constructor
56 57 58 59 60 |
# File 'lib/midilib/measure.rb', line 56 def initialize(max_time, ppqd) super(0) @max_time = max_time @ppqd = ppqd end |
Instance Attribute Details
#max_time ⇒ Object (readonly)
The highest event time in the sequence (at the time when the object was created)
50 51 52 |
# File 'lib/midilib/measure.rb', line 50 def max_time @max_time end |
#ppqd ⇒ Object (readonly)
The ppqd from the sequence
53 54 55 |
# File 'lib/midilib/measure.rb', line 53 def ppqd @ppqd end |
Instance Method Details
#measure_for_event(e) ⇒ Object
Returns the MIDI::Measure object where the event is located. Returns nil
if the event isn’t found in the container (should never happen if the MIDI::Measures object is up to date).
65 66 67 |
# File 'lib/midilib/measure.rb', line 65 def measure_for_event(e) detect { |m| m.contains_event?(e) } end |
#to_mbt(e) ⇒ Object
Returns the event’s time as a formatted MBT string (Measure:Beat:Ticks) as found in MIDI sequencers.
71 72 73 74 75 76 |
# File 'lib/midilib/measure.rb', line 71 def to_mbt(e) m = measure_for_event(e) b = (e.time_from_start.to_f - m.start.to_f) / @ppqd b *= 24 / m.metronome_ticks format('%d:%02d:%03d', m.measure_number, b.to_i + 1, (b - b.to_i) * @ppqd) end |