Control Surface new-input
MIDI Control Surface library for Arduino
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
SerialMIDI_Parser Class Reference

#include <MIDI_Parsers/SerialMIDI_Parser.hpp>

Detailed Description

Parser for Serial MIDI streams (and BLE-MIDI).

Definition at line 13 of file SerialMIDI_Parser.hpp.

+ Inheritance diagram for SerialMIDI_Parser:
+ Collaboration diagram for SerialMIDI_Parser:

Public Member Functions

 SerialMIDI_Parser (bool sysCommonCancelsRunningStatus=true)
template<class BytePuller >
MIDIReadEvent pull (BytePuller &&puller)
 Parse one incoming MIDI message. More...
SysExMessage getSysExMessage () const
 Get the latest SysEx message.
void cancelRunningStatus ()
 Clear the running status header for MIDI Channel messages. More...
ChannelMessage getChannelMessage () const
 Get the latest MIDI channel voice message.
SysCommonMessage getSysCommonMessage () const
 Get the latest MIDI system common message.
RealTimeMessage getRealTimeMessage () const
 Get the latest MIDI real-time message.

Static Public Member Functions

static bool isStatus (uint8_t data)
 Check if the given byte is a MIDI header/status byte.
static bool isData (uint8_t data)
 Check if the given byte is a MIDI data byte.

Protected Member Functions

MIDIReadEvent feed (uint8_t midibyte)
 Feed a new byte to the parser.
MIDIReadEvent resume ()
 Resume the parser with the previously stored and unhandled byte.
void addSysExByte (uint8_t data)
bool hasSysExSpace () const
void startSysEx ()
void endSysEx ()
MIDIReadEvent handleRealTime (uint8_t midiByte)
MIDIReadEvent handleStatus (uint8_t midiByte)
MIDIReadEvent handleData (uint8_t midiByte)
void storeByte (uint8_t midiByte)
 Store a byte to parse later. More...
bool hasStoredByte () const
 Check whether there's a stored byte. More...
uint8_t popStoredByte ()
 Get the stored byte. Afterwards, hasStoredByte will return false.

Protected Attributes

SysExBuffer sysexbuffer
MIDIMessage midimsg = {0x00, 0x00, 0x00}
RealTimeMessage rtmsg = {0x00}

Private Attributes

bool sysCommonCancelsRunningStatus
 Accounts for running status differences between MIDI 1.0 and BLE-MIDI.
bool thirdByte = false
 Flag that remembers that the next data byte will be the third byte of a message.
uint8_t currentHeader = 0
 Current header (not necessarily running), contains the header of the message that's currently being received. More...
uint8_t runningHeader = 0
 Running status header.
uint8_t storedByte = 0xFF

Member Function Documentation

◆ pull()

MIDIReadEvent pull ( BytePuller &&  puller)

Parse one incoming MIDI message.

pullerThe source of MIDI bytes.
The type of MIDI message available, or MIDIReadEvent::NO_MESSAGE if puller ran out of bytes before a complete message was parsed.

Definition at line 93 of file SerialMIDI_Parser.hpp.

◆ storeByte()

void storeByte ( uint8_t  midiByte)

Store a byte to parse later.

This is used when the SysEx buffer is full, for example. The byte cannot be added to the buffer now, so store it to add it the next time the parser is updated.

Definition at line 60 of file SerialMIDI_Parser.hpp.

◆ hasStoredByte()

bool hasStoredByte ( ) const

Check whether there's a stored byte.

If this is the case, this byte should be parsed before reading a new byte.

Definition at line 63 of file SerialMIDI_Parser.hpp.

◆ cancelRunningStatus()

void cancelRunningStatus ( )

Clear the running status header for MIDI Channel messages.

Internal method.

Definition at line 74 of file SerialMIDI_Parser.hpp.

Member Data Documentation

◆ currentHeader

uint8_t currentHeader = 0

Current header (not necessarily running), contains the header of the message that's currently being received.

As soon as the message is complete, it is set to zero.

Definition at line 85 of file SerialMIDI_Parser.hpp.

◆ storedByte

uint8_t storedByte = 0xFF
See also

Definition at line 89 of file SerialMIDI_Parser.hpp.

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