Skip to content

Commit 038d685

Browse files
committed
removed reference to Ethernet.h and templated AppleMidi
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
1 parent 60e7a9f commit 038d685

21 files changed

+1229
-917
lines changed

examples/NoteOnOffEverySec/NoteOnOffEverySec.ino

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

3+
// These need to be included when using standard Ethernet
34
#include <SPI.h>
45
#include <Ethernet.h>
56

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

1415
unsigned long t0 = millis();
1516

17+
APPLEMIDI_CREATE_DEFAULT_INSTANCE(); // see definition in AppleMidi_Defs.h
18+
1619
// -----------------------------------------------------------------------------
1720
//
1821
// -----------------------------------------------------------------------------
@@ -33,24 +36,13 @@ void setup()
3336
;
3437
}
3538

36-
// print your local IP address:
3739
Serial.println();
3840
Serial.print("IP address is ");
39-
for (byte thisByte = 0; thisByte < 4; thisByte++) {
40-
// print the value of each byte of the IP address:
41-
Serial.print(Ethernet.localIP()[thisByte], DEC);
42-
Serial.print(".");
43-
}
44-
Serial.println("");
41+
Serial.println(Ethernet.localIP());
42+
4543
Serial.println("OK, now make sure you an rtpMIDI session that is Enabled");
4644
Serial.print("Add device named Arduino with Host/Port ");
47-
Serial.print(Ethernet.localIP()[0], DEC);
48-
Serial.print(".");
49-
Serial.print(Ethernet.localIP()[1], DEC);
50-
Serial.print(".");
51-
Serial.print(Ethernet.localIP()[2], DEC);
52-
Serial.print(".");
53-
Serial.print(Ethernet.localIP()[3], DEC);
45+
Serial.print(Ethernet.localIP());
5446
Serial.println(":5004");
5547
Serial.println("Then press the Connect button");
5648
Serial.println("Then open a MIDI listener (eg MIDI-OX) and monitor incoming notes");
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// Hardware: Mega 2560 R2 + Ethernet Shield
2+
3+
// These need to be included when using standard Ethernet
4+
#include <ESP8266WiFi.h>
5+
#include <WiFiClient.h>
6+
#include <WiFiUdp.h>
7+
8+
#include "AppleMidi.h"
9+
10+
char ssid[] = "yourNetwork"; // your network SSID (name)
11+
char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)
12+
13+
unsigned long t0 = millis();
14+
15+
APPLEMIDI_CREATE_INSTANCE(WiFiUDP, AppleMIDI); // see definition in AppleMidi_Defs.h
16+
17+
// -----------------------------------------------------------------------------
18+
//
19+
// -----------------------------------------------------------------------------
20+
void setup()
21+
{
22+
// Serial communications and wait for port to open:
23+
Serial.begin(115200);
24+
while (!Serial) {
25+
; // wait for serial port to connect. Needed for Leonardo only
26+
}
27+
28+
Serial.print("Getting IP address...");
29+
30+
31+
WiFi.begin(ssid, password);
32+
33+
while (WiFi.status() != WL_CONNECTED) {
34+
delay(500);
35+
Serial.print(".");
36+
}
37+
Serial.println("");
38+
Serial.println("WiFi connected");
39+
40+
41+
Serial.println();
42+
Serial.print("IP address is ");
43+
Serial.println(WiFi.localIP());
44+
45+
Serial.println("OK, now make sure you an rtpMIDI session that is Enabled");
46+
Serial.print("Add device named Arduino with Host/Port ");
47+
Serial.print(WiFi.localIP());
48+
Serial.println(":5004");
49+
Serial.println("Then press the Connect button");
50+
Serial.println("Then open a MIDI listener (eg MIDI-OX) and monitor incoming notes");
51+
52+
// Create a session and wait for a remote host to connect to us
53+
AppleMIDI.begin("test");
54+
55+
AppleMIDI.OnConnected(OnAppleMidiConnected);
56+
AppleMIDI.OnDisconnected(OnAppleMidiDisconnected);
57+
58+
AppleMIDI.OnReceiveNoteOn(OnAppleMidiNoteOn);
59+
AppleMIDI.OnReceiveNoteOff(OnAppleMidiNoteOff);
60+
61+
Serial.println("Sending NoteOn/Off of note 45, every second");
62+
}
63+
64+
// -----------------------------------------------------------------------------
65+
//
66+
// -----------------------------------------------------------------------------
67+
void loop()
68+
{
69+
// Listen to incoming notes
70+
AppleMIDI.run();
71+
72+
// send a note every second
73+
// (dont cáll delay(1000) as it will stall the pipeline)
74+
if ((millis() - t0) > 1000)
75+
{
76+
t0 = millis();
77+
// Serial.print(".");
78+
79+
int note = 45;
80+
int velocity = 55;
81+
int channel = 1;
82+
83+
AppleMIDI.noteOn(note, velocity, channel);
84+
AppleMIDI.noteOff(note, velocity, channel);
85+
}
86+
}
87+
88+
// ====================================================================================
89+
// Event handlers for incoming MIDI messages
90+
// ====================================================================================
91+
92+
// -----------------------------------------------------------------------------
93+
// rtpMIDI session. Device connected
94+
// -----------------------------------------------------------------------------
95+
void OnAppleMidiConnected(char* name) {
96+
// Serial.print("Connected to session ");
97+
// Serial.println(name);
98+
}
99+
100+
// -----------------------------------------------------------------------------
101+
// rtpMIDI session. Device disconnected
102+
// -----------------------------------------------------------------------------
103+
void OnAppleMidiDisconnected() {
104+
// Serial.println("Disconnected");
105+
}
106+
107+
// -----------------------------------------------------------------------------
108+
//
109+
// -----------------------------------------------------------------------------
110+
void OnAppleMidiNoteOn(byte channel, byte note, byte velocity) {
111+
Serial.print("Incoming NoteOn from channel:");
112+
Serial.print(channel);
113+
Serial.print(" note:");
114+
Serial.print(note);
115+
Serial.print(" velocity:");
116+
Serial.print(velocity);
117+
Serial.println();
118+
}
119+
120+
// -----------------------------------------------------------------------------
121+
//
122+
// -----------------------------------------------------------------------------
123+
void OnAppleMidiNoteOff(byte channel, byte note, byte velocity) {
124+
Serial.print("Incoming NoteOff from channel:");
125+
Serial.print(channel);
126+
Serial.print(" note:");
127+
Serial.print(note);
128+
Serial.print(" velocity:");
129+
Serial.print(velocity);
130+
Serial.println();
131+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
// Hardware: Mega 2560 R2 + Ethernet Shield
2+
3+
// These need to be included when using standard Ethernet
4+
#include <SPI.h>
5+
#include <WiFi.h>
6+
#include <WiFiUdp.h>
7+
8+
#include "AppleMidi.h"
9+
10+
int status = WL_IDLE_STATUS;
11+
char ssid[] = "yourNetwork"; // your network SSID (name)
12+
char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)
13+
int keyIndex = 0; // your network key Index number (needed only for WEP)
14+
15+
16+
unsigned long t0 = millis();
17+
18+
APPLEMIDI_CREATE_INSTANCE(WiFiUDP, AppleMIDI); // see definition in AppleMidi_Defs.h
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+
34+
// check for the presence of the shield:
35+
if (WiFi.status() == WL_NO_SHIELD) {
36+
Serial.println("WiFi shield not present");
37+
// don't continue:
38+
while (true);
39+
}
40+
41+
String fv = WiFi.firmwareVersion();
42+
if ( fv != "1.1.0" )
43+
Serial.println("Please upgrade the firmware");
44+
45+
// attempt to connect to Wifi network:
46+
while ( status != WL_CONNECTED) {
47+
Serial.print("Attempting to connect to SSID: ");
48+
Serial.println(ssid);
49+
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
50+
status = WiFi.begin(ssid);
51+
52+
// wait 10 seconds for connection:
53+
delay(10000);
54+
}
55+
56+
Serial.println();
57+
Serial.print("IP address is ");
58+
Serial.println(WiFi.localIP());
59+
60+
Serial.println("OK, now make sure you an rtpMIDI session that is Enabled");
61+
Serial.print("Add device named Arduino with Host/Port ");
62+
Serial.print(WiFi.localIP());
63+
Serial.println(":5004");
64+
Serial.println("Then press the Connect button");
65+
Serial.println("Then open a MIDI listener (eg MIDI-OX) and monitor incoming notes");
66+
67+
// Create a session and wait for a remote host to connect to us
68+
AppleMIDI.begin("test");
69+
70+
AppleMIDI.OnConnected(OnAppleMidiConnected);
71+
AppleMIDI.OnDisconnected(OnAppleMidiDisconnected);
72+
73+
AppleMIDI.OnReceiveNoteOn(OnAppleMidiNoteOn);
74+
AppleMIDI.OnReceiveNoteOff(OnAppleMidiNoteOff);
75+
76+
Serial.println("Sending NoteOn/Off of note 45, every second");
77+
}
78+
79+
// -----------------------------------------------------------------------------
80+
//
81+
// -----------------------------------------------------------------------------
82+
void loop()
83+
{
84+
// Listen to incoming notes
85+
AppleMIDI.run();
86+
87+
// send a note every second
88+
// (dont cáll delay(1000) as it will stall the pipeline)
89+
if ((millis() - t0) > 1000)
90+
{
91+
t0 = millis();
92+
// Serial.print(".");
93+
94+
int note = 45;
95+
int velocity = 55;
96+
int channel = 1;
97+
98+
AppleMIDI.noteOn(note, velocity, channel);
99+
AppleMIDI.noteOff(note, velocity, channel);
100+
}
101+
}
102+
103+
// ====================================================================================
104+
// Event handlers for incoming MIDI messages
105+
// ====================================================================================
106+
107+
// -----------------------------------------------------------------------------
108+
// rtpMIDI session. Device connected
109+
// -----------------------------------------------------------------------------
110+
void OnAppleMidiConnected(char* name) {
111+
// Serial.print("Connected to session ");
112+
// Serial.println(name);
113+
}
114+
115+
// -----------------------------------------------------------------------------
116+
// rtpMIDI session. Device disconnected
117+
// -----------------------------------------------------------------------------
118+
void OnAppleMidiDisconnected() {
119+
// Serial.println("Disconnected");
120+
}
121+
122+
// -----------------------------------------------------------------------------
123+
//
124+
// -----------------------------------------------------------------------------
125+
void OnAppleMidiNoteOn(byte channel, byte note, byte velocity) {
126+
Serial.print("Incoming NoteOn from channel:");
127+
Serial.print(channel);
128+
Serial.print(" note:");
129+
Serial.print(note);
130+
Serial.print(" velocity:");
131+
Serial.print(velocity);
132+
Serial.println();
133+
}
134+
135+
// -----------------------------------------------------------------------------
136+
//
137+
// -----------------------------------------------------------------------------
138+
void OnAppleMidiNoteOff(byte channel, byte note, byte velocity) {
139+
Serial.print("Incoming NoteOff from channel:");
140+
Serial.print(channel);
141+
Serial.print(" note:");
142+
Serial.print(note);
143+
Serial.print(" velocity:");
144+
Serial.print(velocity);
145+
Serial.println();
146+
}

src/AppleMidi.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,3 @@
1515
#if !(APPLEMIDI_BUILD_INPUT) && !(APPLEMIDI_BUILD_OUTPUT)
1616
# error To use AppleMIDI, you need to enable at least input or output.
1717
#endif
18-
19-
#if APPLEMIDI_AUTO_INSTANCIATE && defined(ARDUINO)
20-
APPLEMIDI_CREATE_INSTANCE;
21-
#endif

0 commit comments

Comments
 (0)