2 Copyright (C) 2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <gtkmm/image.h>
21 #include <gtkmm/stock.h>
23 #include "global_port_matrix.h"
26 #include "ardour/bundle.h"
27 #include "ardour/session.h"
28 #include "ardour/audioengine.h"
29 #include "ardour/port.h"
34 using namespace ARDOUR;
35 using namespace ARDOUR_UI_UTILS;
37 GlobalPortMatrix::GlobalPortMatrix (Gtk::Window* p, Session* s, DataType t)
38 : PortMatrix (p, s, t)
45 GlobalPortMatrix::setup_ports (int dim)
51 _ports[dim].suspend_signals ();
52 _ports[dim].gather (_session, type(), dim == FLOW_IN, false, show_only_bundles ());
53 _ports[dim].resume_signals ();
57 GlobalPortMatrix::set_state (BundleChannel c[2], bool s)
63 Bundle::PortList const & in_ports = c[FLOW_IN].bundle->channel_ports (c[FLOW_IN].channel);
64 Bundle::PortList const & out_ports = c[FLOW_OUT].bundle->channel_ports (c[FLOW_OUT].channel);
66 for (Bundle::PortList::const_iterator i = in_ports.begin(); i != in_ports.end(); ++i) {
67 for (Bundle::PortList::const_iterator j = out_ports.begin(); j != out_ports.end(); ++j) {
69 boost::shared_ptr<Port> p = _session->engine().get_port_by_name (*i);
70 boost::shared_ptr<Port> q = _session->engine().get_port_by_name (*j);
85 /* two non-Ardour ports */
87 AudioEngine::instance()->connect (*j, *i);
89 AudioEngine::instance()->disconnect (*j, *i);
97 GlobalPortMatrix::get_state (BundleChannel c[2]) const
100 return PortMatrixNode::NOT_ASSOCIATED;
103 if (c[0].bundle->nchannels() == ChanCount::ZERO || c[1].bundle->nchannels() == ChanCount::ZERO) {
104 return PortMatrixNode::NOT_ASSOCIATED;
107 Bundle::PortList const & in_ports = c[FLOW_IN].bundle->channel_ports (c[FLOW_IN].channel);
108 Bundle::PortList const & out_ports = c[FLOW_OUT].bundle->channel_ports (c[FLOW_OUT].channel);
109 if (in_ports.empty() || out_ports.empty()) {
110 /* we're looking at a bundle with no parts associated with this channel,
111 so nothing to connect */
112 return PortMatrixNode::NOT_ASSOCIATED;
115 for (Bundle::PortList::const_iterator i = in_ports.begin(); i != in_ports.end(); ++i) {
116 for (Bundle::PortList::const_iterator j = out_ports.begin(); j != out_ports.end(); ++j) {
118 boost::shared_ptr<Port> p = AudioEngine::instance()->get_port_by_name (*i);
119 boost::shared_ptr<Port> q = AudioEngine::instance()->get_port_by_name (*j);
122 /* two non-Ardour ports; things are slightly more involved */
124 /* get a port handle for one of them .. */
126 PortEngine::PortHandle ph = AudioEngine::instance()->port_engine().get_port_by_name (*i);
128 return PortMatrixNode::NOT_ASSOCIATED;
131 /* see if it is connected to the other one ... */
133 if (AudioEngine::instance()->port_engine().connected_to (ph, *j, false)) {
134 return PortMatrixNode::ASSOCIATED;
137 return PortMatrixNode::NOT_ASSOCIATED;
140 if (p && p->connected_to (*j) == false) {
141 return PortMatrixNode::NOT_ASSOCIATED;
142 } else if (q && q->connected_to (*i) == false) {
143 return PortMatrixNode::NOT_ASSOCIATED;
149 return PortMatrixNode::ASSOCIATED;
152 GlobalPortMatrixWindow::GlobalPortMatrixWindow (Session* s, DataType t)
153 : ArdourWindow (X_("reset me soon"))
154 , _port_matrix (this, s, t)
157 case DataType::AUDIO:
158 set_title (_("Audio Connection Manager"));
161 set_title (_("MIDI Connection Manager"));
165 signal_key_press_event().connect (sigc::mem_fun (_port_matrix, &PortMatrix::key_press));
168 _port_matrix.show ();
172 GlobalPortMatrixWindow::on_show ()
174 Gtk::Window::on_show ();
175 pair<uint32_t, uint32_t> const pm_max = _port_matrix.max_size ();
176 resize_window_to_proportion_of_monitor (this, pm_max.first, pm_max.second);
180 GlobalPortMatrixWindow::set_session (Session* s)
182 _port_matrix.set_session (s);
190 GlobalPortMatrix::set_session (Session *s)
192 SessionHandlePtr::set_session (s);
199 GlobalPortMatrix::disassociation_verb () const
201 return _("Disconnect");
205 GlobalPortMatrix::channel_noun () const