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 const char **connections = _offer_inputs ? _io->output(r)->get_connections() : _io->input(r)->get_connections();
85 while (connections && connections[k]) {
86 if (std::string (connections[k]) == p) {
97 IOSelector::n_rows () const
100 return _io->inputs().num_ports (_io->default_type());
102 return _io->outputs().num_ports (_io->default_type());
107 IOSelector::maximum_rows () const
109 if (!_offer_inputs) {
110 return _io->input_maximum ().get (_io->default_type());
112 return _io->output_maximum ().get (_io->default_type());
118 IOSelector::minimum_rows () const
120 if (!_offer_inputs) {
121 return _io->input_minimum ().get (_io->default_type());
123 return _io->output_minimum ().get (_io->default_type());
128 IOSelector::row_name (int r) const
130 if (!_offer_inputs) {
131 return _io->input(r)->name();
133 return _io->output(r)->name();
139 IOSelector::add_row ()
141 // The IO selector only works for single typed IOs
142 const ARDOUR::DataType t = _io->default_type ();
144 if (!_offer_inputs) {
147 _io->add_input_port ("", this);
150 catch (ARDOUR::AudioEngine::PortRegistrationFailure& err) {
151 Gtk::MessageDialog msg (0, _("There are no more JACK ports available."));
158 _io->add_output_port ("", this);
161 catch (ARDOUR::AudioEngine::PortRegistrationFailure& err) {
162 Gtk::MessageDialog msg (0, _("There are no more JACK ports available."));
170 IOSelector::remove_row (int r)
172 // The IO selector only works for single typed IOs
173 const ARDOUR::DataType t = _io->default_type ();
175 if (!_offer_inputs) {
176 _io->remove_input_port (_io->input (r), this);
178 _io->remove_output_port (_io->output (r), this);
183 IOSelector::row_descriptor () const
190 IOSelectorWindow::IOSelectorWindow (
191 ARDOUR::Session& session, boost::shared_ptr<ARDOUR::IO> io, bool for_input, bool can_cancel
193 : ArdourDialog ("I/O selector"),
194 _selector (session, io, !for_input),
195 ok_button (can_cancel ? _("OK"): _("Close")),
196 cancel_button (_("Cancel")),
197 rescan_button (_("Rescan"))
200 add_events (Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);
201 set_name ("IOSelectorWindow2");
205 title = string_compose(_("%1 input"), io->name());
207 title = string_compose(_("%1 output"), io->name());
210 ok_button.set_name ("IOSelectorButton");
212 ok_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CLOSE, Gtk::ICON_SIZE_BUTTON)));
214 cancel_button.set_name ("IOSelectorButton");
215 rescan_button.set_name ("IOSelectorButton");
216 rescan_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::REFRESH, Gtk::ICON_SIZE_BUTTON)));
218 get_action_area()->pack_start (rescan_button, false, false);
221 cancel_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CANCEL, Gtk::ICON_SIZE_BUTTON)));
222 get_action_area()->pack_start (cancel_button, false, false);
224 cancel_button.hide();
227 get_action_area()->pack_start (ok_button, false, false);
229 get_vbox()->set_spacing (8);
230 get_vbox()->pack_start (_selector);
232 ok_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::accept));
233 cancel_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::cancel));
234 rescan_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::rescan));
237 set_position (Gtk::WIN_POS_MOUSE);
241 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window *> (this)));
244 IOSelectorWindow::~IOSelectorWindow()
250 IOSelectorWindow::rescan ()
252 _selector.redisplay ();
256 IOSelectorWindow::cancel ()
258 _selector.Finished (IOSelector::Cancelled);
263 IOSelectorWindow::accept ()
265 _selector.Finished (IOSelector::Accepted);
270 IOSelectorWindow::on_map ()
272 _selector.redisplay ();
277 PortInsertUI::PortInsertUI (ARDOUR::Session& sess, boost::shared_ptr<ARDOUR::PortInsert> pi)
278 : input_selector (sess, pi->io(), true),
279 output_selector (sess, pi->io(), false)
281 hbox.pack_start (output_selector, true, true);
282 hbox.pack_start (input_selector, true, true);
288 PortInsertUI::redisplay ()
290 input_selector.redisplay();
291 output_selector.redisplay();
295 PortInsertUI::finished (IOSelector::Result r)
297 input_selector.Finished (r);
298 output_selector.Finished (r);
302 PortInsertWindow::PortInsertWindow (ARDOUR::Session& sess, boost::shared_ptr<ARDOUR::PortInsert> pi, bool can_cancel)
303 : ArdourDialog ("port insert dialog"),
304 _portinsertui (sess, pi),
305 ok_button (can_cancel ? _("OK"): _("Close")),
306 cancel_button (_("Cancel")),
307 rescan_button (_("Rescan"))
310 set_name ("IOSelectorWindow");
311 string title = _("ardour: ");
315 ok_button.set_name ("IOSelectorButton");
317 ok_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CLOSE, Gtk::ICON_SIZE_BUTTON)));
319 cancel_button.set_name ("IOSelectorButton");
320 rescan_button.set_name ("IOSelectorButton");
321 rescan_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::REFRESH, Gtk::ICON_SIZE_BUTTON)));
323 get_action_area()->pack_start (rescan_button, false, false);
325 cancel_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CANCEL, Gtk::ICON_SIZE_BUTTON)));
326 get_action_area()->pack_start (cancel_button, false, false);
328 cancel_button.hide();
330 get_action_area()->pack_start (ok_button, false, false);
332 get_vbox()->pack_start (_portinsertui);
334 ok_button.signal_clicked().connect (mem_fun (*this, &PortInsertWindow::accept));
335 cancel_button.signal_clicked().connect (mem_fun (*this, &PortInsertWindow::cancel));
336 rescan_button.signal_clicked().connect (mem_fun (*this, &PortInsertWindow::rescan));
338 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window *> (this)));
340 going_away_connection = pi->GoingAway.connect (mem_fun (*this, &PortInsertWindow::plugin_going_away));
344 PortInsertWindow::plugin_going_away ()
346 ENSURE_GUI_THREAD (mem_fun (*this, &PortInsertWindow::plugin_going_away));
348 going_away_connection.disconnect ();
349 delete_when_idle (this);
353 PortInsertWindow::on_map ()
355 _portinsertui.redisplay ();
361 PortInsertWindow::rescan ()
363 _portinsertui.redisplay ();
367 PortInsertWindow::cancel ()
369 _portinsertui.finished (IOSelector::Cancelled);
374 PortInsertWindow::accept ()
376 _portinsertui.finished (IOSelector::Accepted);