2 * Copyright (C) 2014 Robin Gareus <robin@gareus.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #ifndef __libbackend_alsa_rawmidi_h__
20 #define __libbackend_alsa_rawmidi_h__
26 #include <alsa/asoundlib.h>
28 #include "pbd/ringbuffer.h"
29 #include "ardour/types.h"
30 #include "alsa_midi.h"
34 class AlsaRawMidiIO : virtual public AlsaMidiIO {
36 AlsaRawMidiIO (const std::string &name, const char *device, const bool input);
37 virtual ~AlsaRawMidiIO ();
40 snd_rawmidi_t *_device;
43 void init (const char *device_name, const bool input);
46 class AlsaRawMidiOut : public AlsaRawMidiIO, public AlsaMidiOut
49 AlsaRawMidiOut (const std::string &name, const char *device);
50 void* main_process_thread ();
53 class AlsaRawMidiIn : public AlsaRawMidiIO, public AlsaMidiIn
56 AlsaRawMidiIn (const std::string &name, const char *device);
58 void* main_process_thread ();
61 int queue_event (const uint64_t, const uint8_t *, const size_t);
63 void parse_events (const uint64_t, const uint8_t *, const size_t);
64 bool process_byte (const uint64_t, const uint8_t);
66 void record_byte(uint8_t byte) {
67 if (_total_bytes < sizeof(_parser_buffer)) {
68 _parser_buffer[_total_bytes] = byte;
75 void prepare_byte_event(const uint64_t time, const uint8_t byte) {
76 _parser_buffer[0] = byte;
77 _event.prepare(time, 1);
80 bool prepare_buffered_event(const uint64_t time) {
81 const bool result = _unbuffered_bytes == 0;
83 _event.prepare(time, _total_bytes);
86 _unbuffered_bytes = 0;
87 if (_status_byte >= 0xf0) {
98 ParserEvent (const uint64_t time, const size_t size)
103 void prepare(const uint64_t time, const size_t size) {
111 size_t _unbuffered_bytes;
113 size_t _expected_bytes;
114 uint8_t _status_byte;
115 uint8_t _parser_buffer[1024];