2 * Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
3 * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
4 * Copyright (C) 2010-2016 Paul Davis <paul@linuxaudiosystems.com>
5 * Copyright (C) 2013-2014 Robin Gareus <robin@gareus.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <gtkmm/image.h>
23 #include <gtkmm/stock.h>
25 #include "global_port_matrix.h"
28 #include "ardour/bundle.h"
29 #include "ardour/session.h"
30 #include "ardour/audioengine.h"
31 #include "ardour/port.h"
36 using namespace ARDOUR;
37 using namespace ARDOUR_UI_UTILS;
39 GlobalPortMatrix::GlobalPortMatrix (Gtk::Window* p, Session* s, DataType t)
40 : PortMatrix (p, s, t)
47 GlobalPortMatrix::setup_ports (int dim)
53 _ports[dim].suspend_signals ();
54 _ports[dim].gather (_session, type(), dim == FLOW_IN, false, show_only_bundles ());
55 _ports[dim].resume_signals ();
59 GlobalPortMatrix::set_state (BundleChannel c[2], bool s)
65 Bundle::PortList const & in_ports = c[FLOW_IN].bundle->channel_ports (c[FLOW_IN].channel);
66 Bundle::PortList const & out_ports = c[FLOW_OUT].bundle->channel_ports (c[FLOW_OUT].channel);
68 for (Bundle::PortList::const_iterator i = in_ports.begin(); i != in_ports.end(); ++i) {
69 for (Bundle::PortList::const_iterator j = out_ports.begin(); j != out_ports.end(); ++j) {
71 boost::shared_ptr<Port> p = _session->engine().get_port_by_name (*i);
72 boost::shared_ptr<Port> q = _session->engine().get_port_by_name (*j);
87 /* two non-Ardour ports */
89 AudioEngine::instance()->connect (*j, *i);
91 AudioEngine::instance()->disconnect (*j, *i);
99 GlobalPortMatrix::get_state (BundleChannel c[2]) const
102 return PortMatrixNode::NOT_ASSOCIATED;
105 if (c[0].bundle->nchannels() == ChanCount::ZERO || c[1].bundle->nchannels() == ChanCount::ZERO) {
106 return PortMatrixNode::NOT_ASSOCIATED;
109 Bundle::PortList const & in_ports = c[FLOW_IN].bundle->channel_ports (c[FLOW_IN].channel);
110 Bundle::PortList const & out_ports = c[FLOW_OUT].bundle->channel_ports (c[FLOW_OUT].channel);
111 if (in_ports.empty() || out_ports.empty()) {
112 /* we're looking at a bundle with no parts associated with this channel,
113 so nothing to connect */
114 return PortMatrixNode::NOT_ASSOCIATED;
117 for (Bundle::PortList::const_iterator i = in_ports.begin(); i != in_ports.end(); ++i) {
118 for (Bundle::PortList::const_iterator j = out_ports.begin(); j != out_ports.end(); ++j) {
120 boost::shared_ptr<Port> p = AudioEngine::instance()->get_port_by_name (*i);
121 boost::shared_ptr<Port> q = AudioEngine::instance()->get_port_by_name (*j);
124 /* two non-Ardour ports; things are slightly more involved */
126 /* get a port handle for one of them .. */
128 PortEngine::PortHandle ph = AudioEngine::instance()->port_engine().get_port_by_name (*i);
130 return PortMatrixNode::NOT_ASSOCIATED;
133 /* see if it is connected to the other one ... */
135 if (AudioEngine::instance()->port_engine().connected_to (ph, *j, false)) {
136 return PortMatrixNode::ASSOCIATED;
139 return PortMatrixNode::NOT_ASSOCIATED;
142 if (p && p->connected_to (*j) == false) {
143 return PortMatrixNode::NOT_ASSOCIATED;
144 } else if (q && q->connected_to (*i) == false) {
145 return PortMatrixNode::NOT_ASSOCIATED;
151 return PortMatrixNode::ASSOCIATED;
154 GlobalPortMatrixWindow::GlobalPortMatrixWindow (Session* s, DataType t)
155 : ArdourWindow (X_("reset me soon"))
156 , _port_matrix (this, s, t)
159 case DataType::AUDIO:
160 set_title (_("Audio Connection Manager"));
163 set_title (_("MIDI Connection Manager"));
167 signal_key_press_event().connect (sigc::mem_fun (_port_matrix, &PortMatrix::key_press));
170 _port_matrix.show ();
174 GlobalPortMatrixWindow::on_show ()
176 Gtk::Window::on_show ();
177 pair<uint32_t, uint32_t> const pm_max = _port_matrix.max_size ();
178 resize_window_to_proportion_of_monitor (this, pm_max.first, pm_max.second);
182 GlobalPortMatrixWindow::set_session (Session* s)
184 _port_matrix.set_session (s);
192 GlobalPortMatrix::set_session (Session *s)
194 SessionHandlePtr::set_session (s);
201 GlobalPortMatrix::disassociation_verb () const
203 return _("Disconnect");
207 GlobalPortMatrix::channel_noun () const