fix math bug with numthreads computation
[ardour2.git] / gtk2_ardour / global_port_matrix.cc
blob510d3b3ce3cea99897d60be3a24bebda26eb5f19
1 /*
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"
23 #include "utils.h"
25 #include "ardour/bundle.h"
26 #include "ardour/session.h"
27 #include "ardour/audioengine.h"
28 #include "ardour/port.h"
30 #include "i18n.h"
32 using namespace std;
34 GlobalPortMatrix::GlobalPortMatrix (Gtk::Window* p, ARDOUR::Session* s, ARDOUR::DataType t)
35 : PortMatrix (p, s, t)
37 setup_all_ports ();
38 init ();
41 void
42 GlobalPortMatrix::setup_ports (int dim)
44 _ports[dim].suspend_signals ();
45 _ports[dim].gather (_session, dim == IN, false);
46 _ports[dim].resume_signals ();
49 void
50 GlobalPortMatrix::set_state (ARDOUR::BundleChannel c[2], bool s)
52 ARDOUR::Bundle::PortList const & in_ports = c[IN].bundle->channel_ports (c[IN].channel);
53 ARDOUR::Bundle::PortList const & out_ports = c[OUT].bundle->channel_ports (c[OUT].channel);
55 for (ARDOUR::Bundle::PortList::const_iterator i = in_ports.begin(); i != in_ports.end(); ++i) {
56 for (ARDOUR::Bundle::PortList::const_iterator j = out_ports.begin(); j != out_ports.end(); ++j) {
58 ARDOUR::Port* p = _session->engine().get_port_by_name (*i);
59 ARDOUR::Port* q = _session->engine().get_port_by_name (*j);
61 if (p) {
62 if (s) {
63 p->connect (*j);
64 } else {
65 p->disconnect (*j);
67 } else if (q) {
68 if (s) {
69 q->connect (*i);
70 } else {
71 q->disconnect (*i);
73 } else {
74 /* two non-Ardour ports */
75 if (s) {
76 jack_connect (_session->engine().jack (), j->c_str(), i->c_str());
77 } else {
78 jack_disconnect (_session->engine().jack (), j->c_str(), i->c_str());
85 PortMatrixNode::State
86 GlobalPortMatrix::get_state (ARDOUR::BundleChannel c[2]) const
88 if (_session == 0) {
89 return PortMatrixNode::NOT_ASSOCIATED;
92 ARDOUR::Bundle::PortList const & in_ports = c[IN].bundle->channel_ports (c[IN].channel);
93 ARDOUR::Bundle::PortList const & out_ports = c[OUT].bundle->channel_ports (c[OUT].channel);
94 if (in_ports.empty() || out_ports.empty()) {
95 /* we're looking at a bundle with no parts associated with this channel,
96 so nothing to connect */
97 return PortMatrixNode::NOT_ASSOCIATED;
100 for (ARDOUR::Bundle::PortList::const_iterator i = in_ports.begin(); i != in_ports.end(); ++i) {
101 for (ARDOUR::Bundle::PortList::const_iterator j = out_ports.begin(); j != out_ports.end(); ++j) {
103 ARDOUR::Port* p = _session->engine().get_port_by_name (*i);
104 ARDOUR::Port* q = _session->engine().get_port_by_name (*j);
106 if (!p && !q) {
107 /* two non-Ardour ports; things are slightly more involved */
108 /* XXX: is this the easiest way to do this? */
109 /* XXX: isn't this very inefficient? */
111 jack_client_t* jack = _session->engine().jack ();
112 jack_port_t* jp = jack_port_by_name (jack, i->c_str());
113 if (jp == 0) {
114 return PortMatrixNode::NOT_ASSOCIATED;
117 char const ** c = jack_port_get_all_connections (jack, jp);
119 char const ** p = c;
121 while (p && *p != 0) {
122 if (strcmp (*p, j->c_str()) == 0) {
123 free (c);
124 return PortMatrixNode::ASSOCIATED;
126 ++p;
129 free (c);
130 return PortMatrixNode::NOT_ASSOCIATED;
133 if (p && p->connected_to (*j) == false) {
134 return PortMatrixNode::NOT_ASSOCIATED;
135 } else if (q && q->connected_to (*i) == false) {
136 return PortMatrixNode::NOT_ASSOCIATED;
142 return PortMatrixNode::ASSOCIATED;
145 GlobalPortMatrixWindow::GlobalPortMatrixWindow (ARDOUR::Session* s, ARDOUR::DataType t)
146 : _port_matrix (this, s, t)
148 switch (t) {
149 case ARDOUR::DataType::AUDIO:
150 set_title (_("Audio Connection Manager"));
151 break;
152 case ARDOUR::DataType::MIDI:
153 set_title (_("MIDI Connection Manager"));
154 break;
157 add (_port_matrix);
158 _port_matrix.show ();
161 void
162 GlobalPortMatrixWindow::on_show ()
164 Gtk::Window::on_show ();
165 pair<uint32_t, uint32_t> const pm_max = _port_matrix.max_size ();
166 resize_window_to_proportion_of_monitor (this, pm_max.first, pm_max.second);
169 string
170 GlobalPortMatrix::disassociation_verb () const
172 return _("Disconnect");
175 string
176 GlobalPortMatrix::channel_noun () const
178 return _("port");