2 Copyright (C) 2002-2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <cairo/cairo.h>
22 #include "ardour/bundle.h"
23 #include "port_matrix_grid.h"
24 #include "port_matrix.h"
26 PortMatrixGrid::PortMatrixGrid (PortMatrix* p, PortMatrixBody* b)
27 : PortMatrixComponent (b),
34 PortMatrixGrid::compute_dimensions ()
37 for (uint32_t i = 0; i < _body->column_bundles().size(); ++i) {
38 _width += _body->column_bundles()[i]->nchannels() * column_width();
42 for (uint32_t i = 0; i < _body->row_bundles().size(); ++i) {
43 _height += _body->row_bundles()[i]->nchannels() * row_height();
49 PortMatrixGrid::render (cairo_t* cr)
53 set_source_rgb (cr, background_colour());
54 cairo_rectangle (cr, 0, 0, _width, _height);
57 /* VERTICAL GRID LINES */
59 set_source_rgb (cr, grid_colour());
61 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::size_type i = 0; i < _body->column_bundles().size(); ++i) {
63 cairo_set_line_width (cr, thin_grid_line_width());
64 for (uint32_t j = 1; j < _body->column_bundles()[i]->nchannels(); ++j) {
66 cairo_move_to (cr, x, 0);
67 cairo_line_to (cr, x, _height);
71 if (i < (_body->column_bundles().size() - 1)) {
73 cairo_set_line_width (cr, thick_grid_line_width());
74 cairo_move_to (cr, x, 0);
75 cairo_line_to (cr, x, _height);
80 uint32_t grid_width = x + column_width();
82 /* HORIZONTAL GRID LINES */
85 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::size_type i = 0; i < _body->row_bundles().size(); ++i) {
87 cairo_set_line_width (cr, thin_grid_line_width());
88 for (uint32_t j = 1; j < _body->row_bundles()[i]->nchannels(); ++j) {
90 cairo_move_to (cr, 0, y);
91 cairo_line_to (cr, grid_width, y);
95 if (i < (_body->row_bundles().size() - 1)) {
97 cairo_set_line_width (cr, thick_grid_line_width());
98 cairo_move_to (cr, 0, y);
99 cairo_line_to (cr, grid_width, y);
104 /* ASSOCIATION INDICATORS */
109 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->column_bundles().begin(); i < _body->column_bundles().end(); ++i) {
112 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator j = _body->row_bundles().begin(); j < _body->row_bundles().end(); ++j) {
115 for (uint32_t k = 0; k < (*i)->nchannels (); k++) {
118 for (uint32_t l = 0; l < (*j)->nchannels (); ++l) {
120 if (_port_matrix->get_state (*j, l, *i, k)) {
122 set_source_rgba (cr, association_colour(), 0.5);
125 x + column_width() / 2,
126 y + column_width() / 2,
127 (column_width() - (2 * connection_indicator_pad())) / 2,
140 by += (*j)->nchannels () * row_height();
143 bx += (*i)->nchannels () * column_width();
149 PortMatrixGrid::button_press (double x, double y, int b)
151 uint32_t grid_column = x / column_width ();
152 uint32_t grid_row = y / row_height ();
154 boost::shared_ptr<ARDOUR::Bundle> our_bundle;
155 uint32_t our_channel = 0;
156 boost::shared_ptr<ARDOUR::Bundle> other_bundle;
157 uint32_t other_channel = 0;
159 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->row_bundles().begin(); i != _body->row_bundles().end(); ++i) {
160 if (grid_row < (*i)->nchannels ()) {
162 our_channel = grid_row;
165 grid_row -= (*i)->nchannels ();
169 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->column_bundles().begin(); i != _body->column_bundles().end(); ++i) {
170 if (grid_column < (*i)->nchannels ()) {
172 other_channel = grid_column;
175 grid_column -= (*i)->nchannels ();
179 if (our_bundle && other_bundle) {
181 bool const s = _port_matrix->get_state (
182 our_bundle, our_channel, other_bundle, other_channel
185 _port_matrix->set_state (
186 our_bundle, our_channel, other_bundle, other_channel,
191 _body->queue_draw ();