-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
17 changed files
with
755 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
examples/EthernetShield_InitiateSession/EthernetShield_InitiateSession.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
|
||
#include <SPI.h> | ||
#include <Ethernet.h> | ||
|
||
#include "AppleMidi.h" | ||
|
||
// Enter a MAC address for your controller below. | ||
// Newer Ethernet shields have a MAC address printed on a sticker on the shield | ||
byte mac[] = { | ||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED | ||
}; | ||
|
||
unsigned long t0 = millis(); | ||
bool isConnected = false; | ||
|
||
APPLEMIDI_CREATE_DEFAULT_INSTANCE(); // see definition in AppleMidi_Defs.h | ||
|
||
IPAddress remote(192, 168, 0, 119); // replace with remote ip | ||
|
||
// ----------------------------------------------------------------------------- | ||
// | ||
// ----------------------------------------------------------------------------- | ||
void setup() | ||
{ | ||
// Serial communications and wait for port to open: | ||
Serial.begin(115200); | ||
while (!Serial) { | ||
; // wait for serial port to connect. Needed for Leonardo only | ||
} | ||
|
||
Serial.print("Getting IP address..."); | ||
|
||
if (Ethernet.begin(mac) == 0) { | ||
Serial.println(); | ||
Serial.println( "Failed DHCP, check network cable & reboot" ); | ||
for (;;) | ||
; | ||
} | ||
|
||
Serial.println(); | ||
Serial.print("IP address is "); | ||
Serial.println(Ethernet.localIP()); | ||
|
||
Serial.print("AppleMIDI Session "); | ||
Serial.print(AppleMIDI.getSessionName()); | ||
Serial.print(" with SSRC 0x"); | ||
Serial.println(AppleMIDI.getSynchronizationSource(), HEX); | ||
|
||
// Create a session and wait for a remote host to connect to us | ||
AppleMIDI.begin("test"); | ||
|
||
Serial.print("OK, now make an active connection to "); | ||
Serial.println(remote); | ||
|
||
// This is the invite to the remote participant | ||
AppleMIDI.invite(remote); | ||
|
||
AppleMIDI.OnConnected(OnAppleMidiConnected); | ||
AppleMIDI.OnDisconnected(OnAppleMidiDisconnected); | ||
|
||
AppleMIDI.OnReceiveNoteOn(OnAppleMidiNoteOn); | ||
AppleMIDI.OnReceiveNoteOff(OnAppleMidiNoteOff); | ||
|
||
Serial.println("Sending NoteOn/Off of note 45, every second"); | ||
} | ||
|
||
// ----------------------------------------------------------------------------- | ||
// | ||
// ----------------------------------------------------------------------------- | ||
void loop() | ||
{ | ||
// Listen to incoming notes | ||
AppleMIDI.run(); | ||
|
||
// send a note every second | ||
// (dont cáll delay(1000) as it will stall the pipeline) | ||
if (isConnected && (millis() - t0) > 1000) | ||
{ | ||
t0 = millis(); | ||
// Serial.print("."); | ||
|
||
int note = 45; | ||
int velocity = 55; | ||
int channel = 1; | ||
|
||
AppleMIDI.noteOn(note, velocity, channel); | ||
AppleMIDI.noteOff(note, velocity, channel); | ||
} | ||
} | ||
|
||
// ==================================================================================== | ||
// Event handlers for incoming MIDI messages | ||
// ==================================================================================== | ||
|
||
// ----------------------------------------------------------------------------- | ||
// rtpMIDI session. Device connected | ||
// ----------------------------------------------------------------------------- | ||
void OnAppleMidiConnected(long unsigned int ssrc, char* name) { | ||
isConnected = true; | ||
Serial.print("Connected to session "); | ||
Serial.println(name); | ||
} | ||
|
||
// ----------------------------------------------------------------------------- | ||
// rtpMIDI session. Device disconnected | ||
// ----------------------------------------------------------------------------- | ||
void OnAppleMidiDisconnected(long unsigned int ssrc) { | ||
isConnected = false; | ||
Serial.println("Disconnected"); | ||
} | ||
|
||
// ----------------------------------------------------------------------------- | ||
// | ||
// ----------------------------------------------------------------------------- | ||
void OnAppleMidiNoteOn(byte channel, byte note, byte velocity) { | ||
Serial.print("Incoming NoteOn from channel:"); | ||
Serial.print(channel); | ||
Serial.print(" note:"); | ||
Serial.print(note); | ||
Serial.print(" velocity:"); | ||
Serial.print(velocity); | ||
Serial.println(); | ||
} | ||
|
||
// ----------------------------------------------------------------------------- | ||
// | ||
// ----------------------------------------------------------------------------- | ||
void OnAppleMidiNoteOff(byte channel, byte note, byte velocity) { | ||
Serial.print("Incoming NoteOff from channel:"); | ||
Serial.print(channel); | ||
Serial.print(" note:"); | ||
Serial.print(note); | ||
Serial.print(" velocity:"); | ||
Serial.print(velocity); | ||
Serial.println(); | ||
} |
140 changes: 140 additions & 0 deletions
140
examples/EthernetShield_InitiateSessions/EthernetShield_InitiateSessions.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
|
||
#include <SPI.h> | ||
#include <Ethernet.h> | ||
|
||
#include "AppleMidi.h" | ||
|
||
// Enter a MAC address for your controller below. | ||
// Newer Ethernet shields have a MAC address printed on a sticker on the shield | ||
byte mac[] = { | ||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED | ||
}; | ||
|
||
unsigned long t0 = millis(); | ||
bool isConnected = false; | ||
|
||
APPLEMIDI_CREATE_DEFAULT_INSTANCE(); // see definition in AppleMidi_Defs.h | ||
|
||
IPAddress remote1(192, 168, 0, 119); // replace with remote ip | ||
IPAddress remote2(192, 168, 0, 127); // replace with remote ip | ||
|
||
// ----------------------------------------------------------------------------- | ||
// | ||
// ----------------------------------------------------------------------------- | ||
void setup() | ||
{ | ||
// Serial communications and wait for port to open: | ||
Serial.begin(115200); | ||
while (!Serial) { | ||
; // wait for serial port to connect. Needed for Leonardo only | ||
} | ||
|
||
Serial.print("Getting IP address..."); | ||
|
||
if (Ethernet.begin(mac) == 0) { | ||
Serial.println(); | ||
Serial.println( "Failed DHCP, check network cable & reboot" ); | ||
for (;;) | ||
; | ||
} | ||
|
||
Serial.println(); | ||
Serial.print("IP address is "); | ||
Serial.println(Ethernet.localIP()); | ||
|
||
// Create a session and wait for a remote host to connect to us | ||
AppleMIDI.begin("Arduino"); | ||
|
||
Serial.print("AppleMIDI Session "); | ||
Serial.print(AppleMIDI.getSessionName()); | ||
Serial.print(" with SSRC 0x"); | ||
Serial.println(AppleMIDI.getSynchronizationSource(), HEX); | ||
|
||
Serial.print("OK, now make an active connection to "); | ||
Serial.print(remote1); | ||
Serial.print(" and "); | ||
Serial.println(remote2); | ||
|
||
// This is the invite to the remote participant | ||
AppleMIDI.invite(remote1); | ||
AppleMIDI.invite(remote2); | ||
|
||
AppleMIDI.OnConnected(OnAppleMidiConnected); | ||
AppleMIDI.OnDisconnected(OnAppleMidiDisconnected); | ||
|
||
AppleMIDI.OnReceiveNoteOn(OnAppleMidiNoteOn); | ||
AppleMIDI.OnReceiveNoteOff(OnAppleMidiNoteOff); | ||
|
||
Serial.println("Sending NoteOn/Off of note 45, every second"); | ||
} | ||
|
||
// ----------------------------------------------------------------------------- | ||
// | ||
// ----------------------------------------------------------------------------- | ||
void loop() | ||
{ | ||
// Listen to incoming notes | ||
AppleMIDI.run(); | ||
|
||
// send a note every second | ||
// (dont cáll delay(1000) as it will stall the pipeline) | ||
if (isConnected && (millis() - t0) > 250) | ||
{ | ||
t0 = millis(); | ||
// Serial.print("."); | ||
|
||
int note = 45; | ||
int velocity = 55; | ||
int channel = 1; | ||
|
||
AppleMIDI.noteOn(note, velocity, channel); | ||
AppleMIDI.noteOff(note, velocity, channel); | ||
} | ||
} | ||
|
||
// ==================================================================================== | ||
// Event handlers for incoming MIDI messages | ||
// ==================================================================================== | ||
|
||
// ----------------------------------------------------------------------------- | ||
// rtpMIDI session. Device connected | ||
// ----------------------------------------------------------------------------- | ||
void OnAppleMidiConnected(long unsigned int ssrc, char* name) { | ||
isConnected = true; | ||
Serial.print("Connected to session "); | ||
Serial.println(name); | ||
} | ||
|
||
// ----------------------------------------------------------------------------- | ||
// rtpMIDI session. Device disconnected | ||
// ----------------------------------------------------------------------------- | ||
void OnAppleMidiDisconnected(long unsigned int ssrc) { | ||
isConnected = false; | ||
Serial.println("Disconnected"); | ||
} | ||
|
||
// ----------------------------------------------------------------------------- | ||
// | ||
// ----------------------------------------------------------------------------- | ||
void OnAppleMidiNoteOn(byte channel, byte note, byte velocity) { | ||
Serial.print("Incoming NoteOn from channel:"); | ||
Serial.print(channel); | ||
Serial.print(" note:"); | ||
Serial.print(note); | ||
Serial.print(" velocity:"); | ||
Serial.print(velocity); | ||
Serial.println(); | ||
} | ||
|
||
// ----------------------------------------------------------------------------- | ||
// | ||
// ----------------------------------------------------------------------------- | ||
void OnAppleMidiNoteOff(byte channel, byte note, byte velocity) { | ||
Serial.print("Incoming NoteOff from channel:"); | ||
Serial.print(channel); | ||
Serial.print(" note:"); | ||
Serial.print(note); | ||
Serial.print(" velocity:"); | ||
Serial.print(velocity); | ||
Serial.println(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name=Arduino AppleMIDI | ||
name=AppleMIDI | ||
version=1.0.0 | ||
author=lathoub | ||
maintainer=lathoub <[email protected]> | ||
|
Oops, something went wrong.