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_midi_h__
20 #define __libbackend_alsa_midi_h__
26 #include "pbd/ringbuffer.h"
27 #include "ardour/types.h"
34 virtual ~AlsaMidiIO ();
36 int state (void) const { return _state; }
40 void setup_timing (const size_t samples_per_period, const float samplerate);
41 void sync_time(uint64_t);
43 virtual void* main_process_thread () = 0;
45 const std::string & name () const { return _name; }
48 pthread_t _main_thread;
49 pthread_mutex_t _notify_mutex;
50 pthread_cond_t _notify_ready;
58 double _sample_length_us;
59 double _period_length_us;
60 size_t _samples_per_period;
61 uint64_t _clock_monotonic;
63 struct MidiEventHeader {
66 MidiEventHeader(const uint64_t t, const size_t s)
71 RingBuffer<uint8_t>* _rb;
75 virtual void init (const char *device_name, const bool input) = 0;
79 class AlsaMidiOut : virtual public AlsaMidiIO
84 int send_event (const pframes_t, const uint8_t *, const size_t);
87 class AlsaMidiIn : virtual public AlsaMidiIO
92 size_t recv_event (pframes_t &, uint8_t *, size_t &);
95 int queue_event (const uint64_t, const uint8_t *, const size_t);