use new action map API instead of ActionManager::get_action
[ardour.git] / gtk2_ardour / port_matrix_component.cc
index c617070907d9c464e3ef211c73c484559501d0b7..5e11527d299fefc4f4369d7021905a0541320979 100644 (file)
@@ -24,7 +24,8 @@
 using namespace std;
 
 /** Constructor.
- *  @param p Port matrix that we're in.
+ *  @param m Port matrix that we're in.
+ *  @param b Port matrix body that we're in.
  */
 PortMatrixComponent::PortMatrixComponent (PortMatrix* m, PortMatrixBody* b)
        : _matrix (m),
@@ -40,7 +41,7 @@ PortMatrixComponent::PortMatrixComponent (PortMatrix* m, PortMatrixBody* b)
 PortMatrixComponent::~PortMatrixComponent ()
 {
        if (_pixmap) {
-               gdk_pixmap_unref (_pixmap);
+               g_object_unref (_pixmap);
        }
 }
 
@@ -73,7 +74,7 @@ PortMatrixComponent::get_pixmap (GdkDrawable *drawable)
 
                /* make a pixmap of the right size */
                if (_pixmap) {
-                       gdk_pixmap_unref (_pixmap);
+                       g_object_unref (_pixmap);
                }
                _pixmap = gdk_pixmap_new (drawable, _width, _height, -1);
 
@@ -126,64 +127,49 @@ PortMatrixComponent::group_size (boost::shared_ptr<const PortGroup> g) const
 {
        uint32_t s = 0;
 
-       if (g->visible()) {
-               PortGroup::BundleList const & bundles = g->bundles ();
-               if (_matrix->show_only_bundles()) {
-                       s = bundles.size();
-               } else {
-                       for (PortGroup::BundleList::const_iterator i = bundles.begin(); i != bundles.end(); ++i) {
-                               s += i->bundle->nchannels();
-                       }
-               }
+       PortGroup::BundleList const & bundles = g->bundles ();
+       if (_matrix->show_only_bundles()) {
+               s = bundles.size();
        } else {
-               s = 1;
+               for (PortGroup::BundleList::const_iterator i = bundles.begin(); i != bundles.end(); ++i) {
+                       s += _matrix->count_of_our_type_min_1 ((*i)->bundle->nchannels());
+               }
        }
 
        return s;
 }
 
 /** @param bc Channel.
- *  @param groups List of groups.
- *  @return Position of bc in groups in grid units, taking visibility and show_only_bundles into account.
+ *  @param group Group.
+ *  @return Position of bc in groups in grid units, taking show_only_bundles into account.
  */
 uint32_t
-PortMatrixComponent::channel_to_position (ARDOUR::BundleChannel bc, PortGroupList const * groups) const
+PortMatrixComponent::channel_to_position (ARDOUR::BundleChannel bc, boost::shared_ptr<const PortGroup> group) const
 {
        uint32_t p = 0;
 
-       for (PortGroupList::List::const_iterator i = groups->begin(); i != groups->end(); ++i) {
-
-               PortGroup::BundleList const & bundles = (*i)->bundles ();
-
-               for (PortGroup::BundleList::const_iterator j = bundles.begin(); j != bundles.end(); ++j) {
+       PortGroup::BundleList const & bundles = group->bundles ();
 
-                       if (j->bundle == bc.bundle) {
+       for (PortGroup::BundleList::const_iterator i = bundles.begin(); i != bundles.end(); ++i) {
 
-                               /* found the bundle */
+               if ((*i)->bundle == bc.bundle) {
 
-                               if (_matrix->show_only_bundles() || !(*i)->visible()) {
-                                       return p;
-                               } else {
-                                       return p + bc.channel;
-                               }
+                       /* found the bundle */
 
+                       if (_matrix->show_only_bundles()) {
+                               return p;
+                       } else {
+                               return p + bc.bundle->overall_channel_to_type (_matrix->type (), bc.channel);
                        }
 
-                       if ((*i)->visible()) {
-
-                               /* move past this bundle */
-
-                               if (_matrix->show_only_bundles()) {
-                                       p += 1;
-                               } else {
-                                       p += j->bundle->nchannels ();
-                               }
-                       }
                }
 
-               if (!(*i)->visible()) {
-                       /* if this group isn't visible we won't have updated p, so do it now */
+               /* move past this bundle */
+
+               if (_matrix->show_only_bundles()) {
                        p += 1;
+               } else {
+                       p += _matrix->count_of_our_type_min_1 ((*i)->bundle->nchannels());
                }
        }
 
@@ -191,57 +177,40 @@ PortMatrixComponent::channel_to_position (ARDOUR::BundleChannel bc, PortGroupLis
 }
 
 
-pair<boost::shared_ptr<PortGroup>, ARDOUR::BundleChannel>
-PortMatrixComponent::position_to_group_and_channel (double p, double, PortGroupList const * groups) const
+ARDOUR::BundleChannel
+PortMatrixComponent::position_to_channel (double p, double, boost::shared_ptr<const PortGroup> group) const
 {
        p /= grid_spacing ();
-       
-       PortGroupList::List::const_iterator i = groups->begin ();
-
-       while (i != groups->end()) {
 
-               uint32_t const gs = group_size (*i);
+       PortGroup::BundleList const & bundles = group->bundles ();
+       for (PortGroup::BundleList::const_iterator j = bundles.begin(); j != bundles.end(); ++j) {
 
-               if (p < gs) {
-
-                       /* it's in this group */
+               if (_matrix->show_only_bundles()) {
 
-                       if (!(*i)->visible()) {
-                               return make_pair (*i, ARDOUR::BundleChannel (boost::shared_ptr<ARDOUR::Bundle> (), 0));
+                       if (p < 1) {
+                               return ARDOUR::BundleChannel ((*j)->bundle, -1);
+                       } else {
+                               p -= 1;
                        }
 
-                       PortGroup::BundleList const & bundles = (*i)->bundles ();
-                       for (PortGroup::BundleList::const_iterator j = bundles.begin(); j != bundles.end(); ++j) {
-
-                               if (_matrix->show_only_bundles()) {
+               } else {
 
-                                       if (p == 0) {
-                                               return make_pair (*i, ARDOUR::BundleChannel (j->bundle, 0));
-                                       } else {
-                                               p -= 1;
-                                       }
+                       ARDOUR::ChanCount const N = (*j)->bundle->nchannels ();
 
+                       uint32_t const s = _matrix->count_of_our_type_min_1 (N);
+                       if (p < s) {
+                               if (p < _matrix->count_of_our_type (N)) {
+                                       return ARDOUR::BundleChannel ((*j)->bundle, (*j)->bundle->type_channel_to_overall (_matrix->type (), p));
                                } else {
-
-                                       uint32_t const s = j->bundle->nchannels ();
-                                       if (p < s) {
-                                               return make_pair (*i, ARDOUR::BundleChannel (j->bundle, p));
-                                       } else {
-                                               p -= s;
-                                       }
-
+                                       return ARDOUR::BundleChannel (boost::shared_ptr<ARDOUR::Bundle> (), -1);
                                }
-
+                       } else {
+                               p -= s;
                        }
 
-               } else {
-
-                       p -= gs;
-
                }
 
-               ++i;
        }
 
-       return make_pair (boost::shared_ptr<PortGroup> (), ARDOUR::BundleChannel (boost::shared_ptr<ARDOUR::Bundle> (), 0));
+       return ARDOUR::BundleChannel (boost::shared_ptr<ARDOUR::Bundle> (), -1);
 }