Control Surface  1.1.1
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, 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:
void onSysExMessage(Parsing_MIDI_Interface &midi) override {
Serial.print(F("Received SysEx message: "));
SysExMessage sysex = midi.getSysExMessage();
for (uint8_t i = 0; i < sysex.length; ++i)
Serial.print(sysex.data[i], HEX), Serial.print(' ');
Serial.print(F("\t on cable ")), Serial.println(sysex.CN);
}
} 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:35
SysExMessage
Definition: MIDI_Parser.hpp:64
MIDI_Interface::send
void send(uint8_t m, uint8_t c, uint8_t d1, uint8_t d2)
Send a 3-byte MIDI packet.
Definition: MIDI_Interface.cpp:22
SysExMessage::data
const uint8_t * data
Definition: MIDI_Parser.hpp:72
Parsing_MIDI_Interface::getSysExMessage
SysExMessage getSysExMessage() const
Return the received system exclusive message.
Definition: MIDI_Interface.cpp:124
Parsing_MIDI_Interface
An abstract class for MIDI interfaces.
Definition: MIDI_Interface.hpp:188
MIDI_Callbacks::onSysExMessage
virtual void onSysExMessage(Parsing_MIDI_Interface &midi)
Definition: MIDI_Interface.hpp:250
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:132
MIDI_Interface::begin
virtual void begin()
Initialize the MIDI Interface.
Definition: MIDI_Interface.hpp:32
SysExMessage::CN
uint8_t CN
Definition: MIDI_Parser.hpp:74
MIDI_Notes::F
constexpr int8_t F
Definition: Notes.hpp:23
MIDI_Callbacks
A class for callbacks from MIDI input.
Definition: MIDI_Interface.hpp:247
SysExMessage::length
uint8_t length
Definition: MIDI_Parser.hpp:73
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:220