My Fork of F401RE-USBHost. Add USBHostMIDI functions (originaled by Kaoru Shoji http://mbed.org/users/kshoji/code/USBHostMIDI/)
Dependents: F401RE-USBHostMIDI_RecieveExample
Fork of F401RE-USBHost by
USBHostMIDI/USBHostMIDI.h@22:81d8c59d1070, 2014-09-17 (annotated)
- Committer:
- hsgw
- Date:
- Wed Sep 17 13:51:29 2014 +0000
- Revision:
- 22:81d8c59d1070
- Parent:
- 18:bac56d0365e1
- Child:
- 23:9c1d09c6a2b6
change to USBHostMIDI in Official USB-HOST lib. but not tested yet
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hsgw | 22:81d8c59d1070 | 1 | /* Copyright (c) 2014 mbed.org, MIT License |
hsgw | 22:81d8c59d1070 | 2 | * |
hsgw | 22:81d8c59d1070 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
hsgw | 22:81d8c59d1070 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
hsgw | 22:81d8c59d1070 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
hsgw | 22:81d8c59d1070 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
hsgw | 22:81d8c59d1070 | 7 | * Software is furnished to do so, subject to the following conditions: |
hsgw | 22:81d8c59d1070 | 8 | * |
hsgw | 22:81d8c59d1070 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
hsgw | 22:81d8c59d1070 | 10 | * substantial portions of the Software. |
hsgw | 22:81d8c59d1070 | 11 | * |
hsgw | 22:81d8c59d1070 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
hsgw | 22:81d8c59d1070 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
hsgw | 22:81d8c59d1070 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
hsgw | 22:81d8c59d1070 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
hsgw | 22:81d8c59d1070 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
hsgw | 22:81d8c59d1070 | 17 | */ |
hsgw | 22:81d8c59d1070 | 18 | |
hsgw | 22:81d8c59d1070 | 19 | #ifndef USBHOSTMIDI_H |
hsgw | 22:81d8c59d1070 | 20 | #define USBHOSTMIDI_H |
hsgw | 22:81d8c59d1070 | 21 | |
hsgw | 22:81d8c59d1070 | 22 | #include "USBHostConf.h" |
hsgw | 22:81d8c59d1070 | 23 | |
hsgw | 22:81d8c59d1070 | 24 | #if USBHOST_MIDI |
hsgw | 22:81d8c59d1070 | 25 | |
hsgw | 22:81d8c59d1070 | 26 | #include "USBHost.h" |
hsgw | 22:81d8c59d1070 | 27 | |
hsgw | 22:81d8c59d1070 | 28 | /** |
hsgw | 22:81d8c59d1070 | 29 | * A class to communicate a USB MIDI device |
hsgw | 22:81d8c59d1070 | 30 | */ |
hsgw | 22:81d8c59d1070 | 31 | class USBHostMIDI : public IUSBEnumerator { |
hsgw | 22:81d8c59d1070 | 32 | public: |
hsgw | 22:81d8c59d1070 | 33 | /** |
hsgw | 22:81d8c59d1070 | 34 | * Constructor |
hsgw | 22:81d8c59d1070 | 35 | */ |
hsgw | 22:81d8c59d1070 | 36 | USBHostMIDI(); |
hsgw | 22:81d8c59d1070 | 37 | |
hsgw | 22:81d8c59d1070 | 38 | /** |
hsgw | 22:81d8c59d1070 | 39 | * Check if a USB MIDI device is connected |
hsgw | 22:81d8c59d1070 | 40 | * |
hsgw | 22:81d8c59d1070 | 41 | * @returns true if a midi device is connected |
hsgw | 22:81d8c59d1070 | 42 | */ |
hsgw | 22:81d8c59d1070 | 43 | bool connected(); |
hsgw | 22:81d8c59d1070 | 44 | |
hsgw | 22:81d8c59d1070 | 45 | /** |
hsgw | 22:81d8c59d1070 | 46 | * Try to connect a midi device |
hsgw | 22:81d8c59d1070 | 47 | * |
hsgw | 22:81d8c59d1070 | 48 | * @return true if connection was successful |
hsgw | 22:81d8c59d1070 | 49 | */ |
hsgw | 22:81d8c59d1070 | 50 | bool connect(); |
hsgw | 22:81d8c59d1070 | 51 | |
hsgw | 22:81d8c59d1070 | 52 | /** |
hsgw | 22:81d8c59d1070 | 53 | * Attach a callback called when miscellaneous function code is received |
hsgw | 22:81d8c59d1070 | 54 | * |
hsgw | 22:81d8c59d1070 | 55 | * @param ptr function pointer |
hsgw | 22:81d8c59d1070 | 56 | * prototype: void onMiscellaneousFunctionCode(uint8_t data1, uint8_t data2, uint8_t data3); |
hsgw | 22:81d8c59d1070 | 57 | */ |
hsgw | 22:81d8c59d1070 | 58 | inline void attachMiscellaneousFunctionCode(void (*fn)(uint8_t, uint8_t, uint8_t)) { |
hsgw | 22:81d8c59d1070 | 59 | miscellaneousFunctionCode = fn; |
hsgw | 22:81d8c59d1070 | 60 | } |
hsgw | 22:81d8c59d1070 | 61 | |
hsgw | 22:81d8c59d1070 | 62 | /** |
hsgw | 22:81d8c59d1070 | 63 | * Attach a callback called when cable event is received |
hsgw | 22:81d8c59d1070 | 64 | * |
hsgw | 22:81d8c59d1070 | 65 | * @param ptr function pointer |
hsgw | 22:81d8c59d1070 | 66 | * prototype: void onCableEvent(uint8_t data1, uint8_t data2, uint8_t data3); |
hsgw | 22:81d8c59d1070 | 67 | */ |
hsgw | 22:81d8c59d1070 | 68 | inline void attachCableEvent(void (*fn)(uint8_t, uint8_t, uint8_t)) { |
hsgw | 22:81d8c59d1070 | 69 | cableEvent = fn; |
hsgw | 22:81d8c59d1070 | 70 | } |
hsgw | 22:81d8c59d1070 | 71 | |
hsgw | 22:81d8c59d1070 | 72 | /** |
hsgw | 22:81d8c59d1070 | 73 | * Attach a callback called when system exclusive is received |
hsgw | 22:81d8c59d1070 | 74 | * |
hsgw | 22:81d8c59d1070 | 75 | * @param ptr function pointer |
hsgw | 22:81d8c59d1070 | 76 | * prototype: void onSystemCommonTwoBytes(uint8_t data1, uint8_t data2); |
hsgw | 22:81d8c59d1070 | 77 | */ |
hsgw | 22:81d8c59d1070 | 78 | inline void attachSystemCommonTwoBytes(void (*fn)(uint8_t, uint8_t)) { |
hsgw | 22:81d8c59d1070 | 79 | systemCommonTwoBytes = fn; |
hsgw | 22:81d8c59d1070 | 80 | } |
hsgw | 22:81d8c59d1070 | 81 | |
hsgw | 22:81d8c59d1070 | 82 | /** |
hsgw | 22:81d8c59d1070 | 83 | * Attach a callback called when system exclusive is received |
hsgw | 22:81d8c59d1070 | 84 | * |
hsgw | 22:81d8c59d1070 | 85 | * @param ptr function pointer |
hsgw | 22:81d8c59d1070 | 86 | * prototype: void onSystemCommonThreeBytes(uint8_t data1, uint8_t data2, uint8_t data3); |
hsgw | 22:81d8c59d1070 | 87 | */ |
hsgw | 22:81d8c59d1070 | 88 | inline void attachSystemCommonThreeBytes(void (*fn)(uint8_t, uint8_t, uint8_t)) { |
hsgw | 22:81d8c59d1070 | 89 | systemCommonThreeBytes = fn; |
hsgw | 22:81d8c59d1070 | 90 | } |
hsgw | 22:81d8c59d1070 | 91 | |
hsgw | 22:81d8c59d1070 | 92 | /** |
hsgw | 22:81d8c59d1070 | 93 | * Attach a callback called when system exclusive is received |
hsgw | 22:81d8c59d1070 | 94 | * |
hsgw | 22:81d8c59d1070 | 95 | * @param ptr function pointer |
hsgw | 22:81d8c59d1070 | 96 | * prototype: void onSystemExclusive(uint8_t *data, uint16_t length, bool hasNextData); |
hsgw | 22:81d8c59d1070 | 97 | */ |
hsgw | 22:81d8c59d1070 | 98 | inline void attachSystemExclusive(void (*fn)(uint8_t *, uint16_t, bool)) { |
hsgw | 22:81d8c59d1070 | 99 | systemExclusive = fn; |
hsgw | 22:81d8c59d1070 | 100 | } |
hsgw | 22:81d8c59d1070 | 101 | |
hsgw | 22:81d8c59d1070 | 102 | /** |
hsgw | 22:81d8c59d1070 | 103 | * Attach a callback called when note on is received |
hsgw | 22:81d8c59d1070 | 104 | * |
hsgw | 22:81d8c59d1070 | 105 | * @param ptr function pointer |
hsgw | 22:81d8c59d1070 | 106 | * prototype: void onNoteOn(uint8_t channel, uint8_t note, uint8_t velocity); |
hsgw | 22:81d8c59d1070 | 107 | */ |
hsgw | 22:81d8c59d1070 | 108 | inline void attachNoteOn(void (*fn)(uint8_t, uint8_t, uint8_t)) { |
hsgw | 22:81d8c59d1070 | 109 | noteOn = fn; |
hsgw | 22:81d8c59d1070 | 110 | } |
hsgw | 22:81d8c59d1070 | 111 | |
hsgw | 22:81d8c59d1070 | 112 | /** |
hsgw | 22:81d8c59d1070 | 113 | * Attach a callback called when note off is received |
hsgw | 22:81d8c59d1070 | 114 | * |
hsgw | 22:81d8c59d1070 | 115 | * @param ptr function pointer |
hsgw | 22:81d8c59d1070 | 116 | * prototype: void onNoteOff(uint8_t channel, uint8_t note, uint8_t velocity); |
hsgw | 22:81d8c59d1070 | 117 | */ |
hsgw | 22:81d8c59d1070 | 118 | inline void attachNoteOff(void (*fn)(uint8_t, uint8_t, uint8_t)) { |
hsgw | 22:81d8c59d1070 | 119 | noteOff = fn; |
hsgw | 22:81d8c59d1070 | 120 | } |
hsgw | 22:81d8c59d1070 | 121 | |
hsgw | 22:81d8c59d1070 | 122 | /** |
hsgw | 22:81d8c59d1070 | 123 | * Attach a callback called when poly keypress is received |
hsgw | 22:81d8c59d1070 | 124 | * |
hsgw | 22:81d8c59d1070 | 125 | * @param ptr function pointer |
hsgw | 22:81d8c59d1070 | 126 | * prototype: void onPolyKeyPress(uint8_t channel, uint8_t note, uint8_t pressure); |
hsgw | 22:81d8c59d1070 | 127 | */ |
hsgw | 22:81d8c59d1070 | 128 | inline void attachPolyKeyPress(void (*fn)(uint8_t, uint8_t, uint8_t)) { |
hsgw | 22:81d8c59d1070 | 129 | polyKeyPress = fn; |
hsgw | 22:81d8c59d1070 | 130 | } |
hsgw | 22:81d8c59d1070 | 131 | |
hsgw | 22:81d8c59d1070 | 132 | /** |
hsgw | 22:81d8c59d1070 | 133 | * Attach a callback called when control change is received |
hsgw | 22:81d8c59d1070 | 134 | * |
hsgw | 22:81d8c59d1070 | 135 | * @param ptr function pointer |
hsgw | 22:81d8c59d1070 | 136 | * prototype: void onControlChange(uint8_t channel, uint8_t key, uint8_t value); |
hsgw | 22:81d8c59d1070 | 137 | */ |
hsgw | 22:81d8c59d1070 | 138 | inline void attachControlChange(void (*fn)(uint8_t, uint8_t, uint8_t)) { |
hsgw | 22:81d8c59d1070 | 139 | controlChange = fn; |
hsgw | 22:81d8c59d1070 | 140 | } |
hsgw | 22:81d8c59d1070 | 141 | |
hsgw | 22:81d8c59d1070 | 142 | /** |
hsgw | 22:81d8c59d1070 | 143 | * Attach a callback called when program change is received |
hsgw | 22:81d8c59d1070 | 144 | * |
hsgw | 22:81d8c59d1070 | 145 | * @param ptr function pointer |
hsgw | 22:81d8c59d1070 | 146 | * prototype: void onProgramChange(uint8_t channel, uint8_t program); |
hsgw | 22:81d8c59d1070 | 147 | */ |
hsgw | 22:81d8c59d1070 | 148 | inline void attachProgramChange(void (*fn)(uint8_t, uint8_t)) { |
hsgw | 22:81d8c59d1070 | 149 | programChange = fn; |
hsgw | 22:81d8c59d1070 | 150 | } |
hsgw | 22:81d8c59d1070 | 151 | |
hsgw | 22:81d8c59d1070 | 152 | /** |
hsgw | 22:81d8c59d1070 | 153 | * Attach a callback called when channel pressure is received |
hsgw | 22:81d8c59d1070 | 154 | * |
hsgw | 22:81d8c59d1070 | 155 | * @param ptr function pointer |
hsgw | 22:81d8c59d1070 | 156 | * prototype: void onChannelPressure(uint8_t channel, uint8_t pressure); |
hsgw | 22:81d8c59d1070 | 157 | */ |
hsgw | 22:81d8c59d1070 | 158 | inline void attachChannelPressure(void (*fn)(uint8_t, uint8_t)) { |
hsgw | 22:81d8c59d1070 | 159 | channelPressure = fn; |
hsgw | 22:81d8c59d1070 | 160 | } |
hsgw | 22:81d8c59d1070 | 161 | |
hsgw | 22:81d8c59d1070 | 162 | /** |
hsgw | 22:81d8c59d1070 | 163 | * Attach a callback called when pitch bend is received |
hsgw | 22:81d8c59d1070 | 164 | * |
hsgw | 22:81d8c59d1070 | 165 | * @param ptr function pointer |
hsgw | 22:81d8c59d1070 | 166 | * prototype: void onPitchBend(uint8_t channel, uint16_t value); |
hsgw | 22:81d8c59d1070 | 167 | */ |
hsgw | 22:81d8c59d1070 | 168 | inline void attachPitchBend(void (*fn)(uint8_t, uint16_t)) { |
hsgw | 22:81d8c59d1070 | 169 | pitchBend = fn; |
hsgw | 22:81d8c59d1070 | 170 | } |
hsgw | 22:81d8c59d1070 | 171 | |
hsgw | 22:81d8c59d1070 | 172 | /** |
hsgw | 22:81d8c59d1070 | 173 | * Attach a callback called when single byte is received |
hsgw | 22:81d8c59d1070 | 174 | * |
hsgw | 22:81d8c59d1070 | 175 | * @param ptr function pointer |
hsgw | 22:81d8c59d1070 | 176 | * prototype: void onSingleByte(uint8_t value); |
hsgw | 22:81d8c59d1070 | 177 | */ |
hsgw | 22:81d8c59d1070 | 178 | inline void attachSingleByte(void (*fn)(uint8_t)) { |
hsgw | 22:81d8c59d1070 | 179 | singleByte = fn; |
hsgw | 22:81d8c59d1070 | 180 | } |
hsgw | 22:81d8c59d1070 | 181 | |
hsgw | 22:81d8c59d1070 | 182 | /** |
hsgw | 22:81d8c59d1070 | 183 | * Send a cable event with 3 bytes event |
hsgw | 22:81d8c59d1070 | 184 | * |
hsgw | 22:81d8c59d1070 | 185 | * @param data1 0-255 |
hsgw | 22:81d8c59d1070 | 186 | * @param data2 0-255 |
hsgw | 22:81d8c59d1070 | 187 | * @param data3 0-255 |
hsgw | 22:81d8c59d1070 | 188 | * @return true if message sent successfully |
hsgw | 22:81d8c59d1070 | 189 | */ |
hsgw | 22:81d8c59d1070 | 190 | bool sendMiscellaneousFunctionCode(uint8_t data1, uint8_t data2, uint8_t data3); |
hsgw | 22:81d8c59d1070 | 191 | |
hsgw | 22:81d8c59d1070 | 192 | /** |
hsgw | 22:81d8c59d1070 | 193 | * Send a cable event with 3 bytes event |
hsgw | 22:81d8c59d1070 | 194 | * |
hsgw | 22:81d8c59d1070 | 195 | * @param data1 0-255 |
hsgw | 22:81d8c59d1070 | 196 | * @param data2 0-255 |
hsgw | 22:81d8c59d1070 | 197 | * @param data3 0-255 |
hsgw | 22:81d8c59d1070 | 198 | * @return true if message sent successfully |
hsgw | 22:81d8c59d1070 | 199 | */ |
hsgw | 22:81d8c59d1070 | 200 | bool sendCableEvent(uint8_t data1, uint8_t data2, uint8_t data3); |
hsgw | 22:81d8c59d1070 | 201 | |
hsgw | 22:81d8c59d1070 | 202 | /** |
hsgw | 22:81d8c59d1070 | 203 | * Send a system common message with 2 bytes event |
hsgw | 22:81d8c59d1070 | 204 | * |
hsgw | 22:81d8c59d1070 | 205 | * @param data1 0-255 |
hsgw | 22:81d8c59d1070 | 206 | * @param data2 0-255 |
hsgw | 22:81d8c59d1070 | 207 | * @return true if message sent successfully |
hsgw | 22:81d8c59d1070 | 208 | */ |
hsgw | 22:81d8c59d1070 | 209 | bool sendSystemCommmonTwoBytes(uint8_t data1, uint8_t data2); |
hsgw | 22:81d8c59d1070 | 210 | |
hsgw | 22:81d8c59d1070 | 211 | /** |
hsgw | 22:81d8c59d1070 | 212 | * Send a system common message with 3 bytes event |
hsgw | 22:81d8c59d1070 | 213 | * |
hsgw | 22:81d8c59d1070 | 214 | * @param data1 0-255 |
hsgw | 22:81d8c59d1070 | 215 | * @param data2 0-255 |
hsgw | 22:81d8c59d1070 | 216 | * @param data3 0-255 |
hsgw | 22:81d8c59d1070 | 217 | * @return true if message sent successfully |
hsgw | 22:81d8c59d1070 | 218 | */ |
hsgw | 22:81d8c59d1070 | 219 | bool sendSystemCommmonThreeBytes(uint8_t data1, uint8_t data2, uint8_t data3); |
hsgw | 22:81d8c59d1070 | 220 | |
hsgw | 22:81d8c59d1070 | 221 | /** |
hsgw | 22:81d8c59d1070 | 222 | * Send a system exclusive event |
hsgw | 22:81d8c59d1070 | 223 | * |
hsgw | 22:81d8c59d1070 | 224 | * @param buffer, starts with 0xF0, and end with 0xf7 |
hsgw | 22:81d8c59d1070 | 225 | * @param length |
hsgw | 22:81d8c59d1070 | 226 | * @return true if message sent successfully |
hsgw | 22:81d8c59d1070 | 227 | */ |
hsgw | 22:81d8c59d1070 | 228 | bool sendSystemExclusive(uint8_t *buffer, int length); |
hsgw | 22:81d8c59d1070 | 229 | |
hsgw | 22:81d8c59d1070 | 230 | /** |
hsgw | 22:81d8c59d1070 | 231 | * Send a note off event |
hsgw | 22:81d8c59d1070 | 232 | * |
hsgw | 22:81d8c59d1070 | 233 | * @param channel 0-15 |
hsgw | 22:81d8c59d1070 | 234 | * @param note 0-127 |
hsgw | 22:81d8c59d1070 | 235 | * @param velocity 0-127 |
hsgw | 22:81d8c59d1070 | 236 | * @return true if message sent successfully |
hsgw | 22:81d8c59d1070 | 237 | */ |
hsgw | 22:81d8c59d1070 | 238 | bool sendNoteOff(uint8_t channel, uint8_t note, uint8_t velocity); |
hsgw | 22:81d8c59d1070 | 239 | |
hsgw | 22:81d8c59d1070 | 240 | /** |
hsgw | 22:81d8c59d1070 | 241 | * Send a note on event |
hsgw | 22:81d8c59d1070 | 242 | * |
hsgw | 22:81d8c59d1070 | 243 | * @param channel 0-15 |
hsgw | 22:81d8c59d1070 | 244 | * @param note 0-127 |
hsgw | 22:81d8c59d1070 | 245 | * @param velocity 0-127 (0 means note off) |
hsgw | 22:81d8c59d1070 | 246 | * @return true if message sent successfully |
hsgw | 22:81d8c59d1070 | 247 | */ |
hsgw | 22:81d8c59d1070 | 248 | bool sendNoteOn(uint8_t channel, uint8_t note, uint8_t velocity); |
hsgw | 22:81d8c59d1070 | 249 | |
hsgw | 22:81d8c59d1070 | 250 | /** |
hsgw | 22:81d8c59d1070 | 251 | * Send a poly keypress event |
hsgw | 22:81d8c59d1070 | 252 | * |
hsgw | 22:81d8c59d1070 | 253 | * @param channel 0-15 |
hsgw | 22:81d8c59d1070 | 254 | * @param note 0-127 |
hsgw | 22:81d8c59d1070 | 255 | * @param pressure 0-127 |
hsgw | 22:81d8c59d1070 | 256 | * @return true if message sent successfully |
hsgw | 22:81d8c59d1070 | 257 | */ |
hsgw | 22:81d8c59d1070 | 258 | bool sendPolyKeyPress(uint8_t channel, uint8_t note, uint8_t pressure); |
hsgw | 22:81d8c59d1070 | 259 | |
hsgw | 22:81d8c59d1070 | 260 | /** |
hsgw | 22:81d8c59d1070 | 261 | * Send a control change event |
hsgw | 22:81d8c59d1070 | 262 | * |
hsgw | 22:81d8c59d1070 | 263 | * @param channel 0-15 |
hsgw | 22:81d8c59d1070 | 264 | * @param key 0-127 |
hsgw | 22:81d8c59d1070 | 265 | * @param value 0-127 |
hsgw | 22:81d8c59d1070 | 266 | * @return true if message sent successfully |
hsgw | 22:81d8c59d1070 | 267 | */ |
hsgw | 22:81d8c59d1070 | 268 | bool sendControlChange(uint8_t channel, uint8_t key, uint8_t value); |
hsgw | 22:81d8c59d1070 | 269 | |
hsgw | 22:81d8c59d1070 | 270 | /** |
hsgw | 22:81d8c59d1070 | 271 | * Send a program change event |
hsgw | 22:81d8c59d1070 | 272 | * |
hsgw | 22:81d8c59d1070 | 273 | * @param channel 0-15 |
hsgw | 22:81d8c59d1070 | 274 | * @param program 0-127 |
hsgw | 22:81d8c59d1070 | 275 | * @return true if message sent successfully |
hsgw | 22:81d8c59d1070 | 276 | */ |
hsgw | 22:81d8c59d1070 | 277 | bool sendProgramChange(uint8_t channel, uint8_t program); |
hsgw | 22:81d8c59d1070 | 278 | |
hsgw | 22:81d8c59d1070 | 279 | /** |
hsgw | 22:81d8c59d1070 | 280 | * Send a channel pressure event |
hsgw | 22:81d8c59d1070 | 281 | * |
hsgw | 22:81d8c59d1070 | 282 | * @param channel 0-15 |
hsgw | 22:81d8c59d1070 | 283 | * @param pressure 0-127 |
hsgw | 22:81d8c59d1070 | 284 | * @return true if message sent successfully |
hsgw | 22:81d8c59d1070 | 285 | */ |
hsgw | 22:81d8c59d1070 | 286 | bool sendChannelPressure(uint8_t channel, uint8_t pressure); |
hsgw | 22:81d8c59d1070 | 287 | |
hsgw | 22:81d8c59d1070 | 288 | /** |
hsgw | 22:81d8c59d1070 | 289 | * Send a control change event |
hsgw | 22:81d8c59d1070 | 290 | * |
hsgw | 22:81d8c59d1070 | 291 | * @param channel 0-15 |
hsgw | 22:81d8c59d1070 | 292 | * @param key 0(lower)-8191(center)-16383(higher) |
hsgw | 22:81d8c59d1070 | 293 | * @return true if message sent successfully |
hsgw | 22:81d8c59d1070 | 294 | */ |
hsgw | 22:81d8c59d1070 | 295 | bool sendPitchBend(uint8_t channel, uint16_t value); |
hsgw | 22:81d8c59d1070 | 296 | |
hsgw | 22:81d8c59d1070 | 297 | /** |
hsgw | 22:81d8c59d1070 | 298 | * Send a single byte event |
hsgw | 22:81d8c59d1070 | 299 | * |
hsgw | 22:81d8c59d1070 | 300 | * @param data 0-255 |
hsgw | 22:81d8c59d1070 | 301 | * @return true if message sent successfully |
hsgw | 22:81d8c59d1070 | 302 | */ |
hsgw | 22:81d8c59d1070 | 303 | bool sendSingleByte(uint8_t data); |
hsgw | 22:81d8c59d1070 | 304 | |
hsgw | 22:81d8c59d1070 | 305 | protected: |
hsgw | 22:81d8c59d1070 | 306 | //From IUSBEnumerator |
hsgw | 22:81d8c59d1070 | 307 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
hsgw | 22:81d8c59d1070 | 308 | virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed |
hsgw | 22:81d8c59d1070 | 309 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
hsgw | 22:81d8c59d1070 | 310 | |
hsgw | 22:81d8c59d1070 | 311 | private: |
hsgw | 22:81d8c59d1070 | 312 | USBHost * host; |
hsgw | 22:81d8c59d1070 | 313 | USBDeviceConnected * dev; |
hsgw | 22:81d8c59d1070 | 314 | USBEndpoint * bulk_in; |
hsgw | 22:81d8c59d1070 | 315 | USBEndpoint * bulk_out; |
hsgw | 22:81d8c59d1070 | 316 | uint32_t size_bulk_in; |
hsgw | 22:81d8c59d1070 | 317 | uint32_t size_bulk_out; |
hsgw | 22:81d8c59d1070 | 318 | |
hsgw | 22:81d8c59d1070 | 319 | bool dev_connected; |
hsgw | 22:81d8c59d1070 | 320 | |
hsgw | 22:81d8c59d1070 | 321 | void init(); |
hsgw | 22:81d8c59d1070 | 322 | |
hsgw | 22:81d8c59d1070 | 323 | uint8_t buf[64]; |
hsgw | 22:81d8c59d1070 | 324 | |
hsgw | 22:81d8c59d1070 | 325 | void rxHandler(); |
hsgw | 22:81d8c59d1070 | 326 | |
hsgw | 22:81d8c59d1070 | 327 | uint16_t sysExBufferPos; |
hsgw | 22:81d8c59d1070 | 328 | uint8_t sysExBuffer[64]; |
hsgw | 22:81d8c59d1070 | 329 | |
hsgw | 22:81d8c59d1070 | 330 | void (*miscellaneousFunctionCode)(uint8_t, uint8_t, uint8_t); |
hsgw | 22:81d8c59d1070 | 331 | void (*cableEvent)(uint8_t, uint8_t, uint8_t); |
hsgw | 22:81d8c59d1070 | 332 | void (*systemCommonTwoBytes)(uint8_t, uint8_t); |
hsgw | 22:81d8c59d1070 | 333 | void (*systemCommonThreeBytes)(uint8_t, uint8_t, uint8_t); |
hsgw | 22:81d8c59d1070 | 334 | void (*systemExclusive)(uint8_t *, uint16_t, bool); |
hsgw | 22:81d8c59d1070 | 335 | void (*noteOff)(uint8_t, uint8_t, uint8_t); |
hsgw | 22:81d8c59d1070 | 336 | void (*noteOn)(uint8_t, uint8_t, uint8_t); |
hsgw | 22:81d8c59d1070 | 337 | void (*polyKeyPress)(uint8_t, uint8_t, uint8_t); |
hsgw | 22:81d8c59d1070 | 338 | void (*controlChange)(uint8_t, uint8_t, uint8_t); |
hsgw | 22:81d8c59d1070 | 339 | void (*programChange)(uint8_t, uint8_t); |
hsgw | 22:81d8c59d1070 | 340 | void (*channelPressure)(uint8_t, uint8_t); |
hsgw | 22:81d8c59d1070 | 341 | void (*pitchBend)(uint8_t, uint16_t); |
hsgw | 22:81d8c59d1070 | 342 | void (*singleByte)(uint8_t); |
hsgw | 22:81d8c59d1070 | 343 | |
hsgw | 22:81d8c59d1070 | 344 | bool sendMidiBuffer(uint8_t data0, uint8_t data1, uint8_t data2, uint8_t data3); |
hsgw | 22:81d8c59d1070 | 345 | |
hsgw | 22:81d8c59d1070 | 346 | int midi_intf; |
hsgw | 22:81d8c59d1070 | 347 | bool midi_device_found; |
hsgw | 22:81d8c59d1070 | 348 | |
hsgw | 22:81d8c59d1070 | 349 | }; |
hsgw | 22:81d8c59d1070 | 350 | |
hsgw | 22:81d8c59d1070 | 351 | #endif /* USBHOST_MIDI */ |
hsgw | 22:81d8c59d1070 | 352 | |
hsgw | 22:81d8c59d1070 | 353 | #endif /* USBHOSTMIDI_H */ |