Fix thinkos in cubasish theme
[ardour.git] / gtk2_ardour / port_matrix_grid.cc
index 96e9cb949ca905e038c43cef37946eaba8ddd5cb..861794cc24173eb3430e8af23ca64349fcc143a1 100644 (file)
@@ -1,26 +1,26 @@
 /*
-    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) 2009-2011 Carl Hetherington <carl@carlh.net>
+ * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
+ * Copyright (C) 2009-2013 Paul Davis <paul@linuxaudiosystems.com>
+ *
+ * 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 <cairo/cairo.h>
+#include <cairo.h>
 #include "ardour/bundle.h"
-#include "ardour/types.h"
 #include "port_matrix_grid.h"
 #include "port_matrix.h"
 #include "port_matrix_body.h"
@@ -81,7 +81,7 @@ PortMatrixGrid::render (cairo_t* cr)
 
                if (!_matrix->show_only_bundles()) {
                        cairo_set_line_width (cr, thin_grid_line_width());
-                       for (uint32_t j = 0; j < _matrix->count_of_our_type ((*i)->bundle->nchannels()); ++j) {
+                       for (uint32_t j = 0; j < _matrix->count_of_our_type_min_1 ((*i)->bundle->nchannels()); ++j) {
                                x += grid_spacing ();
                                cairo_move_to (cr, x, 0);
                                cairo_line_to (cr, x, _height);
@@ -97,6 +97,12 @@ PortMatrixGrid::render (cairo_t* cr)
                ++N;
        }
 
+       if (_matrix->show_only_bundles ()) {
+               cairo_move_to (cr, x, 0);
+               cairo_line_to (cr, x, _height);
+               cairo_stroke (cr);
+       }
+
        uint32_t y = 0;
 
        /* HORIZONTAL GRID LINES */
@@ -111,7 +117,7 @@ PortMatrixGrid::render (cairo_t* cr)
 
                if (!_matrix->show_only_bundles()) {
                        cairo_set_line_width (cr, thin_grid_line_width());
-                       for (uint32_t j = 0; j < _matrix->count_of_our_type ((*i)->bundle->nchannels()); ++j) {
+                       for (uint32_t j = 0; j < _matrix->count_of_our_type_min_1 ((*i)->bundle->nchannels()); ++j) {
                                y += grid_spacing ();
                                cairo_move_to (cr, 0, y);
                                cairo_line_to (cr, _width, y);
@@ -127,6 +133,12 @@ PortMatrixGrid::render (cairo_t* cr)
                ++N;
        }
 
+       if (_matrix->show_only_bundles ()) {
+               cairo_move_to (cr, 0, y);
+               cairo_line_to (cr, _width, y);
+               cairo_stroke (cr);
+       }
+
        /* ASSOCIATION INDICATORS and NON-CONNECTABLE INDICATORS */
 
        /* we draw a grey square in a matrix box if the two ports that intersect at that box
@@ -173,18 +185,22 @@ PortMatrixGrid::render (cairo_t* cr)
                        for (PortGroup::BundleList::const_iterator j = row_bundles.begin(); j != row_bundles.end(); ++j) {
 
                                x = bx;
-                               for (uint32_t k = 0; k < (*i)->bundle->nchannels().n_total(); ++k) {
+                               for (uint32_t k = 0; k < _matrix->count_of_our_type ((*i)->bundle->nchannels()); ++k) {
 
                                        y = by;
-                                       for (uint32_t l = 0; l < (*j)->bundle->nchannels().n_total(); ++l) {
-
-                                               if (!_matrix->should_show ((*i)->bundle->channel_type(k)) || !_matrix->should_show ((*j)->bundle->channel_type(l))) {
-                                                       continue;
-                                               }
+                                       for (uint32_t l = 0; l < _matrix->count_of_our_type ((*j)->bundle->nchannels()); ++l) {
 
                                                ARDOUR::BundleChannel c[2];
-                                               c[_matrix->column_index()] = ARDOUR::BundleChannel ((*i)->bundle, k);
-                                               c[_matrix->row_index()] = ARDOUR::BundleChannel ((*j)->bundle, l);
+
+                                               c[_matrix->column_index()] = ARDOUR::BundleChannel (
+                                                       (*i)->bundle,
+                                                       (*i)->bundle->type_channel_to_overall (_matrix->type (), k)
+                                                       );
+
+                                               c[_matrix->row_index()] = ARDOUR::BundleChannel (
+                                                       (*j)->bundle,
+                                                       (*j)->bundle->type_channel_to_overall (_matrix->type (), l)
+                                                       );
 
                                                if (c[0].bundle->channel_type (c[0].channel) != c[1].bundle->channel_type (c[1].channel)) {
                                                        /* these two channels are of different types */
@@ -192,15 +208,15 @@ PortMatrixGrid::render (cairo_t* cr)
                                                } else {
                                                        /* these two channels might be associated */
                                                        PortMatrixNode::State const s = _matrix->get_state (c);
-                                                       
+
                                                        switch (s) {
                                                        case PortMatrixNode::ASSOCIATED:
                                                                draw_association_indicator (cr, x, y);
                                                                break;
-                                                               
+
                                                        case PortMatrixNode::NOT_ASSOCIATED:
                                                                break;
-                                                               
+
                                                        default:
                                                                break;
                                                        }
@@ -209,13 +225,31 @@ PortMatrixGrid::render (cairo_t* cr)
                                                y += grid_spacing();
                                        }
 
+                                       if (_matrix->count_of_our_type ((*j)->bundle->nchannels()) == 0) {
+                                               /* the *j bundle has no channels of our type, so it will have a dummy
+                                                  one which needs to be marked non-connectable.
+                                               */
+                                               draw_non_connectable_indicator (cr, x, y);
+                                       }
+
                                        x += grid_spacing();
                                }
 
