Control Surface new-input
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 
19  public:
26  StreamDebugMIDI_Interface(Stream &stream) : hexstream(stream) {}
27 
28  Stream &getStream() const { return hexstream.puller.stream; }
29 
34 
37  return parser.getChannelMessage();
38  }
41  return parser.getSysCommonMessage();
42  }
45  return parser.getRealTimeMessage();
46  }
49 
50  void update() override;
51 
53  void setPrefix(const char *prefix) { this->prefix = prefix; }
54  const char *getPrefix() const { return prefix; }
55 
56  protected:
57  // MIDI send implementations
59  void sendSysCommonImpl(SysCommonMessage) override;
60  void sendSysExImpl(SysExMessage) override;
61  void sendRealTimeImpl(RealTimeMessage) override;
62  void sendNowImpl() override {}
63 
64  private:
65  void handleStall() override;
66 
67  private:
70  const char *prefix = nullptr;
71 };
72 
83 template <typename T>
85  public:
96  unsigned long baud = AH::defaultBaudRate)
97  : StreamDebugMIDI_Interface(serial), baud(baud) {}
98 
102  void begin() override { static_cast<T &>(getStream()).begin(baud); }
103 
104  private:
105  const unsigned long baud;
106 };
107 
115  : public SerialDebugMIDI_Interface<HardwareSerial> {
116  public:
126  HardwareSerialDebugMIDI_Interface(HardwareSerial &serial,
127  unsigned long baud = AH::defaultBaudRate)
128  : SerialDebugMIDI_Interface(serial, baud) {}
129 };
130 
141  : public SerialDebugMIDI_Interface<decltype(Serial)> {
142  public:
150  : SerialDebugMIDI_Interface(Serial, baud) {}
151 };
152 
153 // TODO: Teensy 4.0 SoftwareSerial bug
154 #if defined(__AVR__) || (defined(TEENSYDUINO) && TEENSYDUINO != 147) || \
155  (defined(TEENSYDUINO) && !defined(__IMXRT1052__) && \
156  !defined(__IMXRT1062__))
157 #include <SoftwareSerial.h>
165  : public SerialDebugMIDI_Interface<SoftwareSerial> {
166  public:
176  SoftwareSerialDebugMIDI_Interface(SoftwareSerial &serial,
177  unsigned long baud)
178  : SerialDebugMIDI_Interface(serial, baud) {}
179 };
180 #endif
181 
MIDIReadEvent
Values returned by the MIDI reading functions.
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
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)
Construct a new Debug MIDI Interface on the given HardwareSerial interface with the given baud rate.
Class that parses hexadecimal ASCII text to bytes.
Definition: HexPuller.hpp:25
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
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)
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.
Parser for Serial MIDI streams (and BLE-MIDI).
SysExMessage getSysExMessage() const
Get the latest SysEx message.
A class for debug MIDI interfaces sending and receiving human-readable MIDI messages over a SoftwareS...
SoftwareSerialDebugMIDI_Interface(SoftwareSerial &serial, unsigned long baud)
Construct a SoftwareSerialDebugMIDI_Interface on the given SoftwareSerial interface with the given ba...
A class for MIDI interfaces sending and receiving human-readable MIDI messages over a Stream.
ChannelMessage getChannelMessage() const
Return the received channel voice message.
const char * getPrefix() const
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 setPrefix(const char *prefix)
Set the prefix to be printed before each 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)
Construct a debug MIDI interface on the given Stream.
A class for debug MIDI interfaces sending and receiving human-readable MIDI messages over the USB CDC...
USBDebugMIDI_Interface(unsigned long baud=AH::defaultBaudRate)
Construct a USBDebugMIDI_Interface with the given baud rate.
constexpr unsigned long defaultBaudRate
The default baud rate for debug output.