X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fio_selector.cc;h=519445f12a6541ee33552966d645e1d4ed6a2ca7;hb=ab565167ff36eb473340e950d93d46c3dfaa9616;hp=1708c9036e53e164033bd91d6f7b7c91164c9923;hpb=7a9b4a0aa2f5ccdcd9257a0df12917c0e3b1fd91;p=ardour.git diff --git a/gtk2_ardour/io_selector.cc b/gtk2_ardour/io_selector.cc index 1708c9036e..519445f12a 100644 --- a/gtk2_ardour/io_selector.cc +++ b/gtk2_ardour/io_selector.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2007 Paul Davis + Copyright (C) 2002-2007 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,9 +17,12 @@ */ +#include #include + #include -#include + +#include "ardour/port_insert.h" #include "ardour/session.h" #include "ardour/io.h" #include "ardour/audioengine.h" @@ -27,282 +30,200 @@ #include "ardour/audio_track.h" #include "ardour/midi_track.h" #include "ardour/data_type.h" +#include "ardour/port.h" +#include "ardour/bundle.h" + #include "io_selector.h" #include "utils.h" #include "gui_thread.h" #include "i18n.h" -IOSelector::IOSelector (ARDOUR::Session& session, boost::shared_ptr io, bool offer_inputs) - : PortMatrix ( - session, io->default_type(), offer_inputs, - PortGroupList::Mask (PortGroupList::BUSS | PortGroupList::SYSTEM | PortGroupList::OTHER) - ), - _io (io) +using namespace ARDOUR; +using namespace Gtk; + +IOSelector::IOSelector (Gtk::Window* p, ARDOUR::Session& session, boost::shared_ptr io) + : PortMatrix (p, session, io->default_type()) + , _io (io) { - /* Listen for ports changing on the IO */ - if (_offer_inputs) { - _io->input_changed.connect (mem_fun(*this, &IOSelector::ports_changed)); + /* signal flow from 0 to 1 */ + + _find_inputs_for_io_outputs = (_io->direction() == IO::Output); + + if (_find_inputs_for_io_outputs) { + _other = 1; + _ours = 0; } else { - _io->output_changed.connect (mem_fun(*this, &IOSelector::ports_changed)); + _other = 0; + _ours = 1; } -#ifdef FIXME - /* these got lost in a merge from 2.0 */ - set_button_sensitivity (); - io->name_changed.connect (mem_fun(*this, &IOSelector::name_changed)); -#endif + _port_group.reset (new PortGroup ("")); + _ports[_ours].add_group (_port_group); + setup_all_ports (); } - void -IOSelector::ports_changed (ARDOUR::IOChange change, void *src) +IOSelector::setup_ports (int dim) { - ENSURE_GUI_THREAD (bind (mem_fun (*this, &IOSelector::ports_changed), change, src)); + _ports[dim].suspend_signals (); - redisplay (); -} - - - -void -IOSelector::set_state (int r, std::string const & p, bool s) -{ - if (s) { - if (_offer_inputs) { - _io->connect_input (_io->input(r), p, 0); - } else { - _io->connect_output (_io->output(r), p, 0); - } - } else { - if (_offer_inputs) { - _io->disconnect_input (_io->input(r), p, 0); - } else { - _io->disconnect_output (_io->output(r), p, 0); - } - } -} + if (dim == _other) { -bool -IOSelector::get_state (int r, std::string const & p) const -{ - vector connections; + _ports[_other].gather (_session, _find_inputs_for_io_outputs); - if (_offer_inputs) { - _io->input(r)->get_connections (connections); } else { - _io->output(r)->get_connections (connections); - } - - int k = 0; - for (vector::iterator i = connections.begin(); i != connections.end(); ++i) { - if ((*i)== p) { - return true; - } - - ++k; + _port_group->clear (); + _port_group->add_bundle (_io->bundle (), _io); } - return false; -} - -uint32_t -IOSelector::n_rows () const -{ - if (_offer_inputs) { - return _io->inputs().num_ports (_io->default_type()); - } else { - return _io->outputs().num_ports (_io->default_type()); - } + _ports[dim].resume_signals (); } -uint32_t -IOSelector::maximum_rows () const +void +IOSelector::set_state (ARDOUR::BundleChannel c[2], bool s) { - if (_offer_inputs) { - return _io->input_maximum ().get (_io->default_type()); - } else { - return _io->output_maximum ().get (_io->default_type()); + ARDOUR::Bundle::PortList const & our_ports = c[_ours].bundle->channel_ports (c[_ours].channel); + ARDOUR::Bundle::PortList const & other_ports = c[_other].bundle->channel_ports (c[_other].channel); + + for (ARDOUR::Bundle::PortList::const_iterator i = our_ports.begin(); i != our_ports.end(); ++i) { + for (ARDOUR::Bundle::PortList::const_iterator j = other_ports.begin(); j != other_ports.end(); ++j) { + + Port* f = _session.engine().get_port_by_name (*i); + if (!f) { + return; + } + + if (s) { + _io->connect (f, *j, 0); + } else { + _io->disconnect (f, *j, 0); + } + } } } - -uint32_t -IOSelector::minimum_rows () const +PortMatrixNode::State +IOSelector::get_state (ARDOUR::BundleChannel c[2]) const { - if (_offer_inputs) { - return _io->input_minimum ().get (_io->default_type()); - } else { - return _io->output_minimum ().get (_io->default_type()); - } -} + ARDOUR::Bundle::PortList const & our_ports = c[_ours].bundle->channel_ports (c[_ours].channel); + ARDOUR::Bundle::PortList const & other_ports = c[_other].bundle->channel_ports (c[_other].channel); -std::string -IOSelector::row_name (int r) const -{ - if (_offer_inputs) { - return _io->input(r)->name(); - } else { - return _io->output(r)->name(); + if (our_ports.empty() || other_ports.empty()) { + /* we're looking at a bundle with no parts associated with this channel, + so nothing to connect */ + return PortMatrixNode::UNKNOWN; } - -} -void -IOSelector::add_row () -{ - // The IO selector only works for single typed IOs - const ARDOUR::DataType t = _io->default_type (); + for (ARDOUR::Bundle::PortList::const_iterator i = our_ports.begin(); i != our_ports.end(); ++i) { + for (ARDOUR::Bundle::PortList::const_iterator j = other_ports.begin(); j != other_ports.end(); ++j) { - if (_offer_inputs) { + Port* f = _session.engine().get_port_by_name (*i); - try { - _io->add_input_port ("", this); - } + /* since we are talking about an IO, our ports should all have an associated Port *, + so the above call should never fail */ + assert (f); - catch (ARDOUR::AudioEngine::PortRegistrationFailure& err) { - Gtk::MessageDialog msg (0, _("There are no more JACK ports available.")); - msg.run (); - } - - } else { - - try { - _io->add_output_port ("", this); - } - - catch (ARDOUR::AudioEngine::PortRegistrationFailure& err) { - Gtk::MessageDialog msg (0, _("There are no more JACK ports available.")); - msg.run (); + if (!f->connected_to (*j)) { + /* if any one thing is not connected, all bets are off */ + return PortMatrixNode::NOT_ASSOCIATED; + } } } -} + return PortMatrixNode::ASSOCIATED; +} -void -IOSelector::remove_row (int r) +uint32_t +IOSelector::n_io_ports () const { - // The IO selector only works for single typed IOs - const ARDOUR::DataType t = _io->default_type (); - - if (_offer_inputs) { - _io->remove_input_port (_io->input (r), this); + if (!_find_inputs_for_io_outputs) { + return _io->n_ports().get (_io->default_type()); } else { - _io->remove_output_port (_io->output (r), this); + return _io->n_ports().get (_io->default_type()); } } -std::string -IOSelector::row_descriptor () const +bool +IOSelector::list_is_global (int dim) const { - return _("port"); + return (dim == _other); } - - -IOSelectorWindow::IOSelectorWindow ( - ARDOUR::Session& session, boost::shared_ptr io, bool for_input, bool can_cancel - ) - : ArdourDialog ("I/O selector"), - _selector (session, io, !for_input), - ok_button (can_cancel ? _("OK"): _("Close")), - cancel_button (_("Cancel")), - rescan_button (_("Rescan")) - +IOSelectorWindow::IOSelectorWindow (ARDOUR::Session& session, boost::shared_ptr io, bool /*can_cancel*/) + : _selector (this, session, io) { - add_events (Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK); set_name ("IOSelectorWindow2"); + set_title (_("I/O selector")); - string title; - if (for_input) { - title = string_compose(_("%1 input"), io->name()); - } else { - title = string_compose(_("%1 output"), io->name()); - } - - ok_button.set_name ("IOSelectorButton"); - if (!can_cancel) { - ok_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CLOSE, Gtk::ICON_SIZE_BUTTON))); - } - cancel_button.set_name ("IOSelectorButton"); - rescan_button.set_name ("IOSelectorButton"); - rescan_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::REFRESH, Gtk::ICON_SIZE_BUTTON))); - - get_action_area()->pack_start (rescan_button, false, false); - - if (can_cancel) { - cancel_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CANCEL, Gtk::ICON_SIZE_BUTTON))); - get_action_area()->pack_start (cancel_button, false, false); - } else { - cancel_button.hide(); - } - - get_action_area()->pack_start (ok_button, false, false); + add (_selector); - get_vbox()->set_spacing (8); - get_vbox()->pack_start (_selector); - - ok_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::accept)); - cancel_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::cancel)); - rescan_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::rescan)); - - set_title (title); set_position (Gtk::WIN_POS_MOUSE); + io_name_changed (this); + show_all (); - signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast (this))); + signal_delete_event().connect (mem_fun (*this, &IOSelectorWindow::wm_delete)); } -IOSelectorWindow::~IOSelectorWindow() +bool +IOSelectorWindow::wm_delete (GdkEventAny* /*event*/) { - + _selector.Finished (IOSelector::Accepted); + hide (); + return true; } -void -IOSelectorWindow::rescan () -{ - _selector.redisplay (); -} void -IOSelectorWindow::cancel () +IOSelectorWindow::on_map () { - _selector.Finished (IOSelector::Cancelled); - hide (); + _selector.setup_all_ports (); + Window::on_map (); } void -IOSelectorWindow::accept () +IOSelectorWindow::on_show () { - _selector.Finished (IOSelector::Accepted); - hide (); + Gtk::Window::on_show (); + pair const pm_max = _selector.max_size (); + resize_window_to_proportion_of_monitor (this, pm_max.first, pm_max.second); } void -IOSelectorWindow::on_map () +IOSelectorWindow::io_name_changed (void* src) { - _selector.redisplay (); - Window::on_map (); -} + ENSURE_GUI_THREAD(bind (mem_fun(*this, &IOSelectorWindow::io_name_changed), src)); + string title; -PortInsertUI::PortInsertUI (ARDOUR::Session& sess, boost::shared_ptr pi) - : input_selector (sess, pi->io(), true), - output_selector (sess, pi->io(), false) + if (!_selector.find_inputs_for_io_outputs()) { + title = string_compose(_("%1 input"), _selector.io()->name()); + } else { + title = string_compose(_("%1 output"), _selector.io()->name()); + } + + set_title (title); +} + +PortInsertUI::PortInsertUI (Gtk::Window* parent, ARDOUR::Session& sess, boost::shared_ptr pi) + : input_selector (parent, sess, pi->input()) + , output_selector (parent, sess, pi->output()) { - hbox.pack_start (output_selector, true, true); - hbox.pack_start (input_selector, true, true); + output_selector.set_min_height_divisor (2); + input_selector.set_min_height_divisor (2); - pack_start (hbox); + pack_start (output_selector, true, true); + pack_start (input_selector, true, true); } void PortInsertUI::redisplay () { - input_selector.redisplay(); - output_selector.redisplay(); + input_selector.setup_ports (input_selector.other()); + output_selector.setup_ports (output_selector.other()); } void @@ -315,26 +236,22 @@ PortInsertUI::finished (IOSelector::Result r) PortInsertWindow::PortInsertWindow (ARDOUR::Session& sess, boost::shared_ptr pi, bool can_cancel) : ArdourDialog ("port insert dialog"), - _portinsertui (sess, pi), + _portinsertui (this, sess, pi), ok_button (can_cancel ? _("OK"): _("Close")), - cancel_button (_("Cancel")), - rescan_button (_("Rescan")) + cancel_button (_("Cancel")) { set_name ("IOSelectorWindow"); string title = _("ardour: "); title += pi->name(); set_title (title); - + ok_button.set_name ("IOSelectorButton"); if (!can_cancel) { ok_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CLOSE, Gtk::ICON_SIZE_BUTTON))); } cancel_button.set_name ("IOSelectorButton"); - rescan_button.set_name ("IOSelectorButton"); - rescan_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::REFRESH, Gtk::ICON_SIZE_BUTTON))); - get_action_area()->pack_start (rescan_button, false, false); if (can_cancel) { cancel_button.set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::CANCEL, Gtk::ICON_SIZE_BUTTON))); get_action_area()->pack_start (cancel_button, false, false); @@ -347,18 +264,24 @@ PortInsertWindow::PortInsertWindow (ARDOUR::Session& sess, boost::shared_ptr (this))); + signal_delete_event().connect (mem_fun (*this, &PortInsertWindow::wm_delete), false); going_away_connection = pi->GoingAway.connect (mem_fun (*this, &PortInsertWindow::plugin_going_away)); } +bool +PortInsertWindow::wm_delete (GdkEventAny* /*event*/) +{ + accept (); + return true; +} + void PortInsertWindow::plugin_going_away () { ENSURE_GUI_THREAD (mem_fun (*this, &PortInsertWindow::plugin_going_away)); - + going_away_connection.disconnect (); delete_when_idle (this); } @@ -371,12 +294,6 @@ PortInsertWindow::on_map () } -void -PortInsertWindow::rescan () -{ - _portinsertui.redisplay (); -} - void PortInsertWindow::cancel () { @@ -390,3 +307,4 @@ PortInsertWindow::accept () _portinsertui.finished (IOSelector::Accepted); hide (); } +