summaryrefslogtreecommitdiff
path: root/libs/backends/coreaudio/coreaudio_backend.h
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2016-01-07 16:42:24 -0500
committerPaul Davis <paul@linuxaudiosystems.com>2016-01-07 16:42:34 -0500
commit6e71d3b44521fdfbf731d909f736ec282677f349 (patch)
treea048ef05d27d63557476126f316ed096394348b2 /libs/backends/coreaudio/coreaudio_backend.h
parent4be4f8fb6223394761496173fecaeb09b85eeb6c (diff)
coreaudio: per-port parser for incoming MIDI, copied from ALSA Raw MIDI support
Diffstat (limited to 'libs/backends/coreaudio/coreaudio_backend.h')
-rw-r--r--libs/backends/coreaudio/coreaudio_backend.h98
1 files changed, 58 insertions, 40 deletions
diff --git a/libs/backends/coreaudio/coreaudio_backend.h b/libs/backends/coreaudio/coreaudio_backend.h
index c4cbed91d5..5682cc6966 100644
--- a/libs/backends/coreaudio/coreaudio_backend.h
+++ b/libs/backends/coreaudio/coreaudio_backend.h
@@ -149,10 +149,67 @@ class CoreMidiPort : public CoreBackendPort {
void next_period() { if (_n_periods > 1) { get_buffer(0); _bufperiod = (_bufperiod + 1) % _n_periods; } }
void set_n_periods(int n) { if (n > 0 && n < 3) { _n_periods = n; } }
+ void parse_events (const uint64_t time, const uint8_t *data, const size_t size);
+
private:
CoreMidiBuffer _buffer[2];
int _n_periods;
int _bufperiod;
+
+ int queue_event (void* port_buffer, pframes_t timestamp, const uint8_t* buffer, size_t size);
+ bool process_byte (const uint64_t, const uint8_t);
+
+ void record_byte(uint8_t byte) {
+ if (_total_bytes < sizeof(_parser_buffer)) {
+ _parser_buffer[_total_bytes] = byte;
+ } else {
+ ++_unbuffered_bytes;
+ }
+ ++_total_bytes;
+ }
+
+ void prepare_byte_event(const uint64_t time, const uint8_t byte) {
+ _parser_buffer[0] = byte;
+ _event.prepare(time, 1);
+ }
+
+ bool prepare_buffered_event(const uint64_t time) {
+ const bool result = _unbuffered_bytes == 0;
+ if (result) {
+ _event.prepare(time, _total_bytes);
+ }
+ _total_bytes = 0;
+ _unbuffered_bytes = 0;
+ if (_status_byte >= 0xf0) {
+ _expected_bytes = 0;
+ _status_byte = 0;
+ }
+ return result;
+ }
+
+ struct ParserEvent {
+ uint64_t _time;
+ size_t _size;
+ bool _pending;
+ ParserEvent (const uint64_t time, const size_t size)
+ : _time(time)
+ , _size(size)
+ , _pending(false) {}
+
+ void prepare(const uint64_t time, const size_t size) {
+ _time = time;
+ _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];
+
}; // class CoreMidiPort
class CoreAudioBackend : public AudioBackend {
@@ -293,6 +350,7 @@ class CoreAudioBackend : public AudioBackend {
/* MIDI */
int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t** buf, void* port_buffer, uint32_t event_index);
int midi_event_put (void* port_buffer, pframes_t timestamp, const uint8_t* buffer, size_t size);
+
uint32_t get_midi_event_count (void* port_buffer);
void midi_clear (void* port_buffer);
@@ -449,46 +507,6 @@ class CoreAudioBackend : public AudioBackend {
return NULL;
}
-#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;
- _parser_bytes = 1;
- }
-
- bool midi_prepare_buffered_event () {
- const bool result = _unbuffered_bytes == 0;
- if (result) {
- _parser_bytes = _total_bytes;
- }
- _total_bytes = 0;
- _unbuffered_bytes = 0;
- if (_status_byte >= 0xf0) {
- _expected_bytes = 0;
- _status_byte = 0;
- }
- return result;
- }
-
- size_t _unbuffered_bytes;
- size_t _total_bytes;
- size_t _expected_bytes;
- uint8_t _status_byte;
- uint8_t _parser_buffer[128];
- uint8_t _parser_bytes;
-#endif
-
}; // class CoreAudioBackend
} // namespace