Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
USBMIDI_Interface.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "MIDI_Interface.hpp"
4#include "USBMIDI/USBMIDI.hpp"
5#include "USBMIDI_Sender.hpp"
6#include <AH/Error/Error.hpp>
9
11
16template <class Backend>
18 public:
22 template <class... Args>
24 : backend(std::forward<Args>(args)...),
25 alwaysSendImmediately_(backend.preferImmediateSend()) {}
26
27 private:
28 // MIDI send implementations
33 void sendNowImpl() override { backend.sendNow(); }
34
35 private:
36#if !DISABLE_PIPES
37 void handleStall() override { MIDI_Interface::handleStall(this); }
38#ifdef DEBUG_OUT
39 const char *getName() const override { return "usb"; }
40#endif
41#endif
42
43 public:
46
48 void begin() override;
52 void update() override;
53
55
56 public:
59
64
73
75
76 public:
79
82
83 private:
94
95 private:
102
103 public:
106
122
124};
125
127
128#include "USBMIDI_Interface.ipp"
129
130#if defined(TEENSYDUINO) && !defined(TEENSY_MIDIUSB_ENABLED)
131#pragma message( \
132 "Teensy: USB MIDI not enabled. Enable it from the Tools > USB Type menu.")
133#define CS_USB_MIDI_DISABLED
134#endif
135
136// If MIDI over USB is supported
137#if (!defined(CS_USB_MIDI_NOT_SUPPORTED) && !defined(CS_USB_MIDI_DISABLED)) || \
138 !defined(ARDUINO)
139
141
159 : public GenericUSBMIDI_Interface<USBDeviceMIDIBackend> {
160 public:
161 USBMIDI_Interface() = default;
163};
164
166
167// If the main MCU doesn't have a USB connection:
168// Fall back on Serial connection at the hardware MIDI baud rate.
169// (Can be used with HIDUINO or USBMidiKliK.)
170#elif !defined(CS_USB_MIDI_DISABLED)
171
173
175
185 public:
190};
191
193
194#endif
MIDIReadEvent
Values returned by the MIDI reading functions.
constexpr auto MIDI_BAUD
MIDICodeIndexNumber
MIDI USB Code Index Numbers.
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A type-safe class for MIDI USB Cable numbers.
Definition Cable.hpp:13
A class for MIDI interfaces sending MIDI messages over a USB MIDI connection.
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 alwaysSendImmediately()
Send the USB packets immediately after sending a MIDI 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
Poll the backend (if necessary) and invoke the callbacks for any received MIDI messages,...
void neverSendImmediately()
Don't send the USB packets immediately after sending a MIDI message.
USBMIDI_Sender sender
Sends USB MIDI messages.
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.
USBMIDI_Parser parser
Parses USB packets into MIDI messages.
const char * getName() const override
Get the staller's name for debugging purposes.
Backend backend
The (platform-specific) backend used for MIDI over USB communication.
void begin() override
Initialize.
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.
bool alwaysSendsImmediately() const
Check if this USB interface always sends its USB packets immediately after sending a MIDI message.
GenericUSBMIDI_Interface(Args &&...args)
Construct a new GenericUSBMIDI_Interface.
MIDIReadEvent read()
Try reading and parsing a single incoming MIDI message.
SysExMessage getSysExMessage() const
Return the received system exclusive message.
An abstract class for MIDI interfaces.
A class for MIDI interfaces sending MIDI messages over a USB MIDI connection.
USBMIDI_Interface()=default
Parser for MIDI over USB packets.
A class for sending MIDI USB messages.
A class for MIDI interfaces sending and receiving MIDI messages over the Serial port of the USB conne...
An array wrapper for easy copying, comparing, and iterating.
Definition Array.hpp:32
Functor to send USB MIDI packets.
void operator()(Cable cn, MIDICodeIndexNumber cin, uint8_t d0, uint8_t d1, uint8_t d2)
GenericUSBMIDI_Interface * iface
virtual void handleStall()=0
Call back that should finish any MIDI messages that are in progress, and un-stall the pipe or MIDI so...
AH::Array< uint8_t, 4 > MIDIUSBPacket_t