Apply some missing widget names
[ardour.git] / gtk2_ardour / port_matrix.cc
index e8108555e6f552d71e9aab673824aae42236291b..08000d9122dafe22137fc4282ca29489e878bf26 100644 (file)
@@ -1,23 +1,28 @@
 /*
-    Copyright (C) 2002-2009 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
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
+ * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
+ * Copyright (C) 2008-2011 David Robillard <d@drobilla.net>
+ * Copyright (C) 2008-2016 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2008 Hans Baier <hansfbaier@googlemail.com>
+ * Copyright (C) 2013-2015 Nick Mainsbridge <mainsbridge@gmail.com>
+ * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
 #include <iostream>
+
 #include <gtkmm/scrolledwindow.h>
 #include <gtkmm/adjustment.h>
 #include <gtkmm/label.h>
 #include <gtkmm/menu_elems.h>
 #include <gtkmm/window.h>
 #include <gtkmm/stock.h>
-#include <gtkmm/messagedialog.h>
+
 #include "ardour/bundle.h"
 #include "ardour/types.h"
 #include "ardour/session.h"
 #include "ardour/route.h"
 #include "ardour/audioengine.h"
+
+#include "gtkmm2ext/utils.h"
+
+#include "ardour_dialog.h"
+#include "ardour_message.h"
+#include "gui_thread.h"
 #include "port_matrix.h"
 #include "port_matrix_body.h"
 #include "port_matrix_component.h"
-#include "ardour_dialog.h"
-#include "i18n.h"
-#include "gui_thread.h"
 #include "utils.h"
+#include "ui_config.h"
+
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace Gtk;
 using namespace ARDOUR;
+using namespace ARDOUR_UI_UTILS;
 
 /** PortMatrix constructor.
  *  @param session Our session.
@@ -102,6 +114,8 @@ PortMatrix::PortMatrix (Window* parent, Session* session, DataType type)
        _vspacer.show ();
        _vnotebook.show ();
        _hnotebook.show ();
+
+       UIConfiguration::instance().ParameterChanged.connect (sigc::mem_fun (*this, &PortMatrix::parameter_changed));
 }
 
 PortMatrix::~PortMatrix ()
@@ -151,14 +165,13 @@ PortMatrix::init ()
        _session->RouteAdded.connect (_session_connections, invalidator (*this), boost::bind (&PortMatrix::routes_changed, this), gui_context());
 
        /* and also bundles */
-       _session->BundleAdded.connect (_session_connections, invalidator (*this), boost::bind (&PortMatrix::setup_global_ports, this), gui_context());
-       _session->BundleRemoved.connect (_session_connections, invalidator (*this), boost::bind (&PortMatrix::setup_global_ports, this), gui_context());
+       _session->BundleAddedOrRemoved.connect (_session_connections, invalidator (*this), boost::bind (&PortMatrix::setup_global_ports, this), gui_context());
 
        /* and also ports */
        _session->engine().PortRegisteredOrUnregistered.connect (_session_connections, invalidator (*this), boost::bind (&PortMatrix::setup_global_ports, this), gui_context());
 
        /* watch for route order keys changing, which changes the order of things in our global ports list(s) */
-       Route::SyncOrderKeys.connect (_session_connections, invalidator (*this), boost::bind (&PortMatrix::setup_global_ports_proxy, this, _1), gui_context());
+       PresentationInfo::Change.connect (_session_connections, invalidator (*this), boost::bind (&PortMatrix::setup_global_ports_proxy, this), gui_context());
 
        /* Part 3: other stuff */
 
@@ -248,17 +261,26 @@ PortMatrix::setup_scrollbars ()
 {
        Adjustment* a = _hscroll.get_adjustment ();
        a->set_lower (0);
-       a->set_upper (_body->full_scroll_width());
        a->set_page_size (_body->alloc_scroll_width());
        a->set_step_increment (32);
        a->set_page_increment (128);
 
+       /* Set the adjustment to zero if the size has changed.*/
+       if (a->get_upper() != _body->full_scroll_width()) {
+               a->set_upper (_body->full_scroll_width());
+               a->set_value (0);
+       }
+
        a = _vscroll.get_adjustment ();
        a->set_lower (0);
-       a->set_upper (_body->full_scroll_height());
        a->set_page_size (_body->alloc_scroll_height());
        a->set_step_increment (32);
        a->set_page_increment (128);
+
+       if (a->get_upper() != _body->full_scroll_height()) {
+               a->set_upper (_body->full_scroll_height());
+               a->set_value (0);
+       }
 }
 
 /** Disassociate all of our ports from each other */
