add an explicit midi parser/chunker to CoreAudio

This commit is contained in:
Robin Gareus 2015-07-01 01:12:17 +02:00
parent 619a517f2a
commit b86cf68e1f
2 changed files with 172 additions and 0 deletions

View file

@ -445,6 +445,61 @@ class CoreAudioBackend : public AudioBackend {
return NULL;
}
#define USE_MIDI_PARSER
#ifdef USE_MIDI_PARSER
bool midi_process_byte (const uint8_t);
void midi_record_byte(uint8_t byte) {
if (_total_bytes < sizeof(_parser_buffer)) {
_parser_buffer[_total_bytes] = byte;
} else {
++_unbuffered_bytes;
}
++_total_bytes;
}
void midi_prepare_byte_event(const uint8_t byte) {
_parser_buffer[0] = byte;
_event.prepare(1);
}
bool midi_prepare_buffered_event() {
const bool result = _unbuffered_bytes == 0;
if (result) {
_event.prepare(_total_bytes);
}
_total_bytes = 0;
_unbuffered_bytes = 0;
if (_status_byte >= 0xf0) {
_expected_bytes = 0;
_status_byte = 0;
}
return result;
}
struct ParserEvent {
size_t _size;
bool _pending;
ParserEvent (const size_t size)
: _size(size)
, _pending(false) {}
void prepare(const size_t size) {
_size = size;
_pending = true;
}
} _event;
bool _first_time;
size_t _unbuffered_bytes;
size_t _total_bytes;
size_t _expected_bytes;
uint8_t _status_byte;
uint8_t _parser_buffer[1024];
#endif
}; // class CoreAudioBackend
} // namespace