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 <glibmm/objectbase.h>
21 #include <gtkmm2ext/doi.h>
22 #include <ardour/port_insert.h>
23 #include "ardour/session.h"
24 #include "ardour/io.h"
25 #include "ardour/audioengine.h"
26 #include "ardour/track.h"
27 #include "ardour/audio_track.h"
28 #include "ardour/midi_track.h"
29 #include "ardour/data_type.h"
30 #include "io_selector.h"
32 #include "gui_thread.h"
35 IOSelector::IOSelector (ARDOUR::Session& session, boost::shared_ptr<ARDOUR::IO> io, bool offer_inputs)
37 session, io->default_type(), offer_inputs,
38 PortGroupList::Mask (PortGroupList::BUSS | PortGroupList::SYSTEM | PortGroupList::OTHER)
42 /* Listen for ports changing on the IO */
44 _io->input_changed.connect (mem_fun(*this, &IOSelector::ports_changed));
46 _io->output_changed.connect (mem_fun(*this, &IOSelector::ports_changed));
52 IOSelector::ports_changed (ARDOUR::IOChange change, void *src)
54 ENSURE_GUI_THREAD (bind (mem_fun (*this, &IOSelector::ports_changed), change, src));
62 IOSelector::set_state (int r, std::string const & p, bool s)
66 _io->connect_input (_io->input(r), p, 0);
68 _io->connect_output (_io->output(r), p, 0);
72 _io->disconnect_input (_io->input(r), p, 0);
74 _io->disconnect_output (_io->output(r), p, 0);
80 IOSelector::get_state (int r, std::string const & p) const
82 vector<string> connections;
85 _io->output(r)->get_connections (connections);
87 _io->input(r)->get_connections (connections);
92 for (vector<string>::iterator i = connections.begin(); i != connections.end(); ++i) {
105 IOSelector::n_rows () const
107 if (!_offer_inputs) {
108 return _io->inputs().num_ports (_io->default_type());
110 return _io->outputs().num_ports (_io->default_type());
115 IOSelector::maximum_rows () const
117 if (!_offer_inputs) {
118 return _io->input_maximum ().get (_io->default_type());
120 return _io->output_maximum ().get (_io->default_type());
126 IOSelector::minimum_rows () const
128 if (!_offer_inputs) {
129 return _io->input_minimum ().get (_io->default_type());
131 return _io->output_minimum ().get (_io->default_type());
136 IOSelector::row_name (int r) const
138 if (!_offer_inputs) {
139 return _io->input(r)->name();
141 return _io->output(r)->name();
147 IOSelector::add_row ()
149 // The IO selector only works for single typed IOs
150 const ARDOUR::DataType t = _io->default_type ();
152 if (!_offer_inputs) {
155 _io->add_input_port ("", this);
158 catch (ARDOUR::AudioEngine::PortRegistrationFailure& err) {
159 Gtk::MessageDialog msg (0, _("There are no more JACK ports available."));
166 _io->add_output_port ("", this);
169 catch (ARDOUR::AudioEngine::PortRegistrationFailure& err) {
170 Gtk::MessageDialog msg (0, _("There are no more JACK ports available."));
178 IOSelector::remove_row (int r)
180 // The IO selector only works for single typed IOs
181 const ARDOUR::DataType t = _io->default_type ();
183 if (!_offer_inputs) {
184 _io->remove_input_port (_io->input (r), this);
186 _io->remove_output_port (_io->output (r), this);
191 IOSelector::row_descriptor () const
198 IOSelectorWindow::IOSelectorWindow (
199 ARDOUR::Session& session, boost::shared_ptr<ARDOUR::IO> io, bool for_input, bool can_cancel
201 : ArdourDialog ("I/O selector"),
202 _selector (session, io, !for_input),
203 ok_button (can_cancel ? _("OK"): _("Close")),
204 cancel_button (_("Cancel")),
205 rescan_button (_("Rescan"))
208 add_events (Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);
209 set_name ("IOSelectorWindow2");
213 title = string_compose(_("%1 input"), io->name());
215 title = string_compose(_("%1 output"), io->name());
218 ok_button.set_name ("IOSelectorButton");
220 ok_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CLOSE, Gtk::ICON_SIZE_BUTTON)));
222 cancel_button.set_name ("IOSelectorButton");
223 rescan_button.set_name ("IOSelectorButton");
224 rescan_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::REFRESH, Gtk::ICON_SIZE_BUTTON)));
226 get_action_area()->pack_start (rescan_button, false, false);
229 cancel_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CANCEL, Gtk::ICON_SIZE_BUTTON)));
230 get_action_area()->pack_start (cancel_button, false, false);
232 cancel_button.hide();
235 get_action_area()->pack_start (ok_button, false, false);
237 get_vbox()->set_spacing (8);
238 get_vbox()->pack_start (_selector);
240 ok_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::accept));
241 cancel_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::cancel));
242 rescan_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::rescan));
245 set_position (Gtk::WIN_POS_MOUSE);
249 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window *> (this)));
252 IOSelectorWindow::~IOSelectorWindow()
258 IOSelectorWindow::rescan ()
260 _selector.redisplay ();
264 IOSelectorWindow::cancel ()
266 _selector.Finished (IOSelector::Cancelled);
271 IOSelectorWindow::accept ()
273 _selector.Finished (IOSelector::Accepted);
278 IOSelectorWindow::on_map ()
280 _selector.redisplay ();
285 PortInsertUI::PortInsertUI (ARDOUR::Session& sess, boost::shared_ptr<ARDOUR::PortInsert> pi)
286 : input_selector (sess, pi->io(), true),
287 output_selector (sess, pi->io(), false)
289 hbox.pack_start (output_selector, true, true);
290 hbox.pack_start (input_selector, true, true);
296 PortInsertUI::redisplay ()
298 input_selector.redisplay();
299 output_selector.redisplay();
303 PortInsertUI::finished (IOSelector::Result r)
305 input_selector.Finished (r);
306 output_selector.Finished (r);
310 PortInsertWindow::PortInsertWindow (ARDOUR::Session& sess, boost::shared_ptr<ARDOUR::PortInsert> pi, bool can_cancel)
311 : ArdourDialog ("port insert dialog"),
312 _portinsertui (sess, pi),
313 ok_button (can_cancel ? _("OK"): _("Close")),
314 cancel_button (_("Cancel")),
315 rescan_button (_("Rescan"))
318 set_name ("IOSelectorWindow");
319 string title = _("ardour: ");
323 ok_button.set_name ("IOSelectorButton");
325 ok_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CLOSE, Gtk::ICON_SIZE_BUTTON)));
327 cancel_button.set_name ("IOSelectorButton");
328 rescan_button.set_name ("IOSelectorButton");
329 rescan_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::REFRESH, Gtk::ICON_SIZE_BUTTON)));
331 get_action_area()->pack_start (rescan_button, false, false);
333 cancel_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CANCEL, Gtk::ICON_SIZE_BUTTON)));
334 get_action_area()->pack_start (cancel_button, false, false);
336 cancel_button.hide();
338 get_action_area()->pack_start (ok_button, false, false);
340 get_vbox()->pack_start (_portinsertui);
342 ok_button.signal_clicked().connect (mem_fun (*this, &PortInsertWindow::accept));
343 cancel_button.signal_clicked().connect (mem_fun (*this, &PortInsertWindow::cancel));
344 rescan_button.signal_clicked().connect (mem_fun (*this, &PortInsertWindow::rescan));
346 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window *> (this)));
348 going_away_connection = pi->GoingAway.connect (mem_fun (*this, &PortInsertWindow::plugin_going_away));
352 PortInsertWindow::plugin_going_away ()
354 ENSURE_GUI_THREAD (mem_fun (*this, &PortInsertWindow::plugin_going_away));
356 going_away_connection.disconnect ();
357 delete_when_idle (this);
361 PortInsertWindow::on_map ()
363 _portinsertui.redisplay ();
369 PortInsertWindow::rescan ()
371 _portinsertui.redisplay ();
375 PortInsertWindow::cancel ()
377 _portinsertui.finished (IOSelector::Cancelled);
382 PortInsertWindow::accept ()
384 _portinsertui.finished (IOSelector::Accepted);