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));
50 /* these got lost in a merge from 2.0 */
51 set_button_sensitivity ();
52 io->name_changed.connect (mem_fun(*this, &IOSelector::name_changed));
59 IOSelector::ports_changed (ARDOUR::IOChange change, void *src)
61 ENSURE_GUI_THREAD (bind (mem_fun (*this, &IOSelector::ports_changed), change, src));
69 IOSelector::set_state (int r, std::string const & p, bool s)
73 _io->connect_input (_io->input(r), p, 0);
75 _io->connect_output (_io->output(r), p, 0);
79 _io->disconnect_input (_io->input(r), p, 0);
81 _io->disconnect_output (_io->output(r), p, 0);
87 IOSelector::get_state (int r, std::string const & p) const
89 vector<string> connections;
92 _io->output(r)->get_connections (connections);
94 _io->input(r)->get_connections (connections);
98 for (vector<string>::iterator i = connections.begin(); i != connections.end(); ++i) {
111 IOSelector::n_rows () const
113 if (!_offer_inputs) {
114 return _io->inputs().num_ports (_io->default_type());
116 return _io->outputs().num_ports (_io->default_type());
121 IOSelector::maximum_rows () const
123 if (!_offer_inputs) {
124 return _io->input_maximum ().get (_io->default_type());
126 return _io->output_maximum ().get (_io->default_type());
132 IOSelector::minimum_rows () const
134 if (!_offer_inputs) {
135 return _io->input_minimum ().get (_io->default_type());
137 return _io->output_minimum ().get (_io->default_type());
142 IOSelector::row_name (int r) const
144 if (!_offer_inputs) {
145 return _io->input(r)->name();
147 return _io->output(r)->name();
153 IOSelector::add_row ()
155 // The IO selector only works for single typed IOs
156 const ARDOUR::DataType t = _io->default_type ();
158 if (!_offer_inputs) {
161 _io->add_input_port ("", this);
164 catch (ARDOUR::AudioEngine::PortRegistrationFailure& err) {
165 Gtk::MessageDialog msg (0, _("There are no more JACK ports available."));
172 _io->add_output_port ("", this);
175 catch (ARDOUR::AudioEngine::PortRegistrationFailure& err) {
176 Gtk::MessageDialog msg (0, _("There are no more JACK ports available."));
184 IOSelector::remove_row (int r)
186 // The IO selector only works for single typed IOs
187 const ARDOUR::DataType t = _io->default_type ();
189 if (!_offer_inputs) {
190 _io->remove_input_port (_io->input (r), this);
192 _io->remove_output_port (_io->output (r), this);
197 IOSelector::row_descriptor () const
204 IOSelectorWindow::IOSelectorWindow (
205 ARDOUR::Session& session, boost::shared_ptr<ARDOUR::IO> io, bool for_input, bool can_cancel
207 : ArdourDialog ("I/O selector"),
208 _selector (session, io, !for_input),
209 ok_button (can_cancel ? _("OK"): _("Close")),
210 cancel_button (_("Cancel")),
211 rescan_button (_("Rescan"))
214 add_events (Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);
215 set_name ("IOSelectorWindow2");
219 title = string_compose(_("%1 input"), io->name());
221 title = string_compose(_("%1 output"), io->name());
224 ok_button.set_name ("IOSelectorButton");
226 ok_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CLOSE, Gtk::ICON_SIZE_BUTTON)));
228 cancel_button.set_name ("IOSelectorButton");
229 rescan_button.set_name ("IOSelectorButton");
230 rescan_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::REFRESH, Gtk::ICON_SIZE_BUTTON)));
232 get_action_area()->pack_start (rescan_button, false, false);
235 cancel_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CANCEL, Gtk::ICON_SIZE_BUTTON)));
236 get_action_area()->pack_start (cancel_button, false, false);
238 cancel_button.hide();
241 get_action_area()->pack_start (ok_button, false, false);
243 get_vbox()->set_spacing (8);
244 get_vbox()->pack_start (_selector);
246 ok_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::accept));
247 cancel_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::cancel));
248 rescan_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::rescan));
251 set_position (Gtk::WIN_POS_MOUSE);
255 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window *> (this)));
258 IOSelectorWindow::~IOSelectorWindow()
264 IOSelectorWindow::rescan ()
266 _selector.redisplay ();
270 IOSelectorWindow::cancel ()
272 _selector.Finished (IOSelector::Cancelled);
277 IOSelectorWindow::accept ()
279 _selector.Finished (IOSelector::Accepted);
284 IOSelectorWindow::on_map ()
286 _selector.redisplay ();
291 PortInsertUI::PortInsertUI (ARDOUR::Session& sess, boost::shared_ptr<ARDOUR::PortInsert> pi)
292 : input_selector (sess, pi->io(), true),
293 output_selector (sess, pi->io(), false)
295 hbox.pack_start (output_selector, true, true);
296 hbox.pack_start (input_selector, true, true);
302 PortInsertUI::redisplay ()
304 input_selector.redisplay();
305 output_selector.redisplay();
309 PortInsertUI::finished (IOSelector::Result r)
311 input_selector.Finished (r);
312 output_selector.Finished (r);
316 PortInsertWindow::PortInsertWindow (ARDOUR::Session& sess, boost::shared_ptr<ARDOUR::PortInsert> pi, bool can_cancel)
317 : ArdourDialog ("port insert dialog"),
318 _portinsertui (sess, pi),
319 ok_button (can_cancel ? _("OK"): _("Close")),
320 cancel_button (_("Cancel")),
321 rescan_button (_("Rescan"))
324 set_name ("IOSelectorWindow");
325 string title = _("ardour: ");
329 ok_button.set_name ("IOSelectorButton");
331 ok_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CLOSE, Gtk::ICON_SIZE_BUTTON)));
333 cancel_button.set_name ("IOSelectorButton");
334 rescan_button.set_name ("IOSelectorButton");
335 rescan_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::REFRESH, Gtk::ICON_SIZE_BUTTON)));
337 get_action_area()->pack_start (rescan_button, false, false);
339 cancel_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CANCEL, Gtk::ICON_SIZE_BUTTON)));
340 get_action_area()->pack_start (cancel_button, false, false);
342 cancel_button.hide();
344 get_action_area()->pack_start (ok_button, false, false);
346 get_vbox()->pack_start (_portinsertui);
348 ok_button.signal_clicked().connect (mem_fun (*this, &PortInsertWindow::accept));
349 cancel_button.signal_clicked().connect (mem_fun (*this, &PortInsertWindow::cancel));
350 rescan_button.signal_clicked().connect (mem_fun (*this, &PortInsertWindow::rescan));
352 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window *> (this)));
354 going_away_connection = pi->GoingAway.connect (mem_fun (*this, &PortInsertWindow::plugin_going_away));
358 PortInsertWindow::plugin_going_away ()
360 ENSURE_GUI_THREAD (mem_fun (*this, &PortInsertWindow::plugin_going_away));
362 going_away_connection.disconnect ();
363 delete_when_idle (this);
367 PortInsertWindow::on_map ()
369 _portinsertui.redisplay ();
375 PortInsertWindow::rescan ()
377 _portinsertui.redisplay ();
381 PortInsertWindow::cancel ()
383 _portinsertui.finished (IOSelector::Cancelled);
388 PortInsertWindow::accept ()
390 _portinsertui.finished (IOSelector::Accepted);