summaryrefslogtreecommitdiff
path: root/libs/backends/coreaudio/coreaudio_backend.h
diff options
context:
space:
mode:
Diffstat (limited to 'libs/backends/coreaudio/coreaudio_backend.h')
-rw-r--r--libs/backends/coreaudio/coreaudio_backend.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/libs/backends/coreaudio/coreaudio_backend.h b/libs/backends/coreaudio/coreaudio_backend.h
index 3300fc4216..caf8edafba 100644
--- a/libs/backends/coreaudio/coreaudio_backend.h
+++ b/libs/backends/coreaudio/coreaudio_backend.h
@@ -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