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;
36 GlobalPortMatrix::GlobalPortMatrix (Gtk::Window* p, Session* s, DataType t)
37 : PortMatrix (p, s, t)
44 GlobalPortMatrix::setup_ports (int dim)
50 _ports[dim].suspend_signals ();
51 _ports[dim].gather (_session, type(), dim == FLOW_IN, false, show_only_bundles ());
52 _ports[dim].resume_signals ();
56 GlobalPortMatrix::set_state (BundleChannel c[2], bool s)
62 Bundle::PortList const & in_ports = c[FLOW_IN].bundle->channel_ports (c[FLOW_IN].channel);
63 Bundle::PortList const & out_ports = c[FLOW_OUT].bundle->channel_ports (c[FLOW_OUT].channel);
65 for (Bundle::PortList::const_iterator i = in_ports.begin(); i != in_ports.end(); ++i) {
66 for (Bundle::PortList::const_iterator j = out_ports.begin(); j != out_ports.end(); ++j) {
68 boost::shared_ptr<Port> p = _session->engine().get_port_by_name (*i);
69 boost::shared_ptr<Port> q = _session->engine().get_port_by_name (*j);
84 /* two non-Ardour ports */
86 AudioEngine::instance()->connect (*j, *i);
88 AudioEngine::instance()->disconnect (*j, *i);
96 GlobalPortMatrix::get_state (BundleChannel c[2]) const
99 return PortMatrixNode::NOT_ASSOCIATED;
102 if (c[0].bundle->nchannels() == ChanCount::ZERO || c[1].bundle->nchannels() == ChanCount::ZERO) {
103 return PortMatrixNode::NOT_ASSOCIATED;
106 Bundle::PortList const & in_ports = c[FLOW_IN].bundle->channel_ports (c[FLOW_IN].channel);
107 Bundle::PortList const & out_ports = c[FLOW_OUT].bundle->channel_ports (c[FLOW_OUT].channel);
108 if (in_ports.empty() || out_ports.empty()) {
109 /* we're looking at a bundle with no parts associated with this channel,
110 so nothing to connect */
111 return PortMatrixNode::NOT_ASSOCIATED;
114 for (Bundle::PortList::const_iterator i = in_ports.begin(); i != in_ports.end(); ++i) {
115 for (Bundle::PortList::const_iterator j = out_ports.begin(); j != out_ports.end(); ++j) {
117 boost::shared_ptr<Port> p = AudioEngine::instance()->get_port_by_name (*i);
118 boost::shared_ptr<Port> q = AudioEngine::instance()->get_port_by_name (*j);
121 /* two non-Ardour ports; things are slightly more involved */
123 /* get a port handle for one of them .. */
125 PortEngine::PortHandle ph = AudioEngine::instance()->port_engine().get_port_by_name (*i);
127 return PortMatrixNode::NOT_ASSOCIATED;
130 /* see if it is connected to the other one ... */
132 if (AudioEngine::instance()->port_engine().connected_to (ph, *j, false)) {
133 return PortMatrixNode::ASSOCIATED;
136 return PortMatrixNode::NOT_ASSOCIATED;
139 if (p && p->connected_to (*j) == false) {
140 return PortMatrixNode::NOT_ASSOCIATED;
141 } else if (q && q->connected_to (*i) == false) {
142 return PortMatrixNode::NOT_ASSOCIATED;
148 return PortMatrixNode::ASSOCIATED;
151 GlobalPortMatrixWindow::GlobalPortMatrixWindow (Session* s, DataType t)
152 : ArdourWindow (X_("reset me soon"))
153 , _port_matrix (this, s, t)
156 case DataType::AUDIO:
157 set_title (_("Audio Connection Manager"));
160 set_title (_("MIDI Connection Manager"));
164 signal_key_press_event().connect (sigc::mem_fun (_port_matrix, &PortMatrix::key_press));
167 _port_matrix.show ();
171 GlobalPortMatrixWindow::on_show ()
173 Gtk::Window::on_show ();
174 pair<uint32_t, uint32_t> const pm_max = _port_matrix.max_size ();
175 resize_window_to_proportion_of_monitor (this, pm_max.first, pm_max.second);
179 GlobalPortMatrixWindow::set_session (Session* s)
181 _port_matrix.set_session (s);
189 GlobalPortMatrix::set_session (Session *s)
191 SessionHandlePtr::set_session (s);
198 GlobalPortMatrix::disassociation_verb () const
200 return _("Disconnect");
204 GlobalPortMatrix::channel_noun () const