Class: Vissen::Input::Message::Note

Inherits:
Base
  • Object
show all
Defined in:
lib/vissen/input/message/note.rb

Overview

From the MIDI Association:

Note On event. This message is sent when a note is depressed (start).

Note Off event. This message is sent when a note is released (ended).

Constant Summary collapse

STATUS_MASK =
0xE0
STATUS =
0x80
NOTE_ON =

Note On specifies the value of the lowest status bit for note on messages.

0x10
NOTE_OFF =

Note On specifies the value of the lowest status bit for note off messages.

0x00

Constants inherited from Base

Base::DATA_LENGTH

Constants included from Vissen::Input::Message

CHANNEL_MASK, DATA_LENGTH

Instance Attribute Summary

Attributes included from Vissen::Input::Message

#data, #timestamp

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

[], factory, match, match?, matcher, #valid?

Methods included from Vissen::Input::Message

#channel, #fetch, #initialize, #status, #to_h, #valid?

Class Method Details

.create(*bytes, on: true, **args) ⇒ Note

Parameters:

  • on (true, false) (defaults to: true)

    true if the note should be depressed, otherwise false.

  • bytes (Array<Integer>)

    the message data byte values. Unspecified values default to 0.

Returns:



53
54
55
# File 'lib/vissen/input/message/note.rb', line 53

def create(*bytes, on: true, **args)
  super(*bytes, status: STATUS + (on ? NOTE_ON : NOTE_OFF), **args)
end

Instance Method Details

#noteInteger

Returns the note value.

Returns:

  • (Integer)

    the note value.



28
29
30
# File 'lib/vissen/input/message/note.rb', line 28

def note
  data[1]
end

#off?true, false

Returns true if the note was released.

Returns:

  • (true, false)

    true if the note was released.



38
39
40
# File 'lib/vissen/input/message/note.rb', line 38

def off?
  (data[0] & NOTE_ON).zero?
end

#on?true, false

Returns true if the note was depressed.

Returns:

  • (true, false)

    true if the note was depressed.



43
44
45
# File 'lib/vissen/input/message/note.rb', line 43

def on?
  !off?
end

#velocityInteger

Returns the velocity value.

Returns:

  • (Integer)

    the velocity value.



33
34
35
# File 'lib/vissen/input/message/note.rb', line 33

def velocity
  data[2]
end