Class: MIDI::NoteEvent
- Inherits:
-
ChannelEvent
- Object
- Event
- ChannelEvent
- MIDI::NoteEvent
- Defined in:
- lib/midilib/event.rb
Overview
The abstract superclass of all note on, and note off, and polyphonic pressure events.
Direct Known Subclasses
Constant Summary collapse
- PITCHES =
%w(C C# D D# E F F# G G# A A# B)
Instance Attribute Summary collapse
-
#note ⇒ Object
Returns the value of attribute note.
-
#velocity ⇒ Object
Returns the value of attribute velocity.
Attributes inherited from ChannelEvent
Attributes inherited from Event
#delta_time, #print_decimal_numbers, #print_note_names, #status, #time_from_start
Instance Method Summary collapse
- #data_as_bytes ⇒ Object
-
#note_to_s ⇒ Object
If @print_note_names is true, returns pch_oct(val) else returns value as a number using number_to_s.
-
#pch_oct(val = @note) ⇒ Object
Returns note name as a pitch/octave string like “C4” or “F#6”.
Methods inherited from ChannelEvent
Methods inherited from Event
#<=>, #channel?, #meta?, #note?, #note_off?, #note_on?, #number_to_s, #quantize_to, #realtime?, #system?, #to_s
Instance Attribute Details
#note ⇒ Object
Returns the value of attribute note.
136 137 138 |
# File 'lib/midilib/event.rb', line 136 def note @note end |
#velocity ⇒ Object
Returns the value of attribute velocity.
136 137 138 |
# File 'lib/midilib/event.rb', line 136 def velocity @velocity end |
Instance Method Details
#data_as_bytes ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/midilib/event.rb', line 160 def data_as_bytes data = '' data << (@status + @channel) data << @note data << @velocity return data end |
#note_to_s ⇒ Object
If @print_note_names is true, returns pch_oct(val) else returns value as a number using number_to_s.
156 157 158 |
# File 'lib/midilib/event.rb', line 156 def note_to_s return @print_note_names ? pch_oct(@note) : number_to_s(@note) end |
#pch_oct(val = @note) ⇒ Object
Returns note name as a pitch/octave string like “C4” or “F#6”.
148 149 150 151 152 |
# File 'lib/midilib/event.rb', line 148 def pch_oct(val=@note) pch = val % 12 oct = (val / 12) - 1 "#{PITCHES[pch]}#{oct}" end |