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>
22 #include "global_port_matrix.h"
25 #include "ardour/bundle.h"
26 #include "ardour/session.h"
27 #include "ardour/audioengine.h"
28 #include "ardour/port.h"
33 using namespace ARDOUR;
35 GlobalPortMatrix::GlobalPortMatrix (Gtk::Window* p, Session* s, DataType t)
36 : PortMatrix (p, s, t)
43 GlobalPortMatrix::setup_ports (int dim)
49 _ports[dim].suspend_signals ();
50 _ports[dim].gather (_session, type(), dim == IN, false, show_only_bundles ());
51 _ports[dim].resume_signals ();
55 GlobalPortMatrix::set_state (BundleChannel c[2], bool s)
61 Bundle::PortList const & in_ports = c[IN].bundle->channel_ports (c[IN].channel);
62 Bundle::PortList const & out_ports = c[OUT].bundle->channel_ports (c[OUT].channel);
64 for (Bundle::PortList::const_iterator i = in_ports.begin(); i != in_ports.end(); ++i) {
65 for (Bundle::PortList::const_iterator j = out_ports.begin(); j != out_ports.end(); ++j) {
67 boost::shared_ptr<Port> p = _session->engine().get_port_by_name (*i);
68 boost::shared_ptr<Port> q = _session->engine().get_port_by_name (*j);
83 /* two non-Ardour ports */
85 jack_connect (_session->engine().jack (), j->c_str(), i->c_str());
87 jack_disconnect (_session->engine().jack (), j->c_str(), i->c_str());
95 GlobalPortMatrix::get_state (BundleChannel c[2]) const
98 return PortMatrixNode::NOT_ASSOCIATED;
101 if (c[0].bundle->nchannels() == ChanCount::ZERO || c[1].bundle->nchannels() == ChanCount::ZERO) {
102 return PortMatrixNode::NOT_ASSOCIATED;
105 Bundle::PortList const & in_ports = c[IN].bundle->channel_ports (c[IN].channel);
106 Bundle::PortList const & out_ports = c[OUT].bundle->channel_ports (c[OUT].channel);
107 if (in_ports.empty() || out_ports.empty()) {
108 /* we're looking at a bundle with no parts associated with this channel,
109 so nothing to connect */
110 return PortMatrixNode::NOT_ASSOCIATED;
113 for (Bundle::PortList::const_iterator i = in_ports.begin(); i != in_ports.end(); ++i) {
114 for (Bundle::PortList::const_iterator j = out_ports.begin(); j != out_ports.end(); ++j) {
116 boost::shared_ptr<Port> p = _session->engine().get_port_by_name (*i);
117 boost::shared_ptr<Port> q = _session->engine().get_port_by_name (*j);
120 /* two non-Ardour ports; things are slightly more involved */
121 /* XXX: is this the easiest way to do this? */
122 /* XXX: isn't this very inefficient? */
124 jack_client_t* jack = _session->engine().jack ();
125 jack_port_t* jp = jack_port_by_name (jack, i->c_str());
127 return PortMatrixNode::NOT_ASSOCIATED;
130 char const ** c = jack_port_get_all_connections (jack, jp);
134 while (p && *p != 0) {
135 if (strcmp (*p, j->c_str()) == 0) {
137 return PortMatrixNode::ASSOCIATED;
143 return PortMatrixNode::NOT_ASSOCIATED;
146 if (p && p->connected_to (*j) == false) {
147 return PortMatrixNode::NOT_ASSOCIATED;
148 } else if (q && q->connected_to (*i) == false) {
149 return PortMatrixNode::NOT_ASSOCIATED;
155 return PortMatrixNode::ASSOCIATED;
158 GlobalPortMatrixWindow::GlobalPortMatrixWindow (Session* s, DataType t)
159 : ArdourWindow (X_("reset me soon"))
160 , _port_matrix (this, s, t)
163 case DataType::AUDIO:
164 set_title (_("Audio Connection Manager"));
167 set_title (_("MIDI Connection Manager"));
171 signal_key_press_event().connect (sigc::mem_fun (_port_matrix, &PortMatrix::key_press));
174 _port_matrix.show ();
178 GlobalPortMatrixWindow::on_show ()
180 Gtk::Window::on_show ();
181 pair<uint32_t, uint32_t> const pm_max = _port_matrix.max_size ();
182 resize_window_to_proportion_of_monitor (this, pm_max.first, pm_max.second);
186 GlobalPortMatrixWindow::set_session (Session* s)
188 _port_matrix.set_session (s);
196 GlobalPortMatrix::disassociation_verb () const
198 return _("Disconnect");
202 GlobalPortMatrix::channel_noun () const