Module: MIDIEvents::Message

Defined in:
lib/midi-events/message.rb

Overview

Common behavior amongst all Message types

Instance Method Summary collapse

Instance Method Details

#==(other_message) ⇒ Object



34
35
36
37
# File 'lib/midi-events/message.rb', line 34

def ==(other_message)
  self.class == other_message.class &&
    to_a == other_message.to_a
end

#initialize_message(status_nibble_1, status_nibble_2) ⇒ Object

Initialize the message status

Parameters:

  • status_nibble_1 (Fixnum)

    The first nibble of the status

  • status_nibble_2 (Fixnum)

    The second nibble of the status



7
8
9
10
# File 'lib/midi-events/message.rb', line 7

def initialize_message(status_nibble_1, status_nibble_2)
  @status = [status_nibble_1, status_nibble_2]
  populate_using_const
end

#to_aArray<Fixnum> Also known as: to_byte_a, to_byte_array, to_bytes

Byte array representation of the message eg [0x90, 0x40, 0x40] for NoteOn(0x40, 0x40)

Returns:

  • (Array<Fixnum>)

    The array of bytes in the MIDI message



14
15
16
17
18
# File 'lib/midi-events/message.rb', line 14

def to_a
  data = [@data[0], @data[1]] unless @data.nil?
  data ||= []
  [status_as_byte, *data].compact
end

#to_hex_sString Also known as: to_bytestr

String representation of the message's bytes eg "904040" for NoteOn(0x40, 0x40)

Returns:

  • (String)

    The bytes of the message as a string of hex bytes



25
26
27
# File 'lib/midi-events/message.rb', line 25

def to_hex_s
  TypeConversion.numeric_byte_array_to_hex_string(to_a)
end

#updateObject



30
31
32
# File 'lib/midi-events/message.rb', line 30

def update
  populate_using_const
end