Control Surface new-input
MIDI Control Surface library for Arduino
SerialMIDI_Interface.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "MIDI_Interface.hpp"
4 #include <AH/Arduino-Wrapper.h> // Stream
5 #include <AH/STL/utility>
8 #include <Settings/SettingsWrapper.hpp>
9 
11 
19  public:
25 
30 
39 
40  void update() override;
41 
42  protected:
44  void sendSysCommonImpl(SysCommonMessage) override;
45  void sendSysExImpl(SysExMessage) override;
46  void sendRealTimeImpl(RealTimeMessage) override;
47  void sendNowImpl() override {}
48 
49  protected:
50  void handleStall() override;
51 
52  protected:
53  Stream &stream;
55 };
56 
57 // -------------------------------------------------------------------------- //
58 
69 template <class S>
71  public:
81  SerialMIDI_Interface(S &serial, unsigned long baud = MIDI_BAUD)
82  : StreamMIDI_Interface(serial), baud(baud) {}
83 
87  void begin() override { static_cast<S &>(stream).begin(baud); }
88 
89  private:
90  const unsigned long baud;
91 };
92 
93 // -------------------------------------------------------------------------- //
94 
102  : public SerialMIDI_Interface<HardwareSerial> {
103  public:
113  HardwareSerialMIDI_Interface(HardwareSerial &serial,
114  unsigned long baud = MIDI_BAUD)
115  : SerialMIDI_Interface(serial, baud) {}
116 };
117 
118 // -------------------------------------------------------------------------- //
119 
126 class USBSerialMIDI_Interface : public SerialMIDI_Interface<decltype(Serial)> {
127  public:
135  : SerialMIDI_Interface(Serial, baud) {}
136 };
137 
138 // -------------------------------------------------------------------------- //
139 
140 #if !defined(TEENSYDUINO) || \
141  (defined(TEENSYDUINO) && defined(TEENSY_SERIALUSB_ENABLED))
151  public:
160 };
161 #endif
162 
164 
165 // -------------------------------------------------------------------------- //
166 
167 // TODO: Teensy 4.0 SoftwareSerial bug
168 #if defined(__AVR__) || (defined(TEENSYDUINO) && TEENSYDUINO != 147) || \
169  (defined(TEENSYDUINO) && !defined(__IMXRT1052__) && \
170  !defined(__IMXRT1062__))
171 
172 #include <SoftwareSerial.h>
173 
175 
183  : public SerialMIDI_Interface<SoftwareSerial> {
184  public:
194  SoftwareSerialMIDI_Interface(SoftwareSerial &serial, unsigned long baud)
195  : SerialMIDI_Interface(serial, baud) {}
196 };
197 
199 
200 #endif
MIDIReadEvent
Values returned by the MIDI reading functions.
constexpr auto MIDI_BAUD
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
constexpr unsigned long HAIRLESS_BAUD
The baud rate to use for Hairless MIDI.
A class for MIDI Interfaces sending and receiving data over the USB Serial CDC connection for the use...
HairlessMIDI_Interface(unsigned long baud=HAIRLESS_BAUD)
Construct a HairlessMIDI_Interface.
A class for MIDI interfaces sending and receiving MIDI messages over a Hardware Serial port.
HardwareSerialMIDI_Interface(HardwareSerial &serial, unsigned long baud=MIDI_BAUD)
Construct a new MIDI Interface on the given HardwareSerial interface with the given baud rate.
An abstract class for MIDI interfaces.
A wrapper class for MIDI interfaces sending and receiving MIDI messages over a Serial port of generic...
SerialMIDI_Interface(S &serial, unsigned long baud=MIDI_BAUD)
Create a new MIDI Interface on the given Serial interface with the given baud rate.
const unsigned long baud
void begin() override
Start the Serial interface at the predefined baud rate.
Parser for Serial MIDI streams (and BLE-MIDI).
A class for MIDI interfaces sending and receiving MIDI messages over a SoftwareSerial interface.
SoftwareSerialMIDI_Interface(SoftwareSerial &serial, unsigned long baud)
Create a SoftwareSerialMIDI_Interface on the given SoftwareSerial interface with the given baud rate.
A class for MIDI interfaces sending and receiving 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.
StreamMIDI_Interface(Stream &stream)
Constructor.
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.
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.
A class for MIDI interfaces sending and receiving MIDI messages over the Serial port of the USB conne...
USBSerialMIDI_Interface(unsigned long baud)
Construct a USBSerialMIDI_Interface with the given baud rate.