2 Copyright (C) 2002-2007 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/messagedialog.h>
21 #include <glibmm/objectbase.h>
23 #include <gtkmm2ext/doi.h>
25 #include <ardour/port_insert.h>
26 #include "ardour/session.h"
27 #include "ardour/io.h"
28 #include "ardour/audioengine.h"
29 #include "ardour/track.h"
30 #include "ardour/audio_track.h"
31 #include "ardour/midi_track.h"
32 #include "ardour/data_type.h"
33 #include "ardour/port.h"
34 #include "ardour/bundle.h"
36 #include "io_selector.h"
38 #include "gui_thread.h"
41 using namespace ARDOUR;
44 IOSelector::IOSelector (ARDOUR::Session& session, boost::shared_ptr<ARDOUR::IO> io, bool in)
45 : PortMatrix (session, io->default_type())
47 , _find_inputs_for_io_outputs (in)
49 /* signal flow from 0 to 1 */
50 if (_find_inputs_for_io_outputs) {
58 _port_group = boost::shared_ptr<PortGroup> (new PortGroup (""));
59 _ports[_ours].add_group (_port_group);
65 IOSelector::setup_ports (int dim)
67 _ports[dim].suspend_signals ();
71 _ports[_other].gather (_session, _find_inputs_for_io_outputs);
75 _port_group->clear ();
76 _port_group->add_bundle (
77 _find_inputs_for_io_outputs ? _io->bundle_for_outputs() : _io->bundle_for_inputs()
81 _ports[dim].resume_signals ();
85 IOSelector::set_state (ARDOUR::BundleChannel c[2], bool s)
87 ARDOUR::Bundle::PortList const & our_ports = c[_ours].bundle->channel_ports (c[_ours].channel);
88 ARDOUR::Bundle::PortList const & other_ports = c[_other].bundle->channel_ports (c[_other].channel);
90 for (ARDOUR::Bundle::PortList::const_iterator i = our_ports.begin(); i != our_ports.end(); ++i) {
91 for (ARDOUR::Bundle::PortList::const_iterator j = other_ports.begin(); j != other_ports.end(); ++j) {
93 Port* f = _session.engine().get_port_by_name (*i);
99 if (!_find_inputs_for_io_outputs) {
100 _io->connect_input (f, *j, 0);
102 _io->connect_output (f, *j, 0);
105 if (!_find_inputs_for_io_outputs) {
106 _io->disconnect_input (f, *j, 0);
108 _io->disconnect_output (f, *j, 0);
116 IOSelector::get_state (ARDOUR::BundleChannel c[2]) const
118 ARDOUR::Bundle::PortList const & our_ports = c[_ours].bundle->channel_ports (c[_ours].channel);
119 ARDOUR::Bundle::PortList const & other_ports = c[_other].bundle->channel_ports (c[_other].channel);
121 for (ARDOUR::Bundle::PortList::const_iterator i = our_ports.begin(); i != our_ports.end(); ++i) {
122 for (ARDOUR::Bundle::PortList::const_iterator j = other_ports.begin(); j != other_ports.end(); ++j) {
124 Port* f = _session.engine().get_port_by_name (*i);
126 /* since we are talking about an IO, our ports should all have an associated Port *,
127 so the above call should never fail */
130 if (!f->connected_to (*j)) {
131 /* if any one thing is not connected, all bets are off */
132 return NOT_ASSOCIATED;
141 IOSelector::n_io_ports () const
143 if (!_find_inputs_for_io_outputs) {
144 return _io->inputs().num_ports (_io->default_type());
146 return _io->outputs().num_ports (_io->default_type());
151 IOSelector::maximum_io_ports () const
153 if (!_find_inputs_for_io_outputs) {
154 return _io->input_maximum ().get (_io->default_type());
156 return _io->output_maximum ().get (_io->default_type());
162 IOSelector::minimum_io_ports () const
164 if (!_find_inputs_for_io_outputs) {
165 return _io->input_minimum ().get (_io->default_type());
167 return _io->output_minimum ().get (_io->default_type());
172 IOSelector::add_channel (boost::shared_ptr<ARDOUR::Bundle> b)
174 /* we ignore the bundle parameter, as we know what it is that we're adding to */
176 // The IO selector only works for single typed IOs
177 const ARDOUR::DataType t = _io->default_type ();
179 if (!_find_inputs_for_io_outputs) {
182 _io->add_input_port ("", this);
185 catch (AudioEngine::PortRegistrationFailure& err) {
186 MessageDialog msg (_("There are no more JACK ports available."));
193 _io->add_output_port ("", this);
196 catch (AudioEngine::PortRegistrationFailure& err) {
197 MessageDialog msg (_("There are no more JACK ports available."));
204 IOSelector::remove_channel (ARDOUR::BundleChannel bc)
206 Port* f = _session.engine().get_port_by_name (bc.bundle->channel_ports(bc.channel)[0]);
211 if (_find_inputs_for_io_outputs) {
212 _io->remove_output_port (f, this);
214 _io->remove_input_port (f, this);
219 IOSelector::list_is_global (int dim) const
221 return (dim == _other);
224 IOSelectorWindow::IOSelectorWindow (ARDOUR::Session& session, boost::shared_ptr<ARDOUR::IO> io, bool for_input, bool can_cancel)
225 : ArdourDialog ("I/O selector")
226 , _selector (session, io, !for_input)
227 , add_button (_("Add Port"))
228 , disconnect_button (_("Disconnect All"))
229 , ok_button (can_cancel ? _("OK"): _("Close"))
230 , cancel_button (_("Cancel"))
231 , rescan_button (_("Rescan"))
234 /* XXX: what's this for? */
235 add_events (Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);
237 set_name ("IOSelectorWindow2");
239 /* Disconnect All button */
240 disconnect_button.set_name ("IOSelectorButton");
241 disconnect_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::DISCONNECT, Gtk::ICON_SIZE_BUTTON)));
242 disconnect_button.signal_clicked().connect (sigc::mem_fun (_selector, &IOSelector::disassociate_all));
243 get_action_area()->pack_start (disconnect_button, false, false);
245 /* Add Port button */
246 if (_selector.maximum_io_ports() > _selector.n_io_ports()) {
247 add_button.set_name ("IOSelectorButton");
248 add_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::ADD, Gtk::ICON_SIZE_BUTTON)));
249 get_action_area()->pack_start (add_button, false, false);
250 add_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (_selector, &IOSelector::add_channel), boost::shared_ptr<Bundle> ()));
254 rescan_button.set_name ("IOSelectorButton");
255 rescan_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::REFRESH, Gtk::ICON_SIZE_BUTTON)));
256 rescan_button.signal_clicked().connect (sigc::mem_fun (*this, &IOSelectorWindow::rescan));
257 get_action_area()->pack_start (rescan_button, false, false);
259 io->PortCountChanged.connect (sigc::hide (mem_fun (*this, &IOSelectorWindow::ports_changed)));
263 cancel_button.set_name ("IOSelectorButton");
264 cancel_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CANCEL, Gtk::ICON_SIZE_BUTTON)));
265 get_action_area()->pack_start (cancel_button, false, false);
267 cancel_button.hide();
269 cancel_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::cancel));
272 ok_button.set_name ("IOSelectorButton");
274 ok_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CLOSE, Gtk::ICON_SIZE_BUTTON)));
276 ok_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::accept));
277 get_action_area()->pack_start (ok_button, false, false);
279 get_vbox()->set_spacing (8);
281 get_vbox()->pack_start (_selector, true, true);
283 set_position (Gtk::WIN_POS_MOUSE);
285 io_name_changed (this);
290 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), this));
294 IOSelectorWindow::ports_changed ()
296 if (_selector.maximum_io_ports() > _selector.n_io_ports()) {
297 add_button.set_sensitive (true);
299 add_button.set_sensitive (false);
304 IOSelectorWindow::rescan ()
306 _selector.setup_ports (_selector.other());
310 IOSelectorWindow::cancel ()
312 _selector.Finished (IOSelector::Cancelled);
317 IOSelectorWindow::accept ()
319 _selector.Finished (IOSelector::Accepted);
324 IOSelectorWindow::on_map ()
326 _selector.setup_all_ports ();
331 IOSelectorWindow::io_name_changed (void* src)
333 ENSURE_GUI_THREAD(bind (mem_fun(*this, &IOSelectorWindow::io_name_changed), src));
337 if (!_selector.find_inputs_for_io_outputs()) {
338 title = string_compose(_("%1 input"), _selector.io()->name());
340 title = string_compose(_("%1 output"), _selector.io()->name());
346 PortInsertUI::PortInsertUI (ARDOUR::Session& sess, boost::shared_ptr<ARDOUR::PortInsert> pi)
347 : input_selector (sess, pi->io(), true),
348 output_selector (sess, pi->io(), false)
350 output_selector.set_min_height_divisor (2);
351 input_selector.set_min_height_divisor (2);
353 pack_start (output_selector, true, true);
354 pack_start (input_selector, true, true);
358 PortInsertUI::redisplay ()
360 input_selector.setup_ports (input_selector.other());
361 output_selector.setup_ports (output_selector.other());
365 PortInsertUI::finished (IOSelector::Result r)
367 input_selector.Finished (r);
368 output_selector.Finished (r);
372 PortInsertWindow::PortInsertWindow (ARDOUR::Session& sess, boost::shared_ptr<ARDOUR::PortInsert> pi, bool can_cancel)
373 : ArdourDialog ("port insert dialog"),
374 _portinsertui (sess, pi),
375 ok_button (can_cancel ? _("OK"): _("Close")),
376 cancel_button (_("Cancel")),
377 rescan_button (_("Rescan"))
380 set_name ("IOSelectorWindow");
381 string title = _("ardour: ");
385 ok_button.set_name ("IOSelectorButton");
387 ok_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CLOSE, Gtk::ICON_SIZE_BUTTON)));
389 cancel_button.set_name ("IOSelectorButton");
390 rescan_button.set_name ("IOSelectorButton");
391 rescan_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::REFRESH, Gtk::ICON_SIZE_BUTTON)));
393 get_action_area()->pack_start (rescan_button, false, false);
395 cancel_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CANCEL, Gtk::ICON_SIZE_BUTTON)));
396 get_action_area()->pack_start (cancel_button, false, false);
398 cancel_button.hide();
400 get_action_area()->pack_start (ok_button, false, false);
402 get_vbox()->pack_start (_portinsertui);
404 ok_button.signal_clicked().connect (mem_fun (*this, &PortInsertWindow::accept));
405 cancel_button.signal_clicked().connect (mem_fun (*this, &PortInsertWindow::cancel));
407 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window *> (this)));
409 going_away_connection = pi->GoingAway.connect (mem_fun (*this, &PortInsertWindow::plugin_going_away));
413 PortInsertWindow::plugin_going_away ()
415 ENSURE_GUI_THREAD (mem_fun (*this, &PortInsertWindow::plugin_going_away));
417 going_away_connection.disconnect ();
418 delete_when_idle (this);
422 PortInsertWindow::on_map ()
424 _portinsertui.redisplay ();
430 PortInsertWindow::cancel ()
432 _portinsertui.finished (IOSelector::Cancelled);
437 PortInsertWindow::accept ()
439 _portinsertui.finished (IOSelector::Accepted);