summaryrefslogtreecommitdiff
path: root/libs/midi++2
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2013-07-24 19:29:45 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2013-07-24 19:29:45 -0400
commit9ac6bb9befa047a6c349bed02d40da84600b67cc (patch)
tree5b88f453b8f43d2a43b31cb15b0b50acd6f9eb4a /libs/midi++2
parent3d95822716d2e52b54a5bdbe7be4478ab034f8db (diff)
part-way through getting the audioengine changes to compile
Diffstat (limited to 'libs/midi++2')
-rw-r--r--libs/midi++2/jack_midi_port.cc123
-rw-r--r--libs/midi++2/manager.cc24
-rw-r--r--libs/midi++2/midi++/jack_midi_port.h21
-rw-r--r--libs/midi++2/midi++/manager.h10
-rw-r--r--libs/midi++2/midi++/mmc.h8
-rw-r--r--libs/midi++2/mmc.cc8
-rw-r--r--libs/midi++2/wscript3
7 files changed, 103 insertions, 94 deletions
diff --git a/libs/midi++2/jack_midi_port.cc b/libs/midi++2/jack_midi_port.cc
index 05df3171fa..372a7891c9 100644
--- a/libs/midi++2/jack_midi_port.cc
+++ b/libs/midi++2/jack_midi_port.cc
@@ -22,9 +22,6 @@
#include <fcntl.h>
#include <errno.h>
-#include <jack/jack.h>
-#include <jack/midiport.h>
-
#include "pbd/xml++.h"
#include "pbd/error.h"
#include "pbd/failed_constructor.h"
@@ -45,37 +42,34 @@ template class EventRingBuffer<timestamp_t>;
}
pthread_t JackMIDIPort::_process_thread;
-Signal0<void> JackMIDIPort::JackHalted;
+Signal0<void> JackMIDIPort::EngineHalted;
Signal0<void> JackMIDIPort::MakeConnections;
-JackMIDIPort::JackMIDIPort (string const & name, Flags flags, jack_client_t* jack_client)
+JackMIDIPort::JackMIDIPort (string const & name, Flags flags, ARDOUR::PortEngine& pengine)
: Port (name, flags)
+ , _port_engine (pengine)
+ , _port_handle (0)
, _currently_in_cycle (false)
, _nframes_this_cycle (0)
- , _jack_client (jack_client)
- , _jack_port (0)
, _last_write_timestamp (0)
, output_fifo (512)
, input_fifo (1024)
, xthread (true)
{
- assert (jack_client);
init (name, flags);
}
-JackMIDIPort::JackMIDIPort (const XMLNode& node, jack_client_t* jack_client)
+JackMIDIPort::JackMIDIPort (const XMLNode& node, ARDOUR::PortEngine& pengine)
: Port (node)
+ , _port_engine (pengine)
+ , _port_handle (0)
, _currently_in_cycle (false)
, _nframes_this_cycle (0)
- , _jack_client (jack_client)
- , _jack_port (0)
, _last_write_timestamp (0)
, output_fifo (512)
, input_fifo (1024)
, xthread (true)
{
- assert (jack_client);
-
Descriptor desc (node);
init (desc.tag, desc.flags);
set_state (node);
@@ -89,17 +83,15 @@ JackMIDIPort::init (const string& /*name*/, Flags /*flags*/)
}
MakeConnections.connect_same_thread (connect_connection, boost::bind (&JackMIDIPort::make_connections, this));
- JackHalted.connect_same_thread (halt_connection, boost::bind (&JackMIDIPort::jack_halted, this));
+ EngineHalted.connect_same_thread (halt_connection, boost::bind (&JackMIDIPort::engine_halted, this));
}
JackMIDIPort::~JackMIDIPort ()
{
- if (_jack_port) {
- if (_jack_client) {
- jack_port_unregister (_jack_client, _jack_port);
- _jack_port = 0;
- }
+ if (_port_handle) {
+ _port_engine.unregister_port (_port_handle);
+ _port_handle = 0;
}
}
@@ -143,7 +135,7 @@ JackMIDIPort::parse (framecnt_t timestamp)
void
JackMIDIPort::cycle_start (pframes_t nframes)
{
- assert (_jack_port);
+ assert (_port_handle);
_currently_in_cycle = true;
_nframes_this_cycle = nframes;
@@ -151,21 +143,23 @@ JackMIDIPort::cycle_start (pframes_t nframes)
assert(_nframes_this_cycle == nframes);
if (sends_output()) {
- void *buffer = jack_port_get_buffer (_jack_port, nframes);
+ void *buffer = _port_engine.get_buffer (_port_handle, nframes);
jack_midi_clear_buffer (buffer);
flush (buffer);
}
if (receives_input()) {
- void* jack_buffer = jack_port_get_buffer(_jack_port, nframes);
- const pframes_t event_count = jack_midi_get_event_count(jack_buffer);
+ void* buffer = _port_engine.get_buffer (_port_handle, nframes);
+ const pframes_t event_count = _port_engine.get_midi_event_count (buffer);
- jack_midi_event_t ev;
- timestamp_t cycle_start_frame = jack_last_frame_time (_jack_client);
+ pframes_t time;
+ size_t size;
+ uint8_t* buf;
+ timestamp_t cycle_start_frame = _port_engine.last_frame_time ();
for (pframes_t i = 0; i < event_count; ++i) {
- jack_midi_event_get (&ev, jack_buffer, i);
- input_fifo.write (cycle_start_frame + ev.time, (Evoral::EventType) 0, ev.size, ev.buffer);
+ _port_engine.midi_event_get (time, size, &buf, buffer, i);
+ input_fifo.write (cycle_start_frame + time, (Evoral::EventType) 0, size, buf);
}
if (event_count) {
@@ -178,7 +172,7 @@ void
JackMIDIPort::cycle_end ()
{
if (sends_output()) {
- flush (jack_port_get_buffer (_jack_port, _nframes_this_cycle));
+ flush (_port_engine.get_buffer (_port_handle, _nframes_this_cycle));
}
_currently_in_cycle = false;
@@ -186,10 +180,9 @@ JackMIDIPort::cycle_end ()
}
void
-JackMIDIPort::jack_halted ()
+JackMIDIPort::engine_halted ()
{
- _jack_client = 0;
- _jack_port = 0;
+ _port_handle = 0;
}
void
@@ -216,7 +209,7 @@ JackMIDIPort::write (const byte * msg, size_t msglen, timestamp_t timestamp)
{
int ret = 0;
- if (!_jack_client || !_jack_port) {
+ if (!_port_handle) {
/* poof ! make it just vanish into thin air, since we are no
longer connected to JACK.
*/
@@ -268,18 +261,18 @@ JackMIDIPort::write (const byte * msg, size_t msglen, timestamp_t timestamp)
if (timestamp == 0) {
timestamp = _last_write_timestamp;
}
-
- if ((ret = jack_midi_event_write (jack_port_get_buffer (_jack_port, _nframes_this_cycle),
- timestamp, msg, msglen)) == 0) {
+
+ if ((ret = _port_engine.midi_event_put (_port_engine.get_buffer (_port_handle, _nframes_this_cycle),
+ timestamp, msg, msglen)) == 0) {
ret = msglen;
_last_write_timestamp = timestamp;
} else {
cerr << "write of " << msglen << " @ " << timestamp << " failed, port holds "
- << jack_midi_get_event_count (jack_port_get_buffer (_jack_port, _nframes_this_cycle))
- << " port is " << _jack_port
+ << _port_engine.get_midi_event_count (_port_engine.get_buffer (_port_handle, _nframes_this_cycle))
+ << " port is " << _port_handle
<< " ntf = " << _nframes_this_cycle
- << " buf = " << jack_port_get_buffer (_jack_port, _nframes_this_cycle)
+ << " buf = " << _port_engine.get_buffer (_port_handle, _nframes_this_cycle)
<< " ret = " << ret
<< endl;
PBD::stacktrace (cerr, 20);
@@ -305,7 +298,7 @@ JackMIDIPort::write (const byte * msg, size_t msglen, timestamp_t timestamp)
}
void
-JackMIDIPort::flush (void* jack_port_buffer)
+JackMIDIPort::flush (void* port_buffer)
{
RingBuffer< Evoral::Event<double> >::rw_vector vec = { { 0, 0 }, { 0, 0 } };
size_t written;
@@ -320,8 +313,7 @@ JackMIDIPort::flush (void* jack_port_buffer)
Evoral::Event<double>* evp = vec.buf[0];
for (size_t n = 0; n < vec.len[0]; ++n, ++evp) {
- jack_midi_event_write (jack_port_buffer,
- (timestamp_t) evp->time(), evp->buffer(), evp->size());
+ _port_engine.midi_event_put (port_buffer, (timestamp_t) evp->time(), evp->buffer(), evp->size());
}
}
@@ -329,8 +321,7 @@ JackMIDIPort::flush (void* jack_port_buffer)
Evoral::Event<double>* evp = vec.buf[1];
for (size_t n = 0; n < vec.len[1]; ++n, ++evp) {
- jack_midi_event_write (jack_port_buffer,
- (timestamp_t) evp->time(), evp->buffer(), evp->size());
+ _port_engine.midi_event_put (port_buffer, (timestamp_t) evp->time(), evp->buffer(), evp->size());
}
}
@@ -364,8 +355,21 @@ JackMIDIPort::read (byte *, size_t)
int
JackMIDIPort::create_port ()
{
- _jack_port = jack_port_register(_jack_client, _tagname.c_str(), JACK_DEFAULT_MIDI_TYPE, _flags, 0);
- return _jack_port == 0 ? -1 : 0;
+ ARDOUR::PortFlags f = ARDOUR::PortFlags (0);
+
+ /* convert MIDI::Port::Flags to ARDOUR::PortFlags ... sigh */
+
+ if (_flags & IsInput) {
+ f = ARDOUR::PortFlags (f | ARDOUR::IsInput);
+ }
+
+ if (_flags & IsOutput) {
+ f = ARDOUR::PortFlags (f | ARDOUR::IsOutput);
+ }
+
+ _port_handle = _port_engine.register_port (_tagname, ARDOUR::DataType::MIDI, f);
+
+ return _port_handle == 0 ? -1 : 0;
}
XMLNode&
@@ -386,18 +390,16 @@ JackMIDIPort::get_state () const
write (device_inquiry, sizeof (device_inquiry), 0);
#endif
- if (_jack_port) {
+ if (_port_handle) {
- const char** jc = jack_port_get_connections (_jack_port);
+ vector<string> connections;
+ _port_engine.get_connections (_port_handle, connections);
string connection_string;
- if (jc) {
- for (int i = 0; jc[i]; ++i) {
- if (i > 0) {
- connection_string += ',';
- }
- connection_string += jc[i];
+ for (vector<string>::iterator i = connections.begin(); i != connections.end(); ++i) {
+ if (i != connections.begin()) {
+ connection_string += ',';
}
- free (jc);
+ connection_string += *i;
}
if (!connection_string.empty()) {
@@ -435,14 +437,8 @@ JackMIDIPort::make_connections ()
vector<string> ports;
split (_connections, ports, ',');
for (vector<string>::iterator x = ports.begin(); x != ports.end(); ++x) {
- if (_jack_client) {
- if (receives_input()) {
- jack_connect (_jack_client, (*x).c_str(), jack_port_name (_jack_port));
- } else {
- jack_connect (_jack_client, jack_port_name (_jack_port), (*x).c_str());
- }
- /* ignore failures */
- }
+ _port_engine.connect (_port_handle, *x);
+ /* ignore failures */
}
}
@@ -462,9 +458,8 @@ JackMIDIPort::is_process_thread()
}
void
-JackMIDIPort::reestablish (jack_client_t* jack)
+JackMIDIPort::reestablish ()
{
- _jack_client = jack;
int const r = create_port ();
if (r) {
diff --git a/libs/midi++2/manager.cc b/libs/midi++2/manager.cc
index 822c74e125..3df9681dd3 100644
--- a/libs/midi++2/manager.cc
+++ b/libs/midi++2/manager.cc
@@ -36,17 +36,17 @@ using namespace PBD;
Manager *Manager::theManager = 0;
-Manager::Manager (jack_client_t* jack)
+Manager::Manager (ARDOUR::PortEngine& eng)
: _ports (new PortList)
{
- _mmc = new MachineControl (this, jack);
+ _mmc = new MachineControl (this, eng);
- _mtc_input_port = add_port (new MIDI::JackMIDIPort ("MTC in", Port::IsInput, jack));
- _mtc_output_port = add_port (new MIDI::JackMIDIPort ("MTC out", Port::IsOutput, jack));
- _midi_input_port = add_port (new MIDI::JackMIDIPort ("MIDI control in", Port::IsInput, jack));
- _midi_output_port = add_port (new MIDI::JackMIDIPort ("MIDI control out", Port::IsOutput, jack));
- _midi_clock_input_port = add_port (new MIDI::JackMIDIPort ("MIDI clock in", Port::IsInput, jack));
- _midi_clock_output_port = add_port (new MIDI::JackMIDIPort ("MIDI clock out", Port::IsOutput, jack));
+ _mtc_input_port = add_port (new MIDI::JackMIDIPort ("MTC in", Port::IsInput, eng));
+ _mtc_output_port = add_port (new MIDI::JackMIDIPort ("MTC out", Port::IsOutput, eng));
+ _midi_input_port = add_port (new MIDI::JackMIDIPort ("MIDI control in", Port::IsInput, eng));
+ _midi_output_port = add_port (new MIDI::JackMIDIPort ("MIDI control out", Port::IsOutput, eng));
+ _midi_clock_input_port = add_port (new MIDI::JackMIDIPort ("MIDI clock in", Port::IsInput, eng));
+ _midi_clock_output_port = add_port (new MIDI::JackMIDIPort ("MIDI clock out", Port::IsOutput, eng));
}
Manager::~Manager ()
@@ -113,14 +113,14 @@ Manager::cycle_end()
/** Re-register ports that disappear on JACK shutdown */
void
-Manager::reestablish (jack_client_t* jack)
+Manager::reestablish ()
{
boost::shared_ptr<PortList> pr = _ports.reader ();
for (PortList::const_iterator p = pr->begin(); p != pr->end(); ++p) {
JackMIDIPort* pp = dynamic_cast<JackMIDIPort*> (*p);
if (pp) {
- pp->reestablish (jack);
+ pp->reestablish ();
}
}
}
@@ -157,10 +157,10 @@ Manager::port (string const & n)
}
void
-Manager::create (jack_client_t* jack)
+Manager::create (ARDOUR::PortEngine& eng)
{
assert (theManager == 0);
- theManager = new Manager (jack);
+ theManager = new Manager (eng);
}
void
diff --git a/libs/midi++2/midi++/jack_midi_port.h b/libs/midi++2/midi++/jack_midi_port.h
index a8859387a4..492756067c 100644
--- a/libs/midi++2/midi++/jack_midi_port.h
+++ b/libs/midi++2/midi++/jack_midi_port.h
@@ -22,8 +22,6 @@
#include <string>
#include <iostream>
-#include <jack/types.h>
-
#include "pbd/xml++.h"
#include "pbd/crossthread.h"
#include "pbd/signals.h"
@@ -36,6 +34,8 @@
#include "midi++/parser.h"
#include "midi++/port.h"
+#include "ardour/port_engine.h"
+
namespace MIDI {
class Channel;
@@ -43,8 +43,8 @@ class PortRequest;
class JackMIDIPort : public Port {
public:
- JackMIDIPort (std::string const &, Port::Flags, jack_client_t *);
- JackMIDIPort (const XMLNode&, jack_client_t *);
+ JackMIDIPort (std::string const &, Port::Flags, ARDOUR::PortEngine&);
+ JackMIDIPort (const XMLNode&, ARDOUR::PortEngine&);
~JackMIDIPort ();
XMLNode& get_state () const;
@@ -61,7 +61,7 @@ class JackMIDIPort : public Port {
pframes_t nframes_this_cycle() const { return _nframes_this_cycle; }
- void reestablish (jack_client_t *);
+ void reestablish ();
void reconnect ();
static void set_process_thread (pthread_t);
@@ -69,13 +69,14 @@ class JackMIDIPort : public Port {
static bool is_process_thread();
static PBD::Signal0<void> MakeConnections;
- static PBD::Signal0<void> JackHalted;
+ static PBD::Signal0<void> EngineHalted;
private:
+ ARDOUR::PortEngine& _port_engine;
+ ARDOUR::PortEngine::PortHandle _port_handle;
+
bool _currently_in_cycle;
pframes_t _nframes_this_cycle;
- jack_client_t* _jack_client;
- jack_port_t* _jack_port;
timestamp_t _last_write_timestamp;
RingBuffer< Evoral::Event<double> > output_fifo;
Evoral::EventRingBuffer<timestamp_t> input_fifo;
@@ -89,8 +90,8 @@ private:
std::string _connections;
PBD::ScopedConnection connect_connection;
PBD::ScopedConnection halt_connection;
- void flush (void* jack_port_buffer);
- void jack_halted ();
+ void flush (void* port_buffer);
+ void engine_halted ();
void make_connections ();
void init (std::string const &, Flags);
diff --git a/libs/midi++2/midi++/manager.h b/libs/midi++2/midi++/manager.h
index c37ba392b4..7f4df5c6c8 100644
--- a/libs/midi++2/midi++/manager.h
+++ b/libs/midi++2/midi++/manager.h
@@ -29,6 +29,10 @@
#include "midi++/types.h"
#include "midi++/port.h"
+namespace ARDOUR {
+ class PortEngine;
+}
+
namespace MIDI {
class MachineControl;
@@ -69,14 +73,14 @@ class Manager {
boost::shared_ptr<const PortList> get_midi_ports() const { return _ports.reader (); }
- static void create (jack_client_t* jack);
+ static void create (ARDOUR::PortEngine&);
static Manager *instance () {
return theManager;
}
static void destroy ();
- void reestablish (jack_client_t *);
+ void reestablish ();
void reconnect ();
PBD::Signal0<void> PortsChanged;
@@ -84,7 +88,7 @@ class Manager {
private:
/* This is a SINGLETON pattern */
- Manager (jack_client_t *);
+ Manager (ARDOUR::PortEngine&);
static Manager *theManager;
MIDI::MachineControl* _mmc;
diff --git a/libs/midi++2/midi++/mmc.h b/libs/midi++2/midi++/mmc.h
index 18204e3fa8..0f362678ce 100644
--- a/libs/midi++2/midi++/mmc.h
+++ b/libs/midi++2/midi++/mmc.h
@@ -22,11 +22,17 @@
#include <jack/types.h>
#include "timecode/time.h"
+
#include "pbd/signals.h"
#include "pbd/ringbuffer.h"
+
#include "midi++/types.h"
#include "midi++/parser.h"
+namespace ARDOUR {
+ class PortEngine;
+}
+
namespace MIDI {
class Port;
@@ -89,7 +95,7 @@ class MachineControl
cmdResume = 0x7F
};
- MachineControl (Manager *, jack_client_t *);
+ MachineControl (Manager *, ARDOUR::PortEngine&);
Port* input_port() { return _input_port; }
Port* output_port() { return _output_port; }
diff --git a/libs/midi++2/mmc.cc b/libs/midi++2/mmc.cc
index 06eadb5b34..0a71463721 100644
--- a/libs/midi++2/mmc.cc
+++ b/libs/midi++2/mmc.cc
@@ -22,7 +22,9 @@
#include <map>
#include "timecode/time.h"
+
#include "pbd/error.h"
+
#include "midi++/mmc.h"
#include "midi++/port.h"
#include "midi++/jack_midi_port.h"
@@ -196,15 +198,15 @@ static void build_mmc_cmd_map ()
}
-MachineControl::MachineControl (Manager* m, jack_client_t* jack)
+MachineControl::MachineControl (Manager* m, ARDOUR::PortEngine& pengine)
{
build_mmc_cmd_map ();
_receive_device_id = 0x7f;
_send_device_id = 0x7f;
- _input_port = m->add_port (new JackMIDIPort ("MMC in", Port::IsInput, jack));
- _output_port = m->add_port (new JackMIDIPort ("MMC out", Port::IsOutput, jack));
+ _input_port = m->add_port (new JackMIDIPort ("MMC in", Port::IsInput, pengine));
+ _output_port = m->add_port (new JackMIDIPort ("MMC out", Port::IsOutput, pengine));
_input_port->parser()->mmc.connect_same_thread (port_connections, boost::bind (&MachineControl::process_mmc_message, this, _1, _2, _3));
_input_port->parser()->start.connect_same_thread (port_connections, boost::bind (&MachineControl::spp_start, this));
diff --git a/libs/midi++2/wscript b/libs/midi++2/wscript
index ea8988110d..8a4f2f6c69 100644
--- a/libs/midi++2/wscript
+++ b/libs/midi++2/wscript
@@ -26,6 +26,7 @@ out = 'build'
path_prefix = 'libs/midi++2/'
+
libmidi_sources = [
'midi.cc',
'channel.cc',
@@ -68,7 +69,7 @@ def build(bld):
obj.cxxflags = [ '-fPIC', '-DWITH_JACK_MIDI' ]
# everybody loves JACK
obj.export_includes = ['.']
- obj.includes = ['.', '../surfaces/control_protocol']
+ obj.includes = ['.', '../surfaces/control_protocol', '../ardour' ]
obj.name = 'libmidipp'
obj.target = 'midipp'
obj.uselib = 'GLIBMM SIGCPP XML JACK OSX'