Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
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:
45 void sendSysExImpl(SysExMessage) override;
46 void sendRealTimeImpl(RealTimeMessage) override;
47 void sendNowImpl() override {}
48
49 protected:
50#if !DISABLE_PIPES
51 void handleStall() override { MIDI_Interface::handleStall(this); }
52#ifdef DEBUG_OUT
53 const char *getName() const override { return "ser"; }
54#endif
55#endif
56
57 protected:
58 Stream &stream;
60};
61
62// -------------------------------------------------------------------------- //
63
74template <class S>
76 public:
86 SerialMIDI_Interface(S &serial, unsigned long baud = MIDI_BAUD)
87 : StreamMIDI_Interface(serial), baud(baud) {}
88
92 void begin() override { static_cast<S &>(stream).begin(baud); }
93
94 private:
95 const unsigned long baud;
96};
97
98// -------------------------------------------------------------------------- //
99
107 : public SerialMIDI_Interface<HardwareSerial> {
108 public:
118 HardwareSerialMIDI_Interface(HardwareSerial &serial,
119 unsigned long baud = MIDI_BAUD)
120 : SerialMIDI_Interface(serial, baud) {}
121};
122
123// -------------------------------------------------------------------------- //
124
131class USBSerialMIDI_Interface : public SerialMIDI_Interface<decltype(Serial)> {
132 public:
140 : SerialMIDI_Interface(Serial, baud) {}
141};
142
143// -------------------------------------------------------------------------- //
144
145#if !defined(TEENSYDUINO) || \
146 (defined(TEENSYDUINO) && defined(TEENSY_SERIALUSB_ENABLED))
165#endif
166
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.
virtual void handleStall()=0
Call back that should finish any MIDI messages that are in progress, and un-stall the pipe or MIDI so...
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.
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 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.
const char * getName() const override
Get the staller's name for debugging purposes.
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.