X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fport_matrix_grid.cc;h=77995489a313a407aea439a1112337d551877705;hb=6b1b72a247bf04c81292fc41af4f69c9b7f90379;hp=c2af484e6c2f11501e081ef2779c01faca85020d;hpb=b7cfd2849ebb0d949af3ee39f70cbf1856fbfe0f;p=ardour.git diff --git a/gtk2_ardour/port_matrix_grid.cc b/gtk2_ardour/port_matrix_grid.cc index c2af484e6c..77995489a3 100644 --- a/gtk2_ardour/port_matrix_grid.cc +++ b/gtk2_ardour/port_matrix_grid.cc @@ -18,14 +18,15 @@ */ #include -#include +#include #include "ardour/bundle.h" -#include "ardour/types.h" #include "port_matrix_grid.h" #include "port_matrix.h" #include "port_matrix_body.h" +#include "keyboard.h" using namespace std; +using Gtkmm2ext::Keyboard; PortMatrixGrid::PortMatrixGrid (PortMatrix* m, PortMatrixBody* b) : PortMatrixComponent (m, b), @@ -39,16 +40,16 @@ PortMatrixGrid::PortMatrixGrid (PortMatrix* m, PortMatrixBody* b) void PortMatrixGrid::compute_dimensions () { - if (_matrix->visible_columns() == 0) { - _width = 0; - } else { + if (_matrix->visible_columns()) { _width = group_size (_matrix->visible_columns()) * grid_spacing (); + } else { + _width = 0; } - if (_matrix->visible_rows() == 0) { - _height = 0; - } else { + if (_matrix->visible_rows()) { _height = group_size (_matrix->visible_rows()) * grid_spacing (); + } else { + _height = 0; } } @@ -79,7 +80,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 < 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); @@ -95,6 +96,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 */ @@ -109,7 +116,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 < 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); @@ -125,7 +132,17 @@ PortMatrixGrid::render (cairo_t* cr) ++N; } - /* ASSOCIATION INDICATORS */ + 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 + cannot be connected because they are of different types (MIDI vs. audio) + */ uint32_t bx = 0; uint32_t by = 0; @@ -137,9 +154,9 @@ PortMatrixGrid::render (cairo_t* cr) for (PortGroup::BundleList::const_iterator j = row_bundles.begin(); j != row_bundles.end(); ++j) { - PortMatrixNode::State s = get_association (PortMatrixNode ( - ARDOUR::BundleChannel (i->bundle, 0), - ARDOUR::BundleChannel (j->bundle, 0) + PortMatrixNode::State s = _matrix->get_association (PortMatrixNode ( + ARDOUR::BundleChannel ((*j)->bundle, 0), + ARDOUR::BundleChannel ((*i)->bundle, 0) )); switch (s) { case PortMatrixNode::ASSOCIATED: @@ -167,39 +184,71 @@ 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 (); ++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 (); ++l) { + 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); - - 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; + 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 */ + draw_non_connectable_indicator (cr, x, y); + } 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; + } } 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 += 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 += i->bundle->nchannels () * grid_spacing(); + bx += _matrix->count_of_our_type_min_1 ((*i)->bundle->nchannels()) * grid_spacing(); } } } @@ -235,6 +284,23 @@ PortMatrixGrid::draw_empty_square (cairo_t* cr, uint32_t x, uint32_t y) cairo_fill (cr); } +/** Draw a square to indicate that two channels in a matrix cannot be associated + * with each other. + */ +void +PortMatrixGrid::draw_non_connectable_indicator (cairo_t* cr, uint32_t x, uint32_t y) +{ + set_source_rgb (cr, non_connectable_colour ()); + cairo_rectangle ( + cr, + x + thick_grid_line_width(), + y + thick_grid_line_width(), + grid_spacing() - 2 * thick_grid_line_width(), + grid_spacing() - 2 * thick_grid_line_width() + ); + cairo_fill (cr); +} + PortMatrixNode PortMatrixGrid::position_to_node (double x, double y) const { @@ -245,12 +311,12 @@ PortMatrixGrid::position_to_node (double x, double y) const } void -PortMatrixGrid::button_press (double x, double y, int b, uint32_t t) +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); @@ -259,72 +325,11 @@ PortMatrixGrid::button_press (double x, double y, int b, uint32_t t) _drag_start_x = x / grid_spacing (); _drag_start_y = y / grid_spacing (); - } else if (b == 3) { - - _matrix->popup_menu (px, py, t); - - } -} - -PortMatrixNode::State -PortMatrixGrid::get_association (PortMatrixNode node) const -{ - if (_matrix->show_only_bundles()) { - - bool have_off_diagonal_association = false; - bool have_diagonal_association = false; - bool have_diagonal_not_association = false; - - for (uint32_t i = 0; i < node.row.bundle->nchannels (); ++i) { - - for (uint32_t j = 0; j < node.column.bundle->nchannels (); ++j) { - - ARDOUR::BundleChannel c[2]; - c[_matrix->column_index()] = ARDOUR::BundleChannel (node.row.bundle, i); - c[_matrix->row_index()] = ARDOUR::BundleChannel (node.column.bundle, j); - - PortMatrixNode::State const s = _matrix->get_state (c); - - switch (s) { - case PortMatrixNode::ASSOCIATED: - if (i == j) { - have_diagonal_association = true; - } else { - have_off_diagonal_association = true; - } - break; - - case PortMatrixNode::NOT_ASSOCIATED: - if (i == j) { - have_diagonal_not_association = true; - } - break; - - default: - break; - } - } - } - - if (have_diagonal_association && !have_off_diagonal_association && !have_diagonal_not_association) { - return PortMatrixNode::ASSOCIATED; - } else if (!have_diagonal_association && !have_off_diagonal_association) { - return PortMatrixNode::NOT_ASSOCIATED; - } + } else if (ev->button == 3) { - return PortMatrixNode::PARTIAL; - - } else { - - ARDOUR::BundleChannel c[2]; - c[_matrix->column_index()] = node.column; - c[_matrix->row_index()] = node.row; - return _matrix->get_state (c); + _matrix->popup_menu (px, py, ev->time); } - - /* NOTREACHED */ - return PortMatrixNode::NOT_ASSOCIATED; } void @@ -332,8 +337,12 @@ PortMatrixGrid::set_association (PortMatrixNode node, bool s) { if (_matrix->show_only_bundles()) { - for (uint32_t i = 0; i < node.column.bundle->nchannels(); ++i) { - for (uint32_t j = 0; j < node.row.bundle->nchannels(); ++j) { + for (uint32_t i = 0; i < node.column.bundle->nchannels().n_total(); ++i) { + for (uint32_t j = 0; j < node.row.bundle->nchannels().n_total(); ++j) { + + 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); @@ -349,43 +358,64 @@ 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*/) +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 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()); + PortMatrixNode::State const s = _matrix->get_association (p.front()); for (list::const_iterator i = p.begin(); i != p.end(); ++i) { set_association (*i, toggle_state (s)); } } } - + } else { - - PortMatrixNode const n = position_to_node (x, y); - if (n.row.bundle && n.column.bundle) { - PortMatrixNode::State const s = get_association (n); - set_association (n, toggle_state (s)); + + 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) { + PortMatrixNode const n = position_to_node (x, y); + if (n.row.bundle && n.column.bundle) { + if (s == (PortMatrixNode::State) 0) { + s = _matrix->get_association (n); + } + set_association (n, toggle_state (s)); + } else { + break; + } + 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); + set_association (n, toggle_state (s)); + } } } require_render (); } - + _body->queue_draw (); } @@ -402,11 +432,11 @@ PortMatrixGrid::draw_extra (cairo_t* cr) list const m = _body->mouseover (); for (list::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) { @@ -415,7 +445,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()); @@ -432,7 +462,7 @@ PortMatrixGrid::draw_extra (cairo_t* cr) if (!p.empty()) { - bool const s = toggle_state (get_association (p.front())); + bool const s = toggle_state (_matrix->get_association (p.front())); for (list::const_iterator i = p.begin(); i != p.end(); ++i) { if (s) { @@ -500,7 +530,7 @@ void PortMatrixGrid::queue_draw_for (list const &n) { for (list::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 (); @@ -515,7 +545,7 @@ PortMatrixGrid::queue_draw_for (list 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(),