A class for debug MIDI interfaces sending and receiving human-readable MIDI messages over a HardwareSerial port. More...
#include <MIDI_Interfaces/DebugMIDI_Interface.hpp>
Public Types | |
using | Mutex = typename std::conditional< ThreadSafe, DefaultMutEx, EmptyMutex >::type |
using | LockGuard = typename std::conditional< ThreadSafe, DefaultLockGuard< Mutex >, EmptyLockGuard< Mutex > >::type |
Public Member Functions | |
HardwareSerialDebugMIDI_Interface (HardwareSerial &serial, unsigned long baud=AH::defaultBaudRate) | |
Construct a new Debug MIDI Interface on the given HardwareSerial interface with the given baud rate. More... | |
void | begin () override |
Start the Serial interface at the predefined baud rate. More... | |
MIDIReadEvent | read () override |
Try reading and parsing a single incoming MIDI message. More... | |
void | update () override |
Read the MIDI interface and call the callback if a message is received. More... | |
void | setCallbacks (MIDI_Callbacks *cb) override |
Set the callbacks that will be called when a MIDI message is received. More... | |
virtual void | setCallbacks (MIDI_Callbacks *cb)=0 |
Set the callbacks that will be called when a MIDI message is received. More... | |
void | setCallbacks (MIDI_Callbacks &cb) |
Set the callbacks that will be called when a MIDI message is received. More... | |
Static Public Member Functions | |
static Mutex & | getMutex () |
Protected Member Functions | |
void | sendImpl (uint8_t header, uint8_t d1, uint8_t d2, uint8_t cn) override |
Low-level function for sending a 3-byte MIDI message. More... | |
void | sendImpl (uint8_t header, uint8_t d1, uint8_t cn) override |
Low-level function for sending a 2-byte MIDI message. More... | |
void | sendImpl (const uint8_t *data, size_t length, uint8_t cn) override |
Low-level function for sending a system exclusive MIDI message. More... | |
void | sendImpl (uint8_t rt, uint8_t cn) override |
Low-level function for sending a single-byte MIDI message. More... | |
bool | dispatchMIDIEvent (MIDIReadEvent event) |
void | sinkMIDIfromPipe (ChannelMessage) override |
Accept an incoming MIDI Channel message. More... | |
void | sinkMIDIfromPipe (SysExMessage) override |
Accept an incoming MIDI System Exclusive message. More... | |
void | sinkMIDIfromPipe (RealTimeMessage) override |
Accept an incoming MIDI Real-Time message. More... | |
Protected Attributes | |
SerialMIDI_Parser | parser |
Stream & | stream |
MIDI_Callbacks * | callbacks = nullptr |
MIDIReadEvent | event = MIDIReadEvent::NO_MESSAGE |
MIDI_Pipe * | sourcePipe = nullptr |
MIDI_Pipe * | sinkPipe = nullptr |
Updatable< MIDI_Interface, false > * | next |
Updatable< MIDI_Interface, false > * | previous |
Static Protected Attributes | |
static DoublyLinkedList< Updatable< MIDI_Interface, false > > | updatables |
static Mutex | mutex |
Private Member Functions | |
bool | onRealTimeMessage () |
bool | onChannelMessage () |
bool | onSysExMessage () |
virtual void | lockDownstream (cn_t cn, bool lock) |
Base case for recursive lock function. More... | |
virtual MIDI_Sink * | getFinalSink () |
Base case for recursive function. More... | |
void | disconnectSourcePipesShallow () |
Disconnect only the first pipe connected to this sink. More... | |
virtual MIDI_Source * | getInitialSource () |
Base case for recursive function. More... | |
void | disconnectSinkPipesShallow () |
Disconnect only the first pipe connected to this source. More... | |
Static Private Member Functions | |
static uint8_t | hexCharToNibble (char hex) |
Convert a hexadecimal character to a 4-bit nibble. More... | |
Private Attributes | |
HardwareSerial & | serial |
const unsigned long | baud |
char | firstChar = '\0' |
char | secondChar = '\0' |
Static Private Attributes | |
static MIDI_Interface * | DefaultMIDI_Interface = nullptr |
Main initialization and updating methods | |
static void | applyToAll (const LockGuard &, void(Derived::*method)(Args &&...), Args &&... args) |
static void | applyToAll (void(Derived::*method)(Args &&...), Args &&... args) |
Enabling and disabling updatables | |
void | enable (const LockGuard &lock) |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More... | |
void | enable () |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More... | |
void | disable (const LockGuard &lock) |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More... | |
void | disable () |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More... | |
bool | isEnabled (const LockGuard &) const |
Check if this updatable is enabled. More... | |
bool | isEnabled () |
Check if this updatable is enabled. More... | |
void | moveDown (const LockGuard &) |
Move down this element in the list. More... | |
void | moveDown () |
Move down this element in the list. More... | |
static void | enable (UpdatableCRTP *element) |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More... | |
static void | enable (UpdatableCRTP &element) |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More... | |
static void | enable (U(&array)[N]) |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More... | |
static void | disable (UpdatableCRTP *element) |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More... | |
static void | disable (UpdatableCRTP &element) |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More... | |
static void | disable (U(&array)[N]) |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More... | |
Main initialization and updating methods | |
static void | beginAll () |
Begin all enabled instances of this class. More... | |
static void | updateAll () |
Update all enabled instances of this class. More... | |
Sending MIDI | |
void | send (MIDIMessageType m, Channel c, uint8_t d1, uint8_t d2, Cable cable=CABLE_1) |
Send a 3-byte MIDI packet. More... | |
void | send (MIDIMessageType m, Channel c, uint8_t d1, Cable cable=CABLE_1) |
Send a 2-byte MIDI packet. More... | |
void | send (ChannelMessage message) |
Send a MIDI Channel Message. More... | |
void | send (SysExMessage message) |
Send a MIDI System Exclusive message. More... | |
void | send (const uint8_t(&sysexdata)[N], Cable cable=CABLE_1) |
Send a MIDI System Exclusive message. More... | |
void | send (RealTimeMessage message) |
Send a MIDI Real-Time message. More... | |
void | send (MIDIMessageType rt, Cable cable=CABLE_1) |
Send a single-byte MIDI message. More... | |
void | sendOnCable (MIDIMessageType m, Channel c, uint8_t d1, uint8_t d2, Cable cable) |
Send a 3-byte MIDI packet with cable number. More... | |
void | sendOnCable (MIDIMessageType m, Channel c, uint8_t d1, Cable cable) |
Send a 2-byte MIDI packet with cable number. More... | |
void | sendOnCable (MIDIMessageType rt, Cable cable) |
Send a single-byte MIDI packet with cable number. More... | |
void | sendNoteOn (MIDIAddress address, uint8_t velocity) |
Send a MIDI Note On event. More... | |
void | sendNoteOff (MIDIAddress address, uint8_t velocity) |
Send a MIDI Note Off event. More... | |
void | sendKP (MIDIAddress address, uint8_t pressure) |
Send a MIDI Key Pressure event. More... | |
void | sendCC (MIDIAddress address, uint8_t value) |
Send a MIDI Control Change event. More... | |
void | sendPC (MIDIAddress address) |
Send a MIDI Program Change event. More... | |
void | sendPC (MIDIChannelCN address, uint8_t value) |
Send a MIDI Program Change event. More... | |
void | sendCP (MIDIChannelCN address, uint8_t pressure) |
Send a MIDI Channel Pressure event. More... | |
void | sendPB (MIDIChannelCN address, uint16_t value) |
Send a MIDI Pitch Bend event. More... | |
Default MIDI Interfaces | |
void | setAsDefault () |
Set this MIDI interface as the default interface. More... | |
static MIDI_Interface * | getDefault () |
Return the default MIDI interface. More... | |
MIDI Input Callbacks | |
void | setCallbacks (MIDI_Callbacks &cb) |
Set the callbacks that will be called when a MIDI message is received. More... | |
Parsing MIDI Input | |
MIDI_Parser & | getParser () |
ChannelMessage | getChannelMessage () const |
Return the received channel message. More... | |
RealTimeMessage | getRealTimeMessage () const |
Return the received real-time message. More... | |
SysExMessage | getSysExMessage () const |
Return the received system exclusive message. More... | |
Connecting and disconnecting MIDI Pipes | |
void | connectSourcePipe (MIDI_Pipe *source) |
Fully connect a source pipe to this sink. More... | |
void | disconnectSourcePipes () |
Disconnect all source pipes that sink to this sink (recursively). More... | |
bool | disconnect (TrueMIDI_Source &source) |
Disconnect the given source from this sink. More... | |
bool | hasSourcePipe () const |
Check if this sink is connected to a source pipe. More... | |
Sending data over a MIDI Pipe | |
void | sourceMIDItoPipe (ChannelMessage) |
Send a MIDI Channel Message. More... | |
void | sourceMIDItoPipe (SysExMessage) |
Send a MIDI System Exclusive message. More... | |
void | sourceMIDItoPipe (RealTimeMessage) |
Send a MIDI Real-Time message. More... | |
void | exclusive (cn_t cn, bool exclusive=true) |
Enter or exit exclusive mode for the given cable number. More... | |
bool | canWrite (cn_t cn) const |
Check if this source can write to the sinks it connects to. More... | |
Connecting and disconnecting MIDI Pipes | |
bool | disconnect (TrueMIDI_Sink &sink) |
Disconnect the given sink from this source. More... | |
void | connectSinkPipe (MIDI_Pipe *sink) |
Fully connect a sink pipe to this source. More... | |
void | disconnectSinkPipes () |
Disconnect all sink pipes that this source sinks to (recursively). More... | |
bool | hasSinkPipe () const |
Check if this source is connected to a sink pipe. More... | |
A class for debug MIDI interfaces sending and receiving human-readable MIDI messages over a HardwareSerial port.
Definition at line 88 of file DebugMIDI_Interface.hpp.
|
inherited |
Definition at line 36 of file Updatable.hpp.
|
inherited |
Definition at line 38 of file Updatable.hpp.
|
inline |
Construct a new Debug MIDI Interface on the given HardwareSerial interface with the given baud rate.
serial | The HardwareSerial interface. |
baud | The baud rate for the serial interface. |
Definition at line 100 of file DebugMIDI_Interface.hpp.
|
inlineoverridevirtualinherited |
Start the Serial interface at the predefined baud rate.
Reimplemented from MIDI_Interface.
Definition at line 75 of file DebugMIDI_Interface.hpp.
|
overridevirtualinherited |
Try reading and parsing a single incoming MIDI message.
MIDIReadEvent::NO_MESSAGE
if no MIDI message was available. Implements Parsing_MIDI_Interface.
Definition at line 40 of file DebugMIDI_Interface.cpp.
|
overrideprotectedvirtualinherited |
Low-level function for sending a 3-byte MIDI message.
Implements MIDI_Interface.
Definition at line 77 of file DebugMIDI_Interface.cpp.
|
overrideprotectedvirtualinherited |
Low-level function for sending a 2-byte MIDI message.
Implements MIDI_Interface.
Definition at line 90 of file DebugMIDI_Interface.cpp.
|
overrideprotectedvirtualinherited |
Low-level function for sending a system exclusive MIDI message.
Implements MIDI_Interface.
Definition at line 102 of file DebugMIDI_Interface.cpp.
|
overrideprotectedvirtualinherited |
Low-level function for sending a single-byte MIDI message.
Implements MIDI_Interface.
Definition at line 111 of file DebugMIDI_Interface.cpp.
|
inlinestaticprivateinherited |
Convert a hexadecimal character to a 4-bit nibble.
Definition at line 42 of file DebugMIDI_Interface.hpp.
|
inlineinherited |
Definition at line 248 of file MIDI_Interface.hpp.
|
inlineinherited |
Return the received channel message.
Definition at line 251 of file MIDI_Interface.hpp.
|
inlineinherited |
Return the received real-time message.
Definition at line 256 of file MIDI_Interface.hpp.
|
inlineinherited |
Return the received system exclusive message.
Definition at line 261 of file MIDI_Interface.hpp.
|
overridevirtualinherited |
Read the MIDI interface and call the callback if a message is received.
Implements MIDI_Interface.
Definition at line 34 of file MIDI_Interface.cpp.
|
inlineoverridevirtualinherited |
Set the callbacks that will be called when a MIDI message is received.
cb | A pointer to an object that implements the MIDI_Callbacks class. |
Implements MIDI_Interface.
Definition at line 267 of file MIDI_Interface.hpp.
|
inherited |
Set the callbacks that will be called when a MIDI message is received.
cb | A pointer to an object that implements the MIDI_Callbacks class. |
|
inlineinherited |
Set the callbacks that will be called when a MIDI message is received.
cb | A reference to an object that implements the MIDI_Callbacks class. |
Definition at line 192 of file MIDI_Interface.hpp.
|
inlineinherited |
Set the callbacks that will be called when a MIDI message is received.
cb | A reference to an object that implements the MIDI_Callbacks class. |
Definition at line 192 of file MIDI_Interface.hpp.
|
protectedinherited |
Definition at line 47 of file MIDI_Interface.cpp.
|
privateinherited |
Definition at line 57 of file MIDI_Interface.cpp.
|
privateinherited |
Definition at line 66 of file MIDI_Interface.cpp.
|
privateinherited |
Definition at line 78 of file MIDI_Interface.cpp.
|
staticinherited |
Return the default MIDI interface.
Definition at line 14 of file MIDI_Interface.cpp.
|
inherited |
Set this MIDI interface as the default interface.
Definition at line 12 of file MIDI_Interface.cpp.
|
overrideprotectedvirtualinherited |
Accept an incoming MIDI Channel message.
Implements MIDI_Sink.
Definition at line 28 of file MIDI_Interface.cpp.
|
overrideprotectedvirtualinherited |
Accept an incoming MIDI System Exclusive message.
Implements MIDI_Sink.
Definition at line 29 of file MIDI_Interface.cpp.
|
overrideprotectedvirtualinherited |
Accept an incoming MIDI Real-Time message.
Implements MIDI_Sink.
Definition at line 30 of file MIDI_Interface.cpp.
|
inherited |
Fully connect a source pipe to this sink.
Definition at line 15 of file MIDI_Pipes.cpp.
|
inherited |
Disconnect all source pipes that sink to this sink (recursively).
Definition at line 24 of file MIDI_Pipes.cpp.
|
inherited |
Disconnect the given source from this sink.
Leaves other sources connected. Returns true if the source was found and disconnected, false if the given source was not a direct or indirect source to this sink.
Definition at line 39 of file MIDI_Pipes.cpp.
|
inherited |
Disconnect the given sink from this source.
Leaves other sinks connected. Returns true if the sink was found and disconnected, false if the given sink was not a direct or indirect sink of this source.
Definition at line 94 of file MIDI_Pipes.cpp.
|
inlineinherited |
Check if this sink is connected to a source pipe.
Definition at line 94 of file MIDI_Pipes.hpp.
|
inlineprivatevirtualinherited |
Base case for recursive lock function.
Reimplemented in MIDI_Pipe.
Definition at line 105 of file MIDI_Pipes.hpp.
|
inlineprivatevirtualinherited |
Base case for recursive function.
Reimplemented in MIDI_Pipe.
Definition at line 108 of file MIDI_Pipes.hpp.
|
privateinherited |
Disconnect only the first pipe connected to this sink.
Leaves the other pipes connected to the original pipe, which doesn't have a sink anymore when this function finishes. Used to disconnect a MIDI_Pipe while preserving the connections of its "through" inputs.
Definition at line 32 of file MIDI_Pipes.cpp.
|
inherited |
Send a MIDI Channel Message.
Definition at line 132 of file MIDI_Pipes.cpp.
|
inherited |
Send a MIDI System Exclusive message.
Definition at line 137 of file MIDI_Pipes.cpp.
|
inherited |
Send a MIDI Real-Time message.
Definition at line 142 of file MIDI_Pipes.cpp.
|
inherited |
Enter or exit exclusive mode for the given cable number.
This means that this becomes the only source that can sink to the sinks connected to this source. Other sources have to wait until this source exits exclusive mode until they can send again.
cn | Cable number to set the exclusive mode for [0, 15]. |
exclusive | True to enable exclusive mode, false to disable. |
Definition at line 123 of file MIDI_Pipes.cpp.
|
inherited |
Check if this source can write to the sinks it connects to.
Returns false if any of the sinks have another source that is in exclusive mode.
cn | Cable number to check [0, 15]. |
Definition at line 128 of file MIDI_Pipes.cpp.
|
inherited |
Fully connect a sink pipe to this source.
Definition at line 70 of file MIDI_Pipes.cpp.
|
inherited |
Disconnect all sink pipes that this source sinks to (recursively).
Definition at line 79 of file MIDI_Pipes.cpp.
|
inlineinherited |
Check if this source is connected to a sink pipe.
Definition at line 189 of file MIDI_Pipes.hpp.
|
inlineprivatevirtualinherited |
Base case for recursive function.
Reimplemented in MIDI_Pipe.
Definition at line 200 of file MIDI_Pipes.hpp.
|
privateinherited |
Disconnect only the first pipe connected to this source.
Leaves the other pipes connected to the original pipe, which doesn't have a source anymore when this function finishes. Used to disconnect a MIDI_Pipe while preserving the connections of its "through" outputs.
Definition at line 87 of file MIDI_Pipes.cpp.
|
inherited |
Send a 3-byte MIDI packet.
m | MIDI message type. [0x80, 0xE0] |
c | The MIDI channel. [1, 16] |
d1 | The first data byte. [0, 127] |
d2 | The second data byte. [0, 127] |
cable | The MIDI Cable Number. [1, 16] |
Definition at line 38 of file MIDI_Interface.ipp.
|
inherited |
Send a 2-byte MIDI packet.
m | MIDI message type. [0x80, 0xE0] |
c | The MIDI channel. [1, 16] |
d1 | The first data byte. [0, 127] |
cable | The MIDI Cable Number. [1, 16] |
Definition at line 53 of file MIDI_Interface.ipp.
|
inherited |
Send a MIDI Channel Message.
Definition at line 113 of file MIDI_Interface.ipp.
|
inherited |
Send a MIDI System Exclusive message.
Definition at line 115 of file MIDI_Interface.ipp.
Send a MIDI System Exclusive message.
Definition at line 118 of file MIDI_Interface.hpp.
|
inherited |
Send a MIDI Real-Time message.
Definition at line 122 of file MIDI_Interface.ipp.
|
inherited |
Send a single-byte MIDI message.
Definition at line 124 of file MIDI_Interface.ipp.
|
inherited |
Send a 3-byte MIDI packet with cable number.
m | MIDI message type. [0x80, 0xE0] |
c | The MIDI channel. [1, 16] |
d1 | The first data byte. [0, 127] |
d2 | The second data byte. [0, 127] |
cable | The MIDI Cable Number. [1, 16] |
Definition at line 69 of file MIDI_Interface.ipp.
|
inherited |
Send a 2-byte MIDI packet with cable number.
m | MIDI message type. [0x80, 0xE0] |
c | The MIDI channel. [1, 16] |
d1 | The first data byte. [0, 127] |
cable | The MIDI Cable Number. [1, 16] |
Definition at line 84 of file MIDI_Interface.ipp.
|
inherited |
Send a single-byte MIDI packet with cable number.
rt | The MIDI byte to send. |
cable | The MIDI Cable Number. [1, 16] |
Definition at line 94 of file MIDI_Interface.ipp.
|
inherited |
Send a MIDI Note On event.
Definition at line 97 of file MIDI_Interface.ipp.
|
inherited |
Send a MIDI Note Off event.
Definition at line 99 of file MIDI_Interface.ipp.
|
inherited |
Send a MIDI Key Pressure event.
Definition at line 101 of file MIDI_Interface.ipp.
|
inherited |
Send a MIDI Control Change event.
Definition at line 103 of file MIDI_Interface.ipp.
|
inherited |
Send a MIDI Program Change event.
Definition at line 105 of file MIDI_Interface.ipp.
|
inherited |
Send a MIDI Program Change event.
Definition at line 107 of file MIDI_Interface.ipp.
|
inherited |
Send a MIDI Channel Pressure event.
Definition at line 109 of file MIDI_Interface.ipp.
|
inherited |
Send a MIDI Pitch Bend event.
Definition at line 111 of file MIDI_Interface.ipp.
|
inlinestaticinherited |
Begin all enabled instances of this class.
Definition at line 208 of file Updatable.hpp.
|
inlinestaticinherited |
Update all enabled instances of this class.
Definition at line 212 of file Updatable.hpp.
|
inlinestaticinherited |
Definition at line 79 of file Updatable.hpp.
|
inlinestaticinherited |
Definition at line 85 of file Updatable.hpp.
|
inlinestaticinherited |
Definition at line 93 of file Updatable.hpp.
|
inlineinherited |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 106 of file Updatable.hpp.
|
inlineinherited |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 115 of file Updatable.hpp.
|
inlinestaticinherited |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 144 of file Updatable.hpp.
|
inlinestaticinherited |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 146 of file Updatable.hpp.
|
inlinestaticinherited |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 149 of file Updatable.hpp.
|
inlineinherited |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
Definition at line 119 of file Updatable.hpp.
|
inlineinherited |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
Definition at line 128 of file Updatable.hpp.
|
inlinestaticinherited |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
Definition at line 155 of file Updatable.hpp.
|
inlinestaticinherited |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
Definition at line 157 of file Updatable.hpp.
|
inlinestaticinherited |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
Definition at line 160 of file Updatable.hpp.
|
inlineinherited |
Check if this updatable is enabled.
Definition at line 136 of file Updatable.hpp.
|
inlineinherited |
Check if this updatable is enabled.
Definition at line 141 of file Updatable.hpp.
|
inlineinherited |
Move down this element in the list.
Definition at line 166 of file Updatable.hpp.
|
inlineinherited |
Move down this element in the list.
Definition at line 168 of file Updatable.hpp.
|
privateinherited |
Definition at line 78 of file DebugMIDI_Interface.hpp.
|
privateinherited |
Definition at line 79 of file DebugMIDI_Interface.hpp.
|
privateinherited |
Definition at line 36 of file DebugMIDI_Interface.hpp.
|
privateinherited |
Definition at line 37 of file DebugMIDI_Interface.hpp.
|
protectedinherited |
Definition at line 48 of file SerialMIDI_Interface.hpp.
|
protectedinherited |
Definition at line 91 of file SerialMIDI_Interface.hpp.
|
protectedinherited |
Definition at line 287 of file MIDI_Interface.hpp.
|
protectedinherited |
Definition at line 288 of file MIDI_Interface.hpp.
|
staticprivateinherited |
Definition at line 226 of file MIDI_Interface.hpp.
|
protectedinherited |
Definition at line 117 of file MIDI_Pipes.hpp.
|
protectedinherited |
Definition at line 209 of file MIDI_Pipes.hpp.
|
staticprotectedinherited |
Definition at line 173 of file Updatable.hpp.
|
staticprotectedinherited |
Definition at line 174 of file Updatable.hpp.
|
protectedinherited |
Definition at line 323 of file LinkedList.hpp.
|
protectedinherited |
Definition at line 324 of file LinkedList.hpp.