Fix route port matrix to only display the relevant port types.
authorCarl Hetherington <carl@carlh.net>
Tue, 27 Jul 2010 02:09:51 +0000 (02:09 +0000)
committerCarl Hetherington <carl@carlh.net>
Tue, 27 Jul 2010 02:09:51 +0000 (02:09 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7505 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/io_selector.cc
gtk2_ardour/io_selector.h
gtk2_ardour/port_matrix.cc

index eff2583c42134033420ff40b4d7fae60841ade73..f90ce88545ecb2f86735e60d7ac6303e2441a2ae 100644 (file)
@@ -46,6 +46,8 @@ IOSelector::IOSelector (Gtk::Window* p, ARDOUR::Session* session, boost::shared_
        : 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,17 +63,58 @@ 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) {
index 21bd6a2d3e863c952ad16c3923aa99b0e8339cd8..32946fb1b7718c4687eddd126ef0e005d104ee1b 100644 (file)
@@ -57,11 +57,16 @@ class IOSelector : public PortMatrix
 
   private:
 
+       void setup_type ();
+       void io_changed ();
+       void io_changed_proxy ();
+       
        int _other;
        int _ours;
        boost::shared_ptr<ARDOUR::IO> _io;
        boost::shared_ptr<PortGroup> _port_group;
        bool _find_inputs_for_io_outputs;
+       PBD::ScopedConnection _io_connection;
 };
 
 class IOSelectorWindow : public Gtk::Window
index 6113412df91e4d7b89874fe8279d8d58304d60a2..06f869b67593078394d6dfee4d2febabc8979258 100644 (file)
@@ -215,8 +215,6 @@ void
 PortMatrix::set_type (DataType t)
 {
        _type = t;
-
-       setup_all_ports ();
 }
 
 void