-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmidi.cpp
38 lines (35 loc) · 971 Bytes
/
midi.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "pxt.h"
#include "BluetoothMIDIService.h"
using namespace pxt;
// v0 backward compat support
#ifndef PXT_BUFFER_DATA
#define PXT_BUFFER_DATA(buffer) buffer->payload
#endif
/**
* A set of functions to send MIDI commands over Bluetooth
*/
namespace bluetooth {
BluetoothMIDIService* pMidi = NULL;
BluetoothMIDIService* getMidi()
{
if (NULL == pMidi)
pMidi = new BluetoothMIDIService(uBit.ble);
return pMidi;
}
//%
void midiSendMessage(Buffer data) {
BluetoothMIDIService* pMidi = getMidi();
auto buf = PXT_BUFFER_DATA(data);
switch(data->length) {
case 1:
pMidi->sendMidiMessage(buf[0]);
break;
case 2:
pMidi->sendMidiMessage(buf[0], buf[1]);
break;
case 3:
pMidi->sendMidiMessage(buf[0], buf[1], buf[2]);
break;
}
}
}