Major Theme Manager changes, see ardour-dev
[ardour.git] / gtk2_ardour / io_selector.cc
index 4c1e94ce89404eb77f20fc31b3fd2721b6cc751e..fde793adc785b9b14e3519c722d481348c1af639 100644 (file)
@@ -15,7 +15,6 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
 #include <map>
@@ -185,15 +184,18 @@ IOSelector::IOSelector (Session& sess, boost::shared_ptr<IO> ior, bool input)
 
        port_button_box.pack_start (add_port_button, false, false);
 
+       // The IO selector only works for single typed IOs
+       const ARDOUR::DataType t = io->default_type();
+
        if (for_input) {
-               if (io->input_maximum() < 0 || io->input_maximum() > (int) io->n_inputs()) {
+               if (io->input_maximum().get(t) < 0 || io->input_maximum().get(t) > (size_t) io->n_inputs().get(t)) {
                        add_port_button.set_sensitive (true);
                } else {
                        add_port_button.set_sensitive (false);
                }
 
        } else {
-               if (io->output_maximum() < 0 || io->output_maximum() > (int) io->n_outputs()) {
+               if (io->output_maximum().get(t) < 0 || io->output_maximum().get(t) > (size_t) io->n_outputs().get(t)) {
                        add_port_button.set_sensitive (true);
                } else {
                        add_port_button.set_sensitive (false);
@@ -204,14 +206,14 @@ IOSelector::IOSelector (Session& sess, boost::shared_ptr<IO> ior, bool input)
        port_button_box.pack_start (remove_port_button, false, false);
 
        if (for_input) {
-               if (io->input_minimum() < 0 || io->input_minimum() < (int) io->n_inputs()) {
+               if (io->input_minimum().get(t) < 0 || io->input_minimum().get(t) < (size_t) io->n_inputs().get(t)) {
                        remove_port_button.set_sensitive (true);
                } else {
                        remove_port_button.set_sensitive (false);
                }
                        
        } else {
-               if (io->output_minimum() < 0 || io->output_minimum() < (int) io->n_outputs()) {
+               if (io->output_minimum().get(t) < 0 || io->output_minimum().get(t) < (size_t) io->n_outputs().get(t)) {
                        remove_port_button.set_sensitive (true);
                } else {
                        remove_port_button.set_sensitive (false);
@@ -255,6 +257,46 @@ IOSelector::~IOSelector ()
 {
 }
 
+void 
+IOSelector::set_button_sensitivity ()
+{
+       DataType t = io->default_type();
+
+       if (for_input) {
+
+               if (io->input_maximum().get(t) < 0 || io->input_maximum().get(t) > io->n_inputs().get(t)) {
+                       add_port_button.set_sensitive (true);
+               } else {
+                       add_port_button.set_sensitive (false);
+               }
+
+       } else {
+
+               if (io->output_maximum().get(t) < 0 || io->output_maximum().get(t) > io->n_outputs().get(t)) {
+                       add_port_button.set_sensitive (true);
+               } else {
+                       add_port_button.set_sensitive (false);
+               }
+                       
+       }
+
+       if (for_input) {
+               if (io->n_inputs().get(t) && (io->input_minimum().get(t) < 0 || io->input_minimum().get(t) < io->n_inputs().get(t))) {
+                       remove_port_button.set_sensitive (true);
+               } else {
+                       remove_port_button.set_sensitive (false);
+               }
+                       
+       } else {
+               if (io->n_outputs().get(t) && (io->output_minimum().get(t) < 0 || io->output_minimum().get(t) < io->n_outputs().get(t))) {
+                       remove_port_button.set_sensitive (true);
+               } else {
+                       remove_port_button.set_sensitive (false);
+               }
+       }
+}
+
+
 void
 IOSelector::name_changed (void* src)
 {
@@ -285,12 +327,15 @@ IOSelector::rescan ()
        gint current_page;
        vector<string> rowdata;
 
+       page_selection_connection.disconnect ();
+
        current_page = notebook.get_current_page ();
+
        pages.clear ();
 
        /* get relevant current JACK ports */
 
-       ports = session.engine().get_ports ("", JACK_DEFAULT_AUDIO_TYPE, for_input ? JackPortIsOutput : JackPortIsInput);
+       ports = session.engine().get_ports ("", io->default_type().to_jack_type(), for_input ? JackPortIsOutput : JackPortIsInput);
 
        if (ports == 0) {
                return;
@@ -359,7 +404,7 @@ IOSelector::rescan ()
        }
 
        notebook.set_current_page (current_page);
-       notebook.signal_show().connect (bind (mem_fun (notebook, &Notebook::set_current_page), current_page));
+       page_selection_connection = notebook.signal_show().connect (bind (mem_fun (notebook, &Notebook::set_current_page), current_page));
        selector_box.show_all ();
 }      
 
@@ -373,10 +418,13 @@ IOSelector::display_ports ()
                Port *port;
                uint32_t limit;
                
+               // The IO selector only works for single typed IOs
+               const ARDOUR::DataType t = io->default_type();
+
                if (for_input) {
-                       limit = io->n_inputs();
+                       limit = io->n_inputs().get(t);
                } else {
-                       limit = io->n_outputs();
+                       limit = io->n_outputs().get(t);
                }
                
                for (slist<TreeView *>::iterator i = port_displays.begin(); i != port_displays.end(); ) {
@@ -409,7 +457,7 @@ IOSelector::display_ports ()
                        
                        really_short_name = port->short_name();
                        really_short_name = really_short_name.substr (really_short_name.find ('/') + 1);
-                       
+
                        tview = manage (new TreeView());
                        RefPtr<ListStore> port_model = ListStore::create (port_display_columns);
                        
@@ -420,16 +468,15 @@ IOSelector::display_ports ()
                        tview->set_model (port_model);
                        tview->append_column (really_short_name, port_display_columns.displayed_name);
                        tview->get_selection()->set_mode (SELECTION_SINGLE);
-                       tview->set_data ("port", port);
+                       tview->set_data (X_("port"), port);
                        tview->set_headers_visible (true);
-                       tview->set_name ("IOSelectorPortList");
+                       tview->set_name (X_("IOSelectorPortList"));
                        
                        port_box.pack_start (*tview);
                        port_displays.insert (port_displays.end(), tview);
                        
                        /* now fill the clist with the current connections */
                        
-                       
                        const char **connections = port->get_connections ();
                        
                        if (connections) {
@@ -438,11 +485,11 @@ IOSelector::display_ports ()
                                        row[port_display_columns.displayed_name] = connections[c];
                                        row[port_display_columns.full_name] = connections[c];
                                }
-                       }
+                       } 
                        
                        if (for_input) {
                                
-                               if (io->input_maximum() == 1) {
+                               if (io->input_maximum().get(io->default_type()) == 1) {
                                        selected_port = port;
                                        selected_port_tview = tview;
                                } else {
@@ -453,7 +500,7 @@ IOSelector::display_ports ()
                                
                        } else {
                                
-                               if (io->output_maximum() == 1) {
+                               if (io->output_maximum().get(t) == 1) {
                                        selected_port = port;
                                        selected_port_tview = tview;
                                } else {
@@ -505,7 +552,9 @@ IOSelector::port_selection_changed (GdkEventButton *ev, TreeView* treeview)
        if (for_input) {
                if ((status = io->connect_input (selected_port, other_port_name, this)) == 0) {
                        Port *p = session.engine().get_port_by_name (other_port_name);
-                       p->enable_metering();
+                       if (p) {
+                               p->enable_metering();
+                       }
                }
        } else {
                status = io->connect_output (selected_port, other_port_name, this);
@@ -532,6 +581,9 @@ IOSelector::add_port ()
 {
        /* add a new port, then hide the button if we're up to the maximum allowed */
 
+       // The IO selector only works for single typed IOs
+       const ARDOUR::DataType t = io->default_type();
+
        if (for_input) {
 
                try {
@@ -543,14 +595,6 @@ IOSelector::add_port ()
                        msg.run ();
                }
 
-               if (io->input_maximum() >= 0 && io->input_maximum() <= (int) io->n_inputs()) {
-                       add_port_button.set_sensitive (false);
-               }
-               
-               if (io->input_minimum() < (int) io->n_inputs()) {
-                       remove_port_button.set_sensitive (true);
-               }
-
        } else {
 
                try {
@@ -561,11 +605,9 @@ IOSelector::add_port ()
                        MessageDialog msg (0, _("There are no more JACK ports available."));
                        msg.run ();
                }
-
-               if (io->output_maximum() >= 0 && io->output_maximum() <= (int) io->n_outputs()) {
-                       add_port_button.set_sensitive (false);
-               }
        }
+               
+       set_button_sensitivity ();
 }
 
 void
@@ -573,32 +615,22 @@ IOSelector::remove_port ()
 {
        uint32_t nports;
 
+       // The IO selector only works for single typed IOs
+       const ARDOUR::DataType t = io->default_type();
+       
        // always remove last port
        
        if (for_input) {
-               if ((nports = io->n_inputs()) > 0) {
+               if ((nports = io->n_inputs().get(t)) > 0) {
                        io->remove_input_port (io->input(nports-1), this);
                }
-               if (io->input_minimum() == (int) io->n_inputs()) {
-                       remove_port_button.set_sensitive (false);
-               }
        } else {
-               if ((nports = io->n_outputs()) > 0) {
+               if ((nports = io->n_outputs().get(t)) > 0) {
                        io->remove_output_port (io->output(nports-1), this);
                }
        }
-}
-
-gint
-IOSelector::remove_port_when_idle (Port *port)
-{
-       if (for_input) {
-               io->remove_input_port (port, this);
-       } else {
-               io->remove_output_port (port, this);
-       }
-
-       return FALSE;
+       
+       set_button_sensitivity ();
 }
 
 gint
@@ -628,11 +660,13 @@ IOSelector::connection_button_release (GdkEventButton *ev, TreeView *treeview)
 
                /* path is valid */
                ustring connected_port_name = (*iter)[port_display_columns.full_name];
-               Port *port = reinterpret_cast<Port *> (treeview->get_data (_("port")));
+               Port *port = reinterpret_cast<Port *> (treeview->get_data (X_("port")));
                
                if (for_input) {
                        Port *p = session.engine().get_port_by_name (connected_port_name);
-                       p->disable_metering();
+                       if (p) {
+                               p->disable_metering();
+                       }
                        io->disconnect_input (port, connected_port_name, this);
                } else {
                        io->disconnect_output (port, connected_port_name, this);
@@ -677,7 +711,7 @@ IOSelector::select_treeview (TreeView* tview)
        */
 
        Glib::Mutex::Lock lm  (port_display_lock);
-       Port* port = reinterpret_cast<Port *> (tview->get_data (_("port")));
+       Port* port = reinterpret_cast<Port *> (tview->get_data (X_("port")));
 
        selected_port = port;
 
@@ -720,11 +754,11 @@ IOSelector::redisplay ()
        display_ports ();
 
        if (for_input) {
-               if (io->input_maximum() != 0) {
+               if (io->input_maximum().get(io->default_type()) != 0) {
                        rescan ();
                }
        } else {
-               if (io->output_maximum() != 0) {
+               if (io->output_maximum().get(io->default_type()) != 0) {
                        rescan();
                }
        }
@@ -794,14 +828,15 @@ PortInsertWindow::PortInsertWindow (Session& sess, boost::shared_ptr<PortInsert>
        rescan_button.signal_clicked().connect (mem_fun(*this, &PortInsertWindow::rescan));
 
        signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window *> (this))); 
-       pi->GoingAway.connect (mem_fun(*this, &PortInsertWindow::plugin_going_away));
+
+       going_away_connection = pi->GoingAway.connect (mem_fun(*this, &PortInsertWindow::plugin_going_away));
 }
 
 void
 PortInsertWindow::plugin_going_away ()
 {
        ENSURE_GUI_THREAD(mem_fun(*this, &PortInsertWindow::plugin_going_away));
-       
+       going_away_connection.disconnect ();
        delete_when_idle (this);
 }