-                               by += _matrix->count_of_our_type ((*j)->bundle->nchannels()) * grid_spacing();
+                               if (_matrix->count_of_our_type ((*i)->bundle->nchannels()) == 0) {
+                                       /* draw non-connectable indicators for the case where the *i bundle
+                                          has no channels of our type (and hence has 1 dummy channel)
+                                       */
+                                       y = by;
+                                       for (uint32_t l = 0; l < _matrix->count_of_our_type_min_1 ((*j)->bundle->nchannels()); ++l) {
+                                               draw_non_connectable_indicator (cr, x, y);
+                                               y += grid_spacing ();
+                                       }
+                               }
+
+                               by += _matrix->count_of_our_type_min_1 ((*j)->bundle->nchannels()) * grid_spacing();
                        }
 
-                       bx += _matrix->count_of_our_type ((*i)->bundle->nchannels()) * grid_spacing();
+                       bx += _matrix->count_of_our_type_min_1 ((*i)->bundle->nchannels()) * grid_spacing();
                }
        }
 }
@@ -278,23 +312,23 @@ PortMatrixGrid::position_to_node (double x, double y) const
 }
 
 void
-PortMatrixGrid::button_press (double x, double y, int b, uint32_t t, guint)
+PortMatrixGrid::button_press (double x, double y, GdkEventButton* ev)
 {
        ARDOUR::BundleChannel const px = position_to_channel (x, y, _matrix->visible_columns());
        ARDOUR::BundleChannel const py = position_to_channel (y, x, _matrix->visible_rows());
 
-       if (b == 1) {
-               
+       if (ev->button == 1) {
+
                _dragging = true;
                _drag_valid = (px.bundle && py.bundle);
-               
+
                _moved = false;
                _drag_start_x = x / grid_spacing ();
                _drag_start_y = y / grid_spacing ();
 
-       } else if (b == 3) {
+       } else if (ev->button == 3) {
 
-               _matrix->popup_menu (px, py, t);
+               _matrix->popup_menu (px, py, ev->time);
 
        }
 }
@@ -310,7 +344,7 @@ PortMatrixGrid::set_association (PortMatrixNode node, bool s)
                                if (!_matrix->should_show (node.column.bundle->channel_type(i)) || !_matrix->should_show (node.row.bundle->channel_type(j))) {
                                        continue;
                                }
-                               
+
                                ARDOUR::BundleChannel c[2];
                                c[_matrix->column_index()] = ARDOUR::BundleChannel (node.column.bundle, i);
                                c[_matrix->row_index()] = ARDOUR::BundleChannel (node.row.bundle, j);
@@ -325,23 +359,24 @@ PortMatrixGrid::set_association (PortMatrixNode node, bool s)
                        ARDOUR::BundleChannel c[2];
                        c[_matrix->row_index()] = node.row;
                        c[_matrix->column_index()] = node.column;
+
                        _matrix->set_state (c, s);
                }
        }
 }
 
 void
