Control Surface disable-pipes
MIDI Control Surface library for Arduino
DebugMIDI_Interface.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "MIDI_Interface.hpp"
8#include <Settings/SettingsWrapper.hpp>
9
11
16 protected:
18 void sendSysCommonImpl(Stream &, SysCommonMessage);
19 void sendSysExImpl(Stream &, SysExMessage);
20 void sendRealTimeImpl(Stream &, RealTimeMessage);
21 void sendNowImpl(Stream &) {}
22
23 public:
25
27 void setPrefix(const char *prefix) { this->prefix = prefix; }
28 const char *getPrefix() const { return prefix; }
29
30 private:
31 const char *prefix = nullptr;
32};
33
41 public MIDI_Sender<StreamDebugMIDI_Output>,
42 public TrueMIDI_Sink {
43 public:
44 StreamDebugMIDI_Output(Stream &stream, const char *prefix = nullptr)
46
47 Stream &getStream() const { return stream; }
48
49 protected:
54 void sendNowImpl();
55
56#if !DISABLE_PIPES
57 void sinkMIDIfromPipe(ChannelMessage m) override { send(m); }
58 void sinkMIDIfromPipe(SysExMessage m) override { send(m); }
59 void sinkMIDIfromPipe(SysCommonMessage m) override { send(m); }
60 void sinkMIDIfromPipe(RealTimeMessage m) override { send(m); }
61#endif
62
63 Stream &stream;
64
66};
67
68class MIDIOutputOnly : public AH::UpdatableCRTP<MIDIOutputOnly> {
69 public:
70 virtual ~MIDIOutputOnly() = default;
71 virtual void begin() = 0;
72 static void beginAll() { applyToAll(&MIDIOutputOnly::begin); }
73};
74
85template <typename T>
88 public:
101 const char *prefix = nullptr)
102 : StreamDebugMIDI_Output(serial, prefix), baud(baud) {}
104 SerialDebugMIDI_Output(T &serial, const char *prefix)
106
110 void begin() override { static_cast<T &>(getStream()).begin(baud); }
111
112 private:
113 const unsigned long baud;
114};
115
123 : public SerialDebugMIDI_Output<HardwareSerial> {
124 public:
136 HardwareSerialDebugMIDI_Output(HardwareSerial &serial,
137 unsigned long baud = AH::defaultBaudRate,
138 const char *prefix = nullptr)
139 : SerialDebugMIDI_Output(serial, baud, prefix) {}
141 HardwareSerialDebugMIDI_Output(HardwareSerial &serial, const char *prefix)
142 : SerialDebugMIDI_Output(serial, prefix) {}
143};
144
154class USBDebugMIDI_Output : public SerialDebugMIDI_Output<decltype(Serial)> {
155 public:
165 const char *prefix = nullptr)
166 : SerialDebugMIDI_Output(Serial, baud, prefix) {}
169 : SerialDebugMIDI_Output(Serial, prefix) {}
170};
171
179 public MIDI_Interface {
180 public:
189 StreamDebugMIDI_Interface(Stream &stream, const char *prefix = nullptr)
191
192 Stream &getStream() const { return hexstream.puller.stream; }
193
198
201 return parser.getChannelMessage();
202 }
206 }
209 return parser.getRealTimeMessage();
210 }
213
214 void update() override;
215
216 protected:
217 // MIDI send implementations
219 void sendSysCommonImpl(SysCommonMessage) override;
220 void sendSysExImpl(SysExMessage) override;
221 void sendRealTimeImpl(RealTimeMessage) override;
222 void sendNowImpl() override;
223
224 private:
225#if !DISABLE_PIPES
226 void handleStall() override { MIDI_Interface::handleStall(this); }
227#endif
228
229 private:
232};
233
244template <typename T>
246 public:
259 unsigned long baud = AH::defaultBaudRate,
260 const char *prefix = nullptr)
263 SerialDebugMIDI_Interface(T &serial, const char *prefix)
265
269 void begin() override { static_cast<T &>(getStream()).begin(baud); }
270
271 private:
272 const unsigned long baud;
273};
274
282 : public SerialDebugMIDI_Interface<HardwareSerial> {
283 public:
295 HardwareSerialDebugMIDI_Interface(HardwareSerial &serial,
296 unsigned long baud = AH::defaultBaudRate,
297 const char *prefix = nullptr)
300 HardwareSerialDebugMIDI_Interface(HardwareSerial &serial,
301 const char *prefix)
303};
304
315 : public SerialDebugMIDI_Interface<decltype(Serial)> {
316 public:
326 const char *prefix = nullptr)
331};
332
MIDIReadEvent
Values returned by the MIDI reading functions.
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A super class for object that have to be updated regularly.
Definition: Updatable.hpp:32
A class for debug MIDI interfaces sending and receiving human-readable MIDI messages over a HardwareS...
HardwareSerialDebugMIDI_Interface(HardwareSerial &serial, unsigned long baud=AH::defaultBaudRate, const char *prefix=nullptr)
Construct a new Debug MIDI Interface on the given HardwareSerial interface with the given baud rate.
HardwareSerialDebugMIDI_Interface(HardwareSerial &serial, const char *prefix)
A class for debug MIDI outputs sending human-readable MIDI messages over a HardwareSerial port.
HardwareSerialDebugMIDI_Output(HardwareSerial &serial, const char *prefix)
HardwareSerialDebugMIDI_Output(HardwareSerial &serial, unsigned long baud=AH::defaultBaudRate, const char *prefix=nullptr)
Construct a new Debug MIDI Output on the given HardwareSerial interface with the given baud rate.
CharPuller puller
Definition: HexPuller.hpp:66
static void beginAll()
virtual void begin()=0
virtual ~MIDIOutputOnly()=default
An abstract class for MIDI interfaces.
ChannelMessage getChannelMessage() const
Get the latest MIDI channel voice message.
Definition: MIDI_Parser.hpp:19
RealTimeMessage getRealTimeMessage() const
Get the latest MIDI real-time message.
Definition: MIDI_Parser.hpp:25
SysCommonMessage getSysCommonMessage() const
Get the latest MIDI system common message.
Definition: MIDI_Parser.hpp:21
Statically polymorphic template for classes that send MIDI messages.
Definition: MIDI_Sender.hpp:11
void send(ChannelMessage message)
Send a MIDI Channel Voice message.
Receives MIDI messages from a MIDI pipe.
Definition: MIDI_Pipes.hpp:74
A wrapper class for debug MIDI interfaces sending and receiving human-readable MIDI messages over a S...
SerialDebugMIDI_Interface(T &serial, unsigned long baud=AH::defaultBaudRate, const char *prefix=nullptr)
Construct a new Debug MIDI Interface on the given Serial interface with the given baud rate.
void begin() override
Start the Serial interface at the predefined baud rate.
SerialDebugMIDI_Interface(T &serial, const char *prefix)
A wrapper class for debug MIDI outputs sending human-readable MIDI messages over a Serial port of cla...
SerialDebugMIDI_Output(T &serial, unsigned long baud=AH::defaultBaudRate, const char *prefix=nullptr)
Construct a new Debug MIDI Output on the given Serial interface with the given baud rate.
void begin() override
Start the Serial interface at the predefined baud rate.
SerialDebugMIDI_Output(T &serial, const char *prefix)
Parser for Serial MIDI streams (and BLE-MIDI).
SysExMessage getSysExMessage() const
Get the latest SysEx message.
A class that implements MIDI debug send functions.
void sendRealTimeImpl(Stream &, RealTimeMessage)
const char * getPrefix() const
void sendChannelMessageImpl(Stream &, ChannelMessage)
void sendSysExImpl(Stream &, SysExMessage)
void setPrefix(const char *prefix)
Set the prefix to be printed before each message.
StreamDebugMIDI_Base(const char *prefix)
void sendSysCommonImpl(Stream &, SysCommonMessage)
A class for MIDI interfaces sending and receiving human-readable MIDI messages over a Stream.
ChannelMessage getChannelMessage() const
Return the received channel voice message.
RealTimeMessage getRealTimeMessage() const
Return the received real-time message.
void sendChannelMessageImpl(ChannelMessage) override
Low-level function for sending a MIDI channel voice message.
void handleStall() override
Call back that should finish any MIDI messages that are in progress, and un-stall the pipe or MIDI so...
void update() override
Read the MIDI interface and call the callback if a message was received.
void sendNowImpl() override
Low-level function for sending any buffered outgoing MIDI messages.
SysCommonMessage getSysCommonMessage() const
Return the received system common message.
void sendRealTimeImpl(RealTimeMessage) override
Low-level function for sending a MIDI real-time message.
HexPuller< StreamPuller > hexstream
void sendSysExImpl(SysExMessage) override
Low-level function for sending a system exclusive MIDI message.
void sendSysCommonImpl(SysCommonMessage) override
Low-level function for sending a MIDI system common message.
MIDIReadEvent read()
Try reading and parsing a single incoming MIDI message.
SysExMessage getSysExMessage() const
Return the received system exclusive message.
StreamDebugMIDI_Interface(Stream &stream, const char *prefix=nullptr)
Construct a debug MIDI interface on the given Stream.
A class for MIDI outputs sending human-readable MIDI messages over a Stream.
void sinkMIDIfromPipe(SysExMessage m) override
Accept an incoming MIDI System Exclusive message.
void sinkMIDIfromPipe(ChannelMessage m) override
Accept an incoming MIDI Channel message.
void sendSysExImpl(SysExMessage)
void sinkMIDIfromPipe(RealTimeMessage m) override
Accept an incoming MIDI Real-Time message.
StreamDebugMIDI_Output(Stream &stream, const char *prefix=nullptr)
void sendSysCommonImpl(SysCommonMessage)
void sendChannelMessageImpl(ChannelMessage)
void sendRealTimeImpl(RealTimeMessage)
void sinkMIDIfromPipe(SysCommonMessage m) override
Accept an incoming MIDI System Common message.
Stream & stream
A class for debug MIDI interfaces sending and receiving human-readable MIDI messages over the USB CDC...
USBDebugMIDI_Interface(const char *prefix)
USBDebugMIDI_Interface(unsigned long baud=AH::defaultBaudRate, const char *prefix=nullptr)
Construct a USBDebugMIDI_Interface with the given baud rate.
A class for debug MIDI outputs sending human-readable MIDI messages over the USB CDC connection.
USBDebugMIDI_Output(const char *prefix)
USBDebugMIDI_Output(unsigned long baud=AH::defaultBaudRate, const char *prefix=nullptr)
Construct a USBDebugMIDI_Output with the given baud rate.
PrintStream library
Definition: Array.hpp:14
constexpr unsigned long defaultBaudRate
The default baud rate for debug output.
virtual void handleStall()=0
Call back that should finish any MIDI messages that are in progress, and un-stall the pipe or MIDI so...