Skip to content

Commit e5cbaa4

Browse files
authored
Merge pull request #84 from lathoub/feat/v2.1.0
Feat/v2.1.0
2 parents eddc2a6 + fa1fef3 commit e5cbaa4

File tree

19 files changed

+224
-210
lines changed

19 files changed

+224
-210
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Enables an Arduino with IP/UDP capabilities (Ethernet shield, ESP8266, ESP32, ..
99
* Send and receive all MIDI messages
1010
* Uses callbacks to receive MIDI commands (no need for polling)
1111
* Automatic instantiation of AppleMIDI object (see at the end of 'AppleMidi.h')
12+
* Compiles on Arduino, MacOS (XCode) and Windows (MSVS)
1213

1314
## Installation
1415
From the Arduino IDE Library Manager, search for AppleMIDI

examples/EthernetShield_Bonjour/EthernetShield_Bonjour.ino

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ void setup()
5959
// Stay informed on connection status
6060
AppleMIDI.setHandleConnected(OnAppleMidiConnected);
6161
AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected);
62-
AppleMIDI.setHandleError(OnAppleMidiError);
6362

6463
// and let us know ehen notes come in
6564
MIDI.setHandleNoteOn(OnMidiNoteOn);
@@ -115,14 +114,6 @@ void OnAppleMidiDisconnected(const ssrc_t & ssrc) {
115114
Serial.println(F("Disconnected"));
116115
}
117116

118-
// -----------------------------------------------------------------------------
119-
// rtpMIDI session. Error occorded during processing
120-
// -----------------------------------------------------------------------------
121-
void OnAppleMidiError(const ssrc_t & ssrc, int32_t errorCode) {
122-
Serial.println(F("ERROR"));
123-
exit(1);
124-
}
125-
126117
// -----------------------------------------------------------------------------
127118
//
128119
// -----------------------------------------------------------------------------

examples/EthernetShield_Initiator/EthernetShield_Initiator.ino

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ void setup()
4747
// Stay informed on connection status
4848
AppleMIDI.setHandleConnected(OnAppleMidiConnected);
4949
AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected);
50+
AppleMIDI.setHandleError(OnAppleMidiError);
5051

5152
// and let us know ehen notes come in
5253
MIDI.setHandleNoteOn(OnMidiNoteOn);
5354
MIDI.setHandleNoteOff(OnMidiNoteOff);
5455

5556
// Initiate the session
56-
IPAddress remote(192, 168, 1, 156);
57+
IPAddress remote(192, 168, 1, 4);
5758
AppleMIDI.sendInvite(remote); // port is 5004 by default
5859

5960
Serial.println(F("Every second send a random NoteOn/Off"));
@@ -107,6 +108,23 @@ void OnAppleMidiDisconnected(const ssrc_t & ssrc) {
107108
Serial.println(ssrc, HEX);
108109
}
109110

111+
// -----------------------------------------------------------------------------
112+
// rtpMIDI session. Device disconnected
113+
// -----------------------------------------------------------------------------
114+
void OnAppleMidiError(const ssrc_t& ssrc, int32_t err) {
115+
Serial.print (F("Exception "));
116+
Serial.println(err);
117+
Serial.print (F(" from ssrc 0x"));
118+
Serial.println(ssrc, HEX);
119+
120+
switch (err)
121+
{
122+
case Exception::NoResponseFromConnectionRequestException:
123+
Serial.println(F("xxx:yyy did't respond to the connection request. Check the address and port, and any firewall or router settings. (time)"));
124+
break;
125+
}
126+
}
127+
110128
// -----------------------------------------------------------------------------
111129
//
112130
// -----------------------------------------------------------------------------
@@ -129,4 +147,4 @@ static void OnMidiNoteOff(byte channel, byte note, byte velocity) {
129147
Serial.print(note);
130148
Serial.print(F(", velocity: "));
131149
Serial.println(velocity);
132-
}
150+
}

examples/EthernetShield_RealTimeMessages/EthernetShield_RealTimeMessages.ino

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ void setup()
4646
// check: zien we de connecttion binnenkomen?? Anders terug een ref van maken
4747
AppleMIDI.setHandleConnected(OnAppleMidiConnected);
4848
AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected);
49-
AppleMIDI.setHandleError(OnAppleMidiError);
5049

5150
MIDI.setHandleClock(OnMidiClock);
5251
MIDI.setHandleStart(OnMidiStart);
@@ -81,14 +80,6 @@ void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) {
8180
Serial.println(name);
8281
}
8382

