class MIDI::Measures
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.
Attributes
max_time[R]
The highest event time in the sequence (at the time when the object was created)
ppqd[R]
The ppqd from the sequence
Public Class Methods
new(max_time, ppqd)
click to toggle source
Constructor
Calls superclass method
# File lib/midilib/measure.rb, line 56 def initialize(max_time, ppqd) super(0) @max_time = max_time @ppqd = ppqd end
Public Instance Methods
measure_for_event(e)
click to toggle source
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).
# File lib/midilib/measure.rb, line 65 def measure_for_event(e) detect { |m| m.contains_event?(e) } end
to_mbt(e)
click to toggle source
Returns the event’s time as a formatted MBT string (Measure:Beat:Ticks) as found in MIDI
sequencers.
# 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