Skip to content

Commit 134967d

Browse files
authored
Merge pull request #96 from lathoub/v2.2.0_test
Bug fixes and enhancements
2 parents 3b5c368 + cd14937 commit 134967d

File tree

20 files changed

+215
-388
lines changed

20 files changed

+215
-388
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ install:
1313
- platformio lib -g install [email protected] 870 872
1414

1515
script:
16-
- platformio ci --board=uno --lib=. examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino;
16+
- pio ci --board=uno --lib=. examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino;

examples/ESP32_Callbacks/ESP32_Callbacks.ino

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
33
#define SerialMon Serial
44
#define APPLEMIDI_DEBUG SerialMon
55
#include <AppleMIDI.h>
6-
USING_NAMESPACE_APPLEMIDI
76

8-
#include "arduino_secrets.h"
7+
#include "arduino_secrets.h" // contains SECRET_SSID and SECRET_PASS
98

109
bool isConnected = false;
1110

1211
APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE();
1312

1413
void setup() {
15-
SerialMon.begin(115200);
16-
while (!SerialMon);
17-
14+
DBG_SETUP(115200);
1815
DBG("Booting");
1916

2017
WiFi.begin(SECRET_SSID, SECRET_PASS);
@@ -28,7 +25,6 @@ void setup() {
2825
DBG(F("Add device named Arduino with Host"), WiFi.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")");
2926
DBG(F("Then press the Connect button"));
3027
DBG(F("Then open a MIDI listener and monitor incoming notes"));
31-
DBG(F("Listen to incoming MIDI commands"));
3228

3329
AppleMIDI.setHandleConnected(OnAppleMidiConnected);
3430
AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected);
@@ -65,47 +61,47 @@ void loop() {
6561
// -----------------------------------------------------------------------------
6662
//
6763
// -----------------------------------------------------------------------------
68-
void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) {
64+
void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) {
6965
isConnected = true;
7066
DBG(F("Connected to session"), name);
7167
}
7268

7369
// -----------------------------------------------------------------------------
7470
//
7571
// -----------------------------------------------------------------------------
76-
void OnAppleMidiDisconnected(const ssrc_t & ssrc) {
72+
void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) {
7773
isConnected = false;
7874
DBG(F("Disconnected"));
7975
}
8076

8177
// -----------------------------------------------------------------------------
8278
//
8379
// -----------------------------------------------------------------------------
84-
void OnAppleMidiError(const ssrc_t& ssrc, int32_t err) {
80+
void OnAppleMidiError(const APPLEMIDI_NAMESPACE::ssrc_t& ssrc, int32_t err) {
8581
switch (err)
8682
{
87-
case Exception::BufferFullException:
83+
case APPLEMIDI_NAMESPACE::Exception::BufferFullException:
8884
DBG(F("*** BufferFullException"));
8985
break;
90-
case Exception::ParseException:
86+
case APPLEMIDI_NAMESPACE::Exception::ParseException:
9187
DBG(F("*** ParseException"));
9288
break;
93-
case Exception::TooManyParticipantsException:
89+
case APPLEMIDI_NAMESPACE::Exception::TooManyParticipantsException:
9490
DBG(F("*** TooManyParticipantsException"));
9591
break;
96-
case Exception::UnexpectedInviteException:
92+
case APPLEMIDI_NAMESPACE::Exception::UnexpectedInviteException:
9793
DBG(F("*** UnexpectedInviteException"));
9894
break;
99-
case Exception::ParticipantNotFoundException:
95+
case APPLEMIDI_NAMESPACE::Exception::ParticipantNotFoundException:
10096
DBG(F("*** ParticipantNotFoundException"));
10197
break;
102-
case Exception::ListenerTimeOutException:
98+
case APPLEMIDI_NAMESPACE::Exception::ListenerTimeOutException:
10399
DBG(F("*** ListenerTimeOutException"));
104100
break;
105-
case Exception::MaxAttemptsException:
101+
case APPLEMIDI_NAMESPACE::Exception::MaxAttemptsException:
106102
DBG(F("*** MaxAttemptsException"));
107103
break;
108-
case Exception::NoResponseFromConnectionRequestException:
104+
case APPLEMIDI_NAMESPACE::Exception::NoResponseFromConnectionRequestException:
109105
DBG(F("***:yyy did't respond to the connection request. Check the address and port, and any firewall or router settings. (time)"));
110106
break;
111107
}

examples/ESP8266_NoteOnOffEverySec/ESP8266_NoteOnOffEverySec.ino

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#define SerialMon Serial
66
#define APPLEMIDI_DEBUG SerialMon
77
#include <AppleMIDI.h>
8-
USING_NAMESPACE_APPLEMIDI
98

109
char ssid[] = "yourNetwork"; // your network SSID (name)
1110
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)
@@ -15,21 +14,12 @@ bool isConnected = false;
1514

1615
APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE();
1716

18-
// Forward declaration
19-
void OnAppleMidiConnected(uint32_t ssrc, char* name);
20-
void OnAppleMidiDisconnected(uint32_t ssrc);
21-
void OnMidiNoteOn(byte channel, byte note, byte velocity);
22-
void OnMidiNoteOff(byte channel, byte note, byte velocity);
23-
2417
// -----------------------------------------------------------------------------
2518
//
2619
// -----------------------------------------------------------------------------
2720
void setup()
2821
{
29-
// Serial communications and wait for port to open:
30-
SerialMon.begin(115200);
31-
while (!SerialMon);
32-
22+
DBG_SETUP(115200);
3323
DBG("Booting");
3424

3525
WiFi.begin(ssid, pass);
@@ -48,11 +38,21 @@ void setup()
4838

4939
MIDI.begin();
5040

51-
AppleMIDI.setHandleConnected(OnAppleMidiConnected);
52-
AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected);
53-
54-
MIDI.setHandleNoteOn(OnMidiNoteOn);
55-
MIDI.setHandleNoteOff(OnMidiNoteOff);
41+
AppleMIDI.setHandleConnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) {
42+
isConnected = true;
43+
DBG(F("Connected to session"), name);
44+
});
45+
AppleMIDI.setHandleDisconnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) {
46+
isConnected = false;
47+
DBG(F("Disconnected"));
48+
});
49+
50+
MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) {
51+
DBG(F("NoteOn"), note);
52+
});
53+
MIDI.setHandleNoteOff([](byte channel, byte note, byte velocity) {
54+
DBG(F("NoteOff"), note);
55+
});
5656

