Skip to content

MACRO for creation an AppleMIDI instance

lathoub edited this page Feb 13, 2021 · 20 revisions

Creation MACRO expansion

The mechanism to create the MIDI and AppleMIDI instance uses c++ templates.

This library, and the underlying MIDI library, do not allocate (and free) memory at runtime risking memory fragmentation and reboots.

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

                            Type      Name     SessionName        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.

The MACRO Definition

To make it easier to read, the MACRO has been multi-lined and \ removed

#define APPLEMIDI_CREATE_INSTANCE(Type, Name, SessionName, Port)
1.    APPLEMIDI_NAMESPACE::AppleMIDISession<Type> Apple##Name(SessionName, Port);
2.    MIDI_NAMESPACE::MidiInterface< 
3.          APPLEMIDI_NAMESPACE::AppleMIDISession<Type>, 
4.          APPLEMIDI_NAMESPACE::AppleMIDISettings>
5.       Name((APPLEMIDI_NAMESPACE::AppleMIDISession<Type>&)Apple##Name);
  1. Create an AppleMIDI instance, with a given sessionName and (default) port.
  2. The FortySevenEffects MidiInterface template
  3. Provide the UDP class as Type
  4. Specific AppleMIDI Settings
  5. The MIDI instance