Class: MIDIMessage::Parser
- Inherits:
-
Object
- Object
- MIDIMessage::Parser
- Defined in:
- lib/midi-message/parser.rb
Overview
Simple message parsing For more advanced parsing check out nibbler
Constant Summary collapse
- MESSAGE_TYPE =
[ NoteOff, NoteOn, PolyphonicAftertouch, ControlChange, ProgramChange, ChannelAftertouch, PitchBend, SystemMessage ].freeze
- SYSTEM_MESSAGE_TYPE =
[ SystemExclusive, SystemCommon, SystemRealtime ].freeze
Class Method Summary collapse
-
.parse(*args) ⇒ MIDIMessage
Can take either a hex string eg Parser.new(“904040”) or bytes eg Parser.new(0x90, 0x40, 0x40) or an array of bytes eg Parser.new([0x90, 0x40, 0x40]).
Instance Method Summary collapse
-
#initialize(*args) ⇒ MIDIMessage
constructor
Can take either a hex string eg Parser.new(“904040”) or bytes eg Parser.new(0x90, 0x40, 0x40) or an array of bytes eg Parser.new([0x90, 0x40, 0x40]).
-
#parse ⇒ MIDIMessage
Parse the data and return a message.
Constructor Details
#initialize(*args) ⇒ MIDIMessage
Can take either a hex string eg Parser.new(“904040”) or bytes eg Parser.new(0x90, 0x40, 0x40) or an array of bytes eg Parser.new([0x90, 0x40, 0x40])
39 40 41 42 43 44 45 |
# File 'lib/midi-message/parser.rb', line 39 def initialize(*args) @data = case args.first when Array then args.first when Numeric then args when String then TypeConversion.hex_string_to_numeric_byte_array(args.first) end end |
Class Method Details
.parse(*args) ⇒ MIDIMessage
Can take either a hex string eg Parser.new(“904040”) or bytes eg Parser.new(0x90, 0x40, 0x40) or an array of bytes eg Parser.new([0x90, 0x40, 0x40])
29 30 31 32 |
# File 'lib/midi-message/parser.rb', line 29 def self.parse(*args) parser = new(*args) parser.parse end |
Instance Method Details
#parse ⇒ MIDIMessage
Parse the data and return a message
49 50 51 52 53 54 55 56 57 |
# File 'lib/midi-message/parser.rb', line 49 def parse nibbles = get_nibbles klass = MESSAGE_TYPE.find { |type| type::STATUS == nibbles[0] } if klass == SystemMessage (nibbles[1]) else klass.new(nibbles[1], *@data.drop(1)) end end |