Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
187 commits
Select commit Hold shift + click to select a range
03378d4
working on new version - initial upload
lathoub Sep 18, 2019
47f25ba
working on new version
lathoub Sep 19, 2019
57911d6
more
lathoub Sep 20, 2019
e05f82b
more
lathoub Sep 21, 2019
ddf65b4
we can do incoming MIDI messages :-)
lathoub Sep 22, 2019
dbcd244
more
lathoub Sep 22, 2019
da416f9
more
lathoub Sep 22, 2019
fed41e9
check for long buffer
lathoub Sep 23, 2019
a08b1ef
check for midi messages with more than 3 bytes
lathoub Sep 23, 2019
9859e8b
Update .travis.yml
lathoub Sep 23, 2019
5200c4f
case errors (upper / lower)
lathoub Sep 23, 2019
7aace66
Update AppleMidi.hpp
lathoub Sep 23, 2019
ba8824d
fixed namespace issues
lathoub Sep 23, 2019
b30531e
remvoed anonymous namespace
lathoub Sep 23, 2019
9436a7c
uint8_t* to byte* (avoidwarning)
lathoub Sep 23, 2019
3e6c972
fix cast warning
lathoub Sep 23, 2019
5b67454
removed undefined bahaviour
lathoub Sep 23, 2019
31a81be
optimize - struct redesign
lathoub Sep 25, 2019
f357586
added receiver feedback
lathoub Sep 26, 2019
73f979b
working on rtp_parser
Sep 27, 2019
19b8d45
Update rtpMidi_Parser.h
lathoub Sep 28, 2019
3cd00d2
cleanup
lathoub Sep 28, 2019
e22cebf
better rtp parsing
lathoub Sep 28, 2019
9a65281
more parsing
Sep 28, 2019
92cb332
better rtpMidi parsing
lathoub Sep 28, 2019
022f355
Scaffolding logging using MACROs
lathoub Sep 29, 2019
fb6fa6a
fix timing bug
lathoub Sep 29, 2019
796787c
more logging
lathoub Sep 29, 2019
32ee499
a bit more logging
lathoub Sep 29, 2019
d86cfa4
more logging
lathoub Sep 29, 2019
34383e2
bug fix for RT commands
lathoub Sep 29, 2019
597fe5c
extra logging
lathoub Sep 29, 2019
158927d
added participants
lathoub Oct 2, 2019
cf55f93
added Vs project for testing
lathoub Oct 4, 2019
4ce3a67
fixed signed/unsiged warning - more test data
lathoub Oct 5, 2019
4a111e4
renamed SerialPort to Encoder
lathoub Oct 5, 2019
7f59678
added begin() loop() to mimic Arduino behaviour
lathoub Oct 5, 2019
cad9a77
make testing simialr to Arduino IDE
lathoub Oct 6, 2019
e5f4e96
added esp32 example (working on endian)
lathoub Oct 7, 2019
7e64515
changed endian detection and swappers
lathoub Oct 20, 2019
0eec5ad
modify to get it to compile on ESP32
lathoub Oct 20, 2019
314ff47
initial test on ESP32
lathoub Oct 20, 2019
a956613
guards around #define
Nov 2, 2019
e5fb602
removed ??!?! in a string that confused the parser/compiler
Dec 29, 2019
937fd15
extracted Journal Section and Midi Command from rtpMidi file
Dec 29, 2019
d1e10de
fixed journal section channel flags issue
Dec 29, 2019
38eef63
fixed bug, journal length should be used, not content length
Dec 30, 2019
f123342
cleanup
Dec 30, 2019
efeebad
increase buffer size from 64 to 128
Dec 30, 2019
60466f4
added sendActiveSensing
Dec 31, 2019
290ed7d
Update midi_Settings.h
Jan 5, 2020
1028f9b
project debugging in xcode
Jan 5, 2020
8a14ec1
debugging entie stack in xcode
Jan 11, 2020
7e98318
added ActiveSensing and ReceiverFeedback
Jan 26, 2020
cf897fd
removed TODO for ReceiverFeedback
Jan 26, 2020
9cce2dd
active sending thru sendRealTime and added rtpClock when sending rtp …
Jan 26, 2020
9fa4cbc
added Error callback and timestamp to zero
Jan 26, 2020
9285a1d
added sytem journal parser
Jan 26, 2020
a33d648
simplified system journal parsing (just taking predicted length)
Jan 27, 2020
2b11f5c
Update UserInterfaceState.xcuserstate
Jan 27, 2020
b43f7a4
working on SysEx
lathoub Feb 2, 2020
a5a3a8c
added examples + cleanup
Feb 7, 2020
c8103e3
added examples
Feb 7, 2020
f3c177c
Update README.md
Feb 7, 2020
effc1d4
Update README.md
Feb 7, 2020
9a92d42
working on receiving large SysEx (larger than buffer size)
Feb 8, 2020
cd56163
working on Queue
Feb 8, 2020
ab5a592
fixed activeSensing bug
Feb 9, 2020
ec2a0bd
clean up examples
Feb 9, 2020
e92affa
added Array (in STL style)
Feb 9, 2020
6d0301a
replaced RingBuffer with Deque
Feb 9, 2020
36f7590
working on larger sysex messages (not completed)
Feb 9, 2020
4ff2f83
more long SysEx parsing (unfinsihed)
Feb 10, 2020
ac8665d
added erase to deque
Feb 11, 2020
0a21ef0
rewrite parser for high-volume long-packets (incl long syses)
Feb 11, 2020
cd42af7
optmized used of deque (not using expensive erase function)
Feb 12, 2020
5d928f4
parser optimization, reduced JournalSection significantly
Feb 14, 2020
001d494
Update library.properties
lathoub Feb 14, 2020
97d5a2a
fixed sending larger than buffer sysex
Feb 14, 2020
45a2a7a
Merge branch 'feat/2.0.0' of https://github.com/lathoub/Arduino-Apple…
Feb 14, 2020
596a04f
Update README.md
lathoub Feb 14, 2020
eb03a61
fixed compilation warning
Feb 14, 2020
70eca7d
Merge branch 'feat/2.0.0' of https://github.com/lathoub/Arduino-Apple…
Feb 14, 2020
84915b3
Update README.md
lathoub Feb 14, 2020
17ab15c
Update README.md
lathoub Feb 15, 2020
cb46953
Update README.md
lathoub Feb 15, 2020
97861a3
default to 1 session participant
Feb 15, 2020
bbdc842
Merge branch 'feat/2.0.0' of https://github.com/lathoub/Arduino-Apple…
Feb 15, 2020
c567323
bug fix in Journal section
Feb 15, 2020
fa93ca1
moved logging to utilities folder
Feb 15, 2020
7fe652e
move MIDI to utilities folder
Feb 15, 2020
6258cbd
renamed utilities folder to utility
Feb 15, 2020
5484fe6
added keywords
Feb 15, 2020
41a022a
added callback for incoming MIDI data
Feb 15, 2020
8460f2d
added RawData example
Feb 15, 2020
98e099b
updated ESP32 example
Feb 15, 2020
56261ae
updated example
Feb 15, 2020
f71625e
added getters for Name and Port
Feb 15, 2020
d2a3883
Update EthernetShield_NoteOnOffEverySec.ino
Feb 15, 2020
c507bfa
add comments
Feb 15, 2020
cb67660
renamed AppleMidiTransport -> AppleMidiSession
Feb 16, 2020
07a8f2d
pack all MIDI cmds in 1 rtpMIDI packet per cycle
Feb 22, 2020
fc1f430
Update library.properties
lathoub Feb 22, 2020
ccc574e
Update library.properties
lathoub Feb 22, 2020
02f980a
Update library.properties
lathoub Feb 22, 2020
59b8dcc
Update README.md
lathoub Feb 22, 2020
f856929
added sync (CK) timeouts as disconnected remote partner (after 60s)
Feb 24, 2020
ab9389d
added draft Initiator functionality to Session (and added example)
Feb 27, 2020
155a7b8
Session participants in Deque
Feb 27, 2020
1cc9afe
option to compile as Listener only (saves 2000 bytes)
Feb 27, 2020
6f7091c
define APPLEMIDI_INITIATOR in the .ino
Feb 27, 2020
4d286be
optimized debugging MACRO's
Feb 27, 2020
e8b3b86
tested timeouts
Feb 28, 2020
a1d12ff
better exception handling for listener and initiator
Feb 29, 2020
a567f1f
reuse Invitation struct for Rejection
Feb 29, 2020
7ba7802
Explicit naming of AppleMIDI_InvitationAccepted_t and AppleMIDI_Invit…
Mar 1, 2020
f1e283f
APPLEMIDI_SESSION_NAME_MAX_LEN can be 0 (zero)
Mar 1, 2020
0cf6bf0
cleanup
Mar 1, 2020
d97b0fc
Bug Fix: sending notes and sync to the correct port
lathoub Mar 1, 2020
b050aa3
Delete EthernetShield_NoteOnOffEverySec.ino
Mar 1, 2020
caa7974
code cleanup
Mar 1, 2020
6ef8e8a
Update library.properties
lathoub Mar 1, 2020
3f7c3b5
millis() in a 64bit, to avoid early wraparound
Mar 1, 2020
8d2028f
Midi => MIDI
Mar 2, 2020
da2c04a
added latency calculation (and callback, see Latency example)
Mar 2, 2020
753bbb2
added Platform to abstract millis() implementation per Platform
Mar 5, 2020
a55f275
cleanup
Mar 5, 2020
c0c1841
removed internal version of MIDI_LIbrary
Mar 12, 2020
93918b7
added example for wESP32
Mar 13, 2020
a0ec8a6
renamed file midi -> MIDI
Mar 13, 2020
cfe0b37
renamed midi -> MIDI
Mar 13, 2020
7fd683b
updated example
Mar 14, 2020
01b92c3
Update EthernetShield_Bonjour.ino
Mar 14, 2020
cce1b9c
Create EthernetShield_MultipleSessions_Bonjour.ino
Mar 14, 2020
a20e7dd
Delete EthernetShield_MultipleSessions_Bonjour.ino
Mar 14, 2020
8d74dfc
bug fix
Mar 14, 2020
a9f8db4
add Bonjour to ESP32 wifi sample
Mar 14, 2020
6c3fb85
added url to TrippyLighting/EthernetBonjour on github
Mar 14, 2020
95d5105
Delete ESp32_NoteOnOffEverySec.ino
lathoub Mar 14, 2020
4a78eee
no need for mac with ESP32
Mar 14, 2020
440f376
Merge branch 'feat/2.0.0' of https://github.com/lathoub/Arduino-Apple…
Mar 14, 2020
bdbc912
Delete ESP32_NoteOnOffEverySec.ino
Mar 14, 2020
a845f26
randomSeed(analogRead(0)); causes wESP32 to crash! so remove
Mar 14, 2020
37aa4ad
Delete AppleMidi.cpp
lathoub Mar 14, 2020
5f2b140
Delete AppleMidi.h
lathoub Mar 14, 2020
fec793f
Delete AppleMidi.hpp
lathoub Mar 14, 2020
314e53f
Delete AppleMidi_Settings.h
lathoub Mar 14, 2020
908e8ab
Delete AppleMidi_Parser.h
lathoub Mar 14, 2020
4515455
Delete AppleMidi_Participant.h
lathoub Mar 14, 2020
c692fc5
Delete AppleMidi_Namespace.h
lathoub Mar 14, 2020
0708850
Delete AppleMidi_Defs.h
lathoub Mar 14, 2020
54977fa
Delete rtpMidi_Clock.h
lathoub Mar 14, 2020
2fff3df
Delete rtpMidi_Defs.h
lathoub Mar 14, 2020
a44471a
Delete rtpMidi_Parser.h
lathoub Mar 14, 2020
ce02afd
Delete rtpMidi_Parser_MidiCommandSection.hpp
lathoub Mar 14, 2020
83c5a89
Delete rtpMidi_Parser_JournalSection.hpp
lathoub Mar 14, 2020
7fe5e8a
removed Platform ref
Mar 14, 2020
bb8bfde
use randomSeed with millis (not analogRead(0))
Mar 14, 2020
c11d620
Update AppleMIDI.h
Mar 14, 2020
58266ee
seperate reading Packets from parsing Packets
Mar 15, 2020
a44e3c4
big fix (use controlBuffer, not dataBuffer)
Mar 15, 2020
e08b0ae
use 'const ssrc_t &' to pass ssrc, added start and end events when re…
Mar 15, 2020
019fe53
Update AppleMIDI.h
Mar 15, 2020
a3c5fc6
class Platform for OS related type
Mar 15, 2020
0d0fd77
pop_front/pop_back should be a void
Mar 15, 2020
3ab088f
added keyword
Mar 15, 2020
89135ff
aliasing for callbacks
Mar 18, 2020
425b094
removed unused inChannel argument from begin
lathoub Apr 17, 2020
afb7892
removed getTransportName
lathoub Apr 17, 2020
30f055e
removed typedef from CREATE_INSTANCE MACRO
lathoub Apr 18, 2020
86d3148
added Basic_IO example
lathoub Apr 18, 2020
1c634f9
removed logging
lathoub Apr 19, 2020
bc2f719
added helper for ESP32
lathoub Apr 19, 2020
7d1ac52
added depends on MIDI Library
lathoub Apr 20, 2020
73fe9b0
Add link to MIDI library in platformio (#62)
lathoub Apr 20, 2020
14be703
request version 5 of MIDI library
lathoub Apr 20, 2020
5d9b292
version 5.0.0 of the MIDI library
lathoub Apr 20, 2020
69fe33e
Bug fix: file names are case sensitive in Linux
lathoub Apr 21, 2020
d4a10d4
Update AppleMIDI.hpp
lathoub Apr 21, 2020
6625312
fix signed/unsigned comparison
lathoub Apr 21, 2020
ea22a35
fix signed/unsigned comparison
lathoub Apr 21, 2020
2dfb707
removed unused variable
lathoub Apr 21, 2020
4298781
removed unused variable
lathoub Apr 21, 2020
5005456
Update README.md
lathoub Apr 21, 2020
af70167
Update README.md
lathoub Apr 21, 2020
db1ce49
Update Basic_IO.ino
Apr 21, 2020
81ba8cc
Merge branch 'feat/2.0.0' of https://github.com/lathoub/Arduino-Apple…
Apr 21, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.DS_Store
examples/.DS_Store
src/.DS_Store
test/.vs
test/Debug
examples/ESP32_NoteOnOffEverySec/config.h
src/.vscode
test/x64
.development
examples/ESP32_NoteOnOffEverySec/credentials.h
11 changes: 1 addition & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,7 @@ cache:
install:
- pip install -U platformio
- platformio update
- platformio lib -g install 870 872
- platformio lib -g install 62@5.0.0 870 872

script:
- platformio ci --board=huzzah --lib=. examples/Esp32_NoteOnOffEverySec/Esp32_NoteOnOffEverySec.ino;
- platformio ci --board=huzzah --lib=. examples/Esp8266_2Sessions_NoteOnOffEverySec/Esp8266_2Sessions_NoteOnOffEverySec.ino;
- platformio ci --board=huzzah --lib=. examples/Esp8266_NoteOnOffEverySec/Esp8266_NoteOnOffEverySec.ino;
- platformio ci --board=uno --lib=. examples/EthernetShield_InitiateSession/EthernetShield_InitiateSession.ino;
- platformio ci --board=uno --lib=. examples/EthernetShield_InitiateSessions/EthernetShield_InitiateSessions.ino;
- platformio ci --board=uno --lib=. examples/EthernetShield_NoteOnOffEverySec/EthernetShield_NoteOnOffEverySec.ino;
- platformio ci --board=uno --lib=. examples/EthernetShield_RealTimeMessages/EthernetShield_RealTimeMessages.ino;
- platformio ci --board=uno --lib=. examples/EthernetShield_ReceiveMTC/EthernetShield_ReceiveMTC.ino;
- platformio ci --board=uno --lib=. examples/EthernetShield_SysEx/EthernetShield_SysEx.ino;
- platformio ci --board=uno --lib=. examples/Wifi_NoteOnOffEverySec/Wifi_NoteOnOffEverySec.ino;
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Enables an Arduino with IP/UDP capabilities (Ethernet shield, ESP8266, ESP32, ...) to particpate in an AppleMIDI session.

## Features
* Tested with AppleMIDI on Mac OS (High Sierra) and using [rtpMIDI](https://www.tobias-erichsen.de/software/rtpmidi.html) from Tobias Erichsen on Windows 10
* Tested with AppleMIDI on Mac OS (Catalina) and using [rtpMIDI](https://www.tobias-erichsen.de/software/rtpmidi.html) from Tobias Erichsen on Windows 10
* Send and receive all MIDI messages
* Uses callbacks to receive MIDI commands (no need for polling)
* Automatic instantiation of AppleMIDI object (see at the end of 'AppleMidi.h')
Expand All @@ -15,23 +15,29 @@ From the Arduino IDE Library Manager, search for AppleMIDI

## Basic Usage
```
#include "AppleMidi.h"
#include <Ethernet.h>
#include <AppleMidi.h>

APPLEMIDI_CREATE_DEFAULT_INSTANCE();
APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE();

void setup()
{
// ...setup ethernet connection
AppleMIDI.begin("test"); // 'test' will show up as the session name
MIDI.begin(1);

// Optional
AppleMIDI.setHandleConnected(OnAppleMidiConnected);
}

void loop()
{
AppleMIDI.run();
// ...
// Listen to incoming notes
MIDI.read();

// Send MIDI note 40 on, velocity 55 on channel 1
AppleMIDI.sendNoteOn(40, 55, 1);
MIDI.sendNoteOn(40, 55, 1);
}

void OnAppleMidiConnected(uint32_t ssrc, const char* name) {
}
```
More usages in the `examples` folder
Expand All @@ -44,21 +50,21 @@ More usages in the `examples` folder
* Adafruit Feather M0 WiFi - ATSAMD21 + ATWINC1500

## Memory usage
The code has been pseudo optimized to minimize the memory footprint.
Internal buffers also use valuable memory space. The biggest buffer `PACKET_MAX_SIZE` is set to 350 by default in `AppleMidi_Settings.h`. Albeit this number is somewhat arbitratry (large enough to receive full SysEx messages), it can be reduced significantly if you do not have to receive large messages.
This library is not using any dynamic memory allocation methods - all buffers have a fixed size, set in the `AppleMIDI_Settings.h` file, avoiding potential memory leaks and memory fragmentation.

On an Arduino, 2 sessions can be active at once (W5100 can have max 4 sockets open at the same time, each session needs 2 UDP sockets). Setting MAX_SESSIONS to 1 saves 228 bytes (each session takes 228 bytes).
The minimum buffer size (`MaxBufferSize`) should be set to 64 bytes (also the default). Setting it to a higher value will make sending larger SysEx messages more efficiant (large SysEx messages are chopped in pieces, the larger the buffer, the less pieces needed), at the price of a bigger memory footprint.

Save memory (about 2000 bytes) when the device does not initiate sessions by `#undef APPLEMIDI_REMOTE_SESSIONS` in `AppleMidi_Settings.h`. See the `EthernetShield_NoteOnOffEverySec.ino` example
`MaxNumberOfParticipants` is another way to cut memory - each particpants uses approx 300 bytes. Default number of participants is 1 (using 2 sockets).
Beware: the number of sockets on the Arduino is limited. The W5100 support 4, the W5200 and W5500 based IP chips can use 8 sockets. (Each participant uses 2 sockets: port 5004 and 5004+1). (Base port can be set in `APPLEMIDI_CREATE_DEFAULT_INSTANCE`)

## Network Shields
* Arduino Ethernet shield (Wiznet W5100)
* Arduino Ethernet shield (Wiznet W5100 and W5500)
* Arduino Wifi R3 shield
* MKR ETH shield
* Teensy WIZ820io W5200

## Arduino IDE (arduino.cc)
* 1.8.9
* 1.8.10

## Contributing
I would love to include your enhancements or bug fixes! In lieu of a formal styleguide, please take care to maintain the existing coding style. Please test your code before sending a pull request. It would be very helpful if you include a detailed explanation of your changes in the pull request.
37 changes: 37 additions & 0 deletions examples/Basic_IO/Basic_IO.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#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
};

// Simple tutorial on how to receive and send MIDI messages.
// Here, when receiving any message on channel 4, the Arduino
// will blink a led and play back a note for 1 second.

APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE();

void setup()
{
if (Ethernet.begin(mac) == 0) {
Serial.println(F("Failed DHCP, check network cable & reboot"));
for (;;);
}

pinMode(LED_BUILTIN, OUTPUT);
MIDI.begin(4); // Launch MIDI and listen to channel 4
}

void loop()
{
if (MIDI.read()) // If we have received a message
{
digitalWrite(LED_BUILTIN, HIGH);
MIDI.sendNoteOn(42, 127, 1); // Send a Note (pitch 42, velo 127 on channel 1)
delay(1000); // Wait for a second
MIDI.sendNoteOff(42, 0, 1); // Stop the note
digitalWrite(LED_BUILTIN, LOW);
}
}
Original file line number Diff line number Diff line change
@@ -1,63 +1,48 @@
// These need to be included when using standard Ethernet
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
#include "ETH_Helper.h"

#include "AppleMidi.h"

char ssid[] = "yourNetwork"; // your network SSID (name)
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)
#include <AppleMIDI.h>
USING_NAMESPACE_APPLEMIDI

unsigned long t0 = millis();
bool isConnected = false;

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

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
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(F("Getting IP address..."));

while (!Serial);
Serial.println("Booting");

WiFi.begin(ssid, pass);

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

MDNS.begin(AppleMIDI.getName());


Serial.println();
Serial.print(F("IP address is "));
Serial.println(WiFi.localIP());
Serial.print("\nIP address is ");
Serial.println(ETH.localIP());

Serial.println(F("OK, now make sure you an rtpMIDI session that is Enabled"));
Serial.print(F("Add device named Arduino with Host/Port "));
Serial.print(WiFi.localIP());
Serial.print(ETH.localIP());
Serial.println(F(":5004"));
Serial.println(F("Then press the Connect button"));
Serial.println(F("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");
MIDI.begin(1); // listen on channel 1

AppleMIDI.setHandleConnected(OnAppleMidiConnected);
AppleMIDI.setHandleDisconnected(OnAppleMidiDisconnected);

AppleMIDI.OnConnected(OnAppleMidiConnected);
AppleMIDI.OnDisconnected(OnAppleMidiDisconnected);
MIDI.setHandleNoteOn(OnAppleMidiNoteOn);
MIDI.setHandleNoteOff(OnAppleMidiNoteOff);

AppleMIDI.OnReceiveNoteOn(OnAppleMidiNoteOn);
AppleMIDI.OnReceiveNoteOff(OnAppleMidiNoteOff);
MDNS.addService("apple-midi", "udp", AppleMIDI.getPort());

Serial.println(F("Sending NoteOn/Off of note 45, every second"));
Serial.println(F("Every second send a random NoteOn/Off"));
}

// -----------------------------------------------------------------------------
Expand All @@ -66,21 +51,21 @@ void setup()
void loop()
{
// Listen to incoming notes
AppleMIDI.read();
MIDI.read();

// 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(".");
// Serial.print(F(".");

byte note = 45;
byte note = random(1, 127);
byte velocity = 55;
byte channel = 1;

AppleMIDI.sendNoteOn(note, velocity, channel);
AppleMIDI.sendNoteOff(note, velocity, channel);
MIDI.sendNoteOn(note, velocity, channel);
MIDI.sendNoteOff(note, velocity, channel);
}
}

