ardour
global_port_matrix.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Paul Davis
3 
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.
8 
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.
13 
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.
17 
18 */
19 
20 #include <gtkmm/image.h>
21 #include <gtkmm/stock.h>
22 
23 #include "global_port_matrix.h"
24 #include "utils.h"
25 
26 #include "ardour/bundle.h"
27 #include "ardour/session.h"
28 #include "ardour/audioengine.h"
29 #include "ardour/port.h"
30 
31 #include "i18n.h"
32 
33 using namespace std;
34 using namespace ARDOUR;
35 using namespace ARDOUR_UI_UTILS;
36 
38  : PortMatrix (p, s, t)
39 {
40  setup_all_ports ();
41  init ();
42 }
43 
44 void
46 {
47  if (!_session) {
48  return;
49  }
50 
51  _ports[dim].suspend_signals ();
52  _ports[dim].gather (_session, type(), dim == FLOW_IN, false, show_only_bundles ());
53  _ports[dim].resume_signals ();
54 }
55 
56 void
58 {
59  if (!_session) {
60  return;
61  }
62 
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);
65 
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) {
68 
71 
72  if (p) {
73  if (s) {
74  p->connect (*j);
75  } else {
76  p->disconnect (*j);
77  }
78  } else if (q) {
79  if (s) {
80  q->connect (*i);
81  } else {
82  q->disconnect (*i);
83  }
84  } else {
85  /* two non-Ardour ports */
86  if (s) {
87  AudioEngine::instance()->connect (*j, *i);
88  } else {
89  AudioEngine::instance()->disconnect (*j, *i);
90  }
91  }
92  }
93  }
94 }
95 
98 {
99  if (_session == 0) {
101  }
102 
103  if (c[0].bundle->nchannels() == ChanCount::ZERO || c[1].bundle->nchannels() == ChanCount::ZERO) {
105  }
106 
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 */
113  }
114 
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) {
117 
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);
120 
121  if (!p && !q) {
122  /* two non-Ardour ports; things are slightly more involved */
123 
124  /* get a port handle for one of them .. */
125 
126  PortEngine::PortHandle ph = AudioEngine::instance()->port_engine().get_port_by_name (*i);
127  if (!ph) {
129  }
130 
131  /* see if it is connected to the other one ... */
132 
133  if (AudioEngine::instance()->port_engine().connected_to (ph, *j, false)) {
135  }
136 
138  }
139 
140  if (p && p->connected_to (*j) == false) {
142  } else if (q && q->connected_to (*i) == false) {
144  }
145 
146  }
147  }
148 
150 }
151 
153  : ArdourWindow (X_("reset me soon"))
154  , _port_matrix (this, s, t)
155 {
156  switch (t) {
157  case DataType::AUDIO:
158  set_title (_("Audio Connection Manager"));
159  break;
160  case DataType::MIDI:
161  set_title (_("MIDI Connection Manager"));
162  break;
163  }
164 
165  signal_key_press_event().connect (sigc::mem_fun (_port_matrix, &PortMatrix::key_press));
166 
167  add (_port_matrix);
168  _port_matrix.show ();
169 }
170 
171 void
173 {
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);
177 }
178 
179 void
181 {
183 
184  if (!s) {
185  hide ();
186  }
187 }
188 
189 void
191 {
192  SessionHandlePtr::set_session (s);
193  if (!s) return;
194  setup_all_ports ();
195  init();
196 }
197 
198 string
200 {
201  return _("Disconnect");
202 }
203 
204 string
206 {
207  return _("port");
208 }
209 
void resize_window_to_proportion_of_monitor(Gtk::Window *, int, int)
Definition: utils.cc:831
void setup_all_ports()
Definition: port_matrix.cc:642
void suspend_signals()
Definition: port_group.cc:758
int connect(std::string const &)
Definition: port.cc:172
void resume_signals()
Definition: port_group.cc:764
the ports are not associated
bool connected_to(std::string const &) const
Definition: port.cc:147
void gather(ARDOUR::Session *, ARDOUR::DataType, bool, bool, bool)
Definition: port_group.cc:329
GlobalPortMatrix _port_matrix
std::vector< std::string > PortList
Definition: bundle.h:50
Definition: Beats.hpp:239
GlobalPortMatrix(Gtk::Window *, ARDOUR::Session *, ARDOUR::DataType)
the ports are associated
#define _(Text)
Definition: i18n.h:11
#define port_engine
#define X_(Text)
Definition: i18n.h:13
Definition: amp.h:29
GlobalPortMatrixWindow(ARDOUR::Session *, ARDOUR::DataType)
PortMatrixNode::State get_state(ARDOUR::BundleChannel c[2]) const
bool show_only_bundles() const
Definition: port_matrix.h:94
void set_state(ARDOUR::BundleChannel c[2], bool)
ARDOUR::DataType type() const
Definition: port_matrix.h:68
std::pair< uint32_t, uint32_t > max_size() const
Definition: port_matrix.cc:672
boost::shared_ptr< Port > get_port_by_name(const std::string &)
boost::shared_ptr< Bundle > bundle
Definition: bundle.h:168
std::string disassociation_verb() const
bool key_press(GdkEventKey *)
std::string channel_noun() const
void set_session(ARDOUR::Session *)
void set_session(ARDOUR::Session *s)
int disconnect(std::string const &)
Definition: port.cc:199
ARDOUR::Session * _session
AudioEngine & engine()
Definition: session.h:546
void init()
Definition: port_matrix.cc:122
PortGroupList _ports[2]
Definition: port_matrix.h:176