84-
// -----------------------------------------------------------------------------
85-
// rtpMIDI session. Device disconnected
86-
// -----------------------------------------------------------------------------
87-
void OnAppleMidiDisconnected(const ssrc_t & ssrc) {
88-
isConnected = false;
89-
Serial.println(F("Disconnected"));
90-
}
91-
9283
// -----------------------------------------------------------------------------
9384
// rtpMIDI session. Error occorded during processing
9485
// -----------------------------------------------------------------------------

examples/wESP32_NoteOnOffEverySec/wESP32_NoteOnOffEverySec.ino

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "ETH_Helper.h"
22

3+
#define APPLEMIDI_INITIATOR
34
#include <AppleMIDI.h>
45
USING_NAMESPACE_APPLEMIDI
56

@@ -8,8 +9,6 @@ bool isConnected = false;
89

910
APPLEMIDI_CREATE_DEFAULTSESSION_ESP32_INSTANCE();
1011

11-
//WiFiServer server(80);
12-
1312
// -----------------------------------------------------------------------------
1413
//
1514
// -----------------------------------------------------------------------------
@@ -21,9 +20,6 @@ void setup()
2120

2221
ETH_startup();
2322

24-
// Start TCP (HTTP) server
25-
// server.begin();
26-
2723
MDNS.begin(AppleMIDI.getName());
2824

2925
Serial.print("IP address is ");
@@ -40,6 +36,7 @@ void setup()
4036

4137
AppleMIDI.setHandleConnected(OnAppleMidiConnected);
4238
AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected);
39+
AppleMIDI.setHandleError(OnAppleMidiError);
4340

4441
MIDI.setHandleNoteOn(OnAppleMidiNoteOn);
4542
MIDI.setHandleNoteOff(OnAppleMidiNoteOff);
@@ -48,6 +45,10 @@ void setup()
4845
MDNS.addService("http", "tcp", 80);
4946

5047
Serial.println(F("Every second send a random NoteOn/Off"));
48+
49+
// Initiate the session
50+
IPAddress remote(192, 168, 1, 4);
51+
AppleMIDI.sendInvite(remote); // port is 5004 by default
5152
}
5253

5354
// -----------------------------------------------------------------------------
@@ -96,7 +97,24 @@ void OnAppleMidiDisconnected(const ssrc_t & ssrc) {
9697
}
9798

9899
// -----------------------------------------------------------------------------
99-
//
100+
// rtpMIDI session. Device disconnected
101+
// -----------------------------------------------------------------------------
102+
void OnAppleMidiError(const ssrc_t& ssrc, int32_t err) {
103+
Serial.print (F("Exception "));
104+
Serial.print (err);
105+
Serial.print (F(" from ssrc 0x"));
106+
Serial.println(ssrc, HEX);
107+
108+
switch (err)
109+
{
110+
case Exception::NoResponseFromConnectionRequestException:
111+
Serial.println(F("xxx:yyy did't respond to the connection request. Check the address and port, and any firewall or router settings. (time)"));
112+
break;
113+
}
114+
}
115+
116+
// -----------------------------------------------------------------------------
117+
//
100118
// -----------------------------------------------------------------------------
101119
static void OnAppleMidiNoteOn(byte channel, byte note, byte velocity) {
102120
Serial.print(F("Incoming NoteOn from channel: "));
@@ -117,4 +135,4 @@ static void OnAppleMidiNoteOff(byte channel, byte note, byte velocity) {
117135
Serial.print(note);
118136
Serial.print(F(", velocity: "));
119137
Serial.println(velocity);
120-
}
138+
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=AppleMIDI
2-
version=2.0.5
2+
version=2.1.0
33
author=lathoub
44
maintainer=lathoub <lathoub@gmail.com>
55
sentence=AppleMIDI (rtpMIDI) protocol for Arduino

src/AppleMIDI.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ using namespace MIDI_NAMESPACE;
77

88
#include "IPAddress.h"
99

10+
#include "AppleMIDI_PlatformBegin.h"
1011
#include "AppleMIDI_Defs.h"
1112
#include "AppleMIDI_Settings.h"
12-
#include "AppleMIDI_Platform.h"
1313

1414
#include "rtp_Defs.h"
1515
#include "rtpMIDI_Defs.h"
@@ -22,10 +22,6 @@ using namespace MIDI_NAMESPACE;
2222

2323
#include "AppleMIDI_Namespace.h"
2424

25-
#ifndef UDP_TX_PACKET_MAX_SIZE
26-
#define UDP_TX_PACKET_MAX_SIZE 24
27-
#endif
28-
2925
BEGIN_APPLEMIDI_NAMESPACE
3026

3127
static unsigned long now;
@@ -37,7 +33,7 @@ struct AppleMIDISettings : public MIDI_NAMESPACE::DefaultSettings
3733
static const bool Use1ByteParsing = false;
3834
};
3935

