ardour
monitor_selector.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2007 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 <stdint.h>
21 
22 #include <glibmm/objectbase.h>
23 
24 #include <gtkmm2ext/doi.h>
25 
26 #include "ardour/audioengine.h"
27 #include "ardour/bundle.h"
28 #include "ardour/data_type.h"
29 #include "ardour/io.h"
30 #include "ardour/port.h"
31 #include "ardour/session.h"
32 
33 #include "monitor_selector.h"
34 #include "utils.h"
35 #include "gui_thread.h"
36 #include "i18n.h"
37 
38 using namespace ARDOUR;
39 using namespace ARDOUR_UI_UTILS;
40 using namespace Gtk;
41 
43  : PortMatrix (p, session, DataType::AUDIO)
44  , _io (io)
45 {
46  set_type (DataType::AUDIO);
47 
48  /* signal flow from 0 to 1 */
49 
50  _find_inputs_for_io_outputs = (_io->direction() == IO::Output);
51 
53  _other = 1;
54  _ours = 0;
55  } else {
56  _other = 0;
57  _ours = 1;
58  }
59 
60  _port_group.reset (new PortGroup (io->name()));
62 
63  io->changed.connect (_io_connection, invalidator (*this), boost::bind (&MonitorSelector::io_changed_proxy, this), gui_context ());
64 
65  setup_all_ports ();
66  init ();
67 }
68 
69 void
71 {
72  /* The IO's changed signal is emitted from code that holds its route's processor lock,
73  so we can't call setup_all_ports (which results in a call to Route::foreach_processor)
74  without a deadlock unless we break things up with this idle handler.
75  */
76 
77  Glib::signal_idle().connect_once (sigc::mem_fun (*this, &MonitorSelector::io_changed));
78 }
79 
80 void
82 {
83  setup_all_ports ();
84 }
85 
86 void
88 {
89  if (!_session) {
90  return;
91  }
92 
93  _ports[dim].suspend_signals ();
94 
95  if (dim == _other) {
96 
98 
99  } else {
100 
101  _port_group->clear ();
103  }
104 
105  _ports[dim].resume_signals ();
106 }
107 
108 void
110 {
111  ARDOUR::Bundle::PortList const & our_ports = c[_ours].bundle->channel_ports (c[_ours].channel);
112  ARDOUR::Bundle::PortList const & other_ports = c[_other].bundle->channel_ports (c[_other].channel);
113 
114  for (ARDOUR::Bundle::PortList::const_iterator i = our_ports.begin(); i != our_ports.end(); ++i) {
115  for (ARDOUR::Bundle::PortList::const_iterator j = other_ports.begin(); j != other_ports.end(); ++j) {
116 
118  if (!f) {
119  return;
120  }
121 
122  if (s) {
123  if (!f->connected_to (*j)) {
124  _io->connect (f, *j, 0);
125  }
126  } else {
127  if (f->connected_to (*j)) {
128  _io->disconnect (f, *j, 0);
129  }
130  }
131  }
132  }
133 }
134 
137 {
138  if (c[0].bundle->nchannels() == ChanCount::ZERO || c[1].bundle->nchannels() == ChanCount::ZERO) {
140  }
141 
142  ARDOUR::Bundle::PortList const & our_ports = c[_ours].bundle->channel_ports (c[_ours].channel);
143  ARDOUR::Bundle::PortList const & other_ports = c[_other].bundle->channel_ports (c[_other].channel);
144 
145  if (!_session || our_ports.empty() || other_ports.empty()) {
146  /* we're looking at a bundle with no parts associated with this channel,
147  so nothing to connect */
149  }
150 
151  for (ARDOUR::Bundle::PortList::const_iterator i = our_ports.begin(); i != our_ports.end(); ++i) {
152  for (ARDOUR::Bundle::PortList::const_iterator j = other_ports.begin(); j != other_ports.end(); ++j) {
153 
155 
156  /* since we are talking about an IO, our ports should all have an associated Port *,
157  so the above call should never fail */
158  assert (f);
159 
160  if (!f->connected_to (*j)) {
161  /* if any one thing is not connected, all bets are off */
163  }
164  }
165  }
166 
168 }
169 
170 uint32_t
172 {
174  return _io->n_ports().get (_io->default_type());
175  } else {
176  return _io->n_ports().get (_io->default_type());
177  }
178 }
179 
180 bool
182 {
183  return (dim == _other);
184 }
185 
186 std::string
188 {
189  return _("Disconnect");
190 }
191 
192 std::string
194 {
195  return _("port");
196 }
197 
199  : ArdourWindow (_("Monitor output selector"))
200  , _selector (this, session, io)
201 {
202  set_name ("IOSelectorWindow2");
203 
204  add (_selector);
205 
206  io_name_changed (this);
207 
208  show_all ();
209 
210  signal_delete_event().connect (sigc::mem_fun (*this, &MonitorSelectorWindow::wm_delete));
211 }
212 
213 bool
214 MonitorSelectorWindow::wm_delete (GdkEventAny* /*event*/)
215 {
217  return false;
218 }
219 
220 
221 void
223 {
225  Window::on_map ();
226 }
227 
228 void
230 {
231  Gtk::Window::on_show ();
232  std::pair<uint32_t, uint32_t> const pm_max = _selector.max_size ();
233  resize_window_to_proportion_of_monitor (this, pm_max.first, pm_max.second);
234 }
235 
236 void
238 {
240 
241  std::string title;
242 
244  title = string_compose(_("%1 input"), _selector.io()->name());
245  } else {
246  title = string_compose(_("%1 output"), _selector.io()->name());
247  }
248 
249  set_title (title);
250 }
251 
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
void io_name_changed(void *src)
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
boost::shared_ptr< ARDOUR::IO > const io()
Definition: ardour_ui.h:130
std::vector< std::string > PortList
Definition: bundle.h:50
Direction direction() const
Definition: io.h:82
void clear()
Definition: port_group.cc:160
tuple f
Definition: signals.py:35
void add_group(boost::shared_ptr< PortGroup >)
Definition: port_group.cc:718
#define ENSURE_GUI_THREAD(obj, method,...)
Definition: gui_thread.h:34
#define invalidator(x)
Definition: gui_thread.h:40
the ports are associated
std::string channel_noun() const
#define _(Text)
Definition: i18n.h:11
const ChanCount & n_ports() const
Definition: io.h:135
PBD::ScopedConnection _io_connection
boost::shared_ptr< PortGroup > _port_group
void add_bundle(boost::shared_ptr< ARDOUR::Bundle >, bool allow_dups=false)
Definition: port_group.cc:73
boost::shared_ptr< Bundle > bundle()
Definition: io.h:102
Definition: amp.h:29
DataType default_type() const
Definition: io.h:84
#define gui_context()
Definition: gui_thread.h:36
PBD::Signal2< void, IOChange, void * > changed
Definition: io.h:141
MonitorSelectorWindow(ARDOUR::Session *, boost::shared_ptr< ARDOUR::IO >, bool can_cancel=false)
bool list_is_global(int) const
bool _find_inputs_for_io_outputs
void set_type(ARDOUR::DataType)
Definition: port_matrix.cc:229
uint32_t n_io_ports() const
boost::shared_ptr< ARDOUR::IO > _io
bool show_only_bundles() const
Definition: port_matrix.h:94
ARDOUR::DataType type() const
Definition: port_matrix.h:68
PortMatrixNode::State get_state(ARDOUR::BundleChannel c[2]) const
std::pair< uint32_t, uint32_t > max_size() const
Definition: port_matrix.cc:672
uint32_t get(DataType t) const
Definition: chan_count.h:59
int connect(boost::shared_ptr< Port > our_port, std::string other_port, void *src)
Definition: io.cc:224
boost::shared_ptr< Port > get_port_by_name(const std::string &)
boost::shared_ptr< Bundle > bundle
Definition: bundle.h:168
std::string name() const
MonitorSelector _selector
sigc::signal< void, Result > Finished
Definition: port_matrix.h:164
bool wm_delete(GdkEventAny *)
int disconnect(boost::shared_ptr< Port > our_port, std::string other_port, void *src)
std::string disassociation_verb() const
void set_state(ARDOUR::BundleChannel c[2], bool)
MonitorSelector(Gtk::Window *, ARDOUR::Session *, boost::shared_ptr< ARDOUR::IO >)
ARDOUR::Session * _session
AudioEngine & engine()
Definition: session.h:546
void init()
Definition: port_matrix.cc:122
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:208
bool find_inputs_for_io_outputs() const
PortGroupList _ports[2]
Definition: port_matrix.h:176