5757
DBG(F("Sending NoteOn/Off of note 45, every second"));
5858
}
@@ -79,37 +79,3 @@ void loop()
7979
MIDI.sendNoteOff(note, velocity, channel);
8080
}
8181
}
82-
83-
// ====================================================================================
84-
// Event handlers for incoming MIDI messages
85-
// ====================================================================================
86-
87-
// -----------------------------------------------------------------------------
88-
// rtpMIDI session. Device connected
89-
// -----------------------------------------------------------------------------
90-
void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) {
91-
isConnected = true;
92-
DBG(F("Connected to session"), name);
93-
}
94-
95-
// -----------------------------------------------------------------------------
96-
// rtpMIDI session. Device disconnected
97-
// -----------------------------------------------------------------------------
98-
void OnAppleMidiDisconnected(const ssrc_t & ssrc) {
99-
isConnected = false;
100-
DBG(F("Disconnected"));
101-
}
102-
103-
// -----------------------------------------------------------------------------
104-
//
105-
// -----------------------------------------------------------------------------
106-
void OnMidiNoteOn(byte channel, byte note, byte velocity) {
107-
DBG(F("in\tNote on"), note, " Velocity", velocity, "\t", channel);
108-
}
109-
110-
// -----------------------------------------------------------------------------
111-
//
112-
// -----------------------------------------------------------------------------
113-
void OnMidiNoteOff(byte channel, byte note, byte velocity) {
114-
DBG(F("in\tNote off"), note, " Velocity", velocity, "\t", channel);
115-
}

examples/EthernetShield_Initiator/EthernetShield_Initiator.ino

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#define APPLEMIDI_DEBUG SerialMon
55
#define APPLEMIDI_INITIATOR
66
#include <AppleMIDI.h>
7-
USING_NAMESPACE_APPLEMIDI
87

98
// Enter a MAC address for your controller below.
109
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
@@ -22,8 +21,7 @@ APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE();
2221
// -----------------------------------------------------------------------------
2322
void setup()
2423
{
25-
SerialMon.begin(115200);
26-
while (!SerialMon);
24+
DBG_SETUP(115200);
2725
DBG("Booting");
2826

2927
if (Ethernet.begin(mac) == 0) {
@@ -32,26 +30,34 @@ void setup()
3230
}
3331

3432
DBG(F("OK, now make sure you an rtpMIDI session that is Enabled"));
35-
DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")");
36-
DBG(F("Then press the Connect button"));
37-
DBG(F("Then open a MIDI listener and monitor incoming notes"));
38-
DBG(F("Listen to incoming MIDI commands"));
3933

4034
MIDI.begin();
4135

42-
// Stay informed on connection status
43-
AppleMIDI.setHandleConnected(OnAppleMidiConnected);
44-
AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected);
45-
46-
// and let us know ehen notes come in
47-
MIDI.setHandleNoteOn(OnMidiNoteOn);
48-
MIDI.setHandleNoteOff(OnMidiNoteOff);
36+
AppleMIDI.setHandleConnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) {
37+
isConnected = true;
38+
DBG(F("Connected to session"), name);
39+
});
40+
AppleMIDI.setHandleDisconnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) {
41+
isConnected = false;
42+
DBG(F("Disconnected"));
43+
});
44+
45+
MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) {
46+
DBG(F("NoteOn"), note);
47+
});
48+
MIDI.setHandleNoteOff([](byte channel, byte note, byte velocity) {
49+
DBG(F("NoteOff"), note);
50+
});
4951

