tempo map debugging with dlp
[ardour.git] / gtk2_ardour / port_matrix.cc
index 9336d520e8d9a23ab117e6cf5b988d8c2fa48f62..8bdc1c4cc03e8aa6525d44fe48d739aeaaf676f6 100644 (file)
@@ -26,6 +26,7 @@
 #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"
@@ -387,13 +388,6 @@ PortMatrix::popup_menu (BundleChannel column, BundleChannel row, uint32_t t)
 {
        using namespace Menu_Helpers;
 
-       if ((row.bundle && row.bundle->nchannels().n_total() == 0) || (column.bundle && column.bundle->nchannels().n_total() == 0)) {
-               /* One of the bundles has no channels, which means that it has none of the appropriate type,
-                  and is only being displayed to look pretty.  So we don't need to do anything.
-               */
-               return;
-       }
-       
        delete _menu;
 
        _menu = new Menu;
@@ -468,16 +462,23 @@ PortMatrix::popup_menu (BundleChannel column, BundleChannel row, uint32_t t)
 
                        uint32_t c = count_of_our_type (bc[dim].bundle->nchannels ());
                        if ((_show_only_bundles && c > 0) || c == 1) {
+
+                               /* 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_channel), w, bc[dim].channel, dim))
+                                       MenuElem (buf, sigc::bind (sigc::mem_fun (*this, &PortMatrix::disassociate_all_on_bundle), w, dim))
                                        );
-
-                       } else {
+                                       
+                       } else if (c != 0) {
 
                                if (bc[dim].channel != -1) {
+                                       /* specific channel under the menu, so just offer to disassociate that */
                                        add_disassociate_option (sub, w, dim, bc[dim].channel);
-                               } else if (count_of_our_type (bc[dim].bundle->nchannels()) != 0) {
+                               } else {
+                                       /* no specific channel; offer to disassociate all, or any one in particular */
                                        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))
@@ -562,7 +563,7 @@ PortMatrix::disassociate_all_on_channel (boost::weak_ptr<Bundle> bundle, uint32_
        for (PortGroup::BundleList::iterator i = a.begin(); i != a.end(); ++i) {
                for (uint32_t j = 0; j < (*i)->bundle->nchannels().n_total(); ++j) {
 
-                       if (should_show ((*i)->bundle->channel_type(j))) {
+                       if (!should_show ((*i)->bundle->channel_type(j))) {
                                continue;
                        }
 
@@ -684,7 +685,14 @@ PortMatrix::add_channel (boost::shared_ptr<Bundle> b, DataType t)
        boost::shared_ptr<IO> io = io_from_bundle (b);
 
        if (io) {
-               io->add_port ("", this, t);
+               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."
+                                                       ));
+                       msg.set_title (_("Cannot add port"));
+                       msg.run ();
+               }
        }
 }
 
@@ -765,7 +773,15 @@ PortMatrix::setup_notebooks ()
                Label* label = manage (new Label ((*i)->name));
                label->set_angle (_arrangement == LEFT_TO_BOTTOM ? 90 : -90);
                label->show ();
-               _vnotebook.prepend_page (*dummy, *label);
+               if (_arrangement == LEFT_TO_BOTTOM) {
+                       _vnotebook.prepend_page (*dummy, *label);
+               } else {
+                       /* Reverse the order of vertical tabs when they are on the right hand side
+                          so that from top to bottom it is the same order as that from left to right
+                          for the top tabs.
+                       */
+                       _vnotebook.append_page (*dummy, *label);
+               }
        }
 
        for (PortGroupList::List::const_iterator i = _ports[_column_index].begin(); i != _ports[_column_index].end(); ++i) {
@@ -870,9 +886,18 @@ PortMatrix::visible_ports (int d) const
        PortGroupList const & p = _ports[d];
        PortGroupList::List::const_iterator j = p.begin ();
 
+       /* The logic to compute the index here is a bit twisty because for
+          the TOP_TO_RIGHT arrangement we reverse the order of the vertical
+          tabs in setup_notebooks ().
+       */
+          
        int n = 0;
        if (d == _row_index) {
-               n = p.size() - _vnotebook.get_current_page () - 1;
+               if (_arrangement == LEFT_TO_BOTTOM) {
+                       n = p.size() - _vnotebook.get_current_page () - 1;
+               } else {
+                       n = _vnotebook.get_current_page ();
+               }
        } else {
                n = _hnotebook.get_current_page ();
        }