From 596a1b0721ca8e8bbf1dc85d6de247a9727cf416 Mon Sep 17 00:00:00 2001 From: lathoub Date: Tue, 11 Jan 2022 07:07:27 +0100 Subject: [PATCH 1/2] added CustomBaudRate example - added customer baudrate example - fixed old refs to examples in Doxygen --- .github/workflows/platformio.yml | 1 + doc/midi_DoxygenMainPage.h | 12 +++++----- examples/CustomBaudRate/CustomBaudRate.ino | 26 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 examples/CustomBaudRate/CustomBaudRate.ino diff --git a/.github/workflows/platformio.yml b/.github/workflows/platformio.yml index 5ccfad38..b4f4891e 100644 --- a/.github/workflows/platformio.yml +++ b/.github/workflows/platformio.yml @@ -23,6 +23,7 @@ jobs: - Input - RPN_NRPN - SimpleSynth + - CustomBaudRate board: - uno - due diff --git a/doc/midi_DoxygenMainPage.h b/doc/midi_DoxygenMainPage.h index 4ece5d01..4e27fa4b 100644 --- a/doc/midi_DoxygenMainPage.h +++ b/doc/midi_DoxygenMainPage.h @@ -12,7 +12,7 @@ // Examples /*! - \example MIDI_Basic_IO.ino + \example Basic_IO.ino This example shows how to perform simple input and output MIDI. \n \n When any message arrives to the Arduino, the LED is turned on, @@ -29,15 +29,15 @@ */ /*! - \example MIDI_Callbacks.ino + \example Callbacks.ino This example shows how to use callbacks for easier MIDI input handling. \n */ /*! - \example MIDI_Bench.ino - \example MIDI_DualMerger.ino - \example MIDI_Input.ino - \example MIDI_SimpleSynth.ino + \example Bench.ino + \example DualMerger.ino + \example Input.ino + \example SimpleSynth.ino */ // ----------------------------------------------------------------------------- diff --git a/examples/CustomBaudRate/CustomBaudRate.ino b/examples/CustomBaudRate/CustomBaudRate.ino new file mode 100644 index 00000000..90511d28 --- /dev/null +++ b/examples/CustomBaudRate/CustomBaudRate.ino @@ -0,0 +1,26 @@ +#include + +// Override the default MIDI baudrate to +// a decoding program such as Hairless MIDI (set baudrate to 115200) + +struct CustomBaudRate : public MIDI_NAMESPACE::DefaultSettings { + static const long BaudRate = 115200; +}; + +MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, CustomBaudRate); + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); + MIDI.begin(MIDI_CHANNEL_OMNI); +} + +void loop() { + if (MIDI.read()) // If we have received a message + { + digitalWrite(LED_BUILTIN, HIGH); + MIDI.sendNoteOn(42, 127, 1); // Send a Note (pitch 42, velo 127 on channel 1) + delay(1000); // Wait for a second + MIDI.sendNoteOff(42, 0, 1); // Stop the note + digitalWrite(LED_BUILTIN, LOW); + } +} \ No newline at end of file From 70b9e26d456392bd14e55cc27cb490260e169cd8 Mon Sep 17 00:00:00 2001 From: lathoub Date: Tue, 11 Jan 2022 07:17:11 +0100 Subject: [PATCH 2/2] fixed compile error for boards that have no Serial --- examples/CustomBaudRate/CustomBaudRate.ino | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/CustomBaudRate/CustomBaudRate.ino b/examples/CustomBaudRate/CustomBaudRate.ino index 90511d28..912eabbf 100644 --- a/examples/CustomBaudRate/CustomBaudRate.ino +++ b/examples/CustomBaudRate/CustomBaudRate.ino @@ -7,7 +7,12 @@ struct CustomBaudRate : public MIDI_NAMESPACE::DefaultSettings { static const long BaudRate = 115200; }; -MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, CustomBaudRate); +#if defined(ARDUINO_SAM_DUE) || defined(USBCON) || defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__) + // Leonardo, Due and other USB boards use Serial1 by default. + MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial1, MIDI, CustomBaudRate); +#else + MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, CustomBaudRate); +#endif void setup() { pinMode(LED_BUILTIN, OUTPUT);