Control Surface pin-t-adl
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 void sinkMIDIfromPipe(ChannelMessage m) override { send(m); }
57 void sinkMIDIfromPipe(SysExMessage m) override { send(m); }
58 void sinkMIDIfromPipe(SysCommonMessage m) override { send(m); }
59 void sinkMIDIfromPipe(RealTimeMessage m) override { send(m); }
60
61 Stream &stream;
62
64};
65
66class MIDIOutputOnly : public AH::UpdatableCRTP<MIDIOutputOnly> {
67 public:
68 virtual ~MIDIOutputOnly() = default;
69 virtual void begin() = 0;
70 static void beginAll() { applyToAll(&MIDIOutputOnly::begin); }
71};
72
83template <typename T>
86 public:
99 const char *prefix = nullptr)
100 : StreamDebugMIDI_Output(serial, prefix), baud(baud) {}
102 SerialDebugMIDI_Output(T &serial, const char *prefix)
104
108 void begin() override { static_cast<T &>(getStream()).begin(baud); }
109
110 private:
111 const unsigned long baud;
112};
113
121 : public SerialDebugMIDI_Output<HardwareSerial> {
122 public:
134 HardwareSerialDebugMIDI_Output(HardwareSerial &serial,
135 unsigned long baud = AH::defaultBaudRate,
136 const char *prefix = nullptr)
137 : SerialDebugMIDI_Output(serial, baud, prefix) {}
139 HardwareSerialDebugMIDI_Output(HardwareSerial &serial, const char *prefix)
140 : SerialDebugMIDI_Output(serial, prefix) {}
141};
142
152class USBDebugMIDI_Output : public SerialDebugMIDI_Output<decltype(Serial)> {
153 public:
163 const char *prefix = nullptr)
164 : SerialDebugMIDI_Output(Serial, baud, prefix) {}
167 : SerialDebugMIDI_Output(Serial, prefix) {}
168};
169
177 public MIDI_Interface {
178 public:
187 StreamDebugMIDI_Interface(Stream &stream, const char *prefix = nullptr)
189
190 Stream &getStream() const { return hexstream.puller.stream; }
191
196
199 return parser.getChannelMessage();
200 }
204 }
207 return parser.getRealTimeMessage();
208 }
211
212 void update() override;
213
214 protected:
215 // MIDI send implementations
217 void sendSysCommonImpl(SysCommonMessage) override;
218 void sendSysExImpl(SysExMessage) override;
219 void sendRealTimeImpl(RealTimeMessage) override;
220 void sendNowImpl() override;
221
222 private:
223 void handleStall() override;
224
225 private:
228};
229
240template <typename T>
242 public:
255 unsigned long baud = AH::defaultBaudRate,
256 const char *prefix = nullptr)
259 SerialDebugMIDI_Interface(T &serial, const char *prefix)
261
265 void begin() override { static_cast<T &>(getStream()).begin(baud); }
266
267 private:
268 const unsigned long baud;
269};
270
278 : public SerialDebugMIDI_Interface<HardwareSerial> {
279 public:
291 HardwareSerialDebugMIDI_Interface(HardwareSerial &serial,
292 unsigned long baud = AH::defaultBaudRate,
293 const char *prefix = nullptr)
296 HardwareSerialDebugMIDI_Interface(HardwareSerial &serial,
297 const char *prefix)
299};
300
311 : public SerialDebugMIDI_Interface<decltype(Serial)> {
312 public:
322 const char *prefix = nullptr)
327};
328
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:71
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.