2009-01-23 16:24:11 -05:00
|
|
|
/*
|
2009-10-14 12:10:01 -04:00
|
|
|
Copyright (C) 2009 Paul Davis
|
2009-01-23 16:24:11 -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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2009-02-10 10:45:06 -05:00
|
|
|
#include <gtkmm/image.h>
|
|
|
|
#include <gtkmm/stock.h>
|
2009-01-23 16:24:11 -05:00
|
|
|
#include "global_port_matrix.h"
|
2009-08-29 16:48:11 -04:00
|
|
|
#include "utils.h"
|
2009-05-13 12:04:41 -04:00
|
|
|
|
2009-01-23 16:24:11 -05:00
|
|
|
#include "ardour/bundle.h"
|
|
|
|
#include "ardour/session.h"
|
|
|
|
#include "ardour/audioengine.h"
|
|
|
|
#include "ardour/port.h"
|
|
|
|
|
2009-05-13 12:04:41 -04:00
|
|
|
#include "i18n.h"
|
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
using namespace std;
|
2010-11-27 11:41:28 -05:00
|
|
|
using namespace ARDOUR;
|
2009-07-17 18:54:45 -04:00
|
|
|
|
2010-11-27 11:41:28 -05:00
|
|
|
GlobalPortMatrix::GlobalPortMatrix (Gtk::Window* p, Session* s, DataType t)
|
2009-07-21 21:28:31 -04:00
|
|
|
: PortMatrix (p, s, t)
|
2009-01-23 16:24:11 -05:00
|
|
|
{
|
2009-02-08 22:18:10 -05:00
|
|
|
setup_all_ports ();
|
2009-11-18 08:35:31 -05:00
|
|
|
init ();
|
2009-01-23 16:24:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-02-08 22:18:10 -05:00
|
|
|
GlobalPortMatrix::setup_ports (int dim)
|
2009-01-23 16:24:11 -05:00
|
|
|
{
|
2009-02-08 22:18:10 -05:00
|
|
|
_ports[dim].suspend_signals ();
|
2012-05-20 17:56:28 -04:00
|
|
|
_ports[dim].gather (_session, type(), dim == IN, false, show_only_bundles ());
|
2009-02-08 22:18:10 -05:00
|
|
|
_ports[dim].resume_signals ();
|
2009-01-23 16:24:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-11-27 11:41:28 -05:00
|
|
|
GlobalPortMatrix::set_state (BundleChannel c[2], bool s)
|
2009-01-23 16:24:11 -05:00
|
|
|
{
|
2010-11-27 11:41:28 -05:00
|
|
|
Bundle::PortList const & in_ports = c[IN].bundle->channel_ports (c[IN].channel);
|
|
|
|
Bundle::PortList const & out_ports = c[OUT].bundle->channel_ports (c[OUT].channel);
|
2009-01-23 16:24:11 -05:00
|
|
|
|
2010-11-27 11:41:28 -05:00
|
|
|
for (Bundle::PortList::const_iterator i = in_ports.begin(); i != in_ports.end(); ++i) {
|
|
|
|
for (Bundle::PortList::const_iterator j = out_ports.begin(); j != out_ports.end(); ++j) {
|
|
|
|
|
2011-10-28 13:04:09 -04:00
|
|
|
boost::shared_ptr<Port> p = _session->engine().get_port_by_name (*i);
|
|
|
|
boost::shared_ptr<Port> q = _session->engine().get_port_by_name (*j);
|
2009-01-23 16:24:11 -05:00
|
|
|
|
|
|
|
if (p) {
|
|
|
|
if (s) {
|
|
|
|
p->connect (*j);
|
|
|
|
} else {
|
|
|
|
p->disconnect (*j);
|
|
|
|
}
|
|
|
|
} else if (q) {
|
|
|
|
if (s) {
|
|
|
|
q->connect (*i);
|
|
|
|
} else {
|
2009-01-30 10:08:09 -05:00
|
|
|
q->disconnect (*i);
|
2009-01-23 16:24:11 -05:00
|
|
|
}
|
2009-11-16 17:32:58 -05:00
|
|
|
} else {
|
|
|
|
/* two non-Ardour ports */
|
|
|
|
if (s) {
|
2009-12-04 22:04:54 -05:00
|
|
|
jack_connect (_session->engine().jack (), j->c_str(), i->c_str());
|
2009-11-16 17:32:58 -05:00
|
|
|
} else {
|
2009-12-04 22:04:54 -05:00
|
|
|
jack_disconnect (_session->engine().jack (), j->c_str(), i->c_str());
|
2009-11-16 17:32:58 -05:00
|
|
|
}
|
2009-01-23 16:24:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-03 10:31:42 -04:00
|
|
|
PortMatrixNode::State
|
2010-11-27 11:41:28 -05:00
|
|
|
GlobalPortMatrix::get_state (BundleChannel c[2]) const
|
2009-01-23 16:24:11 -05:00
|
|
|
{
|
2009-12-04 22:04:54 -05:00
|
|
|
if (_session == 0) {
|
|
|
|
return PortMatrixNode::NOT_ASSOCIATED;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-08-13 16:19:39 -04:00
|
|
|
if (c[0].bundle->nchannels() == ChanCount::ZERO || c[1].bundle->nchannels() == ChanCount::ZERO) {
|
|
|
|
return PortMatrixNode::NOT_ASSOCIATED;
|
|
|
|
}
|
|
|
|
|
2010-11-27 11:41:28 -05:00
|
|
|
Bundle::PortList const & in_ports = c[IN].bundle->channel_ports (c[IN].channel);
|
|
|
|
Bundle::PortList const & out_ports = c[OUT].bundle->channel_ports (c[OUT].channel);
|
2009-02-08 22:18:10 -05:00
|
|
|
if (in_ports.empty() || out_ports.empty()) {
|
2009-02-14 15:17:45 -05:00
|
|
|
/* we're looking at a bundle with no parts associated with this channel,
|
|
|
|
so nothing to connect */
|
2009-11-16 17:32:58 -05:00
|
|
|
return PortMatrixNode::NOT_ASSOCIATED;
|
2009-02-08 22:18:10 -05:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-11-27 11:41:28 -05:00
|
|
|
for (Bundle::PortList::const_iterator i = in_ports.begin(); i != in_ports.end(); ++i) {
|
|
|
|
for (Bundle::PortList::const_iterator j = out_ports.begin(); j != out_ports.end(); ++j) {
|
2009-01-23 16:24:11 -05:00
|
|
|
|
2011-10-28 13:04:09 -04:00
|
|
|
boost::shared_ptr<Port> p = _session->engine().get_port_by_name (*i);
|
|
|
|
boost::shared_ptr<Port> q = _session->engine().get_port_by_name (*j);
|
2009-01-23 16:24:11 -05:00
|
|
|
|
|
|
|
if (!p && !q) {
|
2009-11-16 17:32:58 -05:00
|
|
|
/* two non-Ardour ports; things are slightly more involved */
|
|
|
|
/* XXX: is this the easiest way to do this? */
|
|
|
|
/* XXX: isn't this very inefficient? */
|
|
|
|
|
2009-12-04 22:04:54 -05:00
|
|
|
jack_client_t* jack = _session->engine().jack ();
|
2009-11-16 17:32:58 -05:00
|
|
|
jack_port_t* jp = jack_port_by_name (jack, i->c_str());
|
|
|
|
if (jp == 0) {
|
|
|
|
return PortMatrixNode::NOT_ASSOCIATED;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-11-16 17:32:58 -05:00
|
|
|
char const ** c = jack_port_get_all_connections (jack, jp);
|
|
|
|
|
|
|
|
char const ** p = c;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-11-16 17:32:58 -05:00
|
|
|
while (p && *p != 0) {
|
|
|
|
if (strcmp (*p, j->c_str()) == 0) {
|
|
|
|
free (c);
|
|
|
|
return PortMatrixNode::ASSOCIATED;
|
|
|
|
}
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
|
|
|
|
free (c);
|
|
|
|
return PortMatrixNode::NOT_ASSOCIATED;
|
2009-01-23 16:24:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p && p->connected_to (*j) == false) {
|
2009-05-03 10:31:42 -04:00
|
|
|
return PortMatrixNode::NOT_ASSOCIATED;
|
2009-01-23 16:24:11 -05:00
|
|
|
} else if (q && q->connected_to (*i) == false) {
|
2009-05-03 10:31:42 -04:00
|
|
|
return PortMatrixNode::NOT_ASSOCIATED;
|
2009-01-23 16:24:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-03 10:31:42 -04:00
|
|
|
return PortMatrixNode::ASSOCIATED;
|
2009-01-23 16:24:11 -05:00
|
|
|
}
|
|
|
|
|
2010-11-27 11:41:28 -05:00
|
|
|
GlobalPortMatrixWindow::GlobalPortMatrixWindow (Session* s, DataType t)
|
2011-11-18 19:56:35 -05:00
|
|
|
: ArdourWindow (X_("reset me soon"))
|
|
|
|
, _port_matrix (this, s, t)
|
2009-01-23 16:24:11 -05:00
|
|
|
{
|
2009-01-26 15:41:22 -05:00
|
|
|
switch (t) {
|
2010-11-27 11:41:28 -05:00
|
|
|
case DataType::AUDIO:
|
2009-10-19 13:25:37 -04:00
|
|
|
set_title (_("Audio Connection Manager"));
|
2009-01-26 15:41:22 -05:00
|
|
|
break;
|
2010-11-27 11:41:28 -05:00
|
|
|
case DataType::MIDI:
|
2009-10-19 13:25:37 -04:00
|
|
|
set_title (_("MIDI Connection Manager"));
|
2009-01-26 15:41:22 -05:00
|
|
|
break;
|
|
|
|
}
|
2009-02-10 10:45:06 -05:00
|
|
|
|
2011-11-18 19:56:35 -05:00
|
|
|
add (_port_matrix);
|
2009-12-07 13:35:42 -05:00
|
|
|
_port_matrix.show ();
|
2009-07-18 09:10:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-07-21 21:28:31 -04:00
|
|
|
GlobalPortMatrixWindow::on_show ()
|
2009-07-18 09:10:08 -04:00
|
|
|
{
|
2009-07-21 21:28:31 -04:00
|
|
|
Gtk::Window::on_show ();
|
2009-08-29 16:48:11 -04:00
|
|
|
pair<uint32_t, uint32_t> const pm_max = _port_matrix.max_size ();
|
|
|
|
resize_window_to_proportion_of_monitor (this, pm_max.first, pm_max.second);
|
2009-05-03 10:31:42 -04:00
|
|
|
}
|
2010-05-07 21:20:33 -04:00
|
|
|
|
2010-07-20 13:56:02 -04:00
|
|
|
void
|
2010-11-27 11:41:28 -05:00
|
|
|
GlobalPortMatrixWindow::set_session (Session* s)
|
2010-07-20 13:56:02 -04:00
|
|
|
{
|
|
|
|
_port_matrix.set_session (s);
|
|
|
|
}
|
|
|
|
|
2010-05-07 21:20:33 -04:00
|
|
|
string
|
|
|
|
GlobalPortMatrix::disassociation_verb () const
|
|
|
|
{
|
|
|
|
return _("Disconnect");
|
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
GlobalPortMatrix::channel_noun () const
|
|
|
|
{
|
|
|
|
return _("port");
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|