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.*

Minimum Setup

All examples in the examples folder

W5500 based Ethernet

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

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

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) {
    isConnected++;
    DBG(F("Connected to session"), ssrc, name);
  });
  AppleMIDI.setHandleDisconnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) {
    isConnected--;
    DBG(F("Disconnected"), ssrc);
  });