@@ -436,15 +458,15 @@ PortMatrix::popup_menu (BundleChannel column, BundleChannel row, uint32_t t)
                        if (can_add_channels (bc[dim].bundle)) {
                                /* Start off with options for the `natural' port type */
                                for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) {
-                                       if (should_show (*i)) {
+                                       if (should_show (*i) && can_add_channel_proxy (w, *i)) {
                                                snprintf (buf, sizeof (buf), _("Add %s %s"), (*i).to_i18n_string(), channel_noun().c_str());
                                                sub.push_back (MenuElem (buf, sigc::bind (sigc::mem_fun (*this, &PortMatrix::add_channel_proxy), w, *i)));
                                        }
                                }
-                               
+
                                /* Now add other ones */
                                for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) {
-                                       if (!should_show (*i)) {
+                                       if (!should_show (*i) && can_add_channel_proxy (w, *i)) {
                                                snprintf (buf, sizeof (buf), _("Add %s %s"), (*i).to_i18n_string(), channel_noun().c_str());
                                                sub.push_back (MenuElem (buf, sigc::bind (sigc::mem_fun (*this, &PortMatrix::add_channel_proxy), w, *i)));
                                        }
@@ -473,12 +495,12 @@ PortMatrix::popup_menu (BundleChannel column, BundleChannel row, uint32_t t)
                                                );
 
                                        if (bc[dim].bundle->nchannels().n_total() > 1) {
-                                                for (uint32_t i = 0; i < bc[dim].bundle->nchannels().n_total(); ++i) {
-                                                        if (should_show (bc[dim].bundle->channel_type(i))) {
-                                                                add_remove_option (sub, w, i);
-                                                        }
-                                                }
-                                        }
+                                               for (uint32_t i = 0; i < bc[dim].bundle->nchannels().n_total(); ++i) {
+                                                       if (should_show (bc[dim].bundle->channel_type(i))) {
+                                                               add_remove_option (sub, w, i);
+                                                       }
+                                               }
+                                       }
                                }
                        }
 
@@ -488,12 +510,12 @@ PortMatrix::popup_menu (BundleChannel column, BundleChannel row, uint32_t t)
                                /* we're looking just at bundles, or our bundle has only one channel, so just offer
                                   to disassociate all on the bundle.
                                */
-                               
+
                                snprintf (buf, sizeof (buf), _("%s all"), disassociation_verb().c_str());
                                sub.push_back (
                                        MenuElem (buf, sigc::bind (sigc::mem_fun (*this, &PortMatrix::disassociate_all_on_bundle), w, dim))
                                        );
