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 PortMatrix::State const s = _port_matrix->get_state (*j, l, *i, k);
123 case PortMatrix::ASSOCIATED:
124 set_source_rgba (cr, association_colour(), 0.5);
127 x + column_width() / 2,
128 y + column_width() / 2,
129 (column_width() - (2 * connection_indicator_pad())) / 2,
137 case PortMatrix::UNKNOWN:
138 set_source_rgba (cr, unknown_colour(), 0.5);
141 x + thick_grid_line_width(),
142 y + thick_grid_line_width(),
143 column_width() - 2 * thick_grid_line_width(),
144 row_height() - 2 * thick_grid_line_width()
149 case PortMatrix::NOT_ASSOCIATED:
158 by += (*j)->nchannels () * row_height();
161 bx += (*i)->nchannels () * column_width();
167 PortMatrixGrid::button_press (double x, double y, int b)
169 uint32_t grid_column = x / column_width ();
170 uint32_t grid_row = y / row_height ();
172 boost::shared_ptr<ARDOUR::Bundle> our_bundle;
173 uint32_t our_channel = 0;
174 boost::shared_ptr<ARDOUR::Bundle> other_bundle;
175 uint32_t other_channel = 0;
177 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->row_bundles().begin(); i != _body->row_bundles().end(); ++i) {
178 if (grid_row < (*i)->nchannels ()) {
180 our_channel = grid_row;
183 grid_row -= (*i)->nchannels ();
187 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->column_bundles().begin(); i != _body->column_bundles().end(); ++i) {
188 if (grid_column < (*i)->nchannels ()) {
190 other_channel = grid_column;
193 grid_column -= (*i)->nchannels ();
198 if (our_bundle && other_bundle) {
200 PortMatrix::State const s = _port_matrix->get_state (
201 our_bundle, our_channel, other_bundle, other_channel
204 if (s == PortMatrix::ASSOCIATED || s == PortMatrix::NOT_ASSOCIATED) {
206 bool const n = !(s == PortMatrix::ASSOCIATED);
208 _port_matrix->set_state (
209 our_bundle, our_channel, other_bundle, other_channel,
215 _body->queue_draw ();