Skip to content

Commit

Permalink
Multiple sessions and test IDE 1.6.6
Browse files Browse the repository at this point in the history
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
lathoub committed Nov 29, 2015
1 parent fe048ea commit 094cc86
Show file tree
Hide file tree
Showing 17 changed files with 755 additions and 324 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

#include "AppleMidi.h"

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

unsigned long t0 = millis();
bool isConnected = false;
Expand Down Expand Up @@ -91,18 +91,18 @@ void loop()
// -----------------------------------------------------------------------------
// rtpMIDI session. Device connected
// -----------------------------------------------------------------------------
void OnAppleMidiConnected(char* name) {
void OnAppleMidiConnected(long unsigned int ssrc, char* name) {
isConnected = true;
// Serial.print("Connected to session ");
// Serial.println(name);
Serial.print("Connected to session ");
Serial.println(name);
}

// -----------------------------------------------------------------------------
// rtpMIDI session. Device disconnected
// -----------------------------------------------------------------------------
void OnAppleMidiDisconnected() {
void OnAppleMidiDisconnected(long unsigned int ssrc) {
isConnected = false;
// Serial.println("Disconnected");
Serial.println("Disconnected");
}

// -----------------------------------------------------------------------------
Expand Down
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();
}
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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ void loop()
// -----------------------------------------------------------------------------
// rtpMIDI session. Device connected
// -----------------------------------------------------------------------------
void OnAppleMidiConnected(char* name) {
void OnAppleMidiConnected(long unsigned int ssrc, char* name) {
isConnected = true;
// Serial.print("Connected to session ");
// Serial.println(name);
Serial.print("Connected to session ");
Serial.println(name);
}

// -----------------------------------------------------------------------------
// rtpMIDI session. Device disconnected
// -----------------------------------------------------------------------------
void OnAppleMidiDisconnected() {
void OnAppleMidiDisconnected(long unsigned int ssrc) {
isConnected = false;
// Serial.println("Disconnected");
Serial.println("Disconnected");
}

// -----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Hardware: Mega 2560 R2 + Ethernet Shield
// Hardware: Mega 2560 R2 + Wifi Shield

// These need to be included when using standard Ethernet
#include <SPI.h>
Expand Down Expand Up @@ -107,18 +107,18 @@ void loop()
// -----------------------------------------------------------------------------
// rtpMIDI session. Device connected
// -----------------------------------------------------------------------------
void OnAppleMidiConnected(char* name) {
void OnAppleMidiConnected(long unsigned int ssrc, char* name) {
isConnected = true;
// Serial.print("Connected to session ");
// Serial.println(name);
Serial.print("Connected to session ");
Serial.println(name);
}

// -----------------------------------------------------------------------------
// rtpMIDI session. Device disconnected
// -----------------------------------------------------------------------------
void OnAppleMidiDisconnected() {
void OnAppleMidiDisconnected(long unsigned int ssrc) {
isConnected = false;
// Serial.println("Disconnected");
Serial.println("Disconnected");
}

// -----------------------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#######################################

begin KEYWORD2
invite KEYWORD2
getSessionName KEYWORD2
getSynchronizationSource KEYWORD2
run KEYWORD2
noteOn KEYWORD2
noteOff KEYWORD2
Expand All @@ -32,6 +35,11 @@ Continue KEYWORD2
stop KEYWORD2
activeSensing KEYWORD2
systemReset KEYWORD2
timeCodeQuarterFrame KEYWORD2
sysEx KEYWORD2
afterTouch KEYWORD2
polyPressure KEYWORD2
tick KEYWORD2

#######################################
# Instances (KEYWORD3)
Expand Down
2 changes: 1 addition & 1 deletion library.properties
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]>
Expand Down
Loading

0 comments on commit 094cc86

Please sign in to comment.