Clear out any command line session name on closing a session so that the same session...
[ardour.git] / gtk2_ardour / port_matrix_grid.cc
index 50740cae63931f214f5f173d7583b6f4e3f9f5a7..8e2f379addbca1d81c01bef70f2aeec2ba581af9 100644 (file)
@@ -30,6 +30,7 @@ using namespace std;
 PortMatrixGrid::PortMatrixGrid (PortMatrix* m, PortMatrixBody* b)
        : PortMatrixComponent (m, b),
          _dragging (false),
+         _drag_valid (false),
          _moved (false)
 {
        
@@ -291,18 +292,21 @@ PortMatrixGrid::position_to_node (uint32_t x, uint32_t y) const
 void
 PortMatrixGrid::button_press (double x, double y, int b, uint32_t t)
 {
+       pair<boost::shared_ptr<PortGroup>, ARDOUR::BundleChannel> px = position_to_group_and_channel (x / grid_spacing(), _matrix->columns());
+       pair<boost::shared_ptr<PortGroup>, ARDOUR::BundleChannel> py = position_to_group_and_channel (y / grid_spacing(), _matrix->rows());
+       
        if (b == 1) {
 
                _dragging = true;
+               _drag_valid = (px.second.bundle && py.second.bundle);
+               
                _moved = false;
                _drag_start_x = x / grid_spacing ();
                _drag_start_y = y / grid_spacing ();
 
        } else if (b == 3) {
 
-               _matrix->popup_menu (
-                       position_to_group_and_channel (x / grid_spacing(), _matrix->columns()),
-                       position_to_group_and_channel (y / grid_spacing(), _matrix->rows()), t);
+               _matrix->popup_menu (px, py, t);
                
        }
 }
@@ -402,27 +406,30 @@ PortMatrixGrid::set_association (PortMatrixNode node, bool s)
 }
 
 void
-PortMatrixGrid::button_release (double x, double y, int b, uint32_t t)
+PortMatrixGrid::button_release (double x, double y, int b, uint32_t /*t*/)
 {
        if (b == 1) {
 
                if (_dragging && _moved) {
 
-                       list<PortMatrixNode> const p = nodes_on_line (_drag_start_x, _drag_start_y, _drag_x, _drag_y);
-
-                       if (!p.empty()) {
-                               PortMatrixNode::State const s = get_association (p.front());
-                               for (list<PortMatrixNode>::const_iterator i = p.begin(); i != p.end(); ++i) {
-                                       set_association (*i, toggle_state (s));
+                       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 = get_association (p.front());
+                                       for (list<PortMatrixNode>::const_iterator i = p.begin(); i != p.end(); ++i) {
+                                               set_association (*i, toggle_state (s));
+                                       }
                                }
                        }
 
                } else {
 
                        PortMatrixNode const n = position_to_node (x / grid_spacing(), y / grid_spacing());
-                       PortMatrixNode::State const s = get_association (n);
-
-                       set_association (n, toggle_state (s));
+                       if (n.row.bundle && n.column.bundle) {
+                               PortMatrixNode::State const s = get_association (n);
+                               set_association (n, toggle_state (s));
+                       }
                }
 
                require_render ();
@@ -461,7 +468,7 @@ PortMatrixGrid::draw_extra (cairo_t* cr)
                cairo_stroke (cr);
        }
 
-       if (_dragging && _moved) {
+       if (_dragging && _drag_valid && _moved) {
 
                list<PortMatrixNode> const p = nodes_on_line (_drag_start_x, _drag_start_y, _drag_x, _drag_y);
 
@@ -524,7 +531,7 @@ PortMatrixGrid::motion (double x, double y)
                _moved = true;
        }
 
-       if (_dragging && _moved) {
+       if (_dragging && _drag_valid && _moved) {
                _drag_x = px;
                _drag_y = py;
                _body->queue_draw ();
@@ -619,9 +626,15 @@ PortMatrixGrid::nodes_on_line (int x0, int y0, int x1, int y1) const
 
        for (int x = x0; x <= x1; ++x) {
                if (steep) {
-                       p.push_back (position_to_node (y, x));
+                       PortMatrixNode n = position_to_node (y, x);
+                       if (n.row.bundle && n.column.bundle) {
+                               p.push_back (n);
+                       }
                } else {
-                       p.push_back (position_to_node (x, y));
+                       PortMatrixNode n = position_to_node (x, y);
+                       if (n.row.bundle && n.column.bundle) {
+                               p.push_back (n);
+                       }
                }
 
                err += derr;