Class: MIDI::NoteEvent

Inherits:
ChannelEvent show all
Defined in:
lib/midilib/event.rb

Overview

The abstract superclass of all note on, and note off, and polyphonic pressure events.

Direct Known Subclasses

NoteOff, NoteOn, PolyPressure

Constant Summary collapse

PITCHES =
%w[C C# D D# E F F# G G# A A# B]

Instance Attribute Summary collapse

Attributes inherited from ChannelEvent

#channel

Attributes inherited from Event

#delta_time, #print_channel_numbers_from_one, #print_decimal_numbers, #print_note_names, #status, #time_from_start

Instance Method Summary collapse

Methods inherited from ChannelEvent

#to_s

Methods inherited from Event

#<=>, #channel_to_s, #number_to_s, #quantize_to, #to_s

Instance Attribute Details

#noteObject

Returns the value of attribute note.



101
102
103
# File 'lib/midilib/event.rb', line 101

def note
  @note
end

#velocityObject

Returns the value of attribute velocity.



101
102
103
# File 'lib/midilib/event.rb', line 101

def velocity
  @velocity
end

Instance Method Details

#data_as_bytesObject



125
126
127
128
129
130
# File 'lib/midilib/event.rb', line 125

def data_as_bytes
  data = []
  data << (@status + @channel)
  data << @note
  data << @velocity
end

#note_to_sObject

If @print_note_names is true, returns pch_oct(val) else returns value as a number using number_to_s.



121
122
123
# File 'lib/midilib/event.rb', line 121

def note_to_s
  @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”.



113
114
115
116
117
# File 'lib/midilib/event.rb', line 113

def pch_oct(val = @note)
  pch = val % 12
  oct = (val / 12) - 1
  "#{PITCHES[pch]}#{oct}"
end