X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fio_selector.cc;h=99050cc34ba0a5a75c728d2cf1da11cdd6004b1c;hb=5d2a03578c3f0d0f39562546bd3e4be9be08d2d4;hp=cc5ae58224ab3e08f314f4217e86e4947ef25ebb;hpb=5f67a72c341a96872d9cd3d1de357662295d14b0;p=ardour.git diff --git a/gtk2_ardour/io_selector.cc b/gtk2_ardour/io_selector.cc index cc5ae58224..99050cc34b 100644 --- a/gtk2_ardour/io_selector.cc +++ b/gtk2_ardour/io_selector.cc @@ -17,35 +17,34 @@ */ -#include +#include + #include #include -#include "ardour/port_insert.h" -#include "ardour/session.h" -#include "ardour/io.h" #include "ardour/audioengine.h" -#include "ardour/track.h" -#include "ardour/audio_track.h" -#include "ardour/midi_track.h" -#include "ardour/mtdm.h" +#include "ardour/bundle.h" #include "ardour/data_type.h" +#include "ardour/io.h" #include "ardour/port.h" -#include "ardour/bundle.h" +#include "ardour/session.h" #include "io_selector.h" #include "utils.h" #include "gui_thread.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace ARDOUR; +using namespace ARDOUR_UI_UTILS; using namespace Gtk; IOSelector::IOSelector (Gtk::Window* p, ARDOUR::Session* session, boost::shared_ptr io) - : PortMatrix (p, session, io->default_type()) + : PortMatrix (p, session, DataType::NIL) , _io (io) { + setup_type (); + /* signal flow from 0 to 1 */ _find_inputs_for_io_outputs = (_io->direction() == IO::Output); @@ -61,22 +60,63 @@ IOSelector::IOSelector (Gtk::Window* p, ARDOUR::Session* session, boost::shared_ _port_group.reset (new PortGroup (io->name())); _ports[_ours].add_group (_port_group); + io->changed.connect (_io_connection, invalidator (*this), boost::bind (&IOSelector::io_changed_proxy, this), gui_context ()); + setup_all_ports (); init (); } +void +IOSelector::setup_type () +{ + /* set type according to what's in the IO */ + + int N = 0; + DataType type_with_ports = DataType::NIL; + for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) { + if (_io->ports().num_ports (*i)) { + type_with_ports = *i; + ++N; + } + } + + if (N <= 1) { + set_type (type_with_ports); + } else { + set_type (DataType::NIL); + } +} + +void +IOSelector::io_changed_proxy () +{ + /* The IO's changed signal is emitted from code that holds its route's processor lock, + so we can't call setup_all_ports (which results in a call to Route::foreach_processor) + without a deadlock unless we break things up with this idle handler. + */ + + Glib::signal_idle().connect_once (sigc::mem_fun (*this, &IOSelector::io_changed)); +} + +void +IOSelector::io_changed () +{ + setup_type (); + setup_all_ports (); +} + void IOSelector::setup_ports (int dim) { if (!_session) { return; } - + _ports[dim].suspend_signals (); if (dim == _other) { - _ports[_other].gather (_session, type(), _find_inputs_for_io_outputs, false); + _ports[_other].gather (_session, type(), _find_inputs_for_io_outputs, false, show_only_bundles ()); } else { @@ -96,15 +136,19 @@ IOSelector::set_state (ARDOUR::BundleChannel c[2], bool s) 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); + boost::shared_ptr f = _session->engine().get_port_by_name (*i); if (!f) { return; } if (s) { - _io->connect (f, *j, 0); + if (!f->connected_to (*j)) { + _io->connect (f, *j, 0); + } } else { - _io->disconnect (f, *j, 0); + if (f->connected_to (*j)) { + _io->disconnect (f, *j, 0); + } } } } @@ -113,10 +157,14 @@ IOSelector::set_state (ARDOUR::BundleChannel c[2], bool s) PortMatrixNode::State IOSelector::get_state (ARDOUR::BundleChannel c[2]) const { + if (c[0].bundle->nchannels() == ChanCount::ZERO || c[1].bundle->nchannels() == ChanCount::ZERO) { + return PortMatrixNode::NOT_ASSOCIATED; + } + 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); - if (our_ports.empty() || other_ports.empty()) { + if (!_session || 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::NOT_ASSOCIATED; @@ -125,7 +173,7 @@ IOSelector::get_state (ARDOUR::BundleChannel c[2]) const 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); + boost::shared_ptr f = _session->engine().get_port_by_name (*i); /* since we are talking about an IO, our ports should all have an associated Port *, so the above call should never fail */ @@ -157,29 +205,25 @@ IOSelector::list_is_global (int dim) const return (dim == _other); } -string +std::string IOSelector::disassociation_verb () const { return _("Disconnect"); } -string +std::string IOSelector::channel_noun () const { return _("port"); } IOSelectorWindow::IOSelectorWindow (ARDOUR::Session* session, boost::shared_ptr io, bool /*can_cancel*/) - : _selector (this, session, io) + : ArdourWindow (_("I/O selector")) + , _selector (this, session, io) { set_name ("IOSelectorWindow2"); - set_title (_("I/O selector")); - - Gtk::Alignment* alignment = manage(new Gtk::Alignment(0.5, 0.5, 0.0, 0.0)); - alignment->add (_selector); - add (*alignment); - set_position (Gtk::WIN_POS_MOUSE); + add (_selector); io_name_changed (this); @@ -192,8 +236,7 @@ bool IOSelectorWindow::wm_delete (GdkEventAny* /*event*/) { _selector.Finished (IOSelector::Accepted); - hide (); - return true; + return false; } @@ -208,16 +251,16 @@ void IOSelectorWindow::on_show () { Gtk::Window::on_show (); - pair const pm_max = _selector.max_size (); + std::pair const pm_max = _selector.max_size (); resize_window_to_proportion_of_monitor (this, pm_max.first, pm_max.second); } void -IOSelectorWindow::io_name_changed (void* src) +IOSelectorWindow::io_name_changed (void*) { ENSURE_GUI_THREAD (*this, &IOSelectorWindow::io_name_changed, src) - string title; + std::string title; if (!_selector.find_inputs_for_io_outputs()) { title = string_compose(_("%1 input"), _selector.io()->name()); @@ -228,175 +271,3 @@ IOSelectorWindow::io_name_changed (void* src) set_title (title); } -PortInsertUI::PortInsertUI (Gtk::Window* parent, ARDOUR::Session* sess, boost::shared_ptr pi) - : _pi (pi) - , latency_button (_("Measure Latency")) - , input_selector (parent, sess, pi->input()) - , output_selector (parent, sess, pi->output()) -{ - latency_hbox.pack_start (latency_button, false, false); - latency_hbox.pack_start (latency_display, false, false); - latency_frame.add (latency_hbox); - - output_selector.set_min_height_divisor (2); - input_selector.set_min_height_divisor (2); - - pack_start (latency_frame); - pack_start (output_selector, true, true); - pack_start (input_selector, true, true); - - latency_button.signal_toggled().connect (mem_fun (*this, &PortInsertUI::latency_button_toggled)); -} - -bool -PortInsertUI::check_latency_measurement () -{ - MTDM* mtdm = _pi->mtdm (); - - if (mtdm->resolve () < 0) { - latency_display.set_text (_("No signal detected")); - return true; - } - - if (mtdm->err () > 0.3) { - mtdm->invert (); - mtdm->resolve (); - } - - char buf[64]; - nframes_t sample_rate = AudioEngine::instance()->frame_rate(); - - if (sample_rate == 0) { - latency_display.set_text (_("Disconnected from audio engine")); - _pi->stop_latency_detection (); - return false; - } - - snprintf (buf, sizeof (buf), "%10.3lf frames %10.3lf ms", mtdm->del (), mtdm->del () * 1000.0f/sample_rate); - - bool solid = true; - - if (mtdm->err () > 0.2) { - strcat (buf, " ??"); - solid = false; - } - - if (mtdm->inv ()) { - strcat (buf, " (Inv)"); - solid = false; - } - - if (solid) { - _pi->set_measured_latency ((nframes_t) rint (mtdm->del())); - strcat (buf, " (set)"); - } - - latency_display.set_text (buf); - return true; -} - -void -PortInsertUI::latency_button_toggled () -{ - if (latency_button.get_active ()) { - - _pi->start_latency_detection (); - latency_display.set_text (_("Detecting ...")); - latency_timeout = Glib::signal_timeout().connect (mem_fun (*this, &PortInsertUI::check_latency_measurement), 250); - - } else { - _pi->stop_latency_detection (); - latency_timeout.disconnect (); - } -} - - -void -PortInsertUI::redisplay () -{ - input_selector.setup_ports (input_selector.other()); - output_selector.setup_ports (output_selector.other()); -} - -void -PortInsertUI::finished (IOSelector::Result r) -{ - input_selector.Finished (r); - output_selector.Finished (r); -} - - -PortInsertWindow::PortInsertWindow (ARDOUR::Session* sess, boost::shared_ptr pi, bool can_cancel) - : ArdourDialog ("port insert dialog"), - _portinsertui (this, sess, pi), - ok_button (can_cancel ? _("OK"): _("Close")), - cancel_button (_("Cancel")) -{ - - set_name ("IOSelectorWindow"); - string title = _("Port Insert "); - 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"); - - 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); - - get_vbox()->pack_start (_portinsertui); - - ok_button.signal_clicked().connect (sigc::mem_fun (*this, &PortInsertWindow::accept)); - cancel_button.signal_clicked().connect (sigc::mem_fun (*this, &PortInsertWindow::cancel)); - - signal_delete_event().connect (sigc::mem_fun (*this, &PortInsertWindow::wm_delete), false); - - pi->DropReferences.connect (going_away_connection, invalidator (*this), boost::bind (&PortInsertWindow::plugin_going_away, this), gui_context()); -} - -bool -PortInsertWindow::wm_delete (GdkEventAny* /*event*/) -{ - accept (); - return true; -} - -void -PortInsertWindow::plugin_going_away () -{ - ENSURE_GUI_THREAD (*this, &PortInsertWindow::plugin_going_away) - - going_away_connection.disconnect (); - delete_when_idle (this); -} - -void -PortInsertWindow::on_map () -{ - _portinsertui.redisplay (); - Window::on_map (); -} - - -void -PortInsertWindow::cancel () -{ - _portinsertui.finished (IOSelector::Cancelled); - hide (); -} - -void -PortInsertWindow::accept () -{ - _portinsertui.finished (IOSelector::Accepted); - hide (); -} -