-                                       
+
                        } else if (c != 0) {
 
                                if (bc[dim].channel != -1) {
@@ -534,7 +556,7 @@ PortMatrix::popup_menu (BundleChannel column, BundleChannel row, uint32_t t)
 
        items.push_back (MenuElem (_("Flip"), sigc::mem_fun (*this, &PortMatrix::flip)));
        items.back().set_sensitive (can_flip ());
-       
+
        _menu->popup (1, t);
 }
 
@@ -609,6 +631,7 @@ PortMatrix::disassociate_all_on_channel (boost::weak_ptr<Bundle> bundle, uint32_
 void
 PortMatrix::setup_global_ports ()
 {
+       if (!_session || _session->deletion_in_progress()) return;
        ENSURE_GUI_THREAD (*this, &PortMatrix::setup_global_ports)
 
        for (int i = 0; i < 2; ++i) {
@@ -619,15 +642,13 @@ PortMatrix::setup_global_ports ()
 }
 
 void
-PortMatrix::setup_global_ports_proxy (RouteSortOrderKey sk)
+PortMatrix::setup_global_ports_proxy ()
 {
-       if (sk == EditorSort) {
-               /* Avoid a deadlock by calling this in an idle handler: see IOSelector::io_changed_proxy
-                  for a discussion.
-               */
-               
-               Glib::signal_idle().connect_once (sigc::mem_fun (*this, &PortMatrix::setup_global_ports));
-       }
+       /* Avoid a deadlock by calling this in an idle handler: see IOSelector::io_changed_proxy
+          for a discussion.
+       */
+
+       Glib::signal_idle().connect_once (sigc::mem_fun (*this, &PortMatrix::setup_global_ports));
 }
 
 void
@@ -709,7 +730,7 @@ PortMatrix::io_from_bundle (boost::shared_ptr<Bundle> b) const
 bool
 PortMatrix::can_add_channels (boost::shared_ptr<Bundle> b) const
 {
-       return io_from_bundle (b);
+       return io_from_bundle (b) != 0;
 }
 
 void
@@ -720,9 +741,7 @@ PortMatrix::add_channel (boost::shared_ptr<Bundle> b, DataType t)
        if (io) {
                int const r = io->add_port ("", this, t);
                if (r == -1) {
-                       Gtk::MessageDialog msg (_("It is not possible to add a port here, as the first processor in the track or buss cannot "
-                                                 "support the new configuration."
-                                                       ));
+                       ArdourMessageDialog msg (_("It is not possible to add a port here."));
                        msg.set_title (_("Cannot add port"));
                        msg.run ();
                }
@@ -732,29 +751,37 @@ PortMatrix::add_channel (boost::shared_ptr<Bundle> b, DataType t)
 bool
 PortMatrix::can_remove_channels (boost::shared_ptr<Bundle> b) const
 {
-       return io_from_bundle (b);
+       return io_from_bundle (b) != 0;
 }
 
 void
 PortMatrix::remove_channel (ARDOUR::BundleChannel b)
 {
+       std::string errmsg;
        boost::shared_ptr<IO> io = io_from_bundle (b.bundle);
+       boost::shared_ptr<Port> p = io->nth (b.channel);
 
-       if (io) {
-               boost::shared_ptr<Port> p = io->nth (b.channel);
-               if (p) {
-                       int const r = io->remove_port (p, this);
-                       if (r == -1) {
-                               ArdourDialog d (_("Port removal not allowed"));
-                               Label l (_("This port cannot be removed.\nEither the first plugin in the track or buss cannot accept\nthe new number of inputs or the last plugin has more outputs."));
-                               d.get_vbox()->pack_start (l);
-                               d.add_button (Stock::OK, RESPONSE_ACCEPT);
-                               d.set_modal (true);
-                               d.show_all ();
-                               d.run ();
-                       }
+       if (!io || !p) {
+               return;
+       }
+
+       if (io->n_ports ().n_total () == 1) {
+               errmsg = _("The last port cannot be removed");
+       } else {
+               if (-1 == io->remove_port (p, this)) {
+                       errmsg = _("This port cannot be removed.");
                }
        }
+
+       if (!errmsg.empty ()) {
+               ArdourDialog d (_("Port removal not allowed"));
+               Label l (errmsg);
+               d.get_vbox()->pack_start (l);
+               d.add_button (Stock::OK, RESPONSE_ACCEPT);
+               d.set_modal (true);
+               d.show_all ();
+               d.run ();
+       }
 }
 
 void
@@ -775,6 +802,17 @@ PortMatrix::remove_all_channels (boost::weak_ptr<Bundle> w)
        }
 }
 
+bool
+PortMatrix::can_add_channel_proxy (boost::weak_ptr<Bundle> w, DataType t) const
+{
+       boost::shared_ptr<Bundle> b = w.lock ();
+       if (!b) {
+               return false;
+       }
+       boost::shared_ptr<IO> io = io_from_bundle (b);
+       return io->can_add_port (t);
+}
+
 void
 PortMatrix::add_channel_proxy (boost::weak_ptr<Bundle> w, DataType t)
 {
@@ -927,7 +965,7 @@ PortMatrix::visible_ports (int d) const
           the TOP_TO_RIGHT arrangement we reverse the order of the vertical
           tabs in setup_notebooks ().
        */
-          
+
        int n = 0;
        if (d == _row_index) {
                if (_arrangement == LEFT_TO_BOTTOM) {
@@ -999,11 +1037,11 @@ PortMatrix::update_tab_highlighting ()
        if (!_session) {
                return;
        }
-       
+
        for (int i = 0; i < 2; ++i) {
 
                Gtk::Notebook* notebook = row_index() == i ? &_vnotebook : &_hnotebook;
-               
+
                PortGroupList const * gl = ports (i);
                int p = 0;
                for (PortGroupList::List::const_iterator j = gl->begin(); j != gl->end(); ++j) {
@@ -1033,7 +1071,7 @@ PortMatrix::update_tab_highlighting ()
                                label->set_text ((*j)->name);
                        } else if (c.length() && c[0] != '<' && has_connection) {
                                /* this label is not marked up with <b> but should be */
-                               label->set_markup (string_compose ("<b>%1</b>", Glib::Markup::escape_text ((*j)->name)));
+                               label->set_markup (string_compose ("<b>%1</b>", Gtkmm2ext::markup_escape_text ((*j)->name)));
                        }
 
                        ++p;
@@ -1139,7 +1177,7 @@ PortMatrix::get_association (PortMatrixNode node) const
 
        }
 
-       /* NOTREACHED */
+       abort(); /* NOTREACHED */
        return PortMatrixNode::NOT_ASSOCIATED;
 }
 
@@ -1158,7 +1196,7 @@ pair<int, int>
 PortMatrix::check_flip () const
 {
        /* Look for the row's port group name in the columns */
-       
+
        int new_column = 0;
        boost::shared_ptr<const PortGroup> r = visible_ports (_row_index);
        PortGroupList::List::const_iterator i = _ports[_column_index].begin();
@@ -1172,7 +1210,7 @@ PortMatrix::check_flip () const
        }
 
        /* Look for the column's port group name in the rows */
-       
+
        int new_row = 0;
        boost::shared_ptr<const PortGroup> c = visible_ports (_column_index);
        i = _ports[_row_index].begin();
@@ -1221,3 +1259,11 @@ PortMatrix::key_press (GdkEventKey* k)
 
        return false;
 }
+
+void
+PortMatrix::parameter_changed (string p)
+{
+       if (p == "font-scale") {
+               setup ();
+       }
+}