Utility class for MIDI over Bluetooth LE

Dependencies:   BLE_API mbed nRF51822

Using MIDI over Bluetooth LE

This class enables sending and receiving MIDI packets.

Set up an "BLEMIDI" class instance

Create an instance, and set up to start using it.

Initialization

#include "mbed.h"
#include "BLEDevice.h"
#include "BLEMIDI.h"

BLEDevice device;
BLEMIDI bleMidi(&device);

void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) {
    bleMidi.onBleDisconnection(handle, reason);
}

void connectionCallback(Gap::Handle_t handle, Gap::addr_type_t type, const Gap::address_t addr, const Gap::ConnectionParams_t *params) {
    bleMidi.onBleConnection(handle, type, addr, params);
}

int main(void) {
    device.onConnection(connectionCallback);
    device.onDisconnection(disconnectionCallback);
    
    for (;;) {
        device.waitForEvent();
    }
}

Changing the device name

The default device name is 'MIDI'.
If the another name is preferred, use this constructor. The maximum length of device name is 4 bytes.

Constructor with device name

BLEDevice device;
// BLEMIDI bleMidi(&device);
BLEMIDI bleMidi(&device, "NAME");

Sending MIDI events

For example, send a note on event:

send a note on event

bleMidi.sendNoteOn(0, 63, 127);

About other events, see the BLEMIDI class reference.

Receiving MIDI events

For example, receive note on events:

receive note on events

void onNoteOn(uint8_t channel, uint8_t note, uint8_t velocity) {
    // do something with Note On event
}

bleMidi.attachNoteOn(onNoteOn);

About other events, see the BLEMIDI class reference.

Files at this revision

API Documentation at this revision

Comitter:
kshoji
Date:
Tue Apr 07 09:24:31 2015 +0000
Parent:
2:dbc6f81b9ba0
Commit message:
Removed main.cpp

Changed in this revision

main.cpp Show diff for this revision Revisions of this file
diff -r dbc6f81b9ba0 -r 2b71bfbaa458 main.cpp
--- a/main.cpp	Mon Apr 06 09:10:07 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-#include "mbed.h"
-#include "BLEDevice.h"
-#include "BLEMIDI.h"
-#include "math.h"
-
-BLEDevice device;
-BLEMIDI bleMidi(&device);
-
-PwmOut sound(P0_0);
-
-void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) {
-    bleMidi.onBleDisconnection(handle, reason);
-}
-
-void connectionCallback(Gap::Handle_t handle, Gap::addr_type_t type, const Gap::address_t addr, const Gap::ConnectionParams_t *params) {
-    bleMidi.onBleConnection(handle, type, addr, params);
-}
-
-void onNoteOn(uint8_t channel, uint8_t note, uint8_t velocity) {
-    sound.write(0.5f);
-    sound.period(1.0f / (440.0f * (float)pow(2.0, (note - 69.0) / 12.0)));
-}
-
-void onNoteOff(uint8_t channel, uint8_t note, uint8_t velocity) {
-    sound.pulsewidth(0);
-}
-
-int main(void) {
-    device.onConnection(connectionCallback);
-    device.onDisconnection(disconnectionCallback);
-    
-    bleMidi.attachNoteOn(onNoteOn);
-    bleMidi.attachNoteOff(onNoteOff);
-    
-    for (;;) {
-        device.waitForEvent();
-    }
-}