summaryrefslogtreecommitdiff
path: root/libs/midi++2
diff options
context:
space:
mode:
authorCarl Hetherington <carl@carlh.net>2010-07-07 00:40:58 +0000
committerCarl Hetherington <carl@carlh.net>2010-07-07 00:40:58 +0000
commitea23298f10e9587eba483cb54a6f7d75ca68126a (patch)
treebdd396ac05d0be01cbbcc6447844a04814e79cbf /libs/midi++2
parent6cccf3ce7dc86998d6797f393bec5b69610fc5f3 (diff)
Setup fixed ports for MIDI control data; hence remove configuration of those ports. Move MIDI tracer to the Windows menu. Trim some unused code from the midi++ Manager.
git-svn-id: svn://localhost/ardour2/branches/3.0@7384 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/midi++2')
-rw-r--r--libs/midi++2/manager.cc159
-rw-r--r--libs/midi++2/midi++/manager.h30
-rw-r--r--libs/midi++2/midi++/mmc.h9
-rw-r--r--libs/midi++2/midi++/port.h4
-rw-r--r--libs/midi++2/mmc.cc30
-rw-r--r--libs/midi++2/port.cc55
6 files changed, 76 insertions, 211 deletions
diff --git a/libs/midi++2/manager.cc b/libs/midi++2/manager.cc
index 5c464fa060..c8094d4d4f 100644
--- a/libs/midi++2/manager.cc
+++ b/libs/midi++2/manager.cc
@@ -32,17 +32,10 @@ using namespace std;
using namespace MIDI;
using namespace PBD;
-/* XXX check for strdup leaks */
-
Manager *Manager::theManager = 0;
Manager::Manager ()
{
- inputPort = 0;
- outputPort = 0;
- inputChannelNumber = 0;
- outputChannelNumber = 0;
- api_data = 0;
}
Manager::~Manager ()
@@ -57,144 +50,13 @@ Manager::~Manager ()
}
Port *
-Manager::add_port (const XMLNode& node)
-{
- Port::Descriptor desc (node);
- Port *port;
- PortList::iterator p;
-
- for (p = _ports.begin(); p != _ports.end(); ++p) {
-
- if (desc.tag == (*p)->name()) {
- break;
- }
-
- }
-
- if (p != _ports.end()) {
- return 0;
- }
-
- port = new Port (node, (jack_client_t *) api_data);
-
- if (port == 0) {
- return 0;
- }
-
- if (!port->ok()) {
- delete port;
- return 0;
- }
-
- _ports.push_back (port);
-
- /* first port added becomes the default input
- port.
- */
-
- if (inputPort == 0) {
- inputPort = port;
- }
-
- if (outputPort == 0) {
- outputPort = port;
- }
-
- PortsChanged (); /* EMIT SIGNAL */
-
- return port;
-}
-
-int
-Manager::remove_port (Port* port)
+Manager::add_port (Port* p)
{
- if (inputPort == port) {
- inputPort = 0;
- }
-
- if (outputPort == port) {
- outputPort = 0;
- }
-
- _ports.remove (port);
- delete port;
+ _ports.push_back (p);
PortsChanged (); /* EMIT SIGNAL */
- return 0;
-}
-
-int
-Manager::set_input_port (string tag)
-{
- for (PortList::iterator p = _ports.begin(); p != _ports.end(); ++p) {
- if ((*p)->name() == tag) {
- inputPort = (*p);
- return 0;
- }
- }
-
- return -1;
-}
-
-int
-Manager::set_output_port (string tag)
-{
- PortList::iterator p;
-
- for (p = _ports.begin(); p != _ports.end(); ++p) {
- if ((*p)->name() == tag) {
- inputPort = (*p);
- break;
- }
- }
-
- if (p == _ports.end()) {
- return -1;
- }
-
- // XXX send a signal to say we're about to change output ports
-
- if (outputPort) {
- for (channel_t chan = 0; chan < 16; chan++) {
- outputPort->channel (chan)->all_notes_off (0);
- }
- }
-
- outputPort = (*p);
-
- // XXX send a signal to say we've changed output ports
-
- return 0;
-}
-
-Port *
-Manager::port (string name)
-{
- for (PortList::iterator p = _ports.begin(); p != _ports.end(); ++p) {
- if (name == (*p)->name()) {
- return (*p);
- }
- }
-
- return 0;
-}
-
-int
-Manager::foreach_port (int (*func)(const Port &, size_t, void *),
- void *arg)
-{
- int n = 0;
-
- for (PortList::const_iterator p = _ports.begin(); p != _ports.end(); ++p, ++n) {
- int retval;
-
- if ((retval = func (**p, n, arg)) != 0) {
- return retval;
- }
- }
-
- return 0;
+ return p;
}
void
@@ -230,3 +92,18 @@ Manager::reconnect ()
(*p)->reconnect ();
}
}
+
+Port*
+Manager::port (string const & n)
+{
+ PortList::const_iterator p = _ports.begin();
+ while (p != _ports.end() && (*p)->name() != n) {
+ ++p;
+ }
+
+ if (p == _ports.end()) {
+ return 0;
+ }
+
+ return *p;
+}
diff --git a/libs/midi++2/midi++/manager.h b/libs/midi++2/midi++/manager.h
index 563062aaea..2193c1eb23 100644
--- a/libs/midi++2/midi++/manager.h
+++ b/libs/midi++2/midi++/manager.h
@@ -21,7 +21,6 @@
#define __midi_manager_h__
#include <list>
-#include <vector>
#include <string>
@@ -34,8 +33,6 @@ class Manager {
public:
~Manager ();
- void set_api_data(void* data) { api_data = data; }
-
/** Signal the start of an audio cycle.
* This MUST be called before any reading/writing for this cycle.
* Realtime safe.
@@ -49,26 +46,9 @@ class Manager {
*/
void cycle_end();
- Port *add_port (const XMLNode& node);
- int remove_port (Port*);
-
- Port *port (std::string name);
-
- size_t nports () const { return _ports.size(); }
-
- /* defaults for clients who are not picky */
-
- Port *inputPort;
- Port *outputPort;
- channel_t inputChannelNumber;
- channel_t outputChannelNumber;
-
- int set_input_port (std::string);
- int set_output_port (std::string);
- int set_input_channel (channel_t);
- int set_output_channel (channel_t);
+ Port* add_port (Port *);
- int foreach_port (int (*func)(const Port &, size_t n, void *), void *arg);
+ Port* port (std::string const &);
typedef std::list<Port *> PortList;
@@ -90,13 +70,9 @@ class Manager {
/* This is a SINGLETON pattern */
Manager ();
-
static Manager *theManager;
+
std::list<Port*> _ports;
-
- void* api_data;
-
- void close_ports ();
};
} // namespace MIDI
diff --git a/libs/midi++2/midi++/mmc.h b/libs/midi++2/midi++/mmc.h
index ec48527789..ec3eb8bbb1 100644
--- a/libs/midi++2/midi++/mmc.h
+++ b/libs/midi++2/midi++/mmc.h
@@ -20,6 +20,7 @@
#ifndef __midipp_mmc_h_h__
#define __midipp_mmc_h_h__
+#include <jack/types.h>
#include "control_protocol/timecode.h"
#include "pbd/signals.h"
#include "pbd/ringbuffer.h"
@@ -87,10 +88,9 @@ class MachineControl
cmdResume = 0x7F
};
- MachineControl ();
- void set_port (Port* p);
+ MachineControl (jack_client_t *);
- Port* port() { return _port; }
+ Port* output_port() { return _output_port; }
void set_receive_device_id (byte id);
void set_send_device_id (byte id);
@@ -255,7 +255,8 @@ class MachineControl
private:
byte _receive_device_id;
byte _send_device_id;
- Port* _port;
+ Port* _input_port;
+ Port* _output_port;
bool _enable_send; ///< true if MMC sending is enabled
void process_mmc_message (Parser &p, byte *, size_t len);
diff --git a/libs/midi++2/midi++/port.h b/libs/midi++2/midi++/port.h
index 8c875a6615..ca977fad2f 100644
--- a/libs/midi++2/midi++/port.h
+++ b/libs/midi++2/midi++/port.h
@@ -42,6 +42,7 @@ class PortRequest;
class Port {
public:
+ Port (std::string const &, int, jack_client_t *);
Port (const XMLNode&, jack_client_t *);
~Port ();
@@ -135,7 +136,7 @@ private:
static size_t nports;
- int create_ports(const XMLNode&);
+ void create_port_names ();
int create_ports ();
jack_client_t* _jack_client;
@@ -156,6 +157,7 @@ private:
void flush (void* jack_port_buffer);
void jack_halted ();
void make_connections();
+ void init (std::string const &, int);
static pthread_t _process_thread;
diff --git a/libs/midi++2/mmc.cc b/libs/midi++2/mmc.cc
index 597904d293..406fd0ef19 100644
--- a/libs/midi++2/mmc.cc
+++ b/libs/midi++2/mmc.cc
@@ -18,6 +18,7 @@
$Id$
*/
+#include <fcntl.h>
#include <map>
#include "control_protocol/timecode.h"
@@ -25,6 +26,7 @@
#include "midi++/mmc.h"
#include "midi++/port.h"
#include "midi++/parser.h"
+#include "midi++/manager.h"
using namespace std;
using namespace MIDI;
@@ -193,30 +195,20 @@ static void build_mmc_cmd_map ()
}
-MachineControl::MachineControl ()
- : _port (0)
+MachineControl::MachineControl (jack_client_t* jack)
{
build_mmc_cmd_map ();
_receive_device_id = 0;
_send_device_id = 0x7f;
-}
-
-void
-MachineControl::set_port (Port* p)
-{
- _port = p;
- port_connections.drop_connections ();
+ _input_port = Manager::instance()->add_port (new Port ("MMC", O_RDONLY, jack));
+ _output_port = Manager::instance()->add_port (new Port ("MMC", O_WRONLY, jack));
- if (_port->input()) {
- _port->input()->mmc.connect_same_thread (port_connections, boost::bind (&MachineControl::process_mmc_message, this, _1, _2, _3));
- _port->input()->start.connect_same_thread (port_connections, boost::bind (&MachineControl::spp_start, this, _1, _2));
- _port->input()->contineu.connect_same_thread (port_connections, boost::bind (&MachineControl::spp_continue, this, _1, _2));
- _port->input()->stop.connect_same_thread (port_connections, boost::bind (&MachineControl::spp_stop, this, _1, _2));
- } else {
- warning << "MMC connected to a non-input port: useless!" << endmsg;
- }
+ _input_port->input()->mmc.connect_same_thread (port_connections, boost::bind (&MachineControl::process_mmc_message, this, _1, _2, _3));
+ _input_port->input()->start.connect_same_thread (port_connections, boost::bind (&MachineControl::spp_start, this, _1, _2));
+ _input_port->input()->contineu.connect_same_thread (port_connections, boost::bind (&MachineControl::spp_continue, this, _1, _2));
+ _input_port->input()->stop.connect_same_thread (port_connections, boost::bind (&MachineControl::spp_stop, this, _1, _2));
}
void
@@ -643,7 +635,7 @@ MachineControl::enable_send (bool yn)
void
MachineControl::send (MachineControlCommand const & c)
{
- if (_port == 0 || !_enable_send) {
+ if (_output_port == 0 || !_enable_send) {
// cerr << "Not delivering MMC " << _mmc->port() << " - " << session_send_mmc << endl;
return;
}
@@ -651,7 +643,7 @@ MachineControl::send (MachineControlCommand const & c)
MIDI::byte buffer[32];
MIDI::byte* b = c.fill_buffer (this, buffer);
- if (_port->midimsg (buffer, b - buffer, 0)) {
+ if (_output_port->midimsg (buffer, b - buffer, 0)) {
error << "MMC: cannot send command" << endmsg;
}
}
diff --git a/libs/midi++2/port.cc b/libs/midi++2/port.cc
index 457ff1c358..c2fd4c99e2 100644
--- a/libs/midi++2/port.cc
+++ b/libs/midi++2/port.cc
@@ -44,6 +44,19 @@ pthread_t Port::_process_thread;
Signal0<void> Port::JackHalted;
Signal0<void> Port::MakeConnections;
+Port::Port (string const & name, int mode, jack_client_t* jack_client)
+ : _currently_in_cycle (false)
+ , _nframes_this_cycle (0)
+ , _jack_client (jack_client)
+ , _jack_input_port (0)
+ , _jack_output_port (0)
+ , _last_read_index (0)
+ , output_fifo (512)
+ , input_fifo (1024)
+{
+ init (name, mode);
+}
+
Port::Port (const XMLNode& node, jack_client_t* jack_client)
: _currently_in_cycle (false)
, _nframes_this_cycle (0)
@@ -56,6 +69,14 @@ Port::Port (const XMLNode& node, jack_client_t* jack_client)
{
Descriptor desc (node);
+ init (desc.tag, desc.mode);
+
+ set_state (node);
+}
+
+void
+Port::init (string const & name, int mode)
+{
_ok = false; /* derived class must set to true if constructor
succeeds.
*/
@@ -63,8 +84,8 @@ Port::Port (const XMLNode& node, jack_client_t* jack_client)
input_parser = 0;
output_parser = 0;
- _tagname = desc.tag;
- _mode = desc.mode;
+ _tagname = name;
+ _mode = mode;
if (_mode == O_RDONLY || _mode == O_RDWR) {
input_parser = new Parser (*this);
@@ -90,14 +111,14 @@ Port::Port (const XMLNode& node, jack_client_t* jack_client)
}
}
- if (!create_ports (node)) {
+ create_port_names ();
+
+ if (!create_ports ()) {
_ok = true;
}
MakeConnections.connect_same_thread (connect_connection, boost::bind (&Port::make_connections, this));
JackHalted.connect_same_thread (halt_connection, boost::bind (&Port::jack_halted, this));
-
- set_state (node);
}
@@ -108,17 +129,17 @@ Port::~Port ()
}
if (_jack_input_port) {
- if (_jack_client) {
+ if (_jack_client && _jack_input_port) {
jack_port_unregister (_jack_client, _jack_input_port);
}
_jack_input_port = 0;
}
if (_jack_output_port) {
- if (_jack_client) {
- jack_port_unregister (_jack_client, _jack_input_port);
+ if (_jack_client && _jack_output_port) {
+ jack_port_unregister (_jack_client, _jack_output_port);
}
- _jack_input_port = 0;
+ _jack_output_port = 0;
}
}
@@ -407,23 +428,19 @@ Port::read (byte *, size_t)
return 0;
}
-int
-Port::create_ports(const XMLNode& node)
+void
+Port::create_port_names ()
{
- Descriptor desc (node);
-
assert(!_jack_input_port);
assert(!_jack_output_port);
- if (desc.mode == O_RDWR || desc.mode == O_WRONLY) {
- _jack_output_port_name = string(desc.tag).append ("_out");
+ if (_mode == O_RDWR || _mode == O_WRONLY) {
+ _jack_output_port_name = _tagname.append ("_out");
}
- if (desc.mode == O_RDWR || desc.mode == O_RDONLY) {
- _jack_input_port_name = string(desc.tag).append ("_in");
+ if (_mode == O_RDWR || _mode == O_RDONLY) {
+ _jack_input_port_name = _tagname.append ("_in");
}
-
- return create_ports ();
}
int