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 offer_inputs)
45 : PortMatrix (session, io->default_type(), offer_inputs)
49 /* Listen for ports changing on the IO */
50 _io->PortCountChanged.connect (sigc::hide (mem_fun (*this, &IOSelector::ports_changed)));
52 _port_group = new PortGroup ("", true);
53 _row_ports.push_back (_port_group);
58 IOSelector::~IOSelector ()
66 _port_group->bundles.clear ();
67 _port_group->bundles.push_back (boost::shared_ptr<ARDOUR::Bundle> (new ARDOUR::Bundle));
68 _port_group->bundles.front()->set_name (_io->name());
70 if (offering_input ()) {
71 const PortSet& ps (_io->outputs());
74 for (PortSet::const_iterator i = ps.begin(); i != ps.end(); ++i) {
76 snprintf (buf, sizeof(buf), _("out %d"), j + 1);
77 _port_group->bundles.front()->add_channel (buf);
78 _port_group->bundles.front()->add_port_to_channel (j, _session.engine().make_port_name_non_relative (i->name()));
84 const PortSet& ps (_io->inputs());
87 for (PortSet::const_iterator i = ps.begin(); i != ps.end(); ++i) {
89 snprintf (buf, sizeof(buf), _("in %d"), j + 1);
90 _port_group->bundles.front()->add_channel (buf);
91 _port_group->bundles.front()->add_port_to_channel (j, _session.engine().make_port_name_non_relative (i->name()));
101 IOSelector::ports_changed ()
103 ENSURE_GUI_THREAD (mem_fun (*this, &IOSelector::ports_changed));
109 IOSelector::set_state (
110 boost::shared_ptr<ARDOUR::Bundle> ab,
112 boost::shared_ptr<ARDOUR::Bundle> bb,
118 ARDOUR::Bundle::PortList const& our_ports = ab->channel_ports (ac);
119 ARDOUR::Bundle::PortList const& other_ports = bb->channel_ports (bc);
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);
130 if (!offering_input()) {
131 _io->connect_input (f, *j, 0);
133 _io->connect_output (f, *j, 0);
136 if (!offering_input()) {
137 _io->disconnect_input (f, *j, 0);
139 _io->disconnect_output (f, *j, 0);
147 IOSelector::get_state (
148 boost::shared_ptr<ARDOUR::Bundle> ab,
150 boost::shared_ptr<ARDOUR::Bundle> bb,
154 ARDOUR::Bundle::PortList const& our_ports = ab->channel_ports (ac);
155 ARDOUR::Bundle::PortList const& other_ports = bb->channel_ports (bc);
157 for (ARDOUR::Bundle::PortList::const_iterator i = our_ports.begin(); i != our_ports.end(); ++i) {
158 for (ARDOUR::Bundle::PortList::const_iterator j = other_ports.begin(); j != other_ports.end(); ++j) {
160 Port* f = _session.engine().get_port_by_name (*i);
162 /* since we are talking about an IO, our ports should all have an associated Port *,
163 so the above call should never fail */
166 if (!f->connected_to (*j)) {
167 /* if any one thing is not connected, all bets are off */
168 return NOT_ASSOCIATED;
177 IOSelector::n_rows () const
179 if (!offering_input()) {
180 return _io->inputs().num_ports (_io->default_type());
182 return _io->outputs().num_ports (_io->default_type());
187 IOSelector::maximum_rows () const
189 if (!offering_input()) {
190 return _io->input_maximum ().get (_io->default_type());
192 return _io->output_maximum ().get (_io->default_type());
198 IOSelector::minimum_rows () const
200 if (!offering_input()) {
201 return _io->input_minimum ().get (_io->default_type());
203 return _io->output_minimum ().get (_io->default_type());
208 IOSelector::add_channel (boost::shared_ptr<ARDOUR::Bundle> b)
210 /* we ignore the bundle parameter, as we know what it is that we're adding to */
212 // The IO selector only works for single typed IOs
213 const ARDOUR::DataType t = _io->default_type ();
215 if (!offering_input()) {
218 _io->add_input_port ("", this);
221 catch (AudioEngine::PortRegistrationFailure& err) {
222 MessageDialog msg (_("There are no more JACK ports available."));
229 _io->add_output_port ("", this);
232 catch (AudioEngine::PortRegistrationFailure& err) {
233 MessageDialog msg (_("There are no more JACK ports available."));
240 IOSelector::remove_channel (boost::shared_ptr<ARDOUR::Bundle> b, uint32_t c)
242 Port* f = _session.engine().get_port_by_name (b->channel_ports(c)[0]);
247 if (offering_input()) {
248 _io->remove_output_port (f, this);
250 _io->remove_input_port (f, this);
254 IOSelectorWindow::IOSelectorWindow (ARDOUR::Session& session, boost::shared_ptr<ARDOUR::IO> io, bool for_input, bool can_cancel)
255 : ArdourDialog ("I/O selector")
256 , _selector (session, io, !for_input)
257 , add_button (_("Add Port"))
258 , disconnect_button (_("Disconnect All"))
259 , ok_button (can_cancel ? _("OK"): _("Close"))
260 , cancel_button (_("Cancel"))
261 , rescan_button (_("Rescan"))
264 /* XXX: what's this for? */
265 add_events (Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);
267 set_name ("IOSelectorWindow2");
269 /* Disconnect All button */
270 disconnect_button.set_name ("IOSelectorButton");
271 disconnect_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::DISCONNECT, Gtk::ICON_SIZE_BUTTON)));
272 disconnect_button.signal_clicked().connect (sigc::mem_fun (_selector, &IOSelector::disassociate_all));
273 get_action_area()->pack_start (disconnect_button, false, false);
275 /* Add Port button */
276 if (_selector.maximum_rows() > _selector.n_rows()) {
277 add_button.set_name ("IOSelectorButton");
278 add_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::ADD, Gtk::ICON_SIZE_BUTTON)));
279 get_action_area()->pack_start (add_button, false, false);
280 add_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (_selector, &IOSelector::add_channel), boost::shared_ptr<Bundle> ()));
284 rescan_button.set_name ("IOSelectorButton");
285 rescan_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::REFRESH, Gtk::ICON_SIZE_BUTTON)));
286 rescan_button.signal_clicked().connect (sigc::mem_fun (_selector, &IOSelector::setup));
287 get_action_area()->pack_start (rescan_button, false, false);
289 io->PortCountChanged.connect (sigc::hide (mem_fun (*this, &IOSelectorWindow::ports_changed)));
293 cancel_button.set_name ("IOSelectorButton");
294 cancel_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CANCEL, Gtk::ICON_SIZE_BUTTON)));
295 get_action_area()->pack_start (cancel_button, false, false);
297 cancel_button.hide();
299 cancel_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::cancel));
302 ok_button.set_name ("IOSelectorButton");
304 ok_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CLOSE, Gtk::ICON_SIZE_BUTTON)));
306 ok_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::accept));
307 get_action_area()->pack_start (ok_button, false, false);
309 get_vbox()->set_spacing (8);
311 get_vbox()->pack_start (_selector, true, true);
313 set_position (Gtk::WIN_POS_MOUSE);
315 io_name_changed (this);
320 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), this));
324 IOSelectorWindow::ports_changed ()
326 if (_selector.maximum_rows() > _selector.n_rows()) {
327 add_button.set_sensitive (true);
329 add_button.set_sensitive (false);
334 IOSelectorWindow::cancel ()
336 _selector.Finished (IOSelector::Cancelled);
341 IOSelectorWindow::accept ()
343 _selector.Finished (IOSelector::Accepted);
348 IOSelectorWindow::on_map ()
355 IOSelectorWindow::io_name_changed (void* src)
357 ENSURE_GUI_THREAD(bind (mem_fun(*this, &IOSelectorWindow::io_name_changed), src));
361 if (!_selector.offering_input()) {
362 title = string_compose(_("%1 input"), _selector.io()->name());
364 title = string_compose(_("%1 output"), _selector.io()->name());
370 PortInsertUI::PortInsertUI (ARDOUR::Session& sess, boost::shared_ptr<ARDOUR::PortInsert> pi)
371 : input_selector (sess, pi->io(), true),
372 output_selector (sess, pi->io(), false)
374 pack_start (output_selector, true, true);
375 pack_start (input_selector, true, true);
379 PortInsertUI::redisplay ()
381 input_selector.setup ();
382 output_selector.setup ();
386 PortInsertUI::finished (IOSelector::Result r)
388 input_selector.Finished (r);
389 output_selector.Finished (r);
393 PortInsertWindow::PortInsertWindow (ARDOUR::Session& sess, boost::shared_ptr<ARDOUR::PortInsert> pi, bool can_cancel)
394 : ArdourDialog ("port insert dialog"),
395 _portinsertui (sess, pi),
396 ok_button (can_cancel ? _("OK"): _("Close")),
397 cancel_button (_("Cancel")),
398 rescan_button (_("Rescan"))
401 set_name ("IOSelectorWindow");
402 string title = _("ardour: ");
406 ok_button.set_name ("IOSelectorButton");
408 ok_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CLOSE, Gtk::ICON_SIZE_BUTTON)));
410 cancel_button.set_name ("IOSelectorButton");
411 rescan_button.set_name ("IOSelectorButton");
412 rescan_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::REFRESH, Gtk::ICON_SIZE_BUTTON)));
414 get_action_area()->pack_start (rescan_button, false, false);
416 cancel_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CANCEL, Gtk::ICON_SIZE_BUTTON)));
417 get_action_area()->pack_start (cancel_button, false, false);
419 cancel_button.hide();
421 get_action_area()->pack_start (ok_button, false, false);
423 get_vbox()->pack_start (_portinsertui);
425 ok_button.signal_clicked().connect (mem_fun (*this, &PortInsertWindow::accept));
426 cancel_button.signal_clicked().connect (mem_fun (*this, &PortInsertWindow::cancel));
428 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window *> (this)));
430 going_away_connection = pi->GoingAway.connect (mem_fun (*this, &PortInsertWindow::plugin_going_away));
434 PortInsertWindow::plugin_going_away ()
436 ENSURE_GUI_THREAD (mem_fun (*this, &PortInsertWindow::plugin_going_away));
438 going_away_connection.disconnect ();
439 delete_when_idle (this);
443 PortInsertWindow::on_map ()
445 _portinsertui.redisplay ();
451 PortInsertWindow::cancel ()
453 _portinsertui.finished (IOSelector::Cancelled);
458 PortInsertWindow::accept ()
460 _portinsertui.finished (IOSelector::Accepted);