5052
// Initiate the session
51-
IPAddress remote(192, 168, 1, 4);
53+
IPAddress remote(192, 168, 1, 65);
5254
AppleMIDI.sendInvite(remote, DEFAULT_CONTROL_PORT); // port is 5004 by default
5355

54-
DBG(F("Every second send a random NoteOn/Off"));
56+
DBG(F("Connecting to "), remote, "Port", DEFAULT_CONTROL_PORT, "(Name", AppleMIDI.getName(), ")");
57+
DBG(F("Watch as this session is added to the Participants list"));
58+
DBG(F("Then open a MIDI listener and monitor incoming notes"));
59+
60+
DBG(F("Sending a random NoteOn/Off every second"));
5561
}
5662

5763
// -----------------------------------------------------------------------------
@@ -72,41 +78,7 @@ void loop()
7278
byte velocity = 55;
7379
byte channel = 1;
7480

75-
MIDI.sendNoteOn(note, velocity, channel);
76-
MIDI.sendNoteOff(note, velocity, channel);
81+
// MIDI.sendNoteOn(note, velocity, channel);
82+
// MIDI.sendNoteOff(note, velocity, channel);
7783
}
7884
}
79-
80-
// ====================================================================================
81-
// Event handlers for incoming MIDI messages
82-
// ====================================================================================
83-
84-
// -----------------------------------------------------------------------------
85-
// rtpMIDI session. Device connected
86-
// -----------------------------------------------------------------------------
87-
void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) {
88-
isConnected = true;
89-
DBG(F("Connected to session"), name);
90-
}
91-
92-
// -----------------------------------------------------------------------------
93-
// rtpMIDI session. Device disconnected
94-
// -----------------------------------------------------------------------------
95-
void OnAppleMidiDisconnected(const ssrc_t & ssrc) {
96-
isConnected = false;
97-
DBG(F("Disconnected"));
98-
}
99-
100-
// -----------------------------------------------------------------------------
101-
//
102-
// -----------------------------------------------------------------------------
103-
static void OnMidiNoteOn(byte channel, byte note, byte velocity) {
104-
DBG(F("in\tNote on"), note, " Velocity", velocity, "\t", channel);
105-
}
106-
107-
// -----------------------------------------------------------------------------
108-
//
109-
// -----------------------------------------------------------------------------
110-
static void OnMidiNoteOff(byte channel, byte note, byte velocity) {
111-
DBG(F("in\tNote off"), note, " Velocity", velocity, "\t", channel);
112-
}

examples/EthernetShield_MultipleSessions/EthernetShield_MultipleSessions.ino

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#define SerialMon Serial
44
#define APPLEMIDI_DEBUG SerialMon
55
#include <AppleMIDI.h>
6-
USING_NAMESPACE_APPLEMIDI
76

87
// Enter a MAC address for your controller below.
98
// 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 +
2221
// -----------------------------------------------------------------------------
2322
void setup()
2423
{
25-
SerialMon.begin(115200);
26-
while (!SerialMon);
24+
DBG_SETUP(115200);
2725
DBG("Booting");
2826

2927
if (Ethernet.begin(mac) == 0) {
@@ -32,10 +30,10 @@ void setup()
3230
}
3331

3432
DBG(F("OK, now make sure you an rtpMIDI session that is Enabled"));
35-
DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")");
33+
DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI1.getPort(), "(Name", AppleMIDI1.getName(), ")");
34+
DBG(F("Add device named Arduino with Host"), Ethernet.localIP(), "Port", AppleMIDI2.getPort(), "(Name", AppleMIDI2.getName(), ")");
3635
DBG(F("Then press the Connect button"));
3736
DBG(F("Then open a MIDI listener and monitor incoming notes"));
38-
DBG(F("Listen to incoming MIDI commands"));
3937

4038
// Listen for MIDI messages on channel 1
4139
MIDI1.begin(1);
@@ -84,15 +82,15 @@ void loop()
8482
// -----------------------------------------------------------------------------
8583
// rtpMIDI session. Device connected
8684
// -----------------------------------------------------------------------------
87-
void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) {
85+
void OnAppleMidiConnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) {
8886
isConnected = true;
8987
DBG(F("Connected to session"), name);
9088
}
9189

9290
// -----------------------------------------------------------------------------
9391
// rtpMIDI session. Device disconnected
9492
// -----------------------------------------------------------------------------
95-
void OnAppleMidiDisconnected(const ssrc_t & ssrc) {
93+
void OnAppleMidiDisconnected(const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) {
9694
isConnected = false;
9795
DBG(F("Disconnected"));
9896
}

0 commit comments

Comments
 (0)