Control Surface  1.2.0
MIDI Control Surface library for Arduino
SysEx-Send-Receive.ino

SysEx-Send-Receive

Example showing how to send and receive MIDI System Exclusive messages.

Boards:
AVR, AVR USB, Nano Every, Due, Nano 33, Teensy 3.x, ESP32
// Instantiate the MIDI over USB interface
// Custom MIDI callback that prints incoming SysEx messages.
struct MyMIDI_Callbacks : MIDI_Callbacks {
public:
// This callback function is called when a SysEx message is received.
void onSysExMessage(Parsing_MIDI_Interface &midi) override {
// Get the message from the MIDI interface.
SysExMessage sysex = midi.getSysExMessage();
// Print the message
Serial << F("Received SysEx message: ") << hex;
for (uint8_t i = 0; i < sysex.length; ++i)
Serial << sysex.data[i] << ' ';
Serial << dec << F("\t on cable ") << sysex.CN << endl;
}
} callback = {};
// Push button connected between pin 2 and ground.
// SysEx message is sent when pressed.
Button pushbutton = {2};
void setup() {
Serial.begin(115200);
pushbutton.begin(); // enables internal pull-up
midi.begin();
midi.setCallbacks(callback);
}
void loop() {
// Send a SysEx message when the push button is pressed
uint8_t sysex[] = {0xF0, 0x11, 0x22, 0x33, 0xF7};
if (pushbutton.update() == Button::Falling)
midi.send(sysex);
// Read incoming MIDI data and call the callback if a new
// SysEx message has been received.
midi.update();
}
USBMIDI_Interface
A class for MIDI interfaces sending MIDI messages over a USB MIDI connection.
Definition: USBMIDI_Interface.hpp:41
SysExMessage
Definition: MIDI_MessageTypes.hpp:138
SysExMessage::data
const uint8_t * data
Definition: MIDI_MessageTypes.hpp:156
Parsing_MIDI_Interface::getSysExMessage
SysExMessage getSysExMessage() const
Return the received system exclusive message.
Definition: MIDI_Interface.hpp:261
Parsing_MIDI_Interface
An abstract class for MIDI interfaces.
Definition: MIDI_Interface.hpp:232
AH::dec
Print & dec(Print &printer)
Definition: PrintStream.cpp:77
MIDI_Callbacks::onSysExMessage
virtual void onSysExMessage(Parsing_MIDI_Interface &midi)
Callback for incoming MIDI System Exclusive Messages.
Definition: MIDI_Interface.hpp:301
Control_Surface.h
The main header file that includes all Control-Surface header files.
Parsing_MIDI_Interface::update
void update() override
Read the MIDI interface and call the callback if a message is received.
Definition: MIDI_Interface.cpp:34
MIDI_Sender::send
void send(MIDIMessageType m, Channel c, uint8_t d1, uint8_t d2, Cable cable=CABLE_1)
Send a 3-byte MIDI packet.
Definition: MIDI_Interface.ipp:7
MIDI_Interface::begin
void begin() override
Initialize the MIDI Interface.
Definition: MIDI_Interface.hpp:152
AH::hex
Print & hex(Print &printer)
Definition: PrintStream.cpp:62
SysExMessage::CN
uint8_t CN
Definition: MIDI_MessageTypes.hpp:158
MIDI_Notes::F
constexpr int8_t F
Definition: Notes.hpp:23
MIDI_Callbacks
A class for callbacks from MIDI input.
Definition: MIDI_Interface.hpp:295
SysExMessage::length
uint8_t length
Definition: MIDI_MessageTypes.hpp:157
Parsing_MIDI_Interface::setCallbacks
void setCallbacks(MIDI_Callbacks *cb) override
Set the callbacks that will be called when a MIDI message is received.
Definition: MIDI_Interface.hpp:267
AH::endl
Print & endl(Print &printer)
Definition: PrintStream.cpp:27