My Arduino MIDI Library is using Arduino Streams as a basic design feature and therefore it supports Bluetooth, TCP/IP and UDP.
I am usually programming on an old Macbook, so I was wondering if I can extend my library to support Apple MIDI as well.
After some research I found that Apple MIDI communicates on 2 UDP ports: one for the session management and the other for the midi data. I wanted to avoid me having to implement the protocol myself and found the C implementation from Thorsten Klose which provides a quite nice abstraction layer: All I needed to do was to implemeent my C++ class which provides the necessary callback methods and integrates into my MIDI parser.
Arduino Sketch
Here is the example sketch which uses the new functionality:
#include <WiFi.h>
#include "Midi.h"
MidiCallbackAction action;
AppleMidiServer apple(&action);
const char *SSID = "your ssid";
const char *PWD = "your password";
void onNoteOn(uint8_t channel, uint8_t note, uint8_t velocity) {
Serial.print("onNoteOn: ");
Serial.println(note);
}
void onNoteOff(uint8_t channel, uint8_t note, uint8_t velocity) {
Serial.print("onNoteOff: ");
Serial.println(note);
}
void setupWIFI() {
Serial.begin(119200);
MidiLogLevel = MidiInfo;
WiFi.begin(SSID, PWD);
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
Serial.print("Connected to IP address: ");
Serial.println(WiFi.localIP());
}
void setup() {
action.setCallbacks(onNoteOn, onNoteOff);
setupWIFI();
apple.begin(5004);
}
void loop() {
if (!apple.loop()){
delay(10);
}
}
As you can see, by using the AppleMidiServer class we use the same concepts that we already know from in all other examples and because this is a server class, we can not only receive MIDI messages, but also produce them.
Dependencies
OS/X MIDI Setup
- Connect your MIDI keyboard to the computer.
- Open the Audio Midi Setup tool.
- Goto Window Show MIDI Studio.
- Double click on Network
- The entry ‘AppleMidi’ should be available in the Directory
- Select it and click on the
button - In the Live Routings select your Keyboard on the line with ->
If you hit the keys, you should see the corresponding entries in the Arduino Serial Monitor
0 Comments