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>
|
2013-09-05 21:39:43 -04:00
|
|
|
|
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"
|
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2009-05-13 12:04:41 -04:00
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
using namespace std;
|
2010-11-27 11:41:28 -05:00
|
|
|
using namespace ARDOUR;
|
2014-06-25 15:27:37 -04:00
|
|
|
using namespace ARDOUR_UI_UTILS;
|
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
|
|
|
{
|
2012-11-04 18:41:52 -05:00
|
|
|
if (!_session) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-08 22:18:10 -05:00
|
|
|
_ports[dim].suspend_signals ();
|
2013-07-11 15:22:33 -04:00
|
|
|
_ports[dim].gather (_session, type(), dim == FLOW_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
|
|
|
{
|
2012-11-04 18:41:52 -05:00
|
|
|
if (!_session) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-11 15:22:33 -04:00
|
|
|
Bundle::PortList const & in_ports = c[FLOW_IN].bundle->channel_ports (c[FLOW_IN].channel);
|
|
|
|
Bundle::PortList const & out_ports = c[FLOW_OUT].bundle->channel_ports (c[FLOW_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) {
|
2013-07-30 23:26:46 -04:00
|
|
|
AudioEngine::instance()->connect (*j, *i);
|
2009-11-16 17:32:58 -05:00
|
|
|
} else {
|
2013-07-30 23:26:46 -04:00
|
|
|
AudioEngine::instance()->disconnect (*j, *i);
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-11 15:22:33 -04:00
|
|
|
Bundle::PortList const & in_ports = c[FLOW_IN].bundle->channel_ports (c[FLOW_IN].channel);
|
|
|
|
Bundle::PortList const & out_ports = c[FLOW_OUT].bundle->channel_ports (c[FLOW_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
|
|
|
|
2013-07-30 23:26:46 -04:00
|
|
|
boost::shared_ptr<Port> p = AudioEngine::instance()->get_port_by_name (*i);
|
|
|
|
boost::shared_ptr<Port> q = AudioEngine::instance()->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 */
|
|
|
|
|
2013-09-05 21:39:43 -04:00
|
|
|
/* get a port handle for one of them .. */
|
2009-11-16 17:32:58 -05:00
|
|
|
|
2013-07-30 23:26:46 -04:00
|
|
|
PortEngine::PortHandle ph = AudioEngine::instance()->port_engine().get_port_by_name (*i);
|
|
|
|
if (!ph) {
|
2009-11-16 17:32:58 -05:00
|
|
|
return PortMatrixNode::NOT_ASSOCIATED;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2013-09-05 21:39:43 -04:00
|
|
|
/* see if it is connected to the other one ... */
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2013-09-05 21:39:43 -04:00
|
|
|
if (AudioEngine::instance()->port_engine().connected_to (ph, *j, false)) {
|
2013-07-30 23:26:46 -04:00
|
|
|
return PortMatrixNode::ASSOCIATED;
|
2009-11-16 17:32:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2012-06-20 18:01:22 -04:00
|
|
|
signal_key_press_event().connect (sigc::mem_fun (_port_matrix, &PortMatrix::key_press));
|
|
|
|
|
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);
|
2012-11-04 18:41:52 -05:00
|
|
|
|
|
|
|
if (!s) {
|
|
|
|
hide ();
|
|
|
|
}
|
2010-07-20 13:56:02 -04:00
|
|
|
}
|
|
|
|
|
2013-07-10 07:16:11 -04:00
|
|
|
void
|
|
|
|
GlobalPortMatrix::set_session (Session *s)
|
|
|
|
{
|
|
|
|
SessionHandlePtr::set_session (s);
|
|
|
|
if (!s) return;
|
|
|
|
setup_all_ports ();
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|