40-
template <class UdpClass, class _Settings = DefaultSettings, class _Platform = ArduinoPlatform>
36+
template <class UdpClass, class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
4137
class AppleMIDISession
4238
{
4339
typedef _Settings Settings;
@@ -47,7 +43,6 @@ class AppleMIDISession
4743
// to avoid access by the .ino to internal messages
4844
friend class AppleMIDIParser<UdpClass, Settings, Platform>;
4945
friend class rtpMIDIParser<UdpClass, Settings, Platform>;
50-
friend class MIDI_NAMESPACE::MidiInterface<AppleMIDISession<UdpClass>, AppleMIDISettings>;
5146

5247
public:
5348
AppleMIDISession(const char *name, const uint16_t port = DEFAULT_CONTROL_PORT)
@@ -58,7 +53,7 @@ class AppleMIDISession
5853

5954
void setHandleConnected(void (*fptr)(const ssrc_t&, const char*)) { _connectedCallback = fptr; }
6055
void setHandleDisconnected(void (*fptr)(const ssrc_t&)) { _disconnectedCallback = fptr; }
61-
void setHandleError(void (*fptr)(const ssrc_t&, int32_t)) { _errorCallback = fptr; }
56+
void setHandleError(void (*fptr)(const ssrc_t&, int32_t)) { _exceptionCallback = fptr; }
6257
void setHandleReceivedRtp(void (*fptr)(const ssrc_t&, const Rtp_t&, const int32_t&)) { _receivedRtpCallback = fptr; }
6358
void setHandleStartReceivedMidi(void (*fptr)(const ssrc_t&)) { _startReceivedMidiByteCallback = fptr; }
6459
void setHandleReceivedMidi(void (*fptr)(const ssrc_t&, byte)) { _receivedMidiByteCallback = fptr; }
@@ -72,7 +67,7 @@ class AppleMIDISession
7267
#endif
7368
void sendEndSession();
7469

75-
protected:
70+
public:
7671
static const bool thruActivated = false;
7772

7873
void begin()
@@ -150,8 +145,8 @@ class AppleMIDISession
150145
}
151146
else
152147
{
153-
if (NULL != _errorCallback)
154-
_errorCallback(ssrc, -1);
148+
if (NULL != _exceptionCallback)
149+
_exceptionCallback(ssrc, BufferFullException);
155150
}
156151
}
157152

@@ -204,14 +199,17 @@ class AppleMIDISession
204199
return byte;
205200
};
206201

207-
private:
202+
protected:
208203
UdpClass controlPort;
209204
UdpClass dataPort;
210205

206+
private:
211207
// reading from the network
212208
RtpBuffer_t controlBuffer;
213209
RtpBuffer_t dataBuffer;
214210

211+
byte packetBuffer[Settings::UdpTxPacketMaxSize];
212+
215213
AppleMIDIParser<UdpClass, Settings, Platform> _appleMIDIParser;
216214
rtpMIDIParser<UdpClass, Settings, Platform> _rtpMIDIParser;
217215

@@ -221,7 +219,7 @@ class AppleMIDISession
221219
endReceivedMidiByteCallback _endReceivedMidiByteCallback = nullptr;
222220
receivedRtpCallback _receivedRtpCallback = nullptr;
223221
disconnectedCallback _disconnectedCallback = nullptr;
224-
errorCallback _errorCallback = nullptr;
222+
exceptionCallback _exceptionCallback = nullptr;
225223

226224
// buffer for incoming and outgoing MIDI messages
227225
MidiBuffer_t inMidiBuffer;
@@ -300,3 +298,5 @@ APPLEMIDI_CREATE_INSTANCE(EthernetUDP, MIDI, "Arduino", DEFAULT_CONTROL_PORT);
300298

301299
#define APPLEMIDI_CREATE_DEFAULTSESSION_ESP32_INSTANCE() \
302300
APPLEMIDI_CREATE_INSTANCE(WiFiUDP, MIDI, "ESP32", DEFAULT_CONTROL_PORT);
301+
302+
#include "AppleMIDI_PlatformEnd.h"

0 commit comments

Comments
 (0)