summaryrefslogtreecommitdiff
path: root/libs/midi++2
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2013-09-12 11:28:50 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2013-09-12 11:28:50 -0400
commitbb826f4beebfcedc50570b818c305560d2233e47 (patch)
tree1484460f914e64fdbdce58230ffe7934bc0761f4 /libs/midi++2
parent8c5cff60912c7e0a7256f635641399500d8d00d9 (diff)
parentf85b362351a5f9167f93b6988f2c8a4c7e03a33c (diff)
incomplete merge of master into windows (requires upcoming changes to master to be complete)
Diffstat (limited to 'libs/midi++2')
-rw-r--r--libs/midi++2/jack_midi_port.cc486
-rw-r--r--libs/midi++2/manager.cc183
-rw-r--r--libs/midi++2/midi++/jack_midi_port.h111
-rw-r--r--libs/midi++2/midi++/manager.h103
-rw-r--r--libs/midi++2/midi++/mmc.h11
-rw-r--r--libs/midi++2/midi++/parser.h4
-rw-r--r--libs/midi++2/midi++/port.h7
-rw-r--r--libs/midi++2/mmc.cc17
-rw-r--r--libs/midi++2/mtc.cc2
-rw-r--r--libs/midi++2/parser.cc3
-rw-r--r--libs/midi++2/port.cc2
-rw-r--r--libs/midi++2/wscript5
12 files changed, 26 insertions, 908 deletions
diff --git a/libs/midi++2/jack_midi_port.cc b/libs/midi++2/jack_midi_port.cc
deleted file mode 100644
index 38ec4d35c7..0000000000
--- a/libs/midi++2/jack_midi_port.cc
+++ /dev/null
@@ -1,486 +0,0 @@
-/*
- Copyright (C) 1998 Paul Barton-Davis
-
- 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.
-
- 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., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- $Id$
-*/
-#include <iostream>
-#include <cstdio>
-#include <unistd.h>
-#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"
-#include "pbd/convert.h"
-#include "pbd/strsplit.h"
-#include "pbd/stacktrace.h"
-
-#include "midi++/types.h"
-#include "midi++/jack_midi_port.h"
-#include "midi++/channel.h"
-
-using namespace MIDI;
-using namespace std;
-using namespace PBD;
-
-namespace Evoral {
-template class EventRingBuffer<timestamp_t>;
-}
-
-pthread_t JackMIDIPort::_process_thread;
-Signal0<void> JackMIDIPort::JackHalted;
-Signal0<void> JackMIDIPort::MakeConnections;
-
-JackMIDIPort::JackMIDIPort (string const & name, Flags flags, jack_client_t* jack_client)
- : Port (name, flags)
- , _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)
-#ifndef PLATFORM_WINDOWS
- , xthread (true)
-#endif
-{
- assert (jack_client);
- init (name, flags);
-}
-
-JackMIDIPort::JackMIDIPort (const XMLNode& node, jack_client_t* jack_client)
- : Port (node)
- , _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)
-#ifndef PLATFORM_WINDOWS
- , xthread (true)
-#endif
-{
- assert (jack_client);
-
- Descriptor desc (node);
- init (desc.tag, desc.flags);
- set_state (node);
-}
-
-void
-JackMIDIPort::init (const string& /*name*/, Flags /*flags*/)
-{
- if (!create_port ()) {
- _ok = true;
- }
-
- MakeConnections.connect_same_thread (connect_connection, boost::bind (&JackMIDIPort::make_connections, this));
- JackHalted.connect_same_thread (halt_connection, boost::bind (&JackMIDIPort::jack_halted, this));
-}
-
-
-JackMIDIPort::~JackMIDIPort ()
-{
- if (_jack_port) {
- if (_jack_client) {
- jack_port_unregister (_jack_client, _jack_port);
- _jack_port = 0;
- }
- }
-}
-
-void
-JackMIDIPort::parse (framecnt_t timestamp)
-{
- byte buf[512];
-
- /* NOTE: parsing is done (if at all) by initiating a read from
- the port. Each port implementation calls on the parser
- once it has data ready.
- */
-
- _parser->set_timestamp (timestamp);
-
- while (1) {
-
- // cerr << "+++ READ ON " << name() << endl;
-
- int nread = read (buf, sizeof (buf));
-
- // cerr << "-- READ (" << nread << " ON " << name() << endl;
-
- if (nread > 0) {
- if ((size_t) nread < sizeof (buf)) {
- break;
- } else {
- continue;
- }
- } else if (nread == 0) {
- break;
- } else if (errno == EAGAIN) {
- break;
- } else {
- fatal << "Error reading from MIDI port " << name() << endmsg;
- /*NOTREACHED*/
- }
- }
-}
-
-void
-JackMIDIPort::cycle_start (pframes_t nframes)
-{
- assert (_jack_port);
-
- _currently_in_cycle = true;
- _nframes_this_cycle = nframes;
-
- assert(_nframes_this_cycle == nframes);
-
- if (sends_output()) {
- void *buffer = jack_port_get_buffer (_jack_port, 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);
-
- jack_midi_event_t ev;
- timestamp_t cycle_start_frame = jack_last_frame_time (_jack_client);
-
- 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);
- }
-
- if (event_count) {
-#ifndef PLATFORM_WINDOWS
- xthread.wakeup ();
-#endif
- }
- }
-}
-
-void
-JackMIDIPort::cycle_end ()
-{
- if (sends_output()) {
- flush (jack_port_get_buffer (_jack_port, _nframes_this_cycle));
- }
-
- _currently_in_cycle = false;
- _nframes_this_cycle = 0;
-}
-
-void
-JackMIDIPort::jack_halted ()
-{
- _jack_client = 0;
- _jack_port = 0;
-}
-
-void
-JackMIDIPort::drain (int check_interval_usecs)
-{
- RingBuffer< Evoral::Event<double> >::rw_vector vec = { { 0, 0 }, { 0, 0} };
-
- if (is_process_thread()) {
- error << "Process thread called MIDI::JackMIDIPort::drain() - this cannot work" << endmsg;
- return;
- }
-
- while (1) {
- output_fifo.get_write_vector (&vec);
- if (vec.len[0] + vec.len[1] >= output_fifo.bufsize() - 1) {
- break;
- }
- g_usleep (check_interval_usecs);
- }
-}
-
-int
-JackMIDIPort::write (const MIDI::byte * msg, size_t msglen, timestamp_t timestamp)
-{
- int ret = 0;
-
- if (!_jack_client || !_jack_port) {
- /* poof ! make it just vanish into thin air, since we are no
- longer connected to JACK.
- */
- return msglen;
- }
-
- if (!sends_output()) {
- return ret;
- }
-
- if (!is_process_thread()) {
-
- Glib::Threads::Mutex::Lock lm (output_fifo_lock);
- RingBuffer< Evoral::Event<double> >::rw_vector vec = { { 0, 0 }, { 0, 0} };
-
- output_fifo.get_write_vector (&vec);
-
- if (vec.len[0] + vec.len[1] < 1) {
- error << "no space in FIFO for non-process thread MIDI write" << endmsg;
- return 0;
- }
-
- if (vec.len[0]) {
- if (!vec.buf[0]->owns_buffer()) {
- vec.buf[0]->set_buffer (0, 0, true);
- }
- vec.buf[0]->set (msg, msglen, timestamp);
- } else {
- if (!vec.buf[1]->owns_buffer()) {
- vec.buf[1]->set_buffer (0, 0, true);
- }
- vec.buf[1]->set (msg, msglen, timestamp);
- }
-
- output_fifo.increment_write_idx (1);
-
- ret = msglen;
-
- } else {
-
- if (timestamp >= _nframes_this_cycle) {
- std::cerr << "attempting to write MIDI event of " << msglen << " bytes at time "
- << timestamp << " of " << _nframes_this_cycle
- << " (this will not work - needs a code fix)"
- << std::endl;
- }
-
- if (_currently_in_cycle) {
- 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) {
- 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
- << " ntf = " << _nframes_this_cycle
- << " buf = " << jack_port_get_buffer (_jack_port, _nframes_this_cycle)
- << " ret = " << ret
- << endl;
- PBD::stacktrace (cerr, 20);
- ret = 0;
- }
- } else {
- cerr << "write to JACK midi port failed: not currently in a process cycle." << endl;
- PBD::stacktrace (cerr, 20);
- }
- }
-
- if (ret > 0 && _parser) {
- // ardour doesn't care about this and neither should your app, probably
- // output_parser->raw_preparse (*output_parser, msg, ret);
- for (int i = 0; i < ret; i++) {
- _parser->scanner (msg[i]);
- }
- // ardour doesn't care about this and neither should your app, probably
- // output_parser->raw_postparse (*output_parser, msg, ret);
- }
-
- return ret;
-}
-
-void
-JackMIDIPort::flush (void* jack_port_buffer)
-{
- RingBuffer< Evoral::Event<double> >::rw_vector vec = { { 0, 0 }, { 0, 0 } };
- size_t written;
-
- output_fifo.get_read_vector (&vec);
-
- if (vec.len[0] + vec.len[1]) {
- // cerr << "Flush " << vec.len[0] + vec.len[1] << " events from non-process FIFO\n";
- }
-
- if (vec.len[0]) {
- 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());
- }
- }
-
- if (vec.len[1]) {
- 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());
- }
- }
-
- if ((written = vec.len[0] + vec.len[1]) != 0) {
- output_fifo.increment_read_idx (written);
- }
-}
-
-int
-JackMIDIPort::read (MIDI::byte *, size_t)
-{
- if (!receives_input()) {
- return 0;
- }
-
- timestamp_t time;
- Evoral::EventType type;
- uint32_t size;
- vector<MIDI::byte> buffer(input_fifo.capacity());
-
- while (input_fifo.read (&time, &type, &size, &buffer[0])) {
- _parser->set_timestamp (time);
- for (uint32_t i = 0; i < size; ++i) {
- _parser->scanner (buffer[i]);
- }
- }
-
- return 0;
-}
-
-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;
-}
-
-XMLNode&
-JackMIDIPort::get_state () const
-{
- XMLNode& root = Port::get_state ();
-
-#if 0
- byte device_inquiry[6];
-
- device_inquiry[0] = 0xf0;
- device_inquiry[0] = 0x7e;
- device_inquiry[0] = 0x7f;
- device_inquiry[0] = 0x06;
- device_inquiry[0] = 0x02;
- device_inquiry[0] = 0xf7;
-
- write (device_inquiry, sizeof (device_inquiry), 0);
-#endif
-
- if (_jack_port) {
-
- const char** jc = jack_port_get_connections (_jack_port);
- string connection_string;
- if (jc) {
- for (int i = 0; jc[i]; ++i) {
- if (i > 0) {
- connection_string += ',';
- }
- connection_string += jc[i];
- }
- free (jc);
- }
-
- if (!connection_string.empty()) {
- root.add_property ("connections", connection_string);
- }
- } else {
- if (!_connections.empty()) {
- root.add_property ("connections", _connections);
- }
- }
-
- return root;
-}
-
-void
-JackMIDIPort::set_state (const XMLNode& node)
-{
- const XMLProperty* prop;
-
- if ((prop = node.property ("tag")) == 0 || prop->value() != _tagname) {
- return;
- }
-
- Port::set_state (node);
-
- if ((prop = node.property ("connections")) != 0) {
- _connections = prop->value ();
- }
-}
-
-void
-JackMIDIPort::make_connections ()
-{
- if (!_connections.empty()) {
- 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 */
- }
- }
- }
-
- connect_connection.disconnect ();
-}
-
-void
-JackMIDIPort::set_process_thread (pthread_t thr)
-{
- _process_thread = thr;
-}
-
-bool
-JackMIDIPort::is_process_thread()
-{
- return (pthread_equal(pthread_self(), _process_thread));
-}
-
-void
-JackMIDIPort::reestablish (jack_client_t* jack)
-{
- _jack_client = jack;
- int const r = create_port ();
-
- if (r) {
- PBD::error << "could not reregister ports for " << name() << endmsg;
- }
-}
-
-void
-JackMIDIPort::reconnect ()
-{
- make_connections ();
-}
diff --git a/libs/midi++2/manager.cc b/libs/midi++2/manager.cc
deleted file mode 100644
index 822c74e125..0000000000
--- a/libs/midi++2/manager.cc
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- Copyright (C) 1998-99 Paul Barton-Davis
- 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.
-
- 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., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- $Id$
-*/
-
-#include <fcntl.h>
-
-#include <glib.h>
-
-#include "pbd/error.h"
-
-#include "midi++/types.h"
-#include "midi++/manager.h"
-#include "midi++/channel.h"
-#include "midi++/port.h"
-#include "midi++/jack_midi_port.h"
-#include "midi++/mmc.h"
-
-using namespace std;
-using namespace MIDI;
-using namespace PBD;
-
-Manager *Manager::theManager = 0;
-
-Manager::Manager (jack_client_t* jack)
- : _ports (new PortList)
-{
- _mmc = new MachineControl (this, jack);
-
- _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));
-}
-
-Manager::~Manager ()
-{
- delete _mmc;
-
- /* This will delete our MTC etc. ports */
-
- boost::shared_ptr<PortList> pr = _ports.reader ();
- for (PortList::iterator p = pr->begin(); p != pr->end(); ++p) {
- delete *p;
- }
-
- if (theManager == this) {
- theManager = 0;
- }
-}
-
-Port *
-Manager::add_port (Port* p)
-{
- {
- RCUWriter<PortList> writer (_ports);
- boost::shared_ptr<PortList> pw = writer.get_copy ();
- pw->push_back (p);
- }
-
- PortsChanged (); /* EMIT SIGNAL */
-
- return p;
-}
-
-void
-Manager::remove_port (Port* p)
-{
- {
- RCUWriter<PortList> writer (_ports);
- boost::shared_ptr<PortList> pw = writer.get_copy ();
- pw->remove (p);
- }
-
- PortsChanged (); /* EMIT SIGNAL */
-}
-
-void
-Manager::cycle_start (pframes_t nframes)
-{
- boost::shared_ptr<PortList> pr = _ports.reader ();
-
- for (PortList::iterator p = pr->begin(); p != pr->end(); ++p) {
- (*p)->cycle_start (nframes);
- }
-}
-
-void
-Manager::cycle_end()
-{
- boost::shared_ptr<PortList> pr = _ports.reader ();
-
- for (PortList::iterator p = pr->begin(); p != pr->end(); ++p) {
- (*p)->cycle_end ();
- }
-}
-
-/** Re-register ports that disappear on JACK shutdown */
-void
-Manager::reestablish (jack_client_t* jack)
-{
- 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);
- }
- }
-}
-
-/** Re-connect ports after a reestablish () */
-void
-Manager::reconnect ()
-{
- 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->reconnect ();
- }
- }
-}
-
-Port*
-Manager::port (string const & n)
-{
- boost::shared_ptr<PortList> pr = _ports.reader ();
-
- PortList::const_iterator p = pr->begin();
- while (p != pr->end() && (*p)->name() != n) {
- ++p;
- }
-
- if (p == pr->end()) {
- return 0;
- }
-
- return *p;
-}
-
-void
-Manager::create (jack_client_t* jack)
-{
- assert (theManager == 0);
- theManager = new Manager (jack);
-}
-
-void
-Manager::set_port_states (list<XMLNode*> s)
-{
- boost::shared_ptr<PortList> pr = _ports.reader ();
-
- for (list<XMLNode*>::iterator i = s.begin(); i != s.end(); ++i) {
- for (PortList::const_iterator j = pr->begin(); j != pr->end(); ++j) {
- (*j)->set_state (**i);
- }
- }
-}
-
-void
-Manager::destroy ()
-{
- delete theManager;
- theManager = 0;
-}
diff --git a/libs/midi++2/midi++/jack_midi_port.h b/libs/midi++2/midi++/jack_midi_port.h
deleted file mode 100644
index 284df0ef2d..0000000000
--- a/libs/midi++2/midi++/jack_midi_port.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- Copyright (C) 1998-2010 Paul Barton-Davis
- 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.
-
- 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., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-#ifndef __libmidi_port_h__
-#define __libmidi_port_h__
-
-#include <string>
-#include <iostream>
-
-#include <jack/types.h>
-
-#include "pbd/xml++.h"
-#include "pbd/crossthread.h"
-#include "pbd/signals.h"
-#include "pbd/ringbuffer.h"
-
-#include "evoral/Event.hpp"
-#include "evoral/EventRingBuffer.hpp"
-
-#include "midi++/types.h"
-#include "midi++/parser.h"
-#include "midi++/port.h"
-
-namespace MIDI {
-
-class Channel;
-class PortRequest;
-
-class JackMIDIPort : public Port {
- public:
- JackMIDIPort (std::string const &, Port::Flags, jack_client_t *);
- JackMIDIPort (const XMLNode&, jack_client_t *);
- ~JackMIDIPort ();
-
- XMLNode& get_state () const;
- void set_state (const XMLNode&);
-
- void cycle_start (pframes_t nframes);
- void cycle_end ();
-
- void parse (framecnt_t timestamp);
- int write (const byte *msg, size_t msglen, timestamp_t timestamp);
- int read (byte *buf, size_t bufsize);
- void drain (int check_interval_usecs);
- int selectable () const {
-#ifdef PLATFORM_WINDOWS
- return false;
-#else
- return xthread.selectable();
-#endif
- }
-
- pframes_t nframes_this_cycle() const { return _nframes_this_cycle; }
-
- void reestablish (jack_client_t *);
- void reconnect ();
-
- static void set_process_thread (pthread_t);
- static pthread_t get_process_thread () { return _process_thread; }
- static bool is_process_thread();
-
- static PBD::Signal0<void> MakeConnections;
- static PBD::Signal0<void> JackHalted;
-
-private:
- 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;
- Glib::Threads::Mutex output_fifo_lock;
-#ifndef PLATFORM_WINDOWS
- CrossThreadChannel xthread;
-#endif
-
- int create_port ();
-
- /** Channel used to signal to the MidiControlUI that input has arrived */
-
- std::string _connections;
- PBD::ScopedConnection connect_connection;
- PBD::ScopedConnection halt_connection;
- void flush (void* jack_port_buffer);
- void jack_halted ();
- void make_connections ();
- void init (std::string const &, Flags);
-
- static pthread_t _process_thread;
-
-};
-
-} // namespace MIDI
-
-#endif // __libmidi_port_h__
diff --git a/libs/midi++2/midi++/manager.h b/libs/midi++2/midi++/manager.h
deleted file mode 100644
index c37ba392b4..0000000000
--- a/libs/midi++2/midi++/manager.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- Copyright (C) 1998 Paul Barton-Davis
-
- 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.
-
- 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., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-#ifndef __midi_manager_h__
-#define __midi_manager_h__
-
-#include <list>
-
-#include <string>
-
-#include "pbd/rcu.h"
-
-#include "midi++/types.h"
-#include "midi++/port.h"
-
-namespace MIDI {
-
-class MachineControl;
-
-class Manager {
- public:
- ~Manager ();
-
- /** Signal the start of an audio cycle.
- * This MUST be called before any reading/writing for this cycle.
- * Realtime safe.
- */
- void cycle_start (pframes_t nframes);
-
- /** Signal the end of an audio cycle.
- * This signifies that the cycle began with @ref cycle_start has ended.
- * This MUST be called at the end of each cycle.
- * Realtime safe.
- */
- void cycle_end ();
-
- MachineControl* mmc () const { return _mmc; }
- Port *mtc_input_port() const { return _mtc_input_port; }
- Port *mtc_output_port() const { return _mtc_output_port; }
- Port *midi_input_port() const { return _midi_input_port; }
- Port *midi_output_port() const { return _midi_output_port; }
- Port *midi_clock_input_port() const { return _midi_clock_input_port; }
- Port *midi_clock_output_port() const { return _midi_clock_output_port; }
-
- Port* add_port (Port *);
- void remove_port (Port *);
-
- Port* port (std::string const &);
-
- void set_port_states (std::list<XMLNode*>);
-
- typedef std::list<Port *> PortList;
-
- boost::shared_ptr<const PortList> get_midi_ports() const { return _ports.reader (); }
-
- static void create (jack_client_t* jack);
-
- static Manager *instance () {
- return theManager;
- }
- static void destroy ();
-
- void reestablish (jack_client_t *);
- void reconnect ();
-
- PBD::Signal0<void> PortsChanged;
-
- private:
- /* This is a SINGLETON pattern */
-
- Manager (jack_client_t *);
- static Manager *theManager;
-
- MIDI::MachineControl* _mmc;
- MIDI::Port* _mtc_input_port;
- MIDI::Port* _mtc_output_port;
- MIDI::Port* _midi_input_port;
- MIDI::Port* _midi_output_port;
- MIDI::Port* _midi_clock_input_port;
- MIDI::Port* _midi_clock_output_port;
-
- SerializedRCUManager<PortList> _ports;
-};
-
-} // namespace MIDI
-
-#endif // __midi_manager_h__
diff --git a/libs/midi++2/midi++/mmc.h b/libs/midi++2/midi++/mmc.h
index 18204e3fa8..01f8bf3b8a 100644
--- a/libs/midi++2/midi++/mmc.h
+++ b/libs/midi++2/midi++/mmc.h
@@ -22,17 +22,22 @@
#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;
class Parser;
class MachineControlCommand;
-class Manager;
/** Class to handle incoming and outgoing MIDI machine control messages */
class MachineControl
@@ -89,7 +94,9 @@ class MachineControl
cmdResume = 0x7F
};
- MachineControl (Manager *, jack_client_t *);
+ MachineControl ();
+
+ void set_ports (MIDI::Port* input, MIDI::Port* output);
Port* input_port() { return _input_port; }
Port* output_port() { return _output_port; }
diff --git a/libs/midi++2/midi++/parser.h b/libs/midi++2/midi++/parser.h
index f5f343e952..44897f9d8e 100644
--- a/libs/midi++2/midi++/parser.h
+++ b/libs/midi++2/midi++/parser.h
@@ -41,7 +41,7 @@ typedef PBD::Signal3<void,Parser &, byte *, size_t> Signal;
class Parser {
public:
- Parser (Port &p);
+ Parser ();
~Parser ();
/* sets the time that will be reported for any MTC or MIDI Clock
@@ -105,7 +105,6 @@ class Parser {
const char *midi_event_type_name (MIDI::eventType);
void trace (bool onoff, std::ostream *o, const std::string &prefix = "");
bool tracing() { return trace_stream != 0; }
- Port &port() { return _port; }
void set_offline (bool);
bool offline() const { return _offline; }
@@ -136,7 +135,6 @@ class Parser {
void reset_mtc_state ();
private:
- Port&_port;
/* tracing */
std::ostream *trace_stream;
diff --git a/libs/midi++2/midi++/port.h b/libs/midi++2/midi++/port.h
index 153cfb0529..a915320fa3 100644
--- a/libs/midi++2/midi++/port.h
+++ b/libs/midi++2/midi++/port.h
@@ -55,13 +55,6 @@ class Port {
virtual XMLNode& get_state () const;
virtual void set_state (const XMLNode&);
- // FIXME: make Manager a friend of port so these can be hidden?
-
- /* Only for use by MidiManager. Don't ever call this. */
- virtual void cycle_start (pframes_t) {}
- /* Only for use by MidiManager. Don't ever call this. */
- virtual void cycle_end () {}
-
/** Write a message to port.
* @param msg Raw MIDI message to send
* @param msglen Size of @a msg
diff --git a/libs/midi++2/mmc.cc b/libs/midi++2/mmc.cc
index 1b8de40358..1b9481c9bf 100644
--- a/libs/midi++2/mmc.cc
+++ b/libs/midi++2/mmc.cc
@@ -22,12 +22,12 @@
#include <map>
#include "timecode/time.h"
+
#include "pbd/error.h"
+
#include "midi++/mmc.h"
#include "midi++/port.h"
-#include "midi++/jack_midi_port.h"
#include "midi++/parser.h"
-#include "midi++/manager.h"
#ifndef __INT_MAX__ // 'ssize_t' won't be defined yet
typedef long ssize_t;
@@ -199,16 +199,21 @@ static void build_mmc_cmd_map ()
mmc_cmd_map.insert (newpair);
}
-
-MachineControl::MachineControl (Manager* m, jack_client_t* jack)
+MachineControl::MachineControl ()
{
build_mmc_cmd_map ();
_receive_device_id = 0x7f;
_send_device_id = 0x7f;
+}
+
+void
+MachineControl::set_ports (MIDI::Port* ip, MIDI::Port* op)
+{
+ port_connections.drop_connections ();
- _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 = ip;
+ _output_port = op;
_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/mtc.cc b/libs/midi++2/mtc.cc
index 3c58b6684f..1a477c3b8c 100644
--- a/libs/midi++2/mtc.cc
+++ b/libs/midi++2/mtc.cc
@@ -240,7 +240,7 @@ Parser::process_mtc_quarter_frame (MIDI::byte *msg)
/* time code is looking good */
#ifdef DEBUG_MTC
- // cerr << "for quarter frame " << which_quarter_frame << " byte = " << hex << (int) msg[1] << dec << endl;
+ cerr << "for quarter frame " << which_quarter_frame << " byte = " << hex << (int) msg[1] << dec << endl;
#endif
switch (which_quarter_frame) {
diff --git a/libs/midi++2/parser.cc b/libs/midi++2/parser.cc
index 94daef7871..7d31c99781 100644
--- a/libs/midi++2/parser.cc
+++ b/libs/midi++2/parser.cc
@@ -104,8 +104,7 @@ Parser::midi_event_type_name (eventType t)
}
}
-Parser::Parser (Port &p)
- : _port(p)
+Parser::Parser ()
{
trace_stream = 0;
trace_prefix = "";
diff --git a/libs/midi++2/port.cc b/libs/midi++2/port.cc
index 3e7896631a..1480202867 100644
--- a/libs/midi++2/port.cc
+++ b/libs/midi++2/port.cc
@@ -71,7 +71,7 @@ Port::init (string const & name, Flags flags)
_tagname = name;
_flags = flags;
- _parser = new Parser (*this);
+ _parser = new Parser ();
for (int i = 0; i < 16; i++) {
_channel[i] = new Channel (i, *this);
diff --git a/libs/midi++2/wscript b/libs/midi++2/wscript
index ea8988110d..0abbab7d40 100644
--- a/libs/midi++2/wscript
+++ b/libs/midi++2/wscript
@@ -26,12 +26,11 @@ out = 'build'
path_prefix = 'libs/midi++2/'
+
libmidi_sources = [
'midi.cc',
'channel.cc',
'ipmidi_port.cc',
- 'jack_midi_port.cc',
- 'manager.cc',
'parser.cc',
'port.cc',
'midnam_patch.cc',
@@ -68,7 +67,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'