@@ -176,15 +176,17 @@ void BLEMidi::_write_handler(uint8_t* data, uint16_t len)
176176 while (len)
177177 {
178178
179- if ( bitRead (data[0 ], 7 ) && bitRead (data[1 ], 7 ) )
179+ // timestamp low byte followed by a MIDI status,
180+ // so we drop the timestamp low byte
181+ if ( isStatusByte (data[0 ]) && isStatusByte (data[1 ]) )
180182 {
181- // timestamp low + MIDI status so we skip the timestamp
182183 data++;
183184 len--;
184185 }
185- else if ( bitRead (data[0 ], 7 ) && ! bitRead (data[1 ], 7 ) )
186+ // timestamp low byte on it's own (running status),
187+ // so we drop the timestamp low byte
188+ else if ( isStatusByte (data[0 ]) && ! isStatusByte (data[1 ]) )
186189 {
187- // timestamp low on its own, skip timestamp
188190 data++;
189191 len--;
190192 }
@@ -194,7 +196,6 @@ void BLEMidi::_write_handler(uint8_t* data, uint16_t len)
194196 len--;
195197
196198 if ( _write_cb ) _write_cb ();
197-
198199 }
199200
200201#ifdef MIDI_LIB_INCLUDED
@@ -234,7 +235,7 @@ size_t BLEMidi::write ( uint8_t b )
234235 {
235236 // send and clear the last of the existing buffer.
236237 // it should contain the final bytes in the sysex payload.
237- if (bitRead (buf[0 ], 7 ))
238+ if (isStatusByte (buf[0 ]))
238239 send (buf, count);
239240 else
240241 sendSplit (buf, count);
@@ -259,12 +260,12 @@ size_t BLEMidi::write ( uint8_t b )
259260 count = 0 ;
260261 }
261262
262- // if we have a full buffer at this point, we
263- // need to send a full or split sysex message
264- // and reset the buffer.
263+ // do we have a full buffer at this point?
265264 if (count == BLE_MIDI_TX_BUFFER_SIZE)
266265 {
267- if (bitRead (buf[0 ], 7 ))
266+ // send a full or split message depending
267+ // on the type of the first byte in the buffer
268+ if (isStatusByte (buf[0 ]))
268269 send (buf, count);
269270 else
270271 sendSplit (buf, count);
@@ -275,7 +276,6 @@ size_t BLEMidi::write ( uint8_t b )
275276 }
276277
277278 return 1 ;
278-
279279}
280280
281281int BLEMidi::available ( void )
@@ -297,6 +297,15 @@ void BLEMidi::flush ( void )
297297/* ------------------------------------------------------------------*/
298298/* Message Type Helpers
299299 *------------------------------------------------------------------*/
300+ bool BLEMidi::isStatusByte ( uint8_t b )
301+ {
302+ // if the bit 7 is set, then it's a MIDI status message
303+ if (bitRead (b, 7 ))
304+ return true ;
305+ else
306+ return false ;
307+ }
308+
300309bool BLEMidi::oneByteMessage ( uint8_t status )
301310{
302311 // system messages
0 commit comments