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"
24 #include "ardour/bundle.h"
25 #include "ardour/session.h"
26 #include "ardour/audioengine.h"
27 #include "ardour/port.h"
31 GlobalPortMatrix::GlobalPortMatrix (ARDOUR::Session& s, ARDOUR::DataType t)
38 GlobalPortMatrix::setup_ports (int dim)
40 _ports[dim].suspend_signals ();
41 _ports[dim].gather (_session, dim == IN);
42 _ports[dim].resume_signals ();
46 GlobalPortMatrix::set_state (ARDOUR::BundleChannel c[2], bool s)
48 ARDOUR::Bundle::PortList const & in_ports = c[IN].bundle->channel_ports (c[IN].channel);
49 ARDOUR::Bundle::PortList const & out_ports = c[OUT].bundle->channel_ports (c[OUT].channel);
51 for (ARDOUR::Bundle::PortList::const_iterator i = in_ports.begin(); i != in_ports.end(); ++i) {
52 for (ARDOUR::Bundle::PortList::const_iterator j = out_ports.begin(); j != out_ports.end(); ++j) {
54 ARDOUR::Port* p = _session.engine().get_port_by_name (*i);
55 ARDOUR::Port* q = _session.engine().get_port_by_name (*j);
71 /* we don't handle connections between two non-Ardour ports */
77 GlobalPortMatrix::get_state (ARDOUR::BundleChannel c[2]) const
79 ARDOUR::Bundle::PortList const & in_ports = c[IN].bundle->channel_ports (c[IN].channel);
80 ARDOUR::Bundle::PortList const & out_ports = c[OUT].bundle->channel_ports (c[OUT].channel);
81 if (in_ports.empty() || out_ports.empty()) {
82 /* we're looking at a bundle with no parts associated with this channel,
83 so nothing to connect */
84 return PortMatrixNode::UNKNOWN;
87 for (ARDOUR::Bundle::PortList::const_iterator i = in_ports.begin(); i != in_ports.end(); ++i) {
88 for (ARDOUR::Bundle::PortList::const_iterator j = out_ports.begin(); j != out_ports.end(); ++j) {
90 ARDOUR::Port* p = _session.engine().get_port_by_name (*i);
91 ARDOUR::Port* q = _session.engine().get_port_by_name (*j);
93 /* we don't know the state of connections between two non-Ardour ports */
95 return PortMatrixNode::UNKNOWN;
98 if (p && p->connected_to (*j) == false) {
99 return PortMatrixNode::NOT_ASSOCIATED;
100 } else if (q && q->connected_to (*i) == false) {
101 return PortMatrixNode::NOT_ASSOCIATED;
107 return PortMatrixNode::ASSOCIATED;
110 GlobalPortMatrixWindow::GlobalPortMatrixWindow (ARDOUR::Session& s, ARDOUR::DataType t)
111 : _port_matrix (s, t)
114 case ARDOUR::DataType::AUDIO:
115 set_title (_("Audio Connections Manager"));
117 case ARDOUR::DataType::MIDI:
118 set_title (_("MIDI Connections Manager"));
122 Gtk::HBox* buttons_hbox = Gtk::manage (new Gtk::HBox);
124 _rescan_button.set_label (_("Rescan"));
125 _rescan_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::REFRESH, Gtk::ICON_SIZE_BUTTON)));
126 _rescan_button.signal_clicked().connect (sigc::mem_fun (_port_matrix, &GlobalPortMatrix::setup_all_ports));
127 buttons_hbox->pack_start (_rescan_button, Gtk::PACK_SHRINK);
129 _show_ports_button.set_label (_("Show individual ports"));
130 _show_ports_button.set_active (true);
131 _show_ports_button.signal_toggled().connect (sigc::mem_fun (*this, &GlobalPortMatrixWindow::show_ports_toggled));
132 buttons_hbox->pack_start (_show_ports_button, Gtk::PACK_SHRINK);
134 Gtk::VBox* vbox = Gtk::manage (new Gtk::VBox);
135 vbox->pack_start (_port_matrix);
136 vbox->pack_start (*buttons_hbox, Gtk::PACK_SHRINK);
142 GlobalPortMatrixWindow::show_ports_toggled ()
144 _port_matrix.set_show_only_bundles (!_show_ports_button.get_active());