-PortMatrixGrid::button_release (double x, double y, int b, uint32_t /*t*/, guint s)
+PortMatrixGrid::button_release (double x, double y, GdkEventButton* ev)
 {
-       if (b == 1) {
+       if (ev->button == 1) {
 
                if (x != -1) {
-                       
+
                        if (_dragging && _moved) {
-                               
+
                                if (_drag_valid) {
                                        list<PortMatrixNode> const p = nodes_on_line (_drag_start_x, _drag_start_y, _drag_x, _drag_y);
-                                       
+
                                        if (!p.empty()) {
                                                PortMatrixNode::State const s = _matrix->get_association (p.front());
                                                for (list<PortMatrixNode>::const_iterator i = p.begin(); i != p.end(); ++i) {
@@ -349,10 +384,10 @@ PortMatrixGrid::button_release (double x, double y, int b, uint32_t /*t*/, guint
                                                }
                                        }
                                }
-                               
+
                        } else {
-                               
-                               if (Keyboard::modifier_state_equals (s, Keyboard::PrimaryModifier)) {
+
+                               if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
                                        /* associate/disassociate things diagonally down and right until we run out */
                                        PortMatrixNode::State s = (PortMatrixNode::State) 0;
                                        while (1) {
@@ -368,9 +403,9 @@ PortMatrixGrid::button_release (double x, double y, int b, uint32_t /*t*/, guint
                                                x += grid_spacing ();
                                                y += grid_spacing ();
                                        }
-                                       
+
                                } else {
-                                       
+
                                        PortMatrixNode const n = position_to_node (x, y);
                                        if (n.row.bundle && n.column.bundle) {
                                                PortMatrixNode::State const s = _matrix->get_association (n);
@@ -381,7 +416,7 @@ PortMatrixGrid::button_release (double x, double y, int b, uint32_t /*t*/, guint
 
                        require_render ();
                }
-               
+
                _body->queue_draw ();
        }
 
@@ -398,11 +433,11 @@ PortMatrixGrid::draw_extra (cairo_t* cr)
        list<PortMatrixNode> const m = _body->mouseover ();
 
        for (list<PortMatrixNode>::const_iterator i = m.begin(); i != m.end(); ++i) {
-       
+
                double const x = component_to_parent_x (channel_to_position (i->column, _matrix->visible_columns()) * grid_spacing()) + grid_spacing() / 2;
                double const y = component_to_parent_y (channel_to_position (i->row, _matrix->visible_rows()) * grid_spacing()) + grid_spacing() / 2;
 
-               if (i->row.bundle && i->column.bundle) {
+               if (PortMatrix::bundle_with_channels (i->row.bundle) && PortMatrix::bundle_with_channels (i->column.bundle)) {
 
                        cairo_move_to (cr, x, y);
                        if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
@@ -411,7 +446,7 @@ PortMatrixGrid::draw_extra (cairo_t* cr)
                                cairo_line_to (cr, _parent_rectangle.get_x() + _parent_rectangle.get_width(), y);
                        }
                        cairo_stroke (cr);
-                       
+
                        cairo_move_to (cr, x, y);
                        if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
                                cairo_line_to (cr, x, _parent_rectangle.get_y() + _parent_rectangle.get_height());
@@ -496,7 +531,7 @@ void
 PortMatrixGrid::queue_draw_for (list<PortMatrixNode> const &n)
 {
        for (list<PortMatrixNode>::const_iterator i = n.begin(); i != n.end(); ++i) {
-               
+
                if (i->row.bundle) {
 
                        double const y = channel_to_position (i->row, _matrix->visible_rows()) * grid_spacing ();
@@ -511,7 +546,7 @@ PortMatrixGrid::queue_draw_for (list<PortMatrixNode> const &n)
                if (i->column.bundle) {
 
                        double const x = channel_to_position (i->column, _matrix->visible_columns()) * grid_spacing ();
-                       
+
                        _body->queue_draw_area (
                                component_to_parent_x (x),
                                _parent_rectangle.get_y(),