Expand All @@ -91,42 +76,40 @@ void loop()
// -----------------------------------------------------------------------------
// rtpMIDI session. Device connected
// -----------------------------------------------------------------------------
void OnAppleMidiConnected(uint32_t ssrc, char* name) {
isConnected = true;
void OnAppleMidiConnected(const ssrc_t & ssrc, const char* name) {
isConnected = true;
Serial.print(F("Connected to session "));
Serial.println(name);
}

// -----------------------------------------------------------------------------
// rtpMIDI session. Device disconnected
// -----------------------------------------------------------------------------
void OnAppleMidiDisconnected(uint32_t ssrc) {
isConnected = false;
void OnAppleMidiDisconnected(const ssrc_t & ssrc) {
isConnected = false;
Serial.println(F("Disconnected"));
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void OnAppleMidiNoteOn(byte channel, byte note, byte velocity) {
Serial.print(F("Incoming NoteOn from channel:"));
static void OnAppleMidiNoteOn(byte channel, byte note, byte velocity) {
Serial.print(F("Incoming NoteOn from channel: "));
Serial.print(channel);
Serial.print(F(" note:"));
Serial.print(F(", note: "));
Serial.print(note);
Serial.print(F(" velocity:"));
Serial.print(velocity);
Serial.println();
Serial.print(F(", velocity: "));
Serial.println(velocity);
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void OnAppleMidiNoteOff(byte channel, byte note, byte velocity) {
Serial.print(F("Incoming NoteOff from channel:"));
static void OnAppleMidiNoteOff(byte channel, byte note, byte velocity) {
Serial.print(F("Incoming NoteOff from channel: "));
Serial.print(channel);
Serial.print(F(" note:"));
Serial.print(F(", note: "));
Serial.print(note);
Serial.print(F(" velocity:"));
Serial.print(velocity);
Serial.println();
Serial.print(F(", velocity: "));
Serial.println(velocity);
}
60 changes: 60 additions & 0 deletions examples/ESP32-Ethernet-Kit_A_v1.1_NoteOnOffEverySec/ETH_Helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <ETH.h>
#include <ESPmDNS.h>

#define ETH_ADDR 1
#define ETH_POWER_PIN 5
#define ETH_MDC_PIN 23
#define ETH_MDIO_PIN 18
#define ETH_TYPE ETH_PHY_IP101

static bool eth_connected = false;

void WiFiEvent(WiFiEvent_t event)
{
switch (event) {
case SYSTEM_EVENT_ETH_START:
Serial.println("ETH Started");
//set eth hostname here
ETH.setHostname("esp32-ethernet");
break;
case SYSTEM_EVENT_ETH_CONNECTED:
Serial.println("ETH Connected");
break;
case SYSTEM_EVENT_ETH_GOT_IP:
Serial.print("ETH MAC: ");
Serial.print(ETH.macAddress());
Serial.print(", IPv4: ");
Serial.print(ETH.localIP());
if (ETH.fullDuplex()) {
Serial.print(", FULL_DUPLEX");
}
Serial.print(", ");
Serial.print(ETH.linkSpeed());
Serial.println("Mbps");
eth_connected = true;
break;
case SYSTEM_EVENT_ETH_DISCONNECTED:
Serial.println("ETH Disconnected");
eth_connected = false;
break;
case SYSTEM_EVENT_ETH_STOP:
Serial.println("ETH Stopped");
eth_connected = false;
break;
default:
break;
}
}

bool ETH_startup()
{
WiFi.onEvent(WiFiEvent);
ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE);

Serial.println(F("Getting IP address..."));

while (!eth_connected)
delay(100);

return true;
}
Loading