Skip to content
lathoub edited this page Feb 13, 2021 · 31 revisions

Read the important migration page first, when you are migrating from v1.* to v2.* or from v2.* to v3.*

On RTP-MIDI

From the creators: https://john-lazzaro.github.io/rtpmidi/

Wiki and Introduction to RTP-MIDI aka AppleMIDI

Minimum Setup

All examples in the examples folder

W5*00 based Ethernet

#include <Ethernet.h>
#include <AppleMIDI.h>
APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE();
...
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
...

void setup()
{
  Ethernet.begin(mac);

  MIDI.begin(); // just like the serial MIDI interface

That is it, the rest is like you would make a MIDI application using the FortySevenEffects MIDI library.

APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE();

resolves to

APPLEMIDI_CREATE_INSTANCE(EthernetUDP, MIDI, "AppleMIDI-Arduino", DEFAULT_CONTROL_PORT);

                           |         |             |             |
                           |         |             |             +-> Default UDP port is 5004
                           |         |             +---------------> AppleMIDI session name
                           |         +-----------------------------> Variable name used in the sketch
                           |                                         also create an instance AppleMIDI
                           +---------------------------------------> UDP class from the Ethernet lib.

Minimum Setup on an ESP32

#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>

#include <AppleMIDI.h>
APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE();
...
void setup()
{
  WiFi.begin("yourSSID", "secretpasswd");

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    DBG("Establishing connection to WiFi..");
  }

Knowing when your device is connected to a session

Add callbacks for AppleMIDI connection and disconnection

  AppleMIDI.setHandleConnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) {
    DBG(F("Connected to session"), ssrc, name);
  });
  AppleMIDI.setHandleDisconnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) {
    DBG(F("Disconnected"), ssrc);
  });

More on callbacks