bug fix
Dependencies: BLE_API mbed nRF51822
Fork of BLE_MIDI by
BLEMIDI.h@2:dbc6f81b9ba0, 2015-04-06 (annotated)
- Committer:
- kshoji
- Date:
- Mon Apr 06 09:10:07 2015 +0000
- Revision:
- 2:dbc6f81b9ba0
- Parent:
- 1:cba2eba64f5c
Add documents
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kshoji | 0:83889dc90473 | 1 | /* Copyright (c) 2014 mbed.org, MIT License |
kshoji | 0:83889dc90473 | 2 | * |
kshoji | 0:83889dc90473 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
kshoji | 0:83889dc90473 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
kshoji | 0:83889dc90473 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
kshoji | 0:83889dc90473 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
kshoji | 0:83889dc90473 | 7 | * Software is furnished to do so, subject to the following conditions: |
kshoji | 0:83889dc90473 | 8 | * |
kshoji | 0:83889dc90473 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
kshoji | 0:83889dc90473 | 10 | * substantial portions of the Software. |
kshoji | 0:83889dc90473 | 11 | * |
kshoji | 0:83889dc90473 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
kshoji | 0:83889dc90473 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
kshoji | 0:83889dc90473 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
kshoji | 0:83889dc90473 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kshoji | 0:83889dc90473 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
kshoji | 0:83889dc90473 | 17 | */ |
kshoji | 0:83889dc90473 | 18 | |
kshoji | 0:83889dc90473 | 19 | #ifndef __BLEMIDI_H__ |
kshoji | 0:83889dc90473 | 20 | #define __BLEMIDI_H__ |
kshoji | 0:83889dc90473 | 21 | |
kshoji | 0:83889dc90473 | 22 | #include "BLEDevice.h" |
kshoji | 0:83889dc90473 | 23 | |
kshoji | 0:83889dc90473 | 24 | /** |
kshoji | 0:83889dc90473 | 25 | * A class to communicate a BLE MIDI device |
kshoji | 0:83889dc90473 | 26 | */ |
kshoji | 0:83889dc90473 | 27 | class BLEMIDI { |
kshoji | 0:83889dc90473 | 28 | public: |
kshoji | 0:83889dc90473 | 29 | /** |
kshoji | 0:83889dc90473 | 30 | * Constructor |
kshoji | 0:83889dc90473 | 31 | */ |
kshoji | 0:83889dc90473 | 32 | BLEMIDI(BLEDevice *device); |
kshoji | 2:dbc6f81b9ba0 | 33 | |
kshoji | 2:dbc6f81b9ba0 | 34 | /** |
kshoji | 2:dbc6f81b9ba0 | 35 | * Constructor with device name |
kshoji | 2:dbc6f81b9ba0 | 36 | */ |
kshoji | 2:dbc6f81b9ba0 | 37 | BLEMIDI(BLEDevice *dev, char *deviceName); |
kshoji | 0:83889dc90473 | 38 | |
kshoji | 0:83889dc90473 | 39 | /** |
kshoji | 0:83889dc90473 | 40 | * Check if a BLE MIDI device is connected |
kshoji | 0:83889dc90473 | 41 | * |
kshoji | 0:83889dc90473 | 42 | * @returns true if a midi device is connected |
kshoji | 0:83889dc90473 | 43 | */ |
kshoji | 0:83889dc90473 | 44 | bool connected(); |
kshoji | 0:83889dc90473 | 45 | |
kshoji | 0:83889dc90473 | 46 | /** |
kshoji | 2:dbc6f81b9ba0 | 47 | * Attach a callback called when the `Tune Request` event is received |
kshoji | 0:83889dc90473 | 48 | * |
kshoji | 0:83889dc90473 | 49 | * @param ptr function pointer |
kshoji | 0:83889dc90473 | 50 | * prototype: void onTuneRequest(); |
kshoji | 0:83889dc90473 | 51 | */ |
kshoji | 0:83889dc90473 | 52 | inline void attachTuneRequest(void (*fn)()) { |
kshoji | 0:83889dc90473 | 53 | onTuneRequest = fn; |
kshoji | 0:83889dc90473 | 54 | } |
kshoji | 0:83889dc90473 | 55 | |
kshoji | 0:83889dc90473 | 56 | /** |
kshoji | 2:dbc6f81b9ba0 | 57 | * Attach a callback called when the `Timing Clock` event is received |
kshoji | 0:83889dc90473 | 58 | * |
kshoji | 0:83889dc90473 | 59 | * @param ptr function pointer |
kshoji | 0:83889dc90473 | 60 | * prototype: void onTimingClock(); |
kshoji | 0:83889dc90473 | 61 | */ |
kshoji | 0:83889dc90473 | 62 | inline void attachTimingClock(void (*fn)()) { |
kshoji | 0:83889dc90473 | 63 | onTimingClock = fn; |
kshoji | 0:83889dc90473 | 64 | } |
kshoji | 0:83889dc90473 | 65 | |
kshoji | 0:83889dc90473 | 66 | /** |
kshoji | 2:dbc6f81b9ba0 | 67 | * Attach a callback called when the `Start` event is received |
kshoji | 0:83889dc90473 | 68 | * |
kshoji | 0:83889dc90473 | 69 | * @param ptr function pointer |
kshoji | 0:83889dc90473 | 70 | * prototype: void onStart(); |
kshoji | 0:83889dc90473 | 71 | */ |
kshoji | 0:83889dc90473 | 72 | inline void attachStart(void (*fn)()) { |
kshoji | 0:83889dc90473 | 73 | onStart = fn; |
kshoji | 0:83889dc90473 | 74 | } |
kshoji | 0:83889dc90473 | 75 | |
kshoji | 0:83889dc90473 | 76 | /** |
kshoji | 2:dbc6f81b9ba0 | 77 | * Attach a callback called when the `Continue` event is received |
kshoji | 0:83889dc90473 | 78 | * |
kshoji | 0:83889dc90473 | 79 | * @param ptr function pointer |
kshoji | 0:83889dc90473 | 80 | * prototype: void onContinue(); |
kshoji | 0:83889dc90473 | 81 | */ |
kshoji | 0:83889dc90473 | 82 | inline void attachContinue(void (*fn)()) { |
kshoji | 0:83889dc90473 | 83 | onContinue = fn; |
kshoji | 0:83889dc90473 | 84 | } |
kshoji | 0:83889dc90473 | 85 | |
kshoji | 0:83889dc90473 | 86 | /** |
kshoji | 2:dbc6f81b9ba0 | 87 | * Attach a callback called when the `Stop` event is received |
kshoji | 0:83889dc90473 | 88 | * |
kshoji | 0:83889dc90473 | 89 | * @param ptr function pointer |
kshoji | 0:83889dc90473 | 90 | * prototype: void onStop(); |
kshoji | 0:83889dc90473 | 91 | */ |
kshoji | 0:83889dc90473 | 92 | inline void attachStop(void (*fn)()) { |
kshoji | 0:83889dc90473 | 93 | onStop = fn; |
kshoji | 0:83889dc90473 | 94 | } |
kshoji | 0:83889dc90473 | 95 | |
kshoji | 0:83889dc90473 | 96 | /** |
kshoji | 2:dbc6f81b9ba0 | 97 | * Attach a callback called when the `Active Sensing` event is received |
kshoji | 0:83889dc90473 | 98 | * |
kshoji | 0:83889dc90473 | 99 | * @param ptr function pointer |
kshoji | 0:83889dc90473 | 100 | * prototype: void onActiveSensing(); |
kshoji | 0:83889dc90473 | 101 | */ |
kshoji | 0:83889dc90473 | 102 | inline void attachActiveSensing(void (*fn)()) { |
kshoji | 0:83889dc90473 | 103 | onActiveSensing = fn; |
kshoji | 0:83889dc90473 | 104 | } |
kshoji | 0:83889dc90473 | 105 | |
kshoji | 0:83889dc90473 | 106 | /** |
kshoji | 2:dbc6f81b9ba0 | 107 | * Attach a callback called when the `Reset` event is received |
kshoji | 0:83889dc90473 | 108 | * |
kshoji | 0:83889dc90473 | 109 | * @param ptr function pointer |
kshoji | 0:83889dc90473 | 110 | * prototype: void onReset(); |
kshoji | 0:83889dc90473 | 111 | */ |
kshoji | 0:83889dc90473 | 112 | inline void attachReset(void (*fn)()) { |
kshoji | 0:83889dc90473 | 113 | onReset = fn; |
kshoji | 0:83889dc90473 | 114 | } |
kshoji | 0:83889dc90473 | 115 | |
kshoji | 0:83889dc90473 | 116 | /** |
kshoji | 2:dbc6f81b9ba0 | 117 | * Attach a callback called when the `Program Change` event is received |
kshoji | 0:83889dc90473 | 118 | * |
kshoji | 0:83889dc90473 | 119 | * @param ptr function pointer |
kshoji | 2:dbc6f81b9ba0 | 120 | * prototype: void onProgramChange(uint8_t channel, uint8_t program); |
kshoji | 0:83889dc90473 | 121 | */ |
kshoji | 0:83889dc90473 | 122 | inline void attachnProgramChange(void (*fn)(uint8_t, uint8_t)) { |
kshoji | 0:83889dc90473 | 123 | onProgramChange = fn; |
kshoji | 0:83889dc90473 | 124 | } |
kshoji | 0:83889dc90473 | 125 | |
kshoji | 0:83889dc90473 | 126 | /** |
kshoji | 2:dbc6f81b9ba0 | 127 | * Attach a callback called when the `Channel Aftertouch` event is received |
kshoji | 0:83889dc90473 | 128 | * |
kshoji | 0:83889dc90473 | 129 | * @param ptr function pointer |
kshoji | 2:dbc6f81b9ba0 | 130 | * prototype: void onChannelAftertouch(uint8_t channel, uint8_t pressure); |
kshoji | 0:83889dc90473 | 131 | */ |
kshoji | 0:83889dc90473 | 132 | inline void attachChannelAftertouch(void (*fn)(uint8_t, uint8_t)) { |
kshoji | 0:83889dc90473 | 133 | onChannelAftertouch = fn; |
kshoji | 0:83889dc90473 | 134 | } |
kshoji | 0:83889dc90473 | 135 | |
kshoji | 0:83889dc90473 | 136 | /** |
kshoji | 2:dbc6f81b9ba0 | 137 | * Attach a callback called when the `Time Code Quarter Frame` event is received |
kshoji | 0:83889dc90473 | 138 | * |
kshoji | 0:83889dc90473 | 139 | * @param ptr function pointer |
kshoji | 2:dbc6f81b9ba0 | 140 | * prototype: void onTimeCodeQuarterFrame(uint8_t timing); |
kshoji | 0:83889dc90473 | 141 | */ |
kshoji | 0:83889dc90473 | 142 | inline void attachTimeCodeQuarterFrame(void (*fn)(uint8_t)) { |
kshoji | 0:83889dc90473 | 143 | onTimeCodeQuarterFrame = fn; |
kshoji | 0:83889dc90473 | 144 | } |
kshoji | 0:83889dc90473 | 145 | |
kshoji | 0:83889dc90473 | 146 | /** |
kshoji | 2:dbc6f81b9ba0 | 147 | * Attach a callback called when the `Song Select` event is received |
kshoji | 0:83889dc90473 | 148 | * |
kshoji | 0:83889dc90473 | 149 | * @param ptr function pointer |
kshoji | 2:dbc6f81b9ba0 | 150 | * prototype: void onSongSelect(uint8_t song); |
kshoji | 0:83889dc90473 | 151 | */ |
kshoji | 0:83889dc90473 | 152 | inline void attachSongSelect(void (*fn)(uint8_t)) { |
kshoji | 0:83889dc90473 | 153 | onSongSelect = fn; |
kshoji | 0:83889dc90473 | 154 | } |
kshoji | 0:83889dc90473 | 155 | |
kshoji | 0:83889dc90473 | 156 | /** |
kshoji | 2:dbc6f81b9ba0 | 157 | * Attach a callback called when the `Note Off` event is received |
kshoji | 0:83889dc90473 | 158 | * |
kshoji | 0:83889dc90473 | 159 | * @param ptr function pointer |
kshoji | 2:dbc6f81b9ba0 | 160 | * prototype: void onNoteOff(uint8_t channel, uint8_t note, uint8_t velocity); |
kshoji | 0:83889dc90473 | 161 | */ |
kshoji | 0:83889dc90473 | 162 | inline void attachNoteOff(void (*fn)(uint8_t, uint8_t, uint8_t)) { |
kshoji | 0:83889dc90473 | 163 | onNoteOff = fn; |
kshoji | 0:83889dc90473 | 164 | } |
kshoji | 0:83889dc90473 | 165 | |
kshoji | 0:83889dc90473 | 166 | /** |
kshoji | 2:dbc6f81b9ba0 | 167 | * Attach a callback called when the `Note On` event is received |
kshoji | 0:83889dc90473 | 168 | * |
kshoji | 0:83889dc90473 | 169 | * @param ptr function pointer |
kshoji | 2:dbc6f81b9ba0 | 170 | * prototype: void onNoteOn(uint8_t channel, uint8_t note, uint8_t velocity); |
kshoji | 0:83889dc90473 | 171 | */ |
kshoji | 0:83889dc90473 | 172 | inline void attachNoteOn(void (*fn)(uint8_t, uint8_t, uint8_t)) { |
kshoji | 0:83889dc90473 | 173 | onNoteOn = fn; |
kshoji | 0:83889dc90473 | 174 | } |
kshoji | 0:83889dc90473 | 175 | |
kshoji | 0:83889dc90473 | 176 | /** |
kshoji | 2:dbc6f81b9ba0 | 177 | * Attach a callback called when the `Polyphonic Aftertouch` event is received |
kshoji | 0:83889dc90473 | 178 | * |
kshoji | 0:83889dc90473 | 179 | * @param ptr function pointer |
kshoji | 2:dbc6f81b9ba0 | 180 | * prototype: void onPolyphonicAftertouch(uint8_t channel, uint8_t note, uint8_t pressure); |
kshoji | 0:83889dc90473 | 181 | */ |
kshoji | 0:83889dc90473 | 182 | inline void attachPolyphonicAftertouch(void (*fn)(uint8_t, uint8_t, uint8_t)) { |
kshoji | 0:83889dc90473 | 183 | onPolyphonicAftertouch = fn; |
kshoji | 0:83889dc90473 | 184 | } |
kshoji | 0:83889dc90473 | 185 | |
kshoji | 0:83889dc90473 | 186 | /** |
kshoji | 2:dbc6f81b9ba0 | 187 | * Attach a callback called when the `Control Change` event is received |
kshoji | 0:83889dc90473 | 188 | * |
kshoji | 0:83889dc90473 | 189 | * @param ptr function pointer |
kshoji | 2:dbc6f81b9ba0 | 190 | * prototype: void onControlChange(uint8_t channel, uint8_t function, uint8_t value); |
kshoji | 0:83889dc90473 | 191 | */ |
kshoji | 0:83889dc90473 | 192 | inline void attachControlChange(void (*fn)(uint8_t, uint8_t, uint8_t)) { |
kshoji | 0:83889dc90473 | 193 | onControlChange = fn; |
kshoji | 0:83889dc90473 | 194 | } |
kshoji | 0:83889dc90473 | 195 | |
kshoji | 0:83889dc90473 | 196 | /** |
kshoji | 2:dbc6f81b9ba0 | 197 | * Attach a callback called when the `Pitch Wheel` event is received |
kshoji | 0:83889dc90473 | 198 | * |
kshoji | 0:83889dc90473 | 199 | * @param ptr function pointer |
kshoji | 2:dbc6f81b9ba0 | 200 | * prototype: void onPitchWheel(uint8_t channel, uint16_t amount); |
kshoji | 0:83889dc90473 | 201 | */ |
kshoji | 0:83889dc90473 | 202 | inline void attachPitchWheel(void (*fn)(uint8_t, uint16_t)) { |
kshoji | 0:83889dc90473 | 203 | onPitchWheel = fn; |
kshoji | 0:83889dc90473 | 204 | } |
kshoji | 0:83889dc90473 | 205 | |
kshoji | 0:83889dc90473 | 206 | /** |
kshoji | 2:dbc6f81b9ba0 | 207 | * Attach a callback called when the `Song Position Pointer` event is received |
kshoji | 0:83889dc90473 | 208 | * |
kshoji | 0:83889dc90473 | 209 | * @param ptr function pointer |
kshoji | 2:dbc6f81b9ba0 | 210 | * prototype: void onSongPositionPointer(uint16_t position); |
kshoji | 0:83889dc90473 | 211 | */ |
kshoji | 0:83889dc90473 | 212 | inline void attachSongPositionPointer(void (*fn)(uint16_t)) { |
kshoji | 0:83889dc90473 | 213 | onSongPositionPointer = fn; |
kshoji | 0:83889dc90473 | 214 | } |
kshoji | 0:83889dc90473 | 215 | |
kshoji | 0:83889dc90473 | 216 | /** |
kshoji | 2:dbc6f81b9ba0 | 217 | * Attach a callback called when the `System Exclusive` event is received |
kshoji | 0:83889dc90473 | 218 | * |
kshoji | 0:83889dc90473 | 219 | * @param ptr function pointer |
kshoji | 2:dbc6f81b9ba0 | 220 | * prototype: void onSystemExclusive(uint8_t *sysex, uint16_t length, bool hasNextData); |
kshoji | 0:83889dc90473 | 221 | */ |
kshoji | 2:dbc6f81b9ba0 | 222 | inline void attachSystemExclusive(void (*fn)(uint8_t *, uint16_t, bool)) { |
kshoji | 0:83889dc90473 | 223 | onSystemExclusive = fn; |
kshoji | 0:83889dc90473 | 224 | } |
kshoji | 0:83889dc90473 | 225 | |
kshoji | 2:dbc6f81b9ba0 | 226 | /** |
kshoji | 2:dbc6f81b9ba0 | 227 | * Send a `Tune Request` event |
kshoji | 2:dbc6f81b9ba0 | 228 | */ |
kshoji | 0:83889dc90473 | 229 | void sendTuneRequest(); |
kshoji | 2:dbc6f81b9ba0 | 230 | |
kshoji | 2:dbc6f81b9ba0 | 231 | /** |
kshoji | 2:dbc6f81b9ba0 | 232 | * Send a `Timing Clock` event |
kshoji | 2:dbc6f81b9ba0 | 233 | */ |
kshoji | 0:83889dc90473 | 234 | void sendTimingClock(); |
kshoji | 2:dbc6f81b9ba0 | 235 | |
kshoji | 2:dbc6f81b9ba0 | 236 | /** |
kshoji | 2:dbc6f81b9ba0 | 237 | * Send a `Start` event |
kshoji | 2:dbc6f81b9ba0 | 238 | */ |
kshoji | 0:83889dc90473 | 239 | void sendStart(); |
kshoji | 2:dbc6f81b9ba0 | 240 | |
kshoji | 2:dbc6f81b9ba0 | 241 | /** |
kshoji | 2:dbc6f81b9ba0 | 242 | * Send a `Continue` event |
kshoji | 2:dbc6f81b9ba0 | 243 | */ |
kshoji | 0:83889dc90473 | 244 | void sendContinue(); |
kshoji | 2:dbc6f81b9ba0 | 245 | |
kshoji | 2:dbc6f81b9ba0 | 246 | /** |
kshoji | 2:dbc6f81b9ba0 | 247 | * Send a `Stop` event |
kshoji | 2:dbc6f81b9ba0 | 248 | */ |
kshoji | 0:83889dc90473 | 249 | void sendStop(); |
kshoji | 2:dbc6f81b9ba0 | 250 | |
kshoji | 2:dbc6f81b9ba0 | 251 | /** |
kshoji | 2:dbc6f81b9ba0 | 252 | * Send a `Active Sensing` event |
kshoji | 2:dbc6f81b9ba0 | 253 | */ |
kshoji | 0:83889dc90473 | 254 | void sendActiveSensing(); |
kshoji | 2:dbc6f81b9ba0 | 255 | |
kshoji | 2:dbc6f81b9ba0 | 256 | /** |
kshoji | 2:dbc6f81b9ba0 | 257 | * Send a `Reset` event |
kshoji | 2:dbc6f81b9ba0 | 258 | */ |
kshoji | 0:83889dc90473 | 259 | void sendReset(); |
kshoji | 2:dbc6f81b9ba0 | 260 | |
kshoji | 2:dbc6f81b9ba0 | 261 | /** |
kshoji | 2:dbc6f81b9ba0 | 262 | * Send a `Program Change` event |
kshoji | 2:dbc6f81b9ba0 | 263 | * |
kshoji | 2:dbc6f81b9ba0 | 264 | * @param channel 0-15 |
kshoji | 2:dbc6f81b9ba0 | 265 | * @param program 0-127 |
kshoji | 2:dbc6f81b9ba0 | 266 | */ |
kshoji | 0:83889dc90473 | 267 | void sendProgramChange(uint8_t channel, uint8_t program); |
kshoji | 2:dbc6f81b9ba0 | 268 | |
kshoji | 2:dbc6f81b9ba0 | 269 | /** |
kshoji | 2:dbc6f81b9ba0 | 270 | * Send a `Channel Aftertouch` event |
kshoji | 2:dbc6f81b9ba0 | 271 | * |
kshoji | 2:dbc6f81b9ba0 | 272 | * @param channel 0-15 |
kshoji | 2:dbc6f81b9ba0 | 273 | * @param pressure 0-127 |
kshoji | 2:dbc6f81b9ba0 | 274 | */ |
kshoji | 0:83889dc90473 | 275 | void sendChannelAftertouch(uint8_t channel, uint8_t pressure); |
kshoji | 2:dbc6f81b9ba0 | 276 | |
kshoji | 2:dbc6f81b9ba0 | 277 | /** |
kshoji | 2:dbc6f81b9ba0 | 278 | * Send a `Time Code Quarter Frame` event |
kshoji | 2:dbc6f81b9ba0 | 279 | * |
kshoji | 2:dbc6f81b9ba0 | 280 | * @param timing 0-127 |
kshoji | 2:dbc6f81b9ba0 | 281 | */ |
kshoji | 0:83889dc90473 | 282 | void sendTimeCodeQuarterFrame(uint8_t timing); |
kshoji | 2:dbc6f81b9ba0 | 283 | |
kshoji | 2:dbc6f81b9ba0 | 284 | /** |
kshoji | 2:dbc6f81b9ba0 | 285 | * Send a `Song Select` event |
kshoji | 2:dbc6f81b9ba0 | 286 | * |
kshoji | 2:dbc6f81b9ba0 | 287 | * @param song 0-127 |
kshoji | 2:dbc6f81b9ba0 | 288 | */ |
kshoji | 0:83889dc90473 | 289 | void sendSongSelect(uint8_t song); |
kshoji | 2:dbc6f81b9ba0 | 290 | |
kshoji | 2:dbc6f81b9ba0 | 291 | /** |
kshoji | 2:dbc6f81b9ba0 | 292 | * Send a `Note Off` event |
kshoji | 2:dbc6f81b9ba0 | 293 | * |
kshoji | 2:dbc6f81b9ba0 | 294 | * @param channel 0-15 |
kshoji | 2:dbc6f81b9ba0 | 295 | * @param note 0-127 |
kshoji | 2:dbc6f81b9ba0 | 296 | * @param velocity 0-127 |
kshoji | 2:dbc6f81b9ba0 | 297 | */ |
kshoji | 0:83889dc90473 | 298 | void sendNoteOff(uint8_t channel, uint8_t note, uint8_t velocity); |
kshoji | 2:dbc6f81b9ba0 | 299 | |
kshoji | 2:dbc6f81b9ba0 | 300 | /** |
kshoji | 2:dbc6f81b9ba0 | 301 | * Send a `Note On` event |
kshoji | 2:dbc6f81b9ba0 | 302 | * |
kshoji | 2:dbc6f81b9ba0 | 303 | * @param channel 0-15 |
kshoji | 2:dbc6f81b9ba0 | 304 | * @param note 0-127 |
kshoji | 2:dbc6f81b9ba0 | 305 | * @param velocity 0-127 |
kshoji | 2:dbc6f81b9ba0 | 306 | */ |
kshoji | 0:83889dc90473 | 307 | void sendNoteOn(uint8_t channel, uint8_t note, uint8_t velocity); |
kshoji | 2:dbc6f81b9ba0 | 308 | |
kshoji | 2:dbc6f81b9ba0 | 309 | /** |
kshoji | 2:dbc6f81b9ba0 | 310 | * Send a `Polyphonic Aftertouch` event |
kshoji | 2:dbc6f81b9ba0 | 311 | * |
kshoji | 2:dbc6f81b9ba0 | 312 | * @param channel 0-15 |
kshoji | 2:dbc6f81b9ba0 | 313 | * @param note 0-127 |
kshoji | 2:dbc6f81b9ba0 | 314 | * @param pressure 0-127 |
kshoji | 2:dbc6f81b9ba0 | 315 | */ |
kshoji | 0:83889dc90473 | 316 | void sendPolyphonicAftertouch(uint8_t channel, uint8_t note, uint8_t pressure); |
kshoji | 2:dbc6f81b9ba0 | 317 | |
kshoji | 2:dbc6f81b9ba0 | 318 | /** |
kshoji | 2:dbc6f81b9ba0 | 319 | * Send a `Control Change` event |
kshoji | 2:dbc6f81b9ba0 | 320 | * |
kshoji | 2:dbc6f81b9ba0 | 321 | * @param channel 0-15 |
kshoji | 2:dbc6f81b9ba0 | 322 | * @param function 0-127 |
kshoji | 2:dbc6f81b9ba0 | 323 | * @param value 0-127 |
kshoji | 2:dbc6f81b9ba0 | 324 | */ |
kshoji | 0:83889dc90473 | 325 | void sendControlChange(uint8_t channel, uint8_t function, uint8_t value); |
kshoji | 2:dbc6f81b9ba0 | 326 | |
kshoji | 2:dbc6f81b9ba0 | 327 | /** |
kshoji | 2:dbc6f81b9ba0 | 328 | * Send a `Pitch Wheel` event |
kshoji | 2:dbc6f81b9ba0 | 329 | * |
kshoji | 2:dbc6f81b9ba0 | 330 | * @param channel 0-15 |
kshoji | 2:dbc6f81b9ba0 | 331 | * @param amount 0-8192(center)-16383 |
kshoji | 2:dbc6f81b9ba0 | 332 | */ |
kshoji | 0:83889dc90473 | 333 | void sendPitchWheel(uint8_t channel, uint16_t amount); |
kshoji | 2:dbc6f81b9ba0 | 334 | |
kshoji | 2:dbc6f81b9ba0 | 335 | /** |
kshoji | 2:dbc6f81b9ba0 | 336 | * Send a `Song Position Pointer` event |
kshoji | 2:dbc6f81b9ba0 | 337 | * |
kshoji | 2:dbc6f81b9ba0 | 338 | * @param position 0-16383 |
kshoji | 2:dbc6f81b9ba0 | 339 | */ |
kshoji | 0:83889dc90473 | 340 | void sendSongPositionPointer(uint16_t position); |
kshoji | 2:dbc6f81b9ba0 | 341 | |
kshoji | 2:dbc6f81b9ba0 | 342 | /** |
kshoji | 2:dbc6f81b9ba0 | 343 | * Send a `System Exclusive` event |
kshoji | 2:dbc6f81b9ba0 | 344 | * |
kshoji | 2:dbc6f81b9ba0 | 345 | * @param sysex the data starts with `0xf0` and ends with `0xf7` |
kshoji | 2:dbc6f81b9ba0 | 346 | * @param length |
kshoji | 2:dbc6f81b9ba0 | 347 | */ |
kshoji | 0:83889dc90473 | 348 | void sendSystemExclusive(uint8_t * sysex, uint16_t length); |
kshoji | 0:83889dc90473 | 349 | |
kshoji | 2:dbc6f81b9ba0 | 350 | /** |
kshoji | 2:dbc6f81b9ba0 | 351 | * Notifies BLE disconnection to this BLE MIDI instance |
kshoji | 2:dbc6f81b9ba0 | 352 | */ |
kshoji | 0:83889dc90473 | 353 | void onBleDisconnection(Gap::Handle_t handle, Gap::DisconnectionReason_t reason); |
kshoji | 2:dbc6f81b9ba0 | 354 | |
kshoji | 2:dbc6f81b9ba0 | 355 | /** |
kshoji | 2:dbc6f81b9ba0 | 356 | * Notifies BLE connection to this BLE MIDI instance |
kshoji | 2:dbc6f81b9ba0 | 357 | */ |
kshoji | 0:83889dc90473 | 358 | void onBleConnection(Gap::Handle_t handle, Gap::addr_type_t type, const Gap::address_t addr, const Gap::ConnectionParams_t *params); |
kshoji | 0:83889dc90473 | 359 | |
kshoji | 0:83889dc90473 | 360 | private: |
kshoji | 0:83889dc90473 | 361 | bool isConnected; |
kshoji | 0:83889dc90473 | 362 | |
kshoji | 0:83889dc90473 | 363 | uint16_t sysExBufferPos; |
kshoji | 2:dbc6f81b9ba0 | 364 | uint8_t sysExBuffer[128]; |
kshoji | 1:cba2eba64f5c | 365 | |
kshoji | 0:83889dc90473 | 366 | uint16_t timestamp; |
kshoji | 0:83889dc90473 | 367 | |
kshoji | 0:83889dc90473 | 368 | uint8_t midiEventKind; |
kshoji | 0:83889dc90473 | 369 | uint8_t midiEventNote; |
kshoji | 0:83889dc90473 | 370 | uint8_t midiEventVelocity; |
kshoji | 0:83889dc90473 | 371 | |
kshoji | 0:83889dc90473 | 372 | enum MIDI_STATE { |
kshoji | 0:83889dc90473 | 373 | MIDI_STATE_TIMESTAMP = 0, |
kshoji | 0:83889dc90473 | 374 | MIDI_STATE_WAIT, |
kshoji | 0:83889dc90473 | 375 | MIDI_STATE_SIGNAL_2BYTES_2, |
kshoji | 0:83889dc90473 | 376 | MIDI_STATE_SIGNAL_3BYTES_2, |
kshoji | 0:83889dc90473 | 377 | MIDI_STATE_SIGNAL_3BYTES_3, |
kshoji | 0:83889dc90473 | 378 | MIDI_STATE_SIGNAL_SYSEX |
kshoji | 0:83889dc90473 | 379 | }; |
kshoji | 0:83889dc90473 | 380 | |
kshoji | 0:83889dc90473 | 381 | MIDI_STATE midiState; |
kshoji | 0:83889dc90473 | 382 | |
kshoji | 0:83889dc90473 | 383 | void (*onTuneRequest)(); |
kshoji | 0:83889dc90473 | 384 | void (*onTimingClock)(); |
kshoji | 0:83889dc90473 | 385 | void (*onStart)(); |
kshoji | 0:83889dc90473 | 386 | void (*onContinue)(); |
kshoji | 0:83889dc90473 | 387 | void (*onStop)(); |
kshoji | 0:83889dc90473 | 388 | void (*onActiveSensing)(); |
kshoji | 0:83889dc90473 | 389 | void (*onReset)(); |
kshoji | 0:83889dc90473 | 390 | void (*onProgramChange)(uint8_t, uint8_t); |
kshoji | 0:83889dc90473 | 391 | void (*onChannelAftertouch)(uint8_t, uint8_t); |
kshoji | 0:83889dc90473 | 392 | void (*onTimeCodeQuarterFrame)(uint8_t); |
kshoji | 0:83889dc90473 | 393 | void (*onSongSelect)(uint8_t); |
kshoji | 0:83889dc90473 | 394 | void (*onNoteOff)(uint8_t, uint8_t, uint8_t); |
kshoji | 0:83889dc90473 | 395 | void (*onNoteOn)(uint8_t, uint8_t, uint8_t); |
kshoji | 0:83889dc90473 | 396 | void (*onPolyphonicAftertouch)(uint8_t, uint8_t, uint8_t); |
kshoji | 0:83889dc90473 | 397 | void (*onControlChange)(uint8_t, uint8_t, uint8_t); |
kshoji | 0:83889dc90473 | 398 | void (*onPitchWheel)(uint8_t, uint16_t); |
kshoji | 0:83889dc90473 | 399 | void (*onSongPositionPointer)(uint16_t); |
kshoji | 2:dbc6f81b9ba0 | 400 | void (*onSystemExclusive)(uint8_t *, uint16_t, bool); |
kshoji | 0:83889dc90473 | 401 | |
kshoji | 0:83889dc90473 | 402 | void sendMidiMessage(uint8_t data0); |
kshoji | 0:83889dc90473 | 403 | void sendMidiMessage(uint8_t data0, uint8_t data1); |
kshoji | 0:83889dc90473 | 404 | void sendMidiMessage(uint8_t data0, uint8_t data1, uint8_t data2); |
kshoji | 0:83889dc90473 | 405 | |
kshoji | 0:83889dc90473 | 406 | void dataWrittenCallback(const GattCharacteristicWriteCBParams *params); |
kshoji | 0:83889dc90473 | 407 | |
kshoji | 1:cba2eba64f5c | 408 | uint8_t midi[20]; |
kshoji | 1:cba2eba64f5c | 409 | |
kshoji | 0:83889dc90473 | 410 | BLEDevice *device; |
kshoji | 0:83889dc90473 | 411 | GattCharacteristic *midiCharacteristic; |
kshoji | 0:83889dc90473 | 412 | Timer tick; |
kshoji | 0:83889dc90473 | 413 | }; |
kshoji | 0:83889dc90473 | 414 | |
kshoji | 0:83889dc90473 | 415 | #endif /* __BLEMIDI_H__ */ |