arduino-midi
Loading...
Searching...
No Matches
Public Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
midi::MidiParser Class Reference

A streaming Midi Parser which calls the corresponding events. It supports Midi byte streams (with running status) via parse() and BLE Midi packets via parseBle(). The parser keeps its state between calls, so messages can be split over multiple calls. More...

#include <MidiParser.h>

Inheritance diagram for midi::MidiParser:
midi::MidiBleParser

Public Member Functions

 MidiParser (MidiAction *MidiAction, int filter_channel=-1)
 Constructor with the MidiAction and an optional channel filter (-1 = all channels)
 
void begin (MidiAction *MidiAction, int filter_channel=-1)
 Assigns the MidiAction, optionally defines a channel filter (-1 = all channels) and resets the parser state.
 
virtual void onChannelPressure (uint8_t channel, uint8_t pressure)
 Channel pressure.
 
virtual void onCommand (uint8_t channel, uint8_t status, uint8_t p1, uint8_t p2)
 Called for each complete channel message: dispatches it to the on...() methods.
 
virtual void onControlChange (uint8_t channel, uint8_t controller, uint8_t value)
 Control change.
 
virtual void onNoteOff (uint8_t channel, uint8_t note, uint8_t velocity)
 Note off or note on with velocity 0.
 
virtual void onNoteOn (uint8_t channel, uint8_t note, uint8_t velocity)
 Note on with velocity > 0.
 
virtual void onPitchBend (uint8_t channel, uint8_t value)
 7 bit pitch bend (0..127): not called by the parser any more, use onPitchBend14()
 
virtual void onPitchBend14 (uint8_t channel, uint16_t value)
 14 bit pitch bend: 0..16383, center is 8192
 
virtual void onPolyPressure (uint8_t channel, uint8_t note, uint8_t pressure)
 Polyphonic key pressure.
 
virtual void onProgramChange (uint8_t channel, uint8_t program)
 Program change.
 
void parse (const uint8_t *msg, int len)
 Parse a standard Midi byte stream (supports running status)
 
void parseBle (const uint8_t *msg, int len)
 Parse a BLE Midi packet (header and timestamp bytes are removed)
 
void parseByte (uint8_t byte)
 Parse a single byte of a standard Midi byte stream.
 
void reset ()
 Resets the parser state (e.g. running status)
 

Static Protected Member Functions

static uint8_t dataLength (uint8_t status)
 Number of data bytes for a channel voice status byte.
 

Protected Attributes

uint8_t data [2] = {0, 0}
 
uint8_t data_count = 0
 
int filter_channel = -1
 
bool in_sysex = false
 
MidiAction * p_MidiAction = nullptr
 
uint8_t running_status = 0
 

Detailed Description

A streaming Midi Parser which calls the corresponding events. It supports Midi byte streams (with running status) via parse() and BLE Midi packets via parseBle(). The parser keeps its state between calls, so messages can be split over multiple calls.

Supported channel voice messages: note on/off, poly pressure, control change, program change, channel pressure and 14 bit pitch bend. They are forwarded to the MidiAction. System exclusive, system common and system realtime messages are skipped (realtime messages may also appear in the middle of another message).

If you indicate the channel (0..15) in the constructor or in begin(), it is used as filter to process only the messages for the indicated channel. You can subclass the parser and override the on...() methods to intercept the events.

http://www.hangar42.nl/wp-content/uploads/2017/10/BLE-MIDI-spec.pdf

by Phil Schatzmann

Member Function Documentation

◆ parse()

void midi::MidiParser::parse ( const uint8_t *  msg,
int  len 
)

Parse a standard Midi byte stream (supports running status)

Parse a standard midi byte stream. The state is kept between calls, so messages which are split over multiple calls are supported.

Parameters
[in]msgbyte stream
[in]lenlength of the msg

◆ parseBle()

void midi::MidiParser::parseBle ( const uint8_t *  msg,
int  len 
)

Parse a BLE Midi packet (header and timestamp bytes are removed)

Parse a BLE midi packet: header, then [timestamp] status data... A timestamp followed by a data byte indicates running status.

Parameters
[in]msgBLE packet
[in]lenlength of the msg

The documentation for this class was generated from the following files: