Skip to content

Commit

Permalink
removed reference to Ethernet.h and templated AppleMidi
Browse files Browse the repository at this point in the history
removed reference to Ethernet.h and templated AppleMidi, so that other
ethernet libraries can be used. Wireless (wifishield and Esp8266) is not
tested.
Add 2 UNTESTED examples
  • Loading branch information
lathoub committed Aug 15, 2015
1 parent 60e7a9f commit 038d685
Show file tree
Hide file tree
Showing 21 changed files with 1,229 additions and 917 deletions.
20 changes: 6 additions & 14 deletions examples/NoteOnOffEverySec/NoteOnOffEverySec.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Hardware: Mega 2560 R2 + Ethernet Shield

// These need to be included when using standard Ethernet
#include <SPI.h>
#include <Ethernet.h>

Expand All @@ -13,6 +14,8 @@ byte mac[] = {

unsigned long t0 = millis();

APPLEMIDI_CREATE_DEFAULT_INSTANCE(); // see definition in AppleMidi_Defs.h

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
Expand All @@ -33,24 +36,13 @@ void setup()
;
}

// print your local IP address:
Serial.println();
Serial.print("IP address is ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println("");
Serial.println(Ethernet.localIP());

Serial.println("OK, now make sure you an rtpMIDI session that is Enabled");
Serial.print("Add device named Arduino with Host/Port ");
Serial.print(Ethernet.localIP()[0], DEC);
Serial.print(".");
Serial.print(Ethernet.localIP()[1], DEC);
Serial.print(".");
Serial.print(Ethernet.localIP()[2], DEC);
Serial.print(".");
Serial.print(Ethernet.localIP()[3], DEC);
Serial.print(Ethernet.localIP());
Serial.println(":5004");
Serial.println("Then press the Connect button");
Serial.println("Then open a MIDI listener (eg MIDI-OX) and monitor incoming notes");
Expand Down
131 changes: 131 additions & 0 deletions examples/NoteOnOffEverySecEsp8266/NoteOnOffEverySecEso8266.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// Hardware: Mega 2560 R2 + Ethernet Shield

// These need to be included when using standard Ethernet
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>

#include "AppleMidi.h"

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

unsigned long t0 = millis();

APPLEMIDI_CREATE_INSTANCE(WiFiUDP, AppleMIDI); // see definition in AppleMidi_Defs.h

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
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...");


WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");


Serial.println();
Serial.print("IP address is ");
Serial.println(WiFi.localIP());

Serial.println("OK, now make sure you an rtpMIDI session that is Enabled");
Serial.print("Add device named Arduino with Host/Port ");
Serial.print(WiFi.localIP());
Serial.println(":5004");
Serial.println("Then press the Connect button");
Serial.println("Then open a MIDI listener (eg MIDI-OX) and monitor incoming notes");

// Create a session and wait for a remote host to connect to us
AppleMIDI.begin("test");

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 ((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(char* name) {
// Serial.print("Connected to session ");
// Serial.println(name);
}

// -----------------------------------------------------------------------------
// rtpMIDI session. Device disconnected
// -----------------------------------------------------------------------------
void OnAppleMidiDisconnected() {
// 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();
}
146 changes: 146 additions & 0 deletions examples/NoteOnOffEverySecWifi/NoteOnOffEverySecWifi.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// Hardware: Mega 2560 R2 + Ethernet Shield

// These need to be included when using standard Ethernet
#include <SPI.h>
#include <WiFi.h>
#include <WiFiUdp.h>

#include "AppleMidi.h"

int status = WL_IDLE_STATUS;
char ssid[] = "yourNetwork"; // your network SSID (name)
char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key Index number (needed only for WEP)


unsigned long t0 = millis();

APPLEMIDI_CREATE_INSTANCE(WiFiUDP, AppleMIDI); // see definition in AppleMidi_Defs.h

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
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...");


// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while (true);
}

String fv = WiFi.firmwareVersion();
if ( fv != "1.1.0" )
Serial.println("Please upgrade the firmware");

// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid);

// wait 10 seconds for connection:
delay(10000);
}

Serial.println();
Serial.print("IP address is ");
Serial.println(WiFi.localIP());

Serial.println("OK, now make sure you an rtpMIDI session that is Enabled");
Serial.print("Add device named Arduino with Host/Port ");
Serial.print(WiFi.localIP());
Serial.println(":5004");
Serial.println("Then press the Connect button");
Serial.println("Then open a MIDI listener (eg MIDI-OX) and monitor incoming notes");

// Create a session and wait for a remote host to connect to us
AppleMIDI.begin("test");

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 ((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(char* name) {
// Serial.print("Connected to session ");
// Serial.println(name);
}

// -----------------------------------------------------------------------------
// rtpMIDI session. Device disconnected
// -----------------------------------------------------------------------------
void OnAppleMidiDisconnected() {
// 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();
}
4 changes: 0 additions & 4 deletions src/AppleMidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,3 @@
#if !(APPLEMIDI_BUILD_INPUT) && !(APPLEMIDI_BUILD_OUTPUT)
# error To use AppleMIDI, you need to enable at least input or output.
#endif

#if APPLEMIDI_AUTO_INSTANCIATE && defined(ARDUINO)
APPLEMIDI_CREATE_INSTANCE;
#endif
Loading

0 comments on commit 038d685

Please sign in to comment.