2008-06-02 17:41:35 -04:00
|
|
|
/*
|
|
|
|
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 <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2010-07-05 20:16:36 -04:00
|
|
|
#include <jack/jack.h>
|
|
|
|
#include <jack/midiport.h>
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/xml++.h"
|
|
|
|
#include "pbd/error.h"
|
|
|
|
#include "pbd/failed_constructor.h"
|
2010-07-05 20:16:36 -04:00
|
|
|
#include "pbd/convert.h"
|
|
|
|
#include "pbd/strsplit.h"
|
2012-02-06 10:05:18 -05:00
|
|
|
#include "pbd/stacktrace.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "midi++/types.h"
|
|
|
|
#include "midi++/port.h"
|
|
|
|
#include "midi++/channel.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
using namespace MIDI;
|
|
|
|
using namespace std;
|
|
|
|
using namespace PBD;
|
|
|
|
|
2010-07-05 20:16:36 -04:00
|
|
|
pthread_t Port::_process_thread;
|
|
|
|
Signal0<void> Port::JackHalted;
|
|
|
|
Signal0<void> Port::MakeConnections;
|
2010-07-08 18:55:20 -04:00
|
|
|
string Port::state_node_name = "MIDI-port";
|
2010-07-05 20:16:36 -04:00
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
Port::Port (string const & name, Flags flags, jack_client_t* jack_client)
|
2010-07-06 20:40:58 -04:00
|
|
|
: _currently_in_cycle (false)
|
|
|
|
, _nframes_this_cycle (0)
|
|
|
|
, _jack_client (jack_client)
|
2010-07-07 21:00:46 -04:00
|
|
|
, _jack_port (0)
|
2010-07-06 20:40:58 -04:00
|
|
|
, _last_read_index (0)
|
2011-04-04 08:21:26 -04:00
|
|
|
, xthread (true)
|
2010-07-06 20:40:58 -04:00
|
|
|
, output_fifo (512)
|
|
|
|
, input_fifo (1024)
|
2010-07-07 21:00:46 -04:00
|
|
|
, _flags (flags)
|
2010-07-06 20:40:58 -04:00
|
|
|
{
|
2010-07-29 15:24:25 -04:00
|
|
|
assert (jack_client);
|
2010-07-07 21:00:46 -04:00
|
|
|
init (name, flags);
|
2010-07-06 20:40:58 -04:00
|
|
|
}
|
|
|
|
|
2010-07-05 20:16:36 -04:00
|
|
|
Port::Port (const XMLNode& node, jack_client_t* jack_client)
|
|
|
|
: _currently_in_cycle (false)
|
|
|
|
, _nframes_this_cycle (0)
|
|
|
|
, _jack_client (jack_client)
|
2010-07-07 21:00:46 -04:00
|
|
|
, _jack_port (0)
|
2010-07-05 20:16:36 -04:00
|
|
|
, _last_read_index (0)
|
2011-04-04 08:21:26 -04:00
|
|
|
, xthread (true)
|
2010-07-05 20:16:36 -04:00
|
|
|
, output_fifo (512)
|
|
|
|
, input_fifo (1024)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2010-07-29 15:24:25 -04:00
|
|
|
assert (jack_client);
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
Descriptor desc (node);
|
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
init (desc.tag, desc.flags);
|
2010-07-06 20:40:58 -04:00
|
|
|
|
|
|
|
set_state (node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-07 21:00:46 -04:00
|
|
|
Port::init (string const & name, Flags flags)
|
2010-07-06 20:40:58 -04:00
|
|
|
{
|
2008-06-02 17:41:35 -04:00
|
|
|
_ok = false; /* derived class must set to true if constructor
|
|
|
|
succeeds.
|
|
|
|
*/
|
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
_parser = 0;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2010-07-06 20:40:58 -04:00
|
|
|
_tagname = name;
|
2010-07-07 21:00:46 -04:00
|
|
|
_flags = flags;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
_parser = new Parser (*this);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
for (int i = 0; i < 16; i++) {
|
2010-07-07 21:00:46 -04:00
|
|
|
_channel[i] = new Channel (i, *this);
|
|
|
|
_channel[i]->connect_signals ();
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2010-07-05 20:16:36 -04:00
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
if (!create_port ()) {
|
2010-07-05 20:16:36 -04:00
|
|
|
_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));
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Port::~Port ()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
delete _channel[i];
|
|
|
|
}
|
2010-07-05 20:16:36 -04:00
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
if (_jack_port) {
|
2011-12-15 09:33:20 -05:00
|
|
|
if (_jack_client) {
|
2010-07-07 21:00:46 -04:00
|
|
|
jack_port_unregister (_jack_client, _jack_port);
|
2011-12-15 09:33:20 -05:00
|
|
|
_jack_port = 0;
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-12-03 17:26:29 -05:00
|
|
|
Port::parse (framecnt_t timestamp)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
byte buf[512];
|
|
|
|
|
2009-12-01 16:28:31 -05:00
|
|
|
/* 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.
|
2008-06-02 17:41:35 -04:00
|
|
|
*/
|
2009-12-01 16:28:31 -05:00
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
_parser->set_timestamp (timestamp);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
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*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Send a clock tick message.
|
|
|
|
* \return true on success.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
Port::clock (timestamp_t timestamp)
|
|
|
|
{
|
|
|
|
static byte clockmsg = 0xf8;
|
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
if (sends_output()) {
|
2008-06-02 17:41:35 -04:00
|
|
|
return midimsg (&clockmsg, 1, timestamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-12-03 17:26:29 -05:00
|
|
|
Port::cycle_start (pframes_t nframes)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2010-10-27 17:18:32 -04:00
|
|
|
assert (_jack_port);
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
_currently_in_cycle = true;
|
|
|
|
_nframes_this_cycle = nframes;
|
2010-07-05 20:16:36 -04:00
|
|
|
|
|
|
|
assert(_nframes_this_cycle == nframes);
|
|
|
|
_last_read_index = 0;
|
|
|
|
_last_write_timestamp = 0;
|
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
if (sends_output()) {
|
|
|
|
void *buffer = jack_port_get_buffer (_jack_port, nframes);
|
2010-07-05 20:16:36 -04:00
|
|
|
jack_midi_clear_buffer (buffer);
|
|
|
|
flush (buffer);
|
|
|
|
}
|
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
if (receives_input()) {
|
|
|
|
void* jack_buffer = jack_port_get_buffer(_jack_port, nframes);
|
2010-12-03 17:26:29 -05:00
|
|
|
const pframes_t event_count = jack_midi_get_event_count(jack_buffer);
|
2010-07-05 20:16:36 -04:00
|
|
|
|
|
|
|
jack_midi_event_t ev;
|
|
|
|
timestamp_t cycle_start_frame = jack_last_frame_time (_jack_client);
|
|
|
|
|
2010-12-03 17:26:29 -05:00
|
|
|
for (pframes_t i = 0; i < event_count; ++i) {
|
2010-07-05 20:16:36 -04:00
|
|
|
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) {
|
|
|
|
xthread.wakeup ();
|
|
|
|
}
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Port::cycle_end ()
|
|
|
|
{
|
2010-07-07 21:00:46 -04:00
|
|
|
if (sends_output()) {
|
|
|
|
flush (jack_port_get_buffer (_jack_port, _nframes_this_cycle));
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
_currently_in_cycle = false;
|
|
|
|
_nframes_this_cycle = 0;
|
|
|
|
}
|
|
|
|
|
2010-07-05 20:16:36 -04:00
|
|
|
std::ostream & MIDI::operator << ( std::ostream & os, const MIDI::Port & port )
|
|
|
|
{
|
|
|
|
using namespace std;
|
|
|
|
os << "MIDI::Port { ";
|
|
|
|
os << "name: " << port.name();
|
|
|
|
os << "; ";
|
|
|
|
os << "ok: " << port.ok();
|
|
|
|
os << "; ";
|
|
|
|
os << " }";
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
Port::Descriptor::Descriptor (const XMLNode& node)
|
|
|
|
{
|
|
|
|
const XMLProperty *prop;
|
|
|
|
bool have_tag = false;
|
|
|
|
bool have_mode = false;
|
|
|
|
|
|
|
|
if ((prop = node.property ("tag")) != 0) {
|
|
|
|
tag = prop->value();
|
|
|
|
have_tag = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((prop = node.property ("mode")) != 0) {
|
|
|
|
|
|
|
|
if (strings_equal_ignore_case (prop->value(), "output") || strings_equal_ignore_case (prop->value(), "out")) {
|
2010-07-07 21:00:46 -04:00
|
|
|
flags = IsOutput;
|
2010-07-05 20:16:36 -04:00
|
|
|
} else if (strings_equal_ignore_case (prop->value(), "input") || strings_equal_ignore_case (prop->value(), "in")) {
|
2010-07-07 21:00:46 -04:00
|
|
|
flags = IsInput;
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
have_mode = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!have_tag || !have_mode) {
|
|
|
|
throw failed_constructor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Port::jack_halted ()
|
|
|
|
{
|
|
|
|
_jack_client = 0;
|
2010-07-07 21:00:46 -04:00
|
|
|
_jack_port = 0;
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Port::write(byte * msg, size_t msglen, timestamp_t timestamp)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
if (!sends_output()) {
|
2010-07-05 20:16:36 -04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_process_thread()) {
|
|
|
|
|
|
|
|
Glib::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 {
|
|
|
|
|
|
|
|
// XXX This had to be temporarily commented out to make export work again
|
|
|
|
if (!(timestamp < _nframes_this_cycle)) {
|
2012-02-06 10:05:18 -05:00
|
|
|
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;
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_currently_in_cycle) {
|
|
|
|
if (timestamp == 0) {
|
|
|
|
timestamp = _last_write_timestamp;
|
|
|
|
}
|
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
if (jack_midi_event_write (jack_port_get_buffer (_jack_port, _nframes_this_cycle),
|
2010-07-05 20:16:36 -04:00
|
|
|
timestamp, msg, msglen) == 0) {
|
|
|
|
ret = msglen;
|
|
|
|
_last_write_timestamp = timestamp;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ret = 0;
|
|
|
|
cerr << "write of " << msglen << " failed, port holds "
|
2010-07-07 21:00:46 -04:00
|
|
|
<< jack_midi_get_event_count (jack_port_get_buffer (_jack_port, _nframes_this_cycle))
|
2010-07-05 20:16:36 -04:00
|
|
|
<< endl;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cerr << "write to JACK midi port failed: not currently in a process cycle." << endl;
|
2012-02-06 10:05:18 -05:00
|
|
|
PBD::stacktrace (cerr, 20);
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
if (ret > 0 && _parser) {
|
2010-07-05 20:16:36 -04:00
|
|
|
// 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++) {
|
2010-07-07 21:00:46 -04:00
|
|
|
_parser->scanner (msg[i]);
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
|
|
|
// ardour doesn't care about this and neither should your app, probably
|
|
|
|
// output_parser->raw_postparse (*output_parser, msg, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Port::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
|
|
|
|
Port::read (byte *, size_t)
|
|
|
|
{
|
2010-07-07 21:00:46 -04:00
|
|
|
if (!receives_input()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-07-05 20:16:36 -04:00
|
|
|
timestamp_t time;
|
|
|
|
Evoral::EventType type;
|
|
|
|
uint32_t size;
|
|
|
|
byte buffer[input_fifo.capacity()];
|
|
|
|
|
|
|
|
while (input_fifo.read (&time, &type, &size, buffer)) {
|
2010-07-07 21:00:46 -04:00
|
|
|
_parser->set_timestamp (time);
|
|
|
|
for (uint32_t i = 0; i < size; ++i) {
|
|
|
|
_parser->scanner (buffer[i]);
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-07-07 21:00:46 -04:00
|
|
|
Port::create_port ()
|
2010-07-05 20:16:36 -04:00
|
|
|
{
|
2010-07-07 21:00:46 -04:00
|
|
|
_jack_port = jack_port_register(_jack_client, _tagname.c_str(), JACK_DEFAULT_MIDI_TYPE, _flags, 0);
|
|
|
|
return _jack_port == 0 ? -1 : 0;
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
XMLNode&
|
2008-06-02 17:41:35 -04:00
|
|
|
Port::get_state () const
|
|
|
|
{
|
2010-07-08 18:55:20 -04:00
|
|
|
XMLNode* root = new XMLNode (state_node_name);
|
2010-07-05 20:16:36 -04:00
|
|
|
root->add_property ("tag", _tagname);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
if (_flags == IsInput) {
|
2010-07-05 20:16:36 -04:00
|
|
|
root->add_property ("mode", "input");
|
|
|
|
} else {
|
2010-07-07 21:00:46 -04:00
|
|
|
root->add_property ("mode", "output");
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
|
|
|
|
2009-12-10 15:51:35 -05:00
|
|
|
#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
|
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
if (_jack_port) {
|
2010-07-05 20:16:36 -04:00
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
const char** jc = jack_port_get_connections (_jack_port);
|
2010-07-05 20:16:36 -04:00
|
|
|
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()) {
|
2010-07-07 21:00:46 -04:00
|
|
|
root->add_property ("connections", connection_string);
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
|
|
|
} else {
|
2010-07-07 21:00:46 -04:00
|
|
|
if (!_connections.empty()) {
|
|
|
|
root->add_property ("connections", _connections);
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return *root;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-05 20:16:36 -04:00
|
|
|
Port::set_state (const XMLNode& node)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2010-07-05 20:16:36 -04:00
|
|
|
const XMLProperty* prop;
|
|
|
|
|
2010-07-08 18:55:20 -04:00
|
|
|
if ((prop = node.property ("tag")) == 0 || prop->value() != _tagname) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
if ((prop = node.property ("connections")) != 0 && _jack_port) {
|
|
|
|
_connections = prop->value ();
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-05 20:16:36 -04:00
|
|
|
Port::make_connections ()
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2010-07-07 21:00:46 -04:00
|
|
|
if (!_connections.empty()) {
|
2010-07-05 20:16:36 -04:00
|
|
|
vector<string> ports;
|
2010-07-07 21:00:46 -04:00
|
|
|
split (_connections, ports, ',');
|
2010-07-05 20:16:36 -04:00
|
|
|
for (vector<string>::iterator x = ports.begin(); x != ports.end(); ++x) {
|
|
|
|
if (_jack_client) {
|
2010-07-07 21:00:46 -04:00
|
|
|
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());
|
|
|
|
}
|
2010-07-05 20:16:36 -04:00
|
|
|
/* ignore failures */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
connect_connection.disconnect ();
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-05 20:16:36 -04:00
|
|
|
Port::set_process_thread (pthread_t thr)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2010-07-05 20:16:36 -04:00
|
|
|
_process_thread = thr;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2010-07-05 20:16:36 -04:00
|
|
|
bool
|
|
|
|
Port::is_process_thread()
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2010-07-05 20:16:36 -04:00
|
|
|
return (pthread_self() == _process_thread);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2010-07-05 20:16:36 -04:00
|
|
|
void
|
2010-07-08 18:55:20 -04:00
|
|
|
Port::reestablish (jack_client_t* jack)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2010-07-08 18:55:20 -04:00
|
|
|
_jack_client = jack;
|
2010-07-07 21:00:46 -04:00
|
|
|
int const r = create_port ();
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2010-07-05 20:16:36 -04:00
|
|
|
if (r) {
|
|
|
|
PBD::error << "could not reregister ports for " << name() << endmsg;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-05 20:16:36 -04:00
|
|
|
void
|
|
|
|
Port::reconnect ()
|
|
|
|
{
|
|
|
|
make_connections ();
|
|
|
|
}
|