Skip to content

Commit 094cc86

Browse files
committed
Multiple sessions and test IDE 1.6.6
Fixed bugs for multiple sessions (local and remote) and added examples to test multiple sessions (need feedback if this is working correctly) IDE 1.6.6
1 parent fe048ea commit 094cc86

File tree

17 files changed

+755
-324
lines changed

17 files changed

+755
-324
lines changed

examples/NoteOnOffEverySecEsp8266/NoteOnOffEverySecEsp8266.ino renamed to examples/Esp8266_NoteOnOffEverySec/Esp8266_NoteOnOffEverySec.ino

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
#include "AppleMidi.h"
77

8-
char ssid[] = "The Mighty Network"; // your network SSID (name)
9-
char pass[] = "0208196700"; // your network password (use for WPA, or use as key for WEP)
8+
char ssid[] = "yourNetwork"; // your network SSID (name)
9+
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)
1010

1111
unsigned long t0 = millis();
1212
bool isConnected = false;
@@ -91,18 +91,18 @@ void loop()
9191
// -----------------------------------------------------------------------------
9292
// rtpMIDI session. Device connected
9393
// -----------------------------------------------------------------------------
94-
void OnAppleMidiConnected(char* name) {
94+
void OnAppleMidiConnected(long unsigned int ssrc, char* name) {
9595
isConnected = true;
96-
// Serial.print("Connected to session ");
97-
// Serial.println(name);
96+
Serial.print("Connected to session ");
97+
Serial.println(name);
9898
}
9999

100100
// -----------------------------------------------------------------------------
101101
// rtpMIDI session. Device disconnected
102102
// -----------------------------------------------------------------------------
103-
void OnAppleMidiDisconnected() {
103+
void OnAppleMidiDisconnected(long unsigned int ssrc) {
104104
isConnected = false;
105-
// Serial.println("Disconnected");
105+
Serial.println("Disconnected");
106106
}
107107

108108
// -----------------------------------------------------------------------------
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
2+
#include <SPI.h>
3+
#include <Ethernet.h>
4+
5+
#include "AppleMidi.h"
6+
7+
// Enter a MAC address for your controller below.
8+
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
9+
byte mac[] = {
10+
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
11+
};
12+
13+
unsigned long t0 = millis();
14+
bool isConnected = false;
15+
16+
APPLEMIDI_CREATE_DEFAULT_INSTANCE(); // see definition in AppleMidi_Defs.h
17+
18+
IPAddress remote(192, 168, 0, 119); // replace with remote ip
19+
20+
// -----------------------------------------------------------------------------
21+
//
22+
// -----------------------------------------------------------------------------
23+
void setup()
24+
{
25+
// Serial communications and wait for port to open:
26+
Serial.begin(115200);
27+
while (!Serial) {
28+
; // wait for serial port to connect. Needed for Leonardo only
29+
}
30+
31+
Serial.print("Getting IP address...");
32+
33+
if (Ethernet.begin(mac) == 0) {
34+
Serial.println();
35+
Serial.println( "Failed DHCP, check network cable & reboot" );
36+
for (;;)
37+
;
38+
}
39+
40+
Serial.println();
41+
Serial.print("IP address is ");
42+
Serial.println(Ethernet.localIP());
43+
44+
Serial.print("AppleMIDI Session ");
45+
Serial.print(AppleMIDI.getSessionName());
46+
Serial.print(" with SSRC 0x");
47+
Serial.println(AppleMIDI.getSynchronizationSource(), HEX);
48+
49+
// Create a session and wait for a remote host to connect to us
50+
AppleMIDI.begin("test");
51+
52+
Serial.print("OK, now make an active connection to ");
53+
Serial.println(remote);
54+
55+
// This is the invite to the remote participant
56+
AppleMIDI.invite(remote);
57+
58+
AppleMIDI.OnConnected(OnAppleMidiConnected);
59+
AppleMIDI.OnDisconnected(OnAppleMidiDisconnected);
60+
61+
AppleMIDI.OnReceiveNoteOn(OnAppleMidiNoteOn);
62+
AppleMIDI.OnReceiveNoteOff(OnAppleMidiNoteOff);
63+
64+
Serial.println("Sending NoteOn/Off of note 45, every second");
65+
}
66+
67+
// -----------------------------------------------------------------------------
68+
//
69+
// -----------------------------------------------------------------------------
70+
void loop()
71+
{
72+
// Listen to incoming notes
73+
AppleMIDI.run();
74+
75+
// send a note every second
76+
// (dont cáll delay(1000) as it will stall the pipeline)
77+
if (isConnected && (millis() - t0) > 1000)
78+
{
79+
t0 = millis();
80+
// Serial.print(".");
81+
82+
int note = 45;
83+
int velocity = 55;
84+
int channel = 1;
85+
86+
AppleMIDI.noteOn(note, velocity, channel);
87+
AppleMIDI.noteOff(note, velocity, channel);
88+
}
89+
}
90+
91+
// ====================================================================================
92+
// Event handlers for incoming MIDI messages
93+
// ====================================================================================
94+
95+
// -----------------------------------------------------------------------------
96+
// rtpMIDI session. Device connected
97+
// -----------------------------------------------------------------------------
98+
void OnAppleMidiConnected(long unsigned int ssrc, char* name) {
99+
isConnected = true;
100+
Serial.print("Connected to session ");
101+
Serial.println(name);
102+
}
103+
104+
// -----------------------------------------------------------------------------
105+
// rtpMIDI session. Device disconnected
106+
// -----------------------------------------------------------------------------
107+
void OnAppleMidiDisconnected(long unsigned int ssrc) {
108+
isConnected = false;
109+
Serial.println("Disconnected");
110+
}
111+
112+
// -----------------------------------------------------------------------------
113+
//
114+
// -----------------------------------------------------------------------------
115+
void OnAppleMidiNoteOn(byte channel, byte note, byte velocity) {
116+
Serial.print("Incoming NoteOn from channel:");
117+
Serial.print(channel);
118+
Serial.print(" note:");
119+
Serial.print(note);
120+
Serial.print(" velocity:");
121+
Serial.print(velocity);
122+
Serial.println();
123+
}
124+
125+
// -----------------------------------------------------------------------------
126+
//
127+
// -----------------------------------------------------------------------------
128+
void OnAppleMidiNoteOff(byte channel, byte note, byte velocity) {
129+
Serial.print("Incoming NoteOff from channel:");
130+
Serial.print(channel);
131+
Serial.print(" note:");
132+
Serial.print(note);
133+
Serial.print(" velocity:");
134+
Serial.print(velocity);
135+
Serial.println();
136+
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
2+
#include <SPI.h>
3+
#include <Ethernet.h>
4+
5+
#include "AppleMidi.h"
6+
7+
// Enter a MAC address for your controller below.
8+
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
9+
byte mac[] = {
10+
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
11+
};
12+
13+
unsigned long t0 = millis();
14+
bool isConnected = false;
15+
16+
APPLEMIDI_CREATE_DEFAULT_INSTANCE(); // see definition in AppleMidi_Defs.h
17+
18+
IPAddress remote1(192, 168, 0, 119); // replace with remote ip
19+
IPAddress remote2(192, 168, 0, 127); // replace with remote ip
20+
21+
// -----------------------------------------------------------------------------
22+
//
23+
// -----------------------------------------------------------------------------
24+
void setup()
25+
{
26+
// Serial communications and wait for port to open:
27+
Serial.begin(115200);
28+
while (!Serial) {
29+
; // wait for serial port to connect. Needed for Leonardo only
30+
}
31+
32+
Serial.print("Getting IP address...");
33+
34+
if (Ethernet.begin(mac) == 0) {
35+
Serial.println();
36+
Serial.println( "Failed DHCP, check network cable & reboot" );
37+
for (;;)
38+
;
39+
}
40+
41+
Serial.println();
42+
Serial.print("IP address is ");
43+
Serial.println(Ethernet.localIP());
44+
45+
// Create a session and wait for a remote host to connect to us
46+
AppleMIDI.begin("Arduino");
47+
48+
Serial.print("AppleMIDI Session ");
49+
Serial.print(AppleMIDI.getSessionName());
50+
Serial.print(" with SSRC 0x");
51+
Serial.println(AppleMIDI.getSynchronizationSource(), HEX);
52+
53+
Serial.print("OK, now make an active connection to ");
54+
Serial.print(remote1);
55+
Serial.print(" and ");
56+
Serial.println(remote2);
57+
58+
// This is the invite to the remote participant
59+
AppleMIDI.invite(remote1);
60+
AppleMIDI.invite(remote2);
61+
62+
AppleMIDI.OnConnected(OnAppleMidiConnected);
63+
AppleMIDI.OnDisconnected(OnAppleMidiDisconnected);
64+
65+
AppleMIDI.OnReceiveNoteOn(OnAppleMidiNoteOn);
66+
AppleMIDI.OnReceiveNoteOff(OnAppleMidiNoteOff);
67+
68+
Serial.println("Sending NoteOn/Off of note 45, every second");
69+
}
70+
71+
// -----------------------------------------------------------------------------
72+
//
73+
// -----------------------------------------------------------------------------
74+
void loop()
75+
{
76+
// Listen to incoming notes
77+
AppleMIDI.run();
78+
79+
// send a note every second
80+
// (dont cáll delay(1000) as it will stall the pipeline)
81+
if (isConnected && (millis() - t0) > 250)
82+
{
83+
t0 = millis();
84+
// Serial.print(".");
85+
86+
int note = 45;
87+
int velocity = 55;
88+
int channel = 1;
89+
90+
AppleMIDI.noteOn(note, velocity, channel);
91+
AppleMIDI.noteOff(note, velocity, channel);
92+
}
93+
}
94+
95+
// ====================================================================================
96+
// Event handlers for incoming MIDI messages
97+
// ====================================================================================
98+
99+
// -----------------------------------------------------------------------------
100+
// rtpMIDI session. Device connected
101+
// -----------------------------------------------------------------------------
102+
void OnAppleMidiConnected(long unsigned int ssrc, char* name) {
103+
isConnected = true;
104+
Serial.print("Connected to session ");
105+
Serial.println(name);
106+
}
107+
108+
// -----------------------------------------------------------------------------
109+
// rtpMIDI session. Device disconnected
110+
// -----------------------------------------------------------------------------
111+
void OnAppleMidiDisconnected(long unsigned int ssrc) {
112+
isConnected = false;
113+
Serial.println("Disconnected");
114+
}
115+
116+
// -----------------------------------------------------------------------------
117+
//
118+
// -----------------------------------------------------------------------------
119+
void OnAppleMidiNoteOn(byte channel, byte note, byte velocity) {
120+
Serial.print("Incoming NoteOn from channel:");
121+
Serial.print(channel);
122+
Serial.print(" note:");
123+
Serial.print(note);
124+
Serial.print(" velocity:");
125+
Serial.print(velocity);
126+
Serial.println();
127+
}
128+
129+
// -----------------------------------------------------------------------------
130+
//
131+
// -----------------------------------------------------------------------------
132+
void OnAppleMidiNoteOff(byte channel, byte note, byte velocity) {
133+
Serial.print("Incoming NoteOff from channel:");
134+
Serial.print(channel);
135+
Serial.print(" note:");
136+
Serial.print(note);
137+
Serial.print(" velocity:");
138+
Serial.print(velocity);
139+
Serial.println();
140+
}

examples/NoteOnOffEverySec/NoteOnOffEverySec.ino renamed to examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,18 @@ void loop()
8989
// -----------------------------------------------------------------------------
9090
// rtpMIDI session. Device connected
9191
// -----------------------------------------------------------------------------
92-
void OnAppleMidiConnected(char* name) {
92+
void OnAppleMidiConnected(long unsigned int ssrc, char* name) {
9393
isConnected = true;
94-
// Serial.print("Connected to session ");
95-
// Serial.println(name);
94+
Serial.print("Connected to session ");
95+
Serial.println(name);
9696
}
9797

9898
// -----------------------------------------------------------------------------
9999
// rtpMIDI session. Device disconnected
100100
// -----------------------------------------------------------------------------
101-
void OnAppleMidiDisconnected() {
101+
void OnAppleMidiDisconnected(long unsigned int ssrc) {
102102
isConnected = false;
103-
// Serial.println("Disconnected");
103+
Serial.println("Disconnected");
104104
}
105105

106106
// -----------------------------------------------------------------------------

examples/NoteOnOffEverySecWifi/NoteOnOffEverySecWifi.ino renamed to examples/Wifi_NoteOnOffEverySec/Wifi_NoteOnOffEverySec.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Hardware: Mega 2560 R2 + Ethernet Shield
1+
// Hardware: Mega 2560 R2 + Wifi Shield
22

33
// These need to be included when using standard Ethernet
44
#include <SPI.h>
@@ -107,18 +107,18 @@ void loop()
107107
// -----------------------------------------------------------------------------
108108
// rtpMIDI session. Device connected
109109
// -----------------------------------------------------------------------------
110-
void OnAppleMidiConnected(char* name) {
110+
void OnAppleMidiConnected(long unsigned int ssrc, char* name) {
111111
isConnected = true;
112-
// Serial.print("Connected to session ");
113-
// Serial.println(name);
112+
Serial.print("Connected to session ");
113+
Serial.println(name);
114114
}
115115

116116
// -----------------------------------------------------------------------------
117117
// rtpMIDI session. Device disconnected
118118
// -----------------------------------------------------------------------------
119-
void OnAppleMidiDisconnected() {
119+
void OnAppleMidiDisconnected(long unsigned int ssrc) {
120120
isConnected = false;
121-
// Serial.println("Disconnected");
121+
Serial.println("Disconnected");
122122
}
123123

124124
// -----------------------------------------------------------------------------

keywords.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#######################################
1414

1515
begin KEYWORD2
16+
invite KEYWORD2
17+
getSessionName KEYWORD2
18+
getSynchronizationSource KEYWORD2
1619
run KEYWORD2
1720
noteOn KEYWORD2
1821
noteOff KEYWORD2
@@ -32,6 +35,11 @@ Continue KEYWORD2
3235
stop KEYWORD2
3336
activeSensing KEYWORD2
3437
systemReset KEYWORD2
38+
timeCodeQuarterFrame KEYWORD2
39+
sysEx KEYWORD2
40+
afterTouch KEYWORD2
41+
polyPressure KEYWORD2
42+
tick KEYWORD2
3543

3644
#######################################
3745
# Instances (KEYWORD3)

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name=Arduino AppleMIDI
1+
name=AppleMIDI
22
version=1.0.0
33
author=lathoub
44
maintainer=lathoub <[email protected]>

0 commit comments

Comments
 (0)