Class: MIDI::Event
- Inherits:
-
Object
- Object
- MIDI::Event
- Defined in:
- lib/midilib/event.rb
Overview
The abstract superclass of all MIDI events.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#delta_time ⇒ Object
Modifying delta_time does not affect time_from_start.
-
#print_channel_numbers_from_one ⇒ Object
Determines if to_s outputs MIDI channel numbers from 1-16 instead of the default 0-15.
-
#print_decimal_numbers ⇒ Object
Determines if to_s outputs numbers as hex (false, the default) or decimal # (true).
-
#print_note_names ⇒ Object
Determines if to_s outputs hex note numbers (false, the default) or decimal note names (true).
-
#status ⇒ Object
readonly
The MIDI status byte.
-
#time_from_start ⇒ Object
The start time of this event from the beginning of the track.
Instance Method Summary collapse
-
#<=>(an_event) ⇒ Object
For sorting.
-
#channel_to_s(val) ⇒ Object
Returns
val
as a decimal or hex string, depending upon the value of. -
#data_as_bytes ⇒ Object
Returns the raw bytes that are written to a MIDI file or output to a MIDI stream.
-
#number_to_s(val) ⇒ Object
Returns
val
as a decimal or hex string, depending upon the value of. -
#quantize_to(boundary) ⇒ Object
Quantize this event’s time_from_start by moving it to the nearest multiple of
boundary
. - #to_s ⇒ Object
Instance Attribute Details
#delta_time ⇒ Object
Modifying delta_time does not affect time_from_start. You need to call the event’s track’s recalc_time
method.
11 12 13 |
# File 'lib/midilib/event.rb', line 11 def delta_time @delta_time end |
#print_channel_numbers_from_one ⇒ Object
Determines if to_s outputs MIDI channel numbers from 1-16 instead of the default 0-15.
29 30 31 |
# File 'lib/midilib/event.rb', line 29 def print_channel_numbers_from_one @print_channel_numbers_from_one end |
#print_decimal_numbers ⇒ Object
Determines if to_s outputs numbers as hex (false, the default) or decimal # (true). Delta times are always printed as decimal.
25 26 27 |
# File 'lib/midilib/event.rb', line 25 def print_decimal_numbers @print_decimal_numbers end |
#print_note_names ⇒ Object
Determines if to_s outputs hex note numbers (false, the default) or decimal note names (true).
21 22 23 |
# File 'lib/midilib/event.rb', line 21 def print_note_names @print_note_names end |
#status ⇒ Object (readonly)
The MIDI status byte. Never includes the channel, which is held separately by MIDI::ChannelEvent.
17 18 19 |
# File 'lib/midilib/event.rb', line 17 def status @status end |
#time_from_start ⇒ Object
The start time of this event from the beginning of the track. This value is held here but is maintained by the track.
14 15 16 |
# File 'lib/midilib/event.rb', line 14 def time_from_start @time_from_start end |
Instance Method Details
#<=>(an_event) ⇒ Object
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.
60 61 62 |
# File 'lib/midilib/event.rb', line 60 def <=>(an_event) return @time_from_start <=> an_event.time_from_start end |
#channel_to_s(val) ⇒ Object
Returns val
as a decimal or hex string, depending upon the value of
72 73 74 75 |
# File 'lib/midilib/event.rb', line 72 def channel_to_s(val) val += 1 if @print_channel_numbers_from_one return number_to_s(val) end |
#data_as_bytes ⇒ Object
Returns the raw bytes that are written to a MIDI file or output to a MIDI stream. In MIDI::EVENT this raises a “subclass responsibility” exception.
41 42 43 |
# File 'lib/midilib/event.rb', line 41 def data_as_bytes raise "subclass responsibility" end |
#number_to_s(val) ⇒ Object
Returns val
as a decimal or hex string, depending upon the value of
66 67 68 |
# File 'lib/midilib/event.rb', line 66 def number_to_s(val) return @print_decimal_numbers ? val.to_s : ('%02x' % val) end |
#quantize_to(boundary) ⇒ Object
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.
49 50 51 52 53 54 55 |
# File 'lib/midilib/event.rb', line 49 def quantize_to(boundary) diff = @time_from_start % boundary @time_from_start -= diff if diff >= boundary / 2 @time_from_start += boundary end end |
#to_s ⇒ Object
77 78 79 |
# File 'lib/midilib/event.rb', line 77 def to_s "#{@delta_time}: " end |