From 01b8f829bddd670ae3226442bbfc73887f200abe Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sat, 19 Dec 2020 09:52:17 +0100 Subject: [PATCH 01/17] simply, branch out debug --- .travis.yml | 3 +- examples/ESP32_Callbacks/ESP32_Callbacks.ino | 11 +++---- .../ESP8266_NoteOnOffEverySec.ino | 10 ++----- .../EthernetShield_Initiator.ino | 8 ++--- .../EthernetShield_MultipleSessions.ino | 8 ++--- .../EthernetShield_NonDefaultSession.ino | 8 ++--- .../EthernetShield_NoteOnOffEverySec.ino | 8 ++--- .../EthernetShield_ReceivedRawMidiData.ino | 15 ++++------ .../EthernetShield_SysEx.ino | 10 +++---- examples/MKR_ETH_Bonjour/MKR_ETH_Bonjour.ino | 1 - .../wESP32_NoteOnOffEverySec.ino | 9 ++---- src/AppleMIDI.h | 2 ++ src/AppleMIDI_Debug.h | 29 +++++++++++++++++++ src/AppleMIDI_Defs.h | 24 --------------- test/NoteOn.cpp | 27 +++++++++-------- 15 files changed, 78 insertions(+), 95 deletions(-) create mode 100644 src/AppleMIDI_Debug.h diff --git a/.travis.yml b/.travis.yml index 99f8144..a77ea17 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,5 @@ install: - platformio lib -g install 62@5.0.0 870 872 script: -- platformio ci --board=uno --lib=. examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino; +- platformio ci --board=uno --lib=. examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino; +- platformio ci --board=esp32dev --lib=. examples/\ESP8266_NoteOnOffEverySec/\ESP8266_NoteOnOffEverySec.ino; diff --git a/examples/ESP32_Callbacks/ESP32_Callbacks.ino b/examples/ESP32_Callbacks/ESP32_Callbacks.ino index 9edb964..42fd559 100644 --- a/examples/ESP32_Callbacks/ESP32_Callbacks.ino +++ b/examples/ESP32_Callbacks/ESP32_Callbacks.ino @@ -3,7 +3,6 @@ #define SerialMon Serial #define APPLEMIDI_DEBUG SerialMon #include -USING_NAMESPACE_APPLEMIDI #include "arduino_secrets.h" @@ -12,9 +11,7 @@ bool isConnected = false; APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE(); void setup() { - SerialMon.begin(115200); - while (!SerialMon); - + DBG_SETUP(115200); DBG("Booting"); WiFi.begin(SECRET_SSID, SECRET_PASS); @@ -65,7 +62,7 @@ void loop() { // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { +void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { isConnected = true; DBG(F("Connected to session"), name); } @@ -73,7 +70,7 @@ void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const ssrc_t & ssrc) { +void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { isConnected = false; DBG(F("Disconnected")); } @@ -81,7 +78,7 @@ DBG(F("Disconnected")); // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- -void OnAppleMidiError(const ssrc_t& ssrc, int32_t err) { +void OnAppleMidiError(const APPLEMIDI_NAMESPACE::ssrc_t& ssrc, int32_t err) { switch (err) { case Exception::BufferFullException: diff --git a/examples/ESP8266_NoteOnOffEverySec/ESP8266_NoteOnOffEverySec.ino b/examples/ESP8266_NoteOnOffEverySec/ESP8266_NoteOnOffEverySec.ino index 6c4eb84..db95d13 100644 --- a/examples/ESP8266_NoteOnOffEverySec/ESP8266_NoteOnOffEverySec.ino +++ b/examples/ESP8266_NoteOnOffEverySec/ESP8266_NoteOnOffEverySec.ino @@ -5,7 +5,6 @@ #define SerialMon Serial #define APPLEMIDI_DEBUG SerialMon #include -USING_NAMESPACE_APPLEMIDI char ssid[] = "yourNetwork"; // your network SSID (name) char pass[] = "password"; // your network password (use for WPA, or use as key for WEP) @@ -26,10 +25,7 @@ void OnMidiNoteOff(byte channel, byte note, byte velocity); // ----------------------------------------------------------------------------- void setup() { - // Serial communications and wait for port to open: - SerialMon.begin(115200); - while (!SerialMon); - + DBG_SETUP(115200); DBG("Booting"); WiFi.begin(ssid, pass); @@ -87,7 +83,7 @@ void loop() // ----------------------------------------------------------------------------- // rtpMIDI session. Device connected // ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { +void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { isConnected = true; DBG(F("Connected to session"), name); } @@ -95,7 +91,7 @@ void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { // ----------------------------------------------------------------------------- // rtpMIDI session. Device disconnected // ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const ssrc_t & ssrc) { +void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { isConnected = false; DBG(F("Disconnected")); } diff --git a/examples/EthernetShield_Initiator/EthernetShield_Initiator.ino b/examples/EthernetShield_Initiator/EthernetShield_Initiator.ino index 9b2ab36..5466937 100644 --- a/examples/EthernetShield_Initiator/EthernetShield_Initiator.ino +++ b/examples/EthernetShield_Initiator/EthernetShield_Initiator.ino @@ -4,7 +4,6 @@ #define APPLEMIDI_DEBUG SerialMon #define APPLEMIDI_INITIATOR #include -USING_NAMESPACE_APPLEMIDI // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield @@ -22,8 +21,7 @@ APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE(); // ----------------------------------------------------------------------------- void setup() { - SerialMon.begin(115200); - while (!SerialMon); + DBG_SETUP(115200); DBG("Booting"); if (Ethernet.begin(mac) == 0) { @@ -84,7 +82,7 @@ void loop() // ----------------------------------------------------------------------------- // rtpMIDI session. Device connected // ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { +void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { isConnected = true; DBG(F("Connected to session"), name); } @@ -92,7 +90,7 @@ void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { // ----------------------------------------------------------------------------- // rtpMIDI session. Device disconnected // ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const ssrc_t & ssrc) { +void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { isConnected = false; DBG(F("Disconnected")); } diff --git a/examples/EthernetShield_MultipleSessions/EthernetShield_MultipleSessions.ino b/examples/EthernetShield_MultipleSessions/EthernetShield_MultipleSessions.ino index 7b6fe77..bed7b36 100644 --- a/examples/EthernetShield_MultipleSessions/EthernetShield_MultipleSessions.ino +++ b/examples/EthernetShield_MultipleSessions/EthernetShield_MultipleSessions.ino @@ -3,7 +3,6 @@ #define SerialMon Serial #define APPLEMIDI_DEBUG SerialMon #include -USING_NAMESPACE_APPLEMIDI // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield @@ -22,8 +21,7 @@ APPLEMIDI_CREATE_INSTANCE(EthernetUDP, MIDI2, "Arduino2", DEFAULT_CONTROL_PORT + // ----------------------------------------------------------------------------- void setup() { - SerialMon.begin(115200); - while (!SerialMon); + DBG_SETUP(115200); DBG("Booting"); if (Ethernet.begin(mac) == 0) { @@ -84,7 +82,7 @@ void loop() // ----------------------------------------------------------------------------- // rtpMIDI session. Device connected // ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { +void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { isConnected = true; DBG(F("Connected to session"), name); } @@ -92,7 +90,7 @@ void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { // ----------------------------------------------------------------------------- // rtpMIDI session. Device disconnected // ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const ssrc_t & ssrc) { +void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { isConnected = false; DBG(F("Disconnected")); } diff --git a/examples/EthernetShield_NonDefaultSession/EthernetShield_NonDefaultSession.ino b/examples/EthernetShield_NonDefaultSession/EthernetShield_NonDefaultSession.ino index 279857e..8a10c59 100644 --- a/examples/EthernetShield_NonDefaultSession/EthernetShield_NonDefaultSession.ino +++ b/examples/EthernetShield_NonDefaultSession/EthernetShield_NonDefaultSession.ino @@ -3,7 +3,6 @@ #define SerialMon Serial #define APPLEMIDI_DEBUG SerialMon #include -USING_NAMESPACE_APPLEMIDI // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield @@ -26,8 +25,7 @@ APPLEMIDI_CREATE_INSTANCE(EthernetUDP, MIDI, "MyNamedArduino", DEFAULT_CONTROL_P // ----------------------------------------------------------------------------- void setup() { - SerialMon.begin(115200); - while (!SerialMon); + DBG_SETUP(115200); DBG("Booting"); if (Ethernet.begin(mac) == 0) { @@ -80,7 +78,7 @@ void loop() // ----------------------------------------------------------------------------- // rtpMIDI session. Device connected // ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { +void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { isConnected = true; DBG(F("Connected to session"), name); } @@ -88,7 +86,7 @@ void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { // ----------------------------------------------------------------------------- // rtpMIDI session. Device disconnected // ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const ssrc_t & ssrc) { +void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { isConnected = false; DBG(F("Disconnected")); } diff --git a/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino b/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino index 505eef8..3c19ef6 100644 --- a/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino +++ b/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino @@ -3,7 +3,6 @@ #define SerialMon Serial #define APPLEMIDI_DEBUG SerialMon #include -USING_NAMESPACE_APPLEMIDI // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield @@ -21,8 +20,7 @@ APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE(); // ----------------------------------------------------------------------------- void setup() { - SerialMon.begin(115200); - while (!SerialMon); + DBG_SETUP(115200); DBG("Booting"); if (Ethernet.begin(mac) == 0) { @@ -75,7 +73,7 @@ void loop() // ----------------------------------------------------------------------------- // rtpMIDI session. Device connected // ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { +void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { isConnected = true; DBG(F("Connected to session"), name); } @@ -83,7 +81,7 @@ void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { // ----------------------------------------------------------------------------- // rtpMIDI session. Device disconnected // ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const ssrc_t & ssrc) { +void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { isConnected = false; DBG(F("Disconnected")); } diff --git a/examples/EthernetShield_ReceivedRawMidiData/EthernetShield_ReceivedRawMidiData.ino b/examples/EthernetShield_ReceivedRawMidiData/EthernetShield_ReceivedRawMidiData.ino index 49521dc..1750a8c 100644 --- a/examples/EthernetShield_ReceivedRawMidiData/EthernetShield_ReceivedRawMidiData.ino +++ b/examples/EthernetShield_ReceivedRawMidiData/EthernetShield_ReceivedRawMidiData.ino @@ -3,7 +3,6 @@ #define SerialMon Serial #define APPLEMIDI_DEBUG SerialMon #include -USING_NAMESPACE_APPLEMIDI // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield @@ -21,9 +20,7 @@ APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE(); // ----------------------------------------------------------------------------- void setup() { - SerialMon.begin(115200); - while (!SerialMon); - + DBG_SETUP(115200); DBG("Booting"); if (Ethernet.begin(mac) == 0) { @@ -68,7 +65,7 @@ void loop() // ----------------------------------------------------------------------------- // rtpMIDI session. Device connected // ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { +void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { isConnected = true; DBG(F("Connected to session"), name); } @@ -76,7 +73,7 @@ void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { // ----------------------------------------------------------------------------- // rtpMIDI session. Device disconnected // ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const ssrc_t & ssrc) { +void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { isConnected = false; DBG(F("Disconnected")); } @@ -84,21 +81,21 @@ void OnAppleMidiDisconnected(const ssrc_t & ssrc) { // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- -void OnAppleMidiStartReceived(const ssrc_t & ssrc) { +void OnAppleMidiStartReceived(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { DBG(F("Start receiving"), ssrc); } // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- -void OnAppleMidiReceivedByte(const ssrc_t & ssrc, byte data) { +void OnAppleMidiReceivedByte(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, byte data) { SerialMon.println(data, HEX); } // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- -void OnAppleMidiEndReceive(const ssrc_t & ssrc) { +void OnAppleMidiEndReceive(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { DBG(F("End receiving"), ssrc); } diff --git a/examples/EthernetShield_SysEx/EthernetShield_SysEx.ino b/examples/EthernetShield_SysEx/EthernetShield_SysEx.ino index 0d02e86..8ffe6ea 100644 --- a/examples/EthernetShield_SysEx/EthernetShield_SysEx.ino +++ b/examples/EthernetShield_SysEx/EthernetShield_SysEx.ino @@ -3,7 +3,7 @@ #define SerialMon Serial #define APPLEMIDI_DEBUG SerialMon #include -USING_NAMESPACE_APPLEMIDI + // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield @@ -36,9 +36,7 @@ APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE(); // ----------------------------------------------------------------------------- void setup() { - SerialMon.begin(115200); - while (!SerialMon); - + DBG_SETUP(115200); DBG("Booting"); if (Ethernet.begin(mac) == 0) { @@ -87,7 +85,7 @@ void loop() // ----------------------------------------------------------------------------- // rtpMIDI session. Device connected // ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { +void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { isConnected = true; DBG(F("Connected to session"), name); } @@ -95,7 +93,7 @@ void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { // ----------------------------------------------------------------------------- // rtpMIDI session. Device disconnected // ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const ssrc_t & ssrc) { +void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { isConnected = false; DBG(F("Disconnected")); } diff --git a/examples/MKR_ETH_Bonjour/MKR_ETH_Bonjour.ino b/examples/MKR_ETH_Bonjour/MKR_ETH_Bonjour.ino index baaaf47..a2e35f0 100644 --- a/examples/MKR_ETH_Bonjour/MKR_ETH_Bonjour.ino +++ b/examples/MKR_ETH_Bonjour/MKR_ETH_Bonjour.ino @@ -4,7 +4,6 @@ #define OPTIONAL_MDNS #include -USING_NAMESPACE_APPLEMIDI // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield diff --git a/examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino b/examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino index 3e47216..c997bdf 100644 --- a/examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino +++ b/examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino @@ -1,7 +1,6 @@ #define SerialMon Serial #define APPLEMIDI_DEBUG SerialMon #include -USING_NAMESPACE_APPLEMIDI #include "ETH_Helper.h" @@ -15,9 +14,7 @@ APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE(); // ----------------------------------------------------------------------------- void setup() { - SerialMon.begin(115200); - while (!SerialMon); - + DBG_SETUP(115200); DBG("Booting"); ETH_startup(); @@ -74,7 +71,7 @@ void loop() // ----------------------------------------------------------------------------- // rtpMIDI session. Device connected // ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { +void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { isConnected = true; DBG(F("Connected to session"), name); } @@ -82,7 +79,7 @@ void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { // ----------------------------------------------------------------------------- // rtpMIDI session. Device disconnected // ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const ssrc_t & ssrc) { +void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { isConnected = false; DBG(F("Disconnected")); } diff --git a/src/AppleMIDI.h b/src/AppleMIDI.h index 23c5fa8..bb7da70 100644 --- a/src/AppleMIDI.h +++ b/src/AppleMIDI.h @@ -7,6 +7,8 @@ using namespace MIDI_NAMESPACE; #include "IPAddress.h" +#include "AppleMIDI_Debug.h" + #include "AppleMIDI_PlatformBegin.h" #include "AppleMIDI_Defs.h" #include "AppleMIDI_Settings.h" diff --git a/src/AppleMIDI_Debug.h b/src/AppleMIDI_Debug.h new file mode 100644 index 0000000..3d65291 --- /dev/null +++ b/src/AppleMIDI_Debug.h @@ -0,0 +1,29 @@ +#ifdef APPLEMIDI_DEBUG +namespace { +static void DBG_SETUP(unsigned long baud) { + APPLEMIDI_DEBUG.begin(baud); + while (!APPLEMIDI_DEBUG); +} + +template +static void DBG_PLAIN(T last) { + APPLEMIDI_DEBUG.println(last); +} + +template +static void DBG_PLAIN(T head, Args... tail) { + APPLEMIDI_DEBUG.print(head); + APPLEMIDI_DEBUG.print(' '); + DBG_PLAIN(tail...); +} + +template +static void DBG(Args... args) { + DBG_PLAIN(args...); +} +} // namespace +#else +#define DBG_SETUP(...) +#define DBG_PLAIN(...) +#define DBG(...) +#endif \ No newline at end of file diff --git a/src/AppleMIDI_Defs.h b/src/AppleMIDI_Defs.h index 5eec476..9703c31 100644 --- a/src/AppleMIDI_Defs.h +++ b/src/AppleMIDI_Defs.h @@ -37,30 +37,6 @@ typedef const char* AppleMIDIConstStr; #define GF(x) x #endif -#ifdef APPLEMIDI_DEBUG -namespace { -template -static void DBG_PLAIN(T last) { - APPLEMIDI_DEBUG.println(last); -} - -template -static void DBG_PLAIN(T head, Args... tail) { - APPLEMIDI_DEBUG.print(head); - APPLEMIDI_DEBUG.print(' '); - DBG_PLAIN(tail...); -} - -template -static void DBG(Args... args) { - DBG_PLAIN(args...); -} -} // namespace -#else -#define DBG_PLAIN(...) -#define DBG(...) -#endif - #define RtpBuffer_t Deque #define MidiBuffer_t Deque diff --git a/test/NoteOn.cpp b/test/NoteOn.cpp index 228c6c6..8879397 100644 --- a/test/NoteOn.cpp +++ b/test/NoteOn.cpp @@ -4,7 +4,6 @@ #define APPLEMIDI_INITIATOR #include "AppleMIDI.h" -USING_NAMESPACE_APPLEMIDI unsigned long t0 = millis(); bool isConnected = false; @@ -33,7 +32,7 @@ APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE(); // ----------------------------------------------------------------------------- // rtpMIDI session. Device connected // ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { +void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { isConnected = true; DBG(F("Connected to session"), name); } @@ -41,17 +40,17 @@ void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) { // ----------------------------------------------------------------------------- // rtpMIDI session. Device disconnected // ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const ssrc_t & ssrc) { +void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { isConnected = false; - N_DEBUG_PRINTLN(F("Disconnected")); + DBG(F("Disconnected")); } // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- -void OnAppleMidiByte(const ssrc_t & ssrc, byte data) { - N_DEBUG_PRINT(F("MIDI: ")); - N_DEBUG_PRINTLN(data); +void OnAppleMidiByte(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, byte data) { + DBG(F("MIDI: ")); + DBG(data); } // ----------------------------------------------------------------------------- @@ -84,17 +83,17 @@ char getSysExStatus(const byte* data, uint16_t length) } static void OnMidiSystemExclusive(byte* array, unsigned size) { - N_DEBUG_PRINT(F("Incoming SysEx: ")); - N_DEBUG_PRINT(getSysExStatus(array, size)); + DBG(F("Incoming SysEx: ")); + DBG(getSysExStatus(array, size)); unsigned i = 0; for (; i < size - 1; i++) { - N_DEBUG_PRINT(F(" 0x")); - N_DEBUG_PRINT(array[i], HEX); + DBG(F(" 0x")); + DBG(array[i], HEX); } - N_DEBUG_PRINT(F(" 0x")); - N_DEBUG_PRINT(array[i], HEX); - N_DEBUG_PRINTLN(); + DBG(F(" 0x")); + DBG(array[i], HEX); + DBG(); } void begin() From 71d8d5009b8c015b8ffba44407531a3d274c1b28 Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sat, 19 Dec 2020 09:57:28 +0100 Subject: [PATCH 02/17] Update EthernetShield_NoteOnOffEverySec.ino --- .../EthernetShield_NoteOnOffEverySec.ino | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino b/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino index 3c19ef6..1c4e46a 100644 --- a/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino +++ b/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino @@ -43,6 +43,22 @@ void setup() DBG(F("Send MIDI messages every second")); } +// ----------------------------------------------------------------------------- +// rtpMIDI session. Device connected +// ----------------------------------------------------------------------------- +void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { + isConnected = true; + DBG(F("Connected to session"), name); +} + +// ----------------------------------------------------------------------------- +// rtpMIDI session. Device disconnected +// ----------------------------------------------------------------------------- +void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { + isConnected = false; + DBG(F("Disconnected")); +} + // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- @@ -69,19 +85,3 @@ void loop() // ==================================================================================== // Event handlers for incoming MIDI messages // ==================================================================================== - -// ----------------------------------------------------------------------------- -// rtpMIDI session. Device connected -// ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { - isConnected = true; - DBG(F("Connected to session"), name); -} - -// ----------------------------------------------------------------------------- -// rtpMIDI session. Device disconnected -// ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { - isConnected = false; - DBG(F("Disconnected")); -} From d2d7d1e6a7e94f94ded910e6048c341181d3f236 Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sat, 19 Dec 2020 10:01:48 +0100 Subject: [PATCH 03/17] Update EthernetShield_NoteOnOffEverySec.ino --- .../EthernetShield_NoteOnOffEverySec.ino | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino b/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino index 1c4e46a..444bb9f 100644 --- a/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino +++ b/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino @@ -15,6 +15,26 @@ bool isConnected = false; APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE(); +// ==================================================================================== +// Event handlers for incoming MIDI messages +// ==================================================================================== + +// ----------------------------------------------------------------------------- +// rtpMIDI session. Device connected +// ----------------------------------------------------------------------------- +void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { + isConnected = true; + DBG(F("Connected to session"), name); +} + +// ----------------------------------------------------------------------------- +// rtpMIDI session. Device disconnected +// ----------------------------------------------------------------------------- +void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { + isConnected = false; + DBG(F("Disconnected")); +} + // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- @@ -43,22 +63,6 @@ void setup() DBG(F("Send MIDI messages every second")); } -// ----------------------------------------------------------------------------- -// rtpMIDI session. Device connected -// ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { - isConnected = true; - DBG(F("Connected to session"), name); -} - -// ----------------------------------------------------------------------------- -// rtpMIDI session. Device disconnected -// ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { - isConnected = false; - DBG(F("Disconnected")); -} - // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- @@ -81,7 +85,3 @@ void loop() MIDI.sendNoteOff(note, velocity, channel); } } - -// ==================================================================================== -// Event handlers for incoming MIDI messages -// ==================================================================================== From 3a1264a9aa901593659824f7230407cf88fb8a8b Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sat, 19 Dec 2020 10:10:32 +0100 Subject: [PATCH 04/17] Update EthernetShield_NoteOnOffEverySec.ino --- .../EthernetShield_NoteOnOffEverySec.ino | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino b/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino index 444bb9f..84ad36c 100644 --- a/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino +++ b/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino @@ -15,26 +15,6 @@ bool isConnected = false; APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE(); -// ==================================================================================== -// Event handlers for incoming MIDI messages -// ==================================================================================== - -// ----------------------------------------------------------------------------- -// rtpMIDI session. Device connected -// ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { - isConnected = true; - DBG(F("Connected to session"), name); -} - -// ----------------------------------------------------------------------------- -// rtpMIDI session. Device disconnected -// ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { - isConnected = false; - DBG(F("Disconnected")); -} - // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- @@ -57,8 +37,20 @@ void setup() MIDI.begin(); // Stay informed on connection status - AppleMIDI.setHandleConnected(OnAppleMidiConnected); - AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected); + AppleMIDI.setHandleConnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { + isConnected = true; + DBG(F("Connected to session"), name); + }); + AppleMIDI.setHandleDisconnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { + isConnected = false; + DBG(F("Disconnected")); + }); + MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) { + DBG(F("NoteOn "), note); + }); + MIDI.setHandleNoteOff([](byte channel, byte note, byte velocity) { + DBG(F("NoteOff "), note); + }); DBG(F("Send MIDI messages every second")); } From 06147a4d7d3432d78106e85972c2e8578b1f48a8 Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sat, 19 Dec 2020 10:14:57 +0100 Subject: [PATCH 05/17] testing esp8266 --- .travis.yml | 2 +- .../ESP8266_NoteOnOffEverySec.ino | 61 +++++-------------- .../EthernetShield_NoteOnOffEverySec.ino | 1 + 3 files changed, 18 insertions(+), 46 deletions(-) diff --git a/.travis.yml b/.travis.yml index a77ea17..0f4737e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,4 +14,4 @@ install: script: - platformio ci --board=uno --lib=. examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino; -- platformio ci --board=esp32dev --lib=. examples/\ESP8266_NoteOnOffEverySec/\ESP8266_NoteOnOffEverySec.ino; +- platformio ci --board=espressif8266 --lib=. examples/\ESP8266_NoteOnOffEverySec/\ESP8266_NoteOnOffEverySec.ino; diff --git a/examples/ESP8266_NoteOnOffEverySec/ESP8266_NoteOnOffEverySec.ino b/examples/ESP8266_NoteOnOffEverySec/ESP8266_NoteOnOffEverySec.ino index db95d13..86098fa 100644 --- a/examples/ESP8266_NoteOnOffEverySec/ESP8266_NoteOnOffEverySec.ino +++ b/examples/ESP8266_NoteOnOffEverySec/ESP8266_NoteOnOffEverySec.ino @@ -14,12 +14,6 @@ bool isConnected = false; APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE(); -// Forward declaration -void OnAppleMidiConnected(uint32_t ssrc, char* name); -void OnAppleMidiDisconnected(uint32_t ssrc); -void OnMidiNoteOn(byte channel, byte note, byte velocity); -void OnMidiNoteOff(byte channel, byte note, byte velocity); - // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- @@ -44,11 +38,22 @@ void setup() MIDI.begin(); - AppleMIDI.setHandleConnected(OnAppleMidiConnected); - AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected); - - MIDI.setHandleNoteOn(OnMidiNoteOn); - MIDI.setHandleNoteOff(OnMidiNoteOff); + // Stay informed on connection status + AppleMIDI.setHandleConnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { + isConnected = true; + DBG(F("Connected to session"), name); + }); + AppleMIDI.setHandleDisconnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { + isConnected = false; + DBG(F("Disconnected")); + }); + + MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) { + DBG(F("NoteOn "), note); + }); + MIDI.setHandleNoteOff([](byte channel, byte note, byte velocity) { + DBG(F("NoteOff "), note); + }); DBG(F("Sending NoteOn/Off of note 45, every second")); } @@ -75,37 +80,3 @@ void loop() MIDI.sendNoteOff(note, velocity, channel); } } - -// ==================================================================================== -// Event handlers for incoming MIDI messages -// ==================================================================================== - -// ----------------------------------------------------------------------------- -// rtpMIDI session. Device connected -// ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { - isConnected = true; - DBG(F("Connected to session"), name); -} - -// ----------------------------------------------------------------------------- -// rtpMIDI session. Device disconnected -// ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { - isConnected = false; - DBG(F("Disconnected")); -} - -// ----------------------------------------------------------------------------- -// -// ----------------------------------------------------------------------------- -void OnMidiNoteOn(byte channel, byte note, byte velocity) { - DBG(F("in\tNote on"), note, " Velocity", velocity, "\t", channel); -} - -// ----------------------------------------------------------------------------- -// -// ----------------------------------------------------------------------------- -void OnMidiNoteOff(byte channel, byte note, byte velocity) { - DBG(F("in\tNote off"), note, " Velocity", velocity, "\t", channel); -} diff --git a/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino b/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino index 84ad36c..d9e4198 100644 --- a/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino +++ b/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino @@ -45,6 +45,7 @@ void setup() isConnected = false; DBG(F("Disconnected")); }); + MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) { DBG(F("NoteOn "), note); }); From 9ba46b1035d4b608449f38b895c6b9758ccdde3e Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sat, 19 Dec 2020 10:26:24 +0100 Subject: [PATCH 06/17] Update .travis.yml --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0f4737e..c111536 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,11 +7,13 @@ cache: directories: - "~/.platformio" +env: + - PLATFORMIO_CI_SRC=examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino + install: - pip install -U platformio - platformio update - platformio lib -g install 62@5.0.0 870 872 script: -- platformio ci --board=uno --lib=. examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino; -- platformio ci --board=espressif8266 --lib=. examples/\ESP8266_NoteOnOffEverySec/\ESP8266_NoteOnOffEverySec.ino; +- pio ci --board=uno From ed6ebc6825b426dcee553a984fc08daa2901cf3b Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sat, 19 Dec 2020 10:28:52 +0100 Subject: [PATCH 07/17] Update .travis.yml --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index c111536..f189e73 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,13 +7,10 @@ cache: directories: - "~/.platformio" -env: - - PLATFORMIO_CI_SRC=examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino - install: - pip install -U platformio - platformio update - platformio lib -g install 62@5.0.0 870 872 script: -- pio ci --board=uno +- pio ci --board=uno --lib=. examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino; From 0a7f096009716ee6a997502fcb8b1824f6cda2cf Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sat, 19 Dec 2020 10:40:37 +0100 Subject: [PATCH 08/17] fixed warnings --- src/AppleMIDI.hpp | 2 +- src/rtpMIDI_Parser_JournalSection.hpp | 4 ++-- src/rtpMIDI_Parser_MidiCommandSection.hpp | 4 ---- src/utility/Deque.h | 2 -- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/AppleMIDI.hpp b/src/AppleMIDI.hpp index a32cd28..07ec39c 100644 --- a/src/AppleMIDI.hpp +++ b/src/AppleMIDI.hpp @@ -532,7 +532,7 @@ void AppleMIDISession::writeRtpMidiBuffer(Particip } // write out the MIDI Section - for (auto i = 0; i < bufferLen; i++) + for (size_t i = 0; i < bufferLen; i++) dataPort.write(outMidiBuffer[i]); // *No* journal section (Not supported) diff --git a/src/rtpMIDI_Parser_JournalSection.hpp b/src/rtpMIDI_Parser_JournalSection.hpp index bd72c29..41b0def 100644 --- a/src/rtpMIDI_Parser_JournalSection.hpp +++ b/src/rtpMIDI_Parser_JournalSection.hpp @@ -48,7 +48,7 @@ parserReturn decodeJournalSection(RtpBuffer_t &buffer) // stream (modulo 2^16). cb.buffer[0] = buffer[i++]; cb.buffer[1] = buffer[i++]; - uint16_t checkPoint = ntohs(cb.value16); + uint16_t checkPoint = ntohs(cb.value16); // unused // (RFC 4695, 5 Recovery Journal Format) // If A and Y are both zero, the recovery journal only contains its 3- @@ -132,7 +132,7 @@ parserReturn decodeJournalSection(RtpBuffer_t &buffer) uint32_t chanflags = ntohl(cb.value32); uint16_t chanjourlen = (chanflags & RTP_MIDI_CJ_MASK_LENGTH) >> 8; - uint16_t channelNr = (chanflags & RTP_MIDI_CJ_MASK_CHANNEL) >> RTP_MIDI_CJ_CHANNEL_SHIFT; + // uint16_t channelNr = (chanflags & RTP_MIDI_CJ_MASK_CHANNEL) >> RTP_MIDI_CJ_CHANNEL_SHIFT; // unused // We have the most important bit of information - the length of the channel information // no more need to further parse. diff --git a/src/rtpMIDI_Parser_MidiCommandSection.hpp b/src/rtpMIDI_Parser_MidiCommandSection.hpp index 5b5f8f4..2f3711e 100644 --- a/src/rtpMIDI_Parser_MidiCommandSection.hpp +++ b/src/rtpMIDI_Parser_MidiCommandSection.hpp @@ -72,7 +72,6 @@ size_t decodeMidi(RtpBuffer_t &buffer, uint8_t &runningstatus) size_t consumed = 0; auto octet = buffer[0]; - bool using_rs; /* MIDI realtime-data -> one octet -- unlike serial-wired MIDI realtime-commands in RTP-MIDI will * not be intermingled with other MIDI-commands, so we handle this case right here and return */ @@ -96,12 +95,9 @@ size_t decodeMidi(RtpBuffer_t &buffer, uint8_t &runningstatus) /* our first octet is "virtual" coming from a preceding MIDI-command, * so actually we have not really consumed anything yet */ octet = runningstatus; - using_rs = true; } else { - /* We have a "real" status-byte */ - using_rs = false; /* Let's see how this octet influences our running-status */ /* if we have a "normal" MIDI-command then the new status replaces the current running-status */ if (octet < 0xf0) diff --git a/src/utility/Deque.h b/src/utility/Deque.h index afc0eac..76a0988 100644 --- a/src/utility/Deque.h +++ b/src/utility/Deque.h @@ -32,8 +32,6 @@ class Deque { const T& at(size_t) const; void clear(); - - // iterator begin(); // iterator end(); From ba6ecea5b22403bf8c5f440b7c5983f69ee4935d Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sat, 19 Dec 2020 11:14:33 +0100 Subject: [PATCH 09/17] explcit namespace --- examples/ESP32_Callbacks/ESP32_Callbacks.ino | 17 +++--- .../ESP8266_NoteOnOffEverySec.ino | 1 - .../EthernetShield_Initiator.ino | 59 +++++-------------- .../EthernetShield_MultipleSessions.ino | 4 +- .../EthernetShield_NonDefaultSession.ino | 40 ++++--------- .../EthernetShield_NoteOnOffEverySec.ino | 3 +- .../EthernetShield_ReceivedRawMidiData.ino | 51 +++++----------- .../EthernetShield_SysEx.ino | 35 +++-------- examples/MKR_ETH_Bonjour/MKR_ETH_Bonjour.ino | 2 - .../wESP32_NoteOnOffEverySec.ino | 58 +++++------------- test/NoteOn.cpp | 1 - 11 files changed, 75 insertions(+), 196 deletions(-) diff --git a/examples/ESP32_Callbacks/ESP32_Callbacks.ino b/examples/ESP32_Callbacks/ESP32_Callbacks.ino index 42fd559..9186add 100644 --- a/examples/ESP32_Callbacks/ESP32_Callbacks.ino +++ b/examples/ESP32_Callbacks/ESP32_Callbacks.ino @@ -25,7 +25,6 @@ void setup() { DBG(F("Add device named Arduino with Host"), WiFi.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")"); DBG(F("Then press the Connect button")); DBG(F("Then open a MIDI listener and monitor incoming notes")); - DBG(F("Listen to incoming MIDI commands")); AppleMIDI.setHandleConnected(OnAppleMidiConnected); AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected); @@ -81,28 +80,28 @@ DBG(F("Disconnected")); void OnAppleMidiError(const APPLEMIDI_NAMESPACE::ssrc_t& ssrc, int32_t err) { switch (err) { - case Exception::BufferFullException: + case APPLEMIDI_NAMESPACE::Exception::BufferFullException: DBG(F("*** BufferFullException")); break; - case Exception::ParseException: + case APPLEMIDI_NAMESPACE::Exception::ParseException: DBG(F("*** ParseException")); break; - case Exception::TooManyParticipantsException: + case APPLEMIDI_NAMESPACE::Exception::TooManyParticipantsException: DBG(F("*** TooManyParticipantsException")); break; - case Exception::UnexpectedInviteException: + case APPLEMIDI_NAMESPACE::Exception::UnexpectedInviteException: DBG(F("*** UnexpectedInviteException")); break; - case Exception::ParticipantNotFoundException: + case APPLEMIDI_NAMESPACE::Exception::ParticipantNotFoundException: DBG(F("*** ParticipantNotFoundException")); break; - case Exception::ListenerTimeOutException: + case APPLEMIDI_NAMESPACE::Exception::ListenerTimeOutException: DBG(F("*** ListenerTimeOutException")); break; - case Exception::MaxAttemptsException: + case APPLEMIDI_NAMESPACE::Exception::MaxAttemptsException: DBG(F("*** MaxAttemptsException")); break; - case Exception::NoResponseFromConnectionRequestException: + case APPLEMIDI_NAMESPACE::Exception::NoResponseFromConnectionRequestException: DBG(F("***:yyy did't respond to the connection request. Check the address and port, and any firewall or router settings. (time)")); break; } diff --git a/examples/ESP8266_NoteOnOffEverySec/ESP8266_NoteOnOffEverySec.ino b/examples/ESP8266_NoteOnOffEverySec/ESP8266_NoteOnOffEverySec.ino index 86098fa..244560f 100644 --- a/examples/ESP8266_NoteOnOffEverySec/ESP8266_NoteOnOffEverySec.ino +++ b/examples/ESP8266_NoteOnOffEverySec/ESP8266_NoteOnOffEverySec.ino @@ -38,7 +38,6 @@ void setup() MIDI.begin(); - // Stay informed on connection status AppleMIDI.setHandleConnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { isConnected = true; DBG(F("Connected to session"), name); diff --git a/examples/EthernetShield_Initiator/EthernetShield_Initiator.ino b/examples/EthernetShield_Initiator/EthernetShield_Initiator.ino index 5466937..c52689e 100644 --- a/examples/EthernetShield_Initiator/EthernetShield_Initiator.ino +++ b/examples/EthernetShield_Initiator/EthernetShield_Initiator.ino @@ -33,23 +33,30 @@ void setup() DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")"); DBG(F("Then press the Connect button")); DBG(F("Then open a MIDI listener and monitor incoming notes")); - DBG(F("Listen to incoming MIDI commands")); MIDI.begin(); - // Stay informed on connection status - AppleMIDI.setHandleConnected(OnAppleMidiConnected); - AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected); - - // and let us know ehen notes come in - MIDI.setHandleNoteOn(OnMidiNoteOn); - MIDI.setHandleNoteOff(OnMidiNoteOff); + AppleMIDI.setHandleConnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { + isConnected = true; + DBG(F("Connected to session"), name); + }); + AppleMIDI.setHandleDisconnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { + isConnected = false; + DBG(F("Disconnected")); + }); + + MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) { + DBG(F("NoteOn "), note); + }); + MIDI.setHandleNoteOff([](byte channel, byte note, byte velocity) { + DBG(F("NoteOff "), note); + }); // Initiate the session IPAddress remote(192, 168, 1, 4); AppleMIDI.sendInvite(remote, DEFAULT_CONTROL_PORT); // port is 5004 by default - DBG(F("Every second send a random NoteOn/Off")); + DBG(F("Sending a random NoteOn/Off every second")); } // ----------------------------------------------------------------------------- @@ -74,37 +81,3 @@ void loop() MIDI.sendNoteOff(note, velocity, channel); } } - -// ==================================================================================== -// Event handlers for incoming MIDI messages -// ==================================================================================== - -// ----------------------------------------------------------------------------- -// rtpMIDI session. Device connected -// ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { - isConnected = true; - DBG(F("Connected to session"), name); -} - -// ----------------------------------------------------------------------------- -// rtpMIDI session. Device disconnected -// ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { - isConnected = false; - DBG(F("Disconnected")); -} - -// ----------------------------------------------------------------------------- -// -// ----------------------------------------------------------------------------- -static void OnMidiNoteOn(byte channel, byte note, byte velocity) { - DBG(F("in\tNote on"), note, " Velocity", velocity, "\t", channel); -} - -// ----------------------------------------------------------------------------- -// -// ----------------------------------------------------------------------------- -static void OnMidiNoteOff(byte channel, byte note, byte velocity) { - DBG(F("in\tNote off"), note, " Velocity", velocity, "\t", channel); -} \ No newline at end of file diff --git a/examples/EthernetShield_MultipleSessions/EthernetShield_MultipleSessions.ino b/examples/EthernetShield_MultipleSessions/EthernetShield_MultipleSessions.ino index bed7b36..293d659 100644 --- a/examples/EthernetShield_MultipleSessions/EthernetShield_MultipleSessions.ino +++ b/examples/EthernetShield_MultipleSessions/EthernetShield_MultipleSessions.ino @@ -30,10 +30,10 @@ void setup() } DBG(F("OK, now make sure you an rtpMIDI session that is Enabled")); - DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")"); + DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI1.getPort(), "(Name", AppleMIDI1.getName(), ")"); + DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI2.getPort(), "(Name", AppleMIDI2.getName(), ")"); DBG(F("Then press the Connect button")); DBG(F("Then open a MIDI listener and monitor incoming notes")); - DBG(F("Listen to incoming MIDI commands")); // Listen for MIDI messages on channel 1 MIDI1.begin(1); diff --git a/examples/EthernetShield_NonDefaultSession/EthernetShield_NonDefaultSession.ino b/examples/EthernetShield_NonDefaultSession/EthernetShield_NonDefaultSession.ino index 8a10c59..e97c356 100644 --- a/examples/EthernetShield_NonDefaultSession/EthernetShield_NonDefaultSession.ino +++ b/examples/EthernetShield_NonDefaultSession/EthernetShield_NonDefaultSession.ino @@ -13,12 +13,8 @@ byte mac[] = { unsigned long t1 = millis(); bool isConnected = false; -// Custom name -//APPLEMIDI_CREATE_INSTANCE(EthernetUDP, MIDI, "MyNamedArduino", DEFAULT_CONTROL_PORT); -// custom name and random port -//APPLEMIDI_CREATE_INSTANCE(EthernetUDP, MIDI, "MyNamedArduino", 5200); -// custom name and port -APPLEMIDI_CREATE_INSTANCE(EthernetUDP, MIDI, "MyNamedArduino", DEFAULT_CONTROL_PORT + 2); +// Non default portnr +APPLEMIDI_CREATE_INSTANCE(EthernetUDP, MIDI, "MyNamedArduino", 5200); // ----------------------------------------------------------------------------- // @@ -37,13 +33,17 @@ void setup() DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")"); DBG(F("Then press the Connect button")); DBG(F("Then open a MIDI listener and monitor incoming notes")); - DBG(F("Listen to incoming MIDI commands")); MIDI.begin(); - // Stay informed on connection status - AppleMIDI.setHandleConnected(OnAppleMidiConnected); - AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected); + AppleMIDI.setHandleConnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { + isConnected = true; + DBG(F("Connected to session"), name); + }); + AppleMIDI.setHandleDisconnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { + isConnected = false; + DBG(F("Disconnected")); + }); DBG(F("Send MIDI messages every second")); } @@ -70,23 +70,3 @@ void loop() MIDI.sendNoteOff(note, velocity, channel); } } - -// ==================================================================================== -// Event handlers for incoming MIDI messages -// ==================================================================================== - -// ----------------------------------------------------------------------------- -// rtpMIDI session. Device connected -// ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { - isConnected = true; - DBG(F("Connected to session"), name); -} - -// ----------------------------------------------------------------------------- -// rtpMIDI session. Device disconnected -// ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { - isConnected = false; - DBG(F("Disconnected")); -} diff --git a/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino b/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino index d9e4198..2bde13d 100644 --- a/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino +++ b/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino @@ -32,7 +32,6 @@ void setup() DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")"); DBG(F("Then press the Connect button")); DBG(F("Then open a MIDI listener and monitor incoming notes")); - DBG(F("Listen to incoming MIDI commands")); MIDI.begin(); @@ -53,7 +52,7 @@ void setup() DBG(F("NoteOff "), note); }); - DBG(F("Send MIDI messages every second")); + DBG(F("Sending MIDI messages every second")); } // ----------------------------------------------------------------------------- diff --git a/examples/EthernetShield_ReceivedRawMidiData/EthernetShield_ReceivedRawMidiData.ino b/examples/EthernetShield_ReceivedRawMidiData/EthernetShield_ReceivedRawMidiData.ino index 1750a8c..aa3e441 100644 --- a/examples/EthernetShield_ReceivedRawMidiData/EthernetShield_ReceivedRawMidiData.ino +++ b/examples/EthernetShield_ReceivedRawMidiData/EthernetShield_ReceivedRawMidiData.ino @@ -32,21 +32,28 @@ void setup() DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")"); DBG(F("Then press the Connect button")); DBG(F("Then open a MIDI listener and monitor incoming notes")); - DBG(F("Listen to incoming MIDI commands")); MIDI.begin(); // check: zien we de connecttion binnenkomen?? Anders terug een ref van maken - AppleMIDI.setHandleConnected(OnAppleMidiConnected); - AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected); + AppleMIDI.setHandleConnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { + isConnected = true; + DBG(F("Connected to session"), name); + }); + AppleMIDI.setHandleDisconnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { + isConnected = false; + DBG(F("Disconnected")); + }); AppleMIDI.setHandleStartReceivedMidi(OnAppleMidiStartReceived); AppleMIDI.setHandleReceivedMidi(OnAppleMidiReceivedByte); AppleMIDI.setHandleEndReceivedMidi(OnAppleMidiEndReceive); - MIDI.setHandleNoteOn(OnMidiNoteOn); - MIDI.setHandleNoteOff(OnMidiNoteOff); - - DBG(F("Waiting for incoming MIDI messages")); + MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) { + DBG(F("NoteOn "), note); + }); + MIDI.setHandleNoteOff([](byte channel, byte note, byte velocity) { + DBG(F("NoteOff "), note); + }); } // ----------------------------------------------------------------------------- @@ -62,22 +69,6 @@ void loop() // Event handlers for incoming MIDI messages // ==================================================================================== -// ----------------------------------------------------------------------------- -// rtpMIDI session. Device connected -// ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { - isConnected = true; - DBG(F("Connected to session"), name); -} - -// ----------------------------------------------------------------------------- -// rtpMIDI session. Device disconnected -// ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { - isConnected = false; - DBG(F("Disconnected")); -} - // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- @@ -98,17 +89,3 @@ void OnAppleMidiReceivedByte(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, byte data void OnAppleMidiEndReceive(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { DBG(F("End receiving"), ssrc); } - -// ----------------------------------------------------------------------------- -// -// ----------------------------------------------------------------------------- -static void OnMidiNoteOn(byte channel, byte note, byte velocity) { - DBG(F("in\tNote on"), note, " Velocity", velocity, "\t", channel); -} - -// ----------------------------------------------------------------------------- -// -// ----------------------------------------------------------------------------- -static void OnMidiNoteOff(byte channel, byte note, byte velocity) { - DBG(F("in\tNote off"), note, " Velocity", velocity, "\t", channel); -} diff --git a/examples/EthernetShield_SysEx/EthernetShield_SysEx.ino b/examples/EthernetShield_SysEx/EthernetShield_SysEx.ino index 8ffe6ea..801b2e3 100644 --- a/examples/EthernetShield_SysEx/EthernetShield_SysEx.ino +++ b/examples/EthernetShield_SysEx/EthernetShield_SysEx.ino @@ -4,7 +4,6 @@ #define APPLEMIDI_DEBUG SerialMon #include - // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield byte mac[] = { @@ -25,7 +24,6 @@ byte sysexBig[] = { 0xF0, 0x41, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, - 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0xF7 }; @@ -48,17 +46,21 @@ void setup() DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")"); DBG(F("Then press the Connect button")); DBG(F("Then open a MIDI listener and monitor incoming notes")); - DBG(F("Listen to incoming MIDI commands")); MIDI.begin(); - // check: zien we de connecttion binnenkomen?? Anders terug een ref van makenDw - AppleMIDI.setHandleConnected(OnAppleMidiConnected); - AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected); + AppleMIDI.setHandleConnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { + isConnected = true; + DBG(F("Connected to session"), name); + }); + AppleMIDI.setHandleDisconnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { + isConnected = false; + DBG(F("Disconnected")); + }); MIDI.setHandleSystemExclusive(OnMidiSysEx); - DBG(F("Send and Receive SysEx")); + DBG(F("Send SysEx every second")); } // ----------------------------------------------------------------------------- @@ -82,25 +84,6 @@ void loop() // Event handlers for incoming MIDI messages // ==================================================================================== -// ----------------------------------------------------------------------------- -// rtpMIDI session. Device connected -// ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { - isConnected = true; - DBG(F("Connected to session"), name); -} - -// ----------------------------------------------------------------------------- -// rtpMIDI session. Device disconnected -// ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { - isConnected = false; - DBG(F("Disconnected")); -} - -// ----------------------------------------------------------------------------- -// -// ----------------------------------------------------------------------------- void OnMidiSysEx(byte* data, unsigned length) { SerialMon.print(F("SYSEX: (")); SerialMon.print(getSysExStatus(data, length)); diff --git a/examples/MKR_ETH_Bonjour/MKR_ETH_Bonjour.ino b/examples/MKR_ETH_Bonjour/MKR_ETH_Bonjour.ino index a2e35f0..ae73f26 100644 --- a/examples/MKR_ETH_Bonjour/MKR_ETH_Bonjour.ino +++ b/examples/MKR_ETH_Bonjour/MKR_ETH_Bonjour.ino @@ -1,8 +1,6 @@ #include #include // https://github.com/TrippyLighting/EthernetBonjour -#define OPTIONAL_MDNS - #include // Enter a MAC address for your controller below. diff --git a/examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino b/examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino index c997bdf..e95d787 100644 --- a/examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino +++ b/examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino @@ -25,20 +25,26 @@ void setup() DBG(F("Add device named Arduino with Host"), WiFi.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")"); DBG(F("Then press the Connect button")); DBG(F("Then open a MIDI listener and monitor incoming notes")); - DBG(F("Listen to incoming MIDI commands")); MIDI.begin(); - AppleMIDI.setHandleConnected(OnAppleMidiConnected); - AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected); - - MIDI.setHandleNoteOn(OnMidiNoteOn); - MIDI.setHandleNoteOff(OnMidiNoteOff); + AppleMIDI.setHandleConnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { + isConnected = true; + DBG(F("Connected to session"), name); + }); + AppleMIDI.setHandleDisconnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { + isConnected = false; + DBG(F("Disconnected")); + }); + + MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) { + DBG(F("NoteOn "), note); + }); + MIDI.setHandleNoteOff([](byte channel, byte note, byte velocity) { + DBG(F("NoteOff "), note); + }); MDNS.addService("apple-midi", "udp", AppleMIDI.getPort()); - MDNS.addService("http", "tcp", 80); - - DBG(F("Every second send a random NoteOn/Off")); } // ----------------------------------------------------------------------------- @@ -63,37 +69,3 @@ void loop() MIDI.sendNoteOff(note, velocity, channel); } } - -// ==================================================================================== -// Event handlers for incoming MIDI messages -// ==================================================================================== - -// ----------------------------------------------------------------------------- -// rtpMIDI session. Device connected -// ----------------------------------------------------------------------------- -void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { - isConnected = true; - DBG(F("Connected to session"), name); -} - -// ----------------------------------------------------------------------------- -// rtpMIDI session. Device disconnected -// ----------------------------------------------------------------------------- -void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { - isConnected = false; - DBG(F("Disconnected")); -} - -// ----------------------------------------------------------------------------- -// -// ----------------------------------------------------------------------------- -static void OnMidiNoteOn(byte channel, byte note, byte velocity) { - DBG(F("in\tNote on"), note, " Velocity", velocity, "\t", channel); -} - -// ----------------------------------------------------------------------------- -// -// ----------------------------------------------------------------------------- -static void OnMidiNoteOff(byte channel, byte note, byte velocity) { - DBG(F("in\tNote off"), note, " Velocity", velocity, "\t", channel); -} diff --git a/test/NoteOn.cpp b/test/NoteOn.cpp index 8879397..b0cb7cc 100644 --- a/test/NoteOn.cpp +++ b/test/NoteOn.cpp @@ -102,7 +102,6 @@ void begin() DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")"); DBG(F("Then press the Connect button")); DBG(F("Then open a MIDI listener and monitor incoming notes")); - DBG(F("Listen to incoming MIDI commands")); MIDI.begin(); From 3301d94f0df9aac410fda11b6164583944f9bec0 Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sat, 19 Dec 2020 16:36:38 +0100 Subject: [PATCH 10/17] cleanup examples --- examples/ESP32_Callbacks/ESP32_Callbacks.ino | 2 +- .../ESP8266_NoteOnOffEverySec.ino | 4 +-- .../EthernetShield_Initiator.ino | 4 +-- .../EthernetShield_NoteOnOffEverySec.ino | 6 ++-- .../EthernetShield_ReceivedRawMidiData.ino | 4 +-- .../EthernetShield_SysEx.ino | 28 ++----------------- .../wESP32_NoteOnOffEverySec.ino | 4 +-- 7 files changed, 14 insertions(+), 38 deletions(-) diff --git a/examples/ESP32_Callbacks/ESP32_Callbacks.ino b/examples/ESP32_Callbacks/ESP32_Callbacks.ino index 9186add..a431508 100644 --- a/examples/ESP32_Callbacks/ESP32_Callbacks.ino +++ b/examples/ESP32_Callbacks/ESP32_Callbacks.ino @@ -4,7 +4,7 @@ #define APPLEMIDI_DEBUG SerialMon #include -#include "arduino_secrets.h" +#include "arduino_secrets.h" // contains SECRET_SSID and SECRET_PASS bool isConnected = false; diff --git a/examples/ESP8266_NoteOnOffEverySec/ESP8266_NoteOnOffEverySec.ino b/examples/ESP8266_NoteOnOffEverySec/ESP8266_NoteOnOffEverySec.ino index 244560f..4552a6d 100644 --- a/examples/ESP8266_NoteOnOffEverySec/ESP8266_NoteOnOffEverySec.ino +++ b/examples/ESP8266_NoteOnOffEverySec/ESP8266_NoteOnOffEverySec.ino @@ -48,10 +48,10 @@ void setup() }); MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) { - DBG(F("NoteOn "), note); + DBG(F("NoteOn"), note); }); MIDI.setHandleNoteOff([](byte channel, byte note, byte velocity) { - DBG(F("NoteOff "), note); + DBG(F("NoteOff"), note); }); DBG(F("Sending NoteOn/Off of note 45, every second")); diff --git a/examples/EthernetShield_Initiator/EthernetShield_Initiator.ino b/examples/EthernetShield_Initiator/EthernetShield_Initiator.ino index c52689e..010dc29 100644 --- a/examples/EthernetShield_Initiator/EthernetShield_Initiator.ino +++ b/examples/EthernetShield_Initiator/EthernetShield_Initiator.ino @@ -46,10 +46,10 @@ void setup() }); MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) { - DBG(F("NoteOn "), note); + DBG(F("NoteOn"), note); }); MIDI.setHandleNoteOff([](byte channel, byte note, byte velocity) { - DBG(F("NoteOff "), note); + DBG(F("NoteOff"), note); }); // Initiate the session diff --git a/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino b/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino index 2bde13d..066fbbc 100644 --- a/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino +++ b/examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino @@ -46,10 +46,10 @@ void setup() }); MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) { - DBG(F("NoteOn "), note); + DBG(F("NoteOn"), note); }); MIDI.setHandleNoteOff([](byte channel, byte note, byte velocity) { - DBG(F("NoteOff "), note); + DBG(F("NoteOff"), note); }); DBG(F("Sending MIDI messages every second")); @@ -74,6 +74,6 @@ void loop() byte channel = 1; MIDI.sendNoteOn(note, velocity, channel); - MIDI.sendNoteOff(note, velocity, channel); +// MIDI.sendNoteOff(note, velocity, channel); } } diff --git a/examples/EthernetShield_ReceivedRawMidiData/EthernetShield_ReceivedRawMidiData.ino b/examples/EthernetShield_ReceivedRawMidiData/EthernetShield_ReceivedRawMidiData.ino index aa3e441..da139f0 100644 --- a/examples/EthernetShield_ReceivedRawMidiData/EthernetShield_ReceivedRawMidiData.ino +++ b/examples/EthernetShield_ReceivedRawMidiData/EthernetShield_ReceivedRawMidiData.ino @@ -49,10 +49,10 @@ void setup() AppleMIDI.setHandleEndReceivedMidi(OnAppleMidiEndReceive); MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) { - DBG(F("NoteOn "), note); + DBG(F("NoteOn"), note); }); MIDI.setHandleNoteOff([](byte channel, byte note, byte velocity) { - DBG(F("NoteOff "), note); + DBG(F("NoteOff"), note); }); } diff --git a/examples/EthernetShield_SysEx/EthernetShield_SysEx.ino b/examples/EthernetShield_SysEx/EthernetShield_SysEx.ino index 801b2e3..60ea425 100644 --- a/examples/EthernetShield_SysEx/EthernetShield_SysEx.ino +++ b/examples/EthernetShield_SysEx/EthernetShield_SysEx.ino @@ -1,8 +1,4 @@ -#include - -#define SerialMon Serial -#define APPLEMIDI_DEBUG SerialMon -#include +#include // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield @@ -27,7 +23,7 @@ byte sysexBig[] = { 0xF0, 0x41, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0xF7 }; -APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE(); +MIDI_CREATE_DEFAULT_INSTANCE(); // ----------------------------------------------------------------------------- // @@ -37,27 +33,7 @@ void setup() DBG_SETUP(115200); DBG("Booting"); - if (Ethernet.begin(mac) == 0) { - DBG(F("Failed DHCP, check network cable & reboot")); - for (;;); - } - - DBG(F("OK, now make sure you an rtpMIDI session that is Enabled")); - DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")"); - DBG(F("Then press the Connect button")); - DBG(F("Then open a MIDI listener and monitor incoming notes")); - MIDI.begin(); - - AppleMIDI.setHandleConnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { - isConnected = true; - DBG(F("Connected to session"), name); - }); - AppleMIDI.setHandleDisconnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { - isConnected = false; - DBG(F("Disconnected")); - }); - MIDI.setHandleSystemExclusive(OnMidiSysEx); DBG(F("Send SysEx every second")); diff --git a/examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino b/examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino index e95d787..30d402d 100644 --- a/examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino +++ b/examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino @@ -38,10 +38,10 @@ void setup() }); MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) { - DBG(F("NoteOn "), note); + DBG(F("NoteOn"), note); }); MIDI.setHandleNoteOff([](byte channel, byte note, byte velocity) { - DBG(F("NoteOff "), note); + DBG(F("NoteOff"), note); }); MDNS.addService("apple-midi", "udp", AppleMIDI.getPort()); From 64a2f6c6a73116c0a2a2a09bba6112afadf1ddee Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sat, 19 Dec 2020 16:37:16 +0100 Subject: [PATCH 11/17] remove unneeded initialisation --- src/AppleMIDI_Participant.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AppleMIDI_Participant.h b/src/AppleMIDI_Participant.h index 859c807..f1099cf 100644 --- a/src/AppleMIDI_Participant.h +++ b/src/AppleMIDI_Participant.h @@ -16,7 +16,7 @@ struct Participant unsigned long receiverFeedbackStartTime; bool doReceiverFeedback = false; - uint16_t sequenceNr = random(1, UINT16_MAX); // http://www.rfc-editor.org/rfc/rfc6295.txt , 2.1. RTP Header + uint16_t sequenceNr; unsigned long lastSyncExchangeTime; #ifdef APPLEMIDI_INITIATOR From 71a8010ceefcd2dfb46cd232575abc967168cc4b Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sat, 19 Dec 2020 16:38:25 +0100 Subject: [PATCH 12/17] fix bug where using wrong sequenceNr --- src/AppleMIDI.h | 3 ++- src/AppleMIDI.hpp | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/AppleMIDI.h b/src/AppleMIDI.h index bb7da70..86832a7 100644 --- a/src/AppleMIDI.h +++ b/src/AppleMIDI.h @@ -63,7 +63,7 @@ class AppleMIDISession const char* getName() { return this->localName; }; const uint16_t getPort() { return this->port; }; - const ssrc_t getSynchronizationSource() { return this->ssrc; }; + const ssrc_t getSynchronizationSource() { return this->ssrc; }; void setName(const char *sessionName) { strncpy(this->localName, sessionName, DefaultSettings::MaxSessionNameLen); }; @@ -237,6 +237,7 @@ class AppleMIDISession uint16_t port = DEFAULT_CONTROL_PORT; Deque, Settings::MaxNumberOfParticipants> participants; int32_t latencyAdjustment = 0; + uint16_t sequenceNr = random(1, UINT16_MAX); private: void readControlPackets(); diff --git a/src/AppleMIDI.hpp b/src/AppleMIDI.hpp index 07ec39c..10bb292 100644 --- a/src/AppleMIDI.hpp +++ b/src/AppleMIDI.hpp @@ -126,7 +126,6 @@ void AppleMIDISession::ReceivedControlInvitation(A participant.remoteIP = controlPort.remoteIP(); participant.remotePort = controlPort.remotePort(); participant.lastSyncExchangeTime = now; - participant.sequenceNr = random(1, UINT16_MAX); // // http://www.rfc-editor.org/rfc/rfc6295.txt , 2.1. RTP Header #ifdef KEEP_SESSION_NAME strncpy(participant.sessionName, invitation.sessionName, DefaultSettings::MaxSessionNameLen); #endif @@ -345,7 +344,8 @@ void AppleMIDISession::ReceivedSynchronization(App template void AppleMIDISession::ReceivedReceiverFeedback(AppleMIDI_ReceiverFeedback_t &receiverFeedback) { - // As we do not keep any recovery journals, no command history, nothing! + // We do not keep any recovery journals, no command history, nothing! + // If we did, then we can flush the previous sent buffer until receiverFeedback.sequenceNr } template @@ -479,9 +479,7 @@ void AppleMIDISession::writeRtpMidiBuffer(Particip if (!dataPort.beginPacket(remoteIP, remotePort)) return; - - participant->sequenceNr++; // (modulo 2^16) modulo is automatically done for us () - + Rtp rtp; rtp.vpxcc = 0b10000000; // TODO: fun with flags rtp.mpayload = PAYLOADTYPE_RTPMIDI; // TODO: set or unset marker @@ -502,8 +500,12 @@ void AppleMIDISession::writeRtpMidiBuffer(Particip // prepared to defer rendering the messages until the proper time.) // rtp.timestamp = (Settings::TimestampRtpPackets) ? htonl(rtpMidiClock.Now()) : 0; - - rtp.sequenceNr = htons(participant->sequenceNr); + + // + sequenceNr++; // (modulo 2^16) modulo is automatically done for us () + rtp.sequenceNr = htons(sequenceNr); + + dataPort.write((uint8_t *)&rtp, sizeof(rtp)); // only now the length is known @@ -841,7 +843,7 @@ void AppleMIDISession::ReceivedRtp(const Rtp_t& rt auto latency = 0; #endif participant->sequenceNr = rtp.sequenceNr; - + if (NULL != _receivedRtpCallback) _receivedRtpCallback(0, rtp, latency); } From 51ae878c49a8f65e6a5751980921f149b6b3ad20 Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sat, 19 Dec 2020 20:25:39 +0100 Subject: [PATCH 13/17] Update EthernetShield_Initiator.ino --- .../EthernetShield_Initiator.ino | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/EthernetShield_Initiator/EthernetShield_Initiator.ino b/examples/EthernetShield_Initiator/EthernetShield_Initiator.ino index 010dc29..1201965 100644 --- a/examples/EthernetShield_Initiator/EthernetShield_Initiator.ino +++ b/examples/EthernetShield_Initiator/EthernetShield_Initiator.ino @@ -30,9 +30,6 @@ void setup() } DBG(F("OK, now make sure you an rtpMIDI session that is Enabled")); - DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")"); - DBG(F("Then press the Connect button")); - DBG(F("Then open a MIDI listener and monitor incoming notes")); MIDI.begin(); @@ -53,9 +50,13 @@ void setup() }); // Initiate the session - IPAddress remote(192, 168, 1, 4); + IPAddress remote(192, 168, 1, 65); AppleMIDI.sendInvite(remote, DEFAULT_CONTROL_PORT); // port is 5004 by default + DBG(F("Connecting to "), remote, "Port", DEFAULT_CONTROL_PORT, "(Name", AppleMIDI.getName(), ")"); + DBG(F("Watch as this session is added to the Participants list")); + DBG(F("Then open a MIDI listener and monitor incoming notes")); + DBG(F("Sending a random NoteOn/Off every second")); } @@ -77,7 +78,7 @@ void loop() byte velocity = 55; byte channel = 1; - MIDI.sendNoteOn(note, velocity, channel); - MIDI.sendNoteOff(note, velocity, channel); + // MIDI.sendNoteOn(note, velocity, channel); + // MIDI.sendNoteOff(note, velocity, channel); } } From d6087cbd886c6bc9c24029813350762ec813da94 Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sat, 19 Dec 2020 20:30:51 +0100 Subject: [PATCH 14/17] Update AppleMIDI_Defs.h --- src/AppleMIDI_Defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AppleMIDI_Defs.h b/src/AppleMIDI_Defs.h index 9703c31..66b143a 100644 --- a/src/AppleMIDI_Defs.h +++ b/src/AppleMIDI_Defs.h @@ -149,7 +149,7 @@ typedef struct PACKED AppleMIDI_Synchronization { ssrc_t ssrc; uint8_t count; - uint8_t padding[3]; + uint8_t padding[3] = {0,0,0}; timestamp_t timestamps[3]; } AppleMIDI_Synchronization_t; From 9fba5d9afaccc168b6e85f08af19d90b826abc7a Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sat, 19 Dec 2020 21:05:47 +0100 Subject: [PATCH 15/17] Update wESP32_NoteOnOffEverySec.ino --- examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino b/examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino index 30d402d..195e12d 100644 --- a/examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino +++ b/examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino @@ -22,7 +22,7 @@ void setup() MDNS.begin(AppleMIDI.getName()); DBG(F("OK, now make sure you an rtpMIDI session that is Enabled")); - DBG(F("Add device named Arduino with Host"), WiFi.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")"); + DBG(F("Add device named Arduino with Host"), ETH.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")"); DBG(F("Then press the Connect button")); DBG(F("Then open a MIDI listener and monitor incoming notes")); From a84ca70f7e0c887c9fddf082c7ccc616fc03eab2 Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sat, 19 Dec 2020 21:06:14 +0100 Subject: [PATCH 16/17] Update AppleMIDI.hpp fixed htonl changing the ssrc --- src/AppleMIDI.hpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/AppleMIDI.hpp b/src/AppleMIDI.hpp index 10bb292..e9a041e 100644 --- a/src/AppleMIDI.hpp +++ b/src/AppleMIDI.hpp @@ -395,7 +395,8 @@ void AppleMIDISession::writeInvitation(UdpClass &p port.write((uint8_t *)command, sizeof(amInvitation)); port.write((uint8_t *)amProtocolVersion, sizeof(amProtocolVersion)); invitation.initiatorToken = htonl(invitation.initiatorToken); - invitation.ssrc = htonl(ssrc); + invitation.ssrc = ssrc; + invitation.ssrc = htonl(invitation.ssrc); port.write(reinterpret_cast(&invitation), invitation.getLength()); port.endPacket(); @@ -429,7 +430,8 @@ void AppleMIDISession::writeSynchronization(const { dataPort.write((uint8_t *)amSignature, sizeof(amSignature)); dataPort.write((uint8_t *)amSynchronization, sizeof(amSynchronization)); - synchronization.ssrc = htonl(this->ssrc); + synchronization.ssrc = ssrc; + synchronization.ssrc = htonl(synchronization.ssrc); synchronization.timestamps[0] = htonll(synchronization.timestamps[0]); synchronization.timestamps[1] = htonll(synchronization.timestamps[1]); @@ -483,7 +485,8 @@ void AppleMIDISession::writeRtpMidiBuffer(Particip Rtp rtp; rtp.vpxcc = 0b10000000; // TODO: fun with flags rtp.mpayload = PAYLOADTYPE_RTPMIDI; // TODO: set or unset marker - rtp.ssrc = htonl(ssrc); + rtp.ssrc = ssrc; + rtp.ssrc = htonl(rtp.ssrc); // https://developer.apple.com/library/ios/documentation/CoreMidi/Reference/MIDIServices_Reference/#//apple_ref/doc/uid/TP40010316-CHMIDIServiceshFunctions-SW30 // The time at which the events occurred, if receiving MIDI, or, if sending MIDI, @@ -503,8 +506,9 @@ void AppleMIDISession::writeRtpMidiBuffer(Particip // sequenceNr++; // (modulo 2^16) modulo is automatically done for us () - rtp.sequenceNr = htons(sequenceNr); + rtp.sequenceNr = sequenceNr; + rtp.sequenceNr = htons(rtp.sequenceNr); dataPort.write((uint8_t *)&rtp, sizeof(rtp)); From cd149374467caedc25d75cd4e72d06e10c4b6ae8 Mon Sep 17 00:00:00 2001 From: lathoub <4082369+lathoub@users.noreply.github.com> Date: Sat, 19 Dec 2020 21:53:54 +0100 Subject: [PATCH 17/17] Update EthernetShield_SysEx.ino --- .../EthernetShield_SysEx.ino | 52 ++++++++++++++----- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/examples/EthernetShield_SysEx/EthernetShield_SysEx.ino b/examples/EthernetShield_SysEx/EthernetShield_SysEx.ino index 60ea425..2296d8c 100644 --- a/examples/EthernetShield_SysEx/EthernetShield_SysEx.ino +++ b/examples/EthernetShield_SysEx/EthernetShield_SysEx.ino @@ -1,4 +1,8 @@ -#include +#include + +#define SerialMon Serial +#define APPLEMIDI_DEBUG SerialMon +#include // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield @@ -13,17 +17,18 @@ byte sysex14[] = { 0xF0, 0x43, 0x20, 0x7E, 0x4C, 0x4D, 0x20, 0x20, 0x38, 0x39, 0 byte sysex15[] = { 0xF0, 0x43, 0x20, 0x7E, 0x4C, 0x4D, 0x20, 0x20, 0x38, 0x39, 0x37, 0x33, 0x50, 0x4D, 0xF7 }; byte sysex16[] = { 0xF0, 0x43, 0x20, 0x7E, 0x4C, 0x4D, 0x20, 0x20, 0x38, 0x39, 0x37, 0x33, 0x32, 0x50, 0x4D, 0xF7 }; byte sysexBig[] = { 0xF0, 0x41, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, - 0x7a, - 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0xF7 }; - -MIDI_CREATE_DEFAULT_INSTANCE(); + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, + 0x7a, + 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, + 0xF7 + }; + +APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE(); // ----------------------------------------------------------------------------- // @@ -33,6 +38,25 @@ void setup() DBG_SETUP(115200); DBG("Booting"); + if (Ethernet.begin(mac) == 0) { + DBG(F("Failed DHCP, check network cable & reboot")); + for (;;); + } + + DBG(F("OK, now make sure you an rtpMIDI session that is Enabled")); + DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")"); + DBG(F("Then press the Connect button")); + DBG(F("Then open a MIDI listener and monitor incoming notes")); + + AppleMIDI.setHandleConnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) { + isConnected = true; + DBG(F("Connected to session"), name); + }); + AppleMIDI.setHandleDisconnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) { + isConnected = false; + DBG(F("Disconnected")); + }); + MIDI.begin(); MIDI.setHandleSystemExclusive(OnMidiSysEx); @@ -51,8 +75,8 @@ void loop() // (dont cáll delay(1000) as it will stall the pipeline) if (isConnected && (millis() - t1) > 1000) { - MIDI.sendSysEx(sizeof(sysexBig), sysexBig, true); - t1 = millis(); + MIDI.sendSysEx(sizeof(sysexBig), sysexBig, true); + t1 = millis(); } }