Control Surface master
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. More...
 
void cancelRunningStatus ()
 Clear the running status header for MIDI Channel messages. More...
 
ChannelMessage getChannelMessage () const
 Get the latest MIDI channel voice message. More...
 
SysCommonMessage getSysCommonMessage () const
 Get the latest MIDI system common message. More...
 
RealTimeMessage getRealTimeMessage () const
 Get the latest MIDI real-time message. More...
 

Static Public Member Functions

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

Protected Member Functions

MIDIReadEvent feed (uint8_t midibyte)
 Feed a new byte to the parser. More...
 
MIDIReadEvent resume ()
 Resume the parser with the previously stored and unhandled byte. More...
 
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. More...
 

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. More...
 
bool thirdByte = false
 Flag that remembers that the next data byte will be the third byte of a message. More...
 
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. More...
 
uint8_t storedByte = 0xFF
 

Constructor & Destructor Documentation

◆ SerialMIDI_Parser()

SerialMIDI_Parser ( bool  sysCommonCancelsRunningStatus = true)
inline

Definition at line 15 of file SerialMIDI_Parser.hpp.

Member Function Documentation

◆ pull()

MIDIReadEvent pull ( BytePuller &&  puller)
inline

Parse one incoming MIDI message.

Parameters
pullerThe source of MIDI bytes.
Returns
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.

◆ feed()

MIDIReadEvent feed ( uint8_t  midibyte)
protected

Feed a new byte to the parser.

Definition at line 211 of file SerialMIDI_Parser.cpp.

◆ resume()

MIDIReadEvent resume ( )
protected

Resume the parser with the previously stored and unhandled byte.

Definition at line 225 of file SerialMIDI_Parser.cpp.

◆ getSysExMessage()

SysExMessage getSysExMessage ( ) const
inline

Get the latest SysEx message.

Definition at line 38 of file SerialMIDI_Parser.hpp.

◆ addSysExByte()

void addSysExByte ( uint8_t  data)
inlineprotected

Definition at line 43 of file SerialMIDI_Parser.hpp.

◆ hasSysExSpace()

bool hasSysExSpace ( ) const
inlineprotected

Definition at line 44 of file SerialMIDI_Parser.hpp.

◆ startSysEx()

void startSysEx ( )
inlineprotected

Definition at line 45 of file SerialMIDI_Parser.hpp.

◆ endSysEx()

void endSysEx ( )
inlineprotected

Definition at line 46 of file SerialMIDI_Parser.hpp.

◆ handleRealTime()

MIDIReadEvent handleRealTime ( uint8_t  midiByte)
protected

Definition at line 5 of file SerialMIDI_Parser.cpp.

◆ handleStatus()

MIDIReadEvent handleStatus ( uint8_t  midiByte)
protected

Definition at line 18 of file SerialMIDI_Parser.cpp.

◆ handleData()

MIDIReadEvent handleData ( uint8_t  midiByte)
protected

Definition at line 108 of file SerialMIDI_Parser.cpp.

◆ storeByte()

void storeByte ( uint8_t  midiByte)
inlineprotected

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
inlineprotected

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.

◆ popStoredByte()

uint8_t popStoredByte ( )
inlineprotected

Get the stored byte. Afterwards, hasStoredByte will return false.

Definition at line 65 of file SerialMIDI_Parser.hpp.

◆ cancelRunningStatus()

void cancelRunningStatus ( )
inline

Clear the running status header for MIDI Channel messages.

Internal method.

Definition at line 74 of file SerialMIDI_Parser.hpp.

◆ getChannelMessage()

ChannelMessage getChannelMessage ( ) const
inlineinherited

Get the latest MIDI channel voice message.

Definition at line 19 of file MIDI_Parser.hpp.

◆ getSysCommonMessage()

SysCommonMessage getSysCommonMessage ( ) const
inlineinherited

Get the latest MIDI system common message.

Definition at line 21 of file MIDI_Parser.hpp.

◆ getRealTimeMessage()

RealTimeMessage getRealTimeMessage ( ) const
inlineinherited

Get the latest MIDI real-time message.

Definition at line 25 of file MIDI_Parser.hpp.

◆ isStatus()

static bool isStatus ( uint8_t  data)
inlinestaticinherited

Check if the given byte is a MIDI header/status byte.

Definition at line 37 of file MIDI_Parser.hpp.

◆ isData()

static bool isData ( uint8_t  data)
inlinestaticinherited

Check if the given byte is a MIDI data byte.

Definition at line 39 of file MIDI_Parser.hpp.

Member Data Documentation

◆ sysexbuffer

SysExBuffer sysexbuffer
protected

Definition at line 48 of file SerialMIDI_Parser.hpp.

◆ sysCommonCancelsRunningStatus

bool sysCommonCancelsRunningStatus
private

Accounts for running status differences between MIDI 1.0 and BLE-MIDI.

Definition at line 78 of file SerialMIDI_Parser.hpp.

◆ thirdByte

bool thirdByte = false
private

Flag that remembers that the next data byte will be the third byte of a message.

Definition at line 81 of file SerialMIDI_Parser.hpp.

◆ currentHeader

uint8_t currentHeader = 0
private

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.

◆ runningHeader

uint8_t runningHeader = 0
private

Running status header.

Definition at line 87 of file SerialMIDI_Parser.hpp.

◆ storedByte

uint8_t storedByte = 0xFF
private
See also
storeByte

Definition at line 89 of file SerialMIDI_Parser.hpp.

◆ midimsg

MIDIMessage midimsg = {0x00, 0x00, 0x00}
protectedinherited

Definition at line 32 of file MIDI_Parser.hpp.

◆ rtmsg

RealTimeMessage rtmsg = {0x00}
protectedinherited

Definition at line 33 of file MIDI_Parser.hpp.


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