2 * Copyright (C) 2015 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_coremidi_io_h__
20 #define __libbackend_coremidi_io_h__
22 #include <CoreServices/CoreServices.h>
23 #include <CoreAudio/CoreAudio.h>
24 #include <AudioUnit/AudioUnit.h>
26 #include <AudioUnit/AudioUnit.h>
27 #include <AudioToolbox/AudioToolbox.h>
33 #include <boost/shared_ptr.hpp>
34 #include "pbd/ringbuffer.h"
38 typedef struct _CoreMIDIPacket {
39 MIDITimeStamp timeStamp;
43 _CoreMIDIPacket (MIDITimeStamp t, Byte *d, UInt16 l)
51 memcpy(data, d, length);
55 _CoreMIDIPacket (const MIDIPacket *other)
56 : timeStamp(other->timeStamp)
57 , length (other->length)
60 memcpy(data, other->data, length);
65 typedef std::vector<boost::shared_ptr<CoreMIDIPacket> > CoreMIDIQueue;
77 int send_event (uint32_t, double, const uint8_t *, const size_t);
78 int send_events (uint32_t, double, const void *);
79 size_t recv_event (uint32_t, double, uint64_t &, uint8_t *, size_t &);
81 uint32_t n_midi_inputs (void) const { return _n_midi_in; }
82 uint32_t n_midi_outputs (void) const { return _n_midi_out; }
83 std::string port_id (uint32_t, bool input);
84 std::string port_name (uint32_t, bool input);
86 void notify_proc (const MIDINotification *message);
88 void set_enabled (bool yn = true) { _enabled = yn; }
89 bool enabled (void) const { return _active && _enabled; }
91 void set_port_changed_callback (void (changed_callback (void*)), void *arg) {
92 _changed_callback = changed_callback;
100 MIDIClientRef _midi_client;
101 MIDIEndpointRef * _input_endpoints;
102 MIDIEndpointRef * _output_endpoints;
103 MIDIPortRef * _input_ports;
104 MIDIPortRef * _output_ports;
105 CoreMIDIQueue * _input_queue;
107 RingBuffer<uint8_t> ** _rb;
110 uint32_t _n_midi_out;
112 MIDITimeStamp _time_at_cycle_start;
113 bool _active; // internal deactivate during discovery etc
114 bool _enabled; // temporary disable, e.g. during freewheeli
115 bool _run; // general status
117 void (* _changed_callback) (void*);
120 pthread_mutex_t _discovery_lock;
125 #endif /* __libbackend_coremidi_io */