2015-03-05 00:22:33 -05:00
|
|
|
/*
|
2019-08-02 22:11:41 -04:00
|
|
|
* Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
|
2015-03-05 00:22:33 -05:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2019-08-02 22:11:41 -04:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2015-03-05 00:22:33 -05:00
|
|
|
*/
|
|
|
|
|
2015-03-09 14:01:24 -04:00
|
|
|
#ifndef __libbackend_coremidi_io_h__
|
|
|
|
#define __libbackend_coremidi_io_h__
|
|
|
|
|
2015-03-05 00:22:33 -05:00
|
|
|
#include <CoreServices/CoreServices.h>
|
|
|
|
#include <CoreAudio/CoreAudio.h>
|
|
|
|
#include <AudioUnit/AudioUnit.h>
|
|
|
|
|
|
|
|
#include <AudioUnit/AudioUnit.h>
|
|
|
|
#include <AudioToolbox/AudioToolbox.h>
|
|
|
|
|
|
|
|
#include <map>
|
2023-02-16 12:59:41 -05:00
|
|
|
#include <memory>
|
2015-03-05 00:22:33 -05:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "pbd/ringbuffer.h"
|
|
|
|
|
2015-03-09 14:01:24 -04:00
|
|
|
namespace ARDOUR {
|
|
|
|
|
|
|
|
typedef struct _CoreMIDIPacket {
|
2015-10-04 14:51:05 -04:00
|
|
|
MIDITimeStamp timeStamp;
|
|
|
|
UInt16 length;
|
|
|
|
Byte data[256];
|
2015-03-05 00:22:33 -05:00
|
|
|
#if 0 // unused
|
|
|
|
_CoreMIDIPacket (MIDITimeStamp t, Byte *d, UInt16 l)
|
|
|
|
: timeStamp(t)
|
|
|
|
, length (l)
|
|
|
|
{
|
|
|
|
if (l > 256) {
|
|
|
|
length = 256;
|
|
|
|
}
|
|
|
|
if (length > 0) {
|
|
|
|
memcpy(data, d, length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2015-10-04 14:51:05 -04:00
|
|
|
_CoreMIDIPacket (const MIDIPacket *other)
|
2015-03-05 00:22:33 -05:00
|
|
|
: timeStamp(other->timeStamp)
|
|
|
|
, length (other->length)
|
|
|
|
{
|
|
|
|
if (length > 0) {
|
|
|
|
memcpy(data, other->data, length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} CoreMIDIPacket;
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
typedef std::vector<std::shared_ptr<CoreMIDIPacket> > CoreMIDIQueue;
|
2015-03-05 00:22:33 -05:00
|
|
|
|
|
|
|
class CoreMidiIo {
|
|
|
|
public:
|
|
|
|
CoreMidiIo (void);
|
|
|
|
~CoreMidiIo (void);
|
|
|
|
|
2015-03-06 22:15:02 -05:00
|
|
|
void start ();
|
|
|
|
void stop ();
|
|
|
|
|
2015-03-05 00:22:33 -05:00
|
|
|
void start_cycle ();
|
|
|
|
|
|
|
|
int send_event (uint32_t, double, const uint8_t *, const size_t);
|
2015-03-09 18:28:18 -04:00
|
|
|
int send_events (uint32_t, double, const void *);
|
2015-03-05 00:22:33 -05:00
|
|
|
size_t recv_event (uint32_t, double, uint64_t &, uint8_t *, size_t &);
|
|
|
|
|
|
|
|
uint32_t n_midi_inputs (void) const { return _n_midi_in; }
|
|
|
|
uint32_t n_midi_outputs (void) const { return _n_midi_out; }
|
2015-03-08 13:11:38 -04:00
|
|
|
std::string port_id (uint32_t, bool input);
|
2015-03-06 22:15:02 -05:00
|
|
|
std::string port_name (uint32_t, bool input);
|
2015-03-05 00:22:33 -05:00
|
|
|
|
|
|
|
void notify_proc (const MIDINotification *message);
|
|
|
|
|
2015-03-06 22:15:02 -05:00
|
|
|
void set_enabled (bool yn = true) { _enabled = yn; }
|
|
|
|
bool enabled (void) const { return _active && _enabled; }
|
|
|
|
|
2015-03-05 21:21:47 -05:00
|
|
|
void set_port_changed_callback (void (changed_callback (void*)), void *arg) {
|
2015-03-05 00:22:33 -05:00
|
|
|
_changed_callback = changed_callback;
|
|
|
|
_changed_arg = arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-03-06 22:15:02 -05:00
|
|
|
void discover ();
|
2015-03-05 00:22:33 -05:00
|
|
|
void cleanup ();
|
|
|
|
|
2015-03-05 21:21:47 -05:00
|
|
|
MIDIClientRef _midi_client;
|
|
|
|
MIDIEndpointRef * _input_endpoints;
|
|
|
|
MIDIEndpointRef * _output_endpoints;
|
|
|
|
MIDIPortRef * _input_ports;
|
|
|
|
MIDIPortRef * _output_ports;
|
|
|
|
CoreMIDIQueue * _input_queue;
|
|
|
|
|
2017-09-16 09:44:48 -04:00
|
|
|
PBD::RingBuffer<uint8_t> ** _rb;
|
2015-03-05 00:22:33 -05:00
|
|
|
|
2015-03-05 21:21:47 -05:00
|
|
|
uint32_t _n_midi_in;
|
|
|
|
uint32_t _n_midi_out;
|
2015-03-05 00:22:33 -05:00
|
|
|
|
2015-03-05 21:21:47 -05:00
|
|
|
MIDITimeStamp _time_at_cycle_start;
|
2015-03-06 22:15:02 -05:00
|
|
|
bool _active; // internal deactivate during discovery etc
|
|
|
|
bool _enabled; // temporary disable, e.g. during freewheeli
|
|
|
|
bool _run; // general status
|
2015-03-05 00:22:33 -05:00
|
|
|
|
|
|
|
void (* _changed_callback) (void*);
|
|
|
|
void * _changed_arg;
|
2015-03-06 22:15:02 -05:00
|
|
|
|
|
|
|
pthread_mutex_t _discovery_lock;
|
2015-03-05 00:22:33 -05:00
|
|
|
};
|
2015-03-09 14:01:24 -04:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif /* __libbackend_coremidi_io */
|