This is an old version of the documentation. View the latest version here.
Control Surface  1.0.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, 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:43
SysExMessage
Definition: MIDI_Parser.hpp:64
Button::Falling
< Input went from high to high (1,1)
Definition: Button.hpp:53
SysExMessage::length
uint8_t length
Definition: MIDI_Parser.hpp:73
Parsing_MIDI_Interface
An abstract class for MIDI interfaces.
Definition: MIDI_Interface.hpp:188
Button
A class for reading and debouncing buttons and switches.
Definition: Button.hpp:15
Button::update
State update()
Read the button and return its new state.
Definition: Button.cpp:17
Control_Surface.h
The main header file that includes all Control-Surface header files.
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
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_Callbacks::onSysExMessage
virtual void onSysExMessage(UNUSED_PARAM Parsing_MIDI_Interface &midi)
Definition: MIDI_Interface.hpp:250
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
Button::begin
void begin()
Initialize (enable the internal pull-up resistor).
Definition: Button.cpp:9
MIDI_Callbacks
A class for callbacks from MIDI input.
Definition: MIDI_Interface.hpp:247
SysExMessage::CN
uint8_t CN
Definition: MIDI_Parser.hpp:74
Parsing_MIDI_Interface::getSysExMessage
SysExMessage getSysExMessage() const
Return the received system exclusive message.
Definition: MIDI_Interface.cpp:124
SysExMessage::data
const uint8_t * data
Definition: MIDI_Parser.hpp:72
MIDI_Interface::begin
virtual void begin()
Initialize the MIDI Interface.
Definition: MIDI_Interface.hpp:32
MIDI_Notes::F
constexpr int8_t F
Definition: Notes.hpp:23