class MIDI::Event
The abstract superclass of all MIDI
events.
Attributes
Modifying delta_time
does not affect time_from_start. You need to call the event’s track’s recalc_time
method.
Determines if to_s
outputs numbers as hex (false, the default) or decimal # (true). Delta times are always printed as decimal.
Determines if to_s
outputs hex note numbers (false, the default) or decimal note names (true).
The MIDI
status byte. Never includes the channel, which is held separately by MIDI::ChannelEvent
.
The start time of this event from the beginning of the track. This value is held here but is maintained by the track.
Public Class Methods
# File lib/midilib/event.rb, line 29 def initialize(status = 0, delta_time = 0) @status = status @delta_time = delta_time @time_from_start = 0 # maintained by tracks @print_note_names = false @print_decimal_numbers = false @print_channel_numbers_from_one = false end
Public Instance Methods
For sorting. Uses @time_from_start, which is maintained by this event’s track. I’m not sure this is necessary, since each track has to maintain its events’ time-from-start values anyway.
# File lib/midilib/event.rb, line 59 def <=>(other) @time_from_start <=> other.time_from_start end
Returns val
as a decimal or hex string, depending upon the value of @print_decimal_numbers.
# File lib/midilib/event.rb, line 71 def channel_to_s(val) val += 1 if @print_channel_numbers_from_one number_to_s(val) end
Returns val
as a decimal or hex string, depending upon the value of @print_decimal_numbers.
# File lib/midilib/event.rb, line 65 def number_to_s(val) @print_decimal_numbers ? val.to_s : ('%02x' % val) end
Quantize this event’s time_from_start
by moving it to the nearest multiple of boundary
. See MIDI::Track#quantize
. Note: does not modify the event’s delta_time
, though MIDI::Track#quantize
calls recalc_delta_from_times after it asks each event to quantize itself.
# File lib/midilib/event.rb, line 50 def quantize_to(boundary) diff = @time_from_start % boundary @time_from_start -= diff @time_from_start += boundary if diff >= boundary / 2 end
# File lib/midilib/event.rb, line 76 def to_s "#{@delta_time}: " end