2009-01-20 09:46:00 -05:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* 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.
|
|
|
|
*/
|
2009-01-20 09:46:00 -05:00
|
|
|
|
|
|
|
#include <iostream>
|
2013-03-29 20:36:11 -04:00
|
|
|
#include <cairo.h>
|
2009-01-20 09:46:00 -05:00
|
|
|
#include "ardour/bundle.h"
|
|
|
|
#include "port_matrix_grid.h"
|
|
|
|
#include "port_matrix.h"
|
2009-02-04 12:05:26 -05:00
|
|
|
#include "port_matrix_body.h"
|
2009-11-18 10:16:28 -05:00
|
|
|
#include "keyboard.h"
|
2009-01-20 09:46:00 -05:00
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
using namespace std;
|
2009-12-04 17:51:32 -05:00
|
|
|
using Gtkmm2ext::Keyboard;
|
2009-07-17 18:54:45 -04:00
|
|
|
|
2009-01-30 10:08:09 -05:00
|
|
|
PortMatrixGrid::PortMatrixGrid (PortMatrix* m, PortMatrixBody* b)
|
2009-07-17 22:10:15 -04:00
|
|
|
: PortMatrixComponent (m, b),
|
|
|
|
_dragging (false),
|
2009-07-19 17:57:51 -04:00
|
|
|
_drag_valid (false),
|
2009-07-17 22:10:15 -04:00
|
|
|
_moved (false)
|
2009-01-20 09:46:00 -05:00
|
|
|
{
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PortMatrixGrid::compute_dimensions ()
|
|
|
|
{
|
2009-12-06 19:41:50 -05:00
|
|
|
if (_matrix->visible_columns()) {
|
2009-11-18 08:35:31 -05:00
|
|
|
_width = group_size (_matrix->visible_columns()) * grid_spacing ();
|
2009-12-06 19:41:50 -05:00
|
|
|
} else {
|
|
|
|
_width = 0;
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
|
|
|
|
2009-12-06 19:41:50 -05:00
|
|
|
if (_matrix->visible_rows()) {
|
2009-11-18 08:35:31 -05:00
|
|
|
_height = group_size (_matrix->visible_rows()) * grid_spacing ();
|
2009-12-06 19:41:50 -05:00
|
|
|
} else {
|
|
|
|
_height = 0;
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PortMatrixGrid::render (cairo_t* cr)
|
|
|
|
{
|
|
|
|
set_source_rgb (cr, background_colour());
|
|
|
|
cairo_rectangle (cr, 0, 0, _width, _height);
|
|
|
|
cairo_fill (cr);
|
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
PortGroup::BundleList const & row_bundles = _matrix->visible_rows()->bundles();
|
|
|
|
PortGroup::BundleList const & column_bundles = _matrix->visible_columns()->bundles();
|
2009-07-17 18:54:45 -04:00
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
uint32_t x = 0;
|
2009-07-17 18:54:45 -04:00
|
|
|
|
2009-01-20 09:46:00 -05:00
|
|
|
/* VERTICAL GRID LINES */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-01-20 09:46:00 -05:00
|
|
|
set_source_rgb (cr, grid_colour());
|
2009-07-17 09:18:58 -04:00
|
|
|
uint32_t N = 0;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
for (PortGroup::BundleList::const_iterator i = column_bundles.begin(); i != column_bundles.end(); ++i) {
|
2009-01-20 09:46:00 -05:00
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
cairo_set_line_width (cr, thick_grid_line_width());
|
2009-11-18 08:35:31 -05:00
|
|
|
cairo_move_to (cr, x, 0);
|
|
|
|
cairo_line_to (cr, x, _height);
|
2009-07-17 18:54:45 -04:00
|
|
|
cairo_stroke (cr);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-05-03 10:31:42 -04:00
|
|
|
if (!_matrix->show_only_bundles()) {
|
|
|
|
cairo_set_line_width (cr, thin_grid_line_width());
|
2011-08-13 16:19:39 -04:00
|
|
|
for (uint32_t j = 0; j < _matrix->count_of_our_type_min_1 ((*i)->bundle->nchannels()); ++j) {
|
2009-11-18 08:35:31 -05:00
|
|
|
x += grid_spacing ();
|
|
|
|
cairo_move_to (cr, x, 0);
|
|
|
|
cairo_line_to (cr, x, _height);
|
2009-05-03 10:31:42 -04:00
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
} else {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
x += grid_spacing ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
++N;
|
|
|
|
}
|
|
|
|
|
2011-08-13 16:19:39 -04:00
|
|
|
if (_matrix->show_only_bundles ()) {
|
|
|
|
cairo_move_to (cr, x, 0);
|
|
|
|
cairo_line_to (cr, x, _height);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
uint32_t y = 0;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-01-20 09:46:00 -05:00
|
|
|
/* HORIZONTAL GRID LINES */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-07-17 09:18:58 -04:00
|
|
|
N = 0;
|
2009-07-17 18:54:45 -04:00
|
|
|
for (PortGroup::BundleList::const_iterator i = row_bundles.begin(); i != row_bundles.end(); ++i) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
cairo_set_line_width (cr, thick_grid_line_width());
|
2009-11-18 08:35:31 -05:00
|
|
|
cairo_move_to (cr, 0, y);
|
|
|
|
cairo_line_to (cr, _width, y);
|
2009-07-17 18:54:45 -04:00
|
|
|
cairo_stroke (cr);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-05-03 10:31:42 -04:00
|
|
|
if (!_matrix->show_only_bundles()) {
|
|
|
|
cairo_set_line_width (cr, thin_grid_line_width());
|
2011-08-13 16:19:39 -04:00
|
|
|
for (uint32_t j = 0; j < _matrix->count_of_our_type_min_1 ((*i)->bundle->nchannels()); ++j) {
|
2009-11-18 08:35:31 -05:00
|
|
|
y += grid_spacing ();
|
|
|
|
cairo_move_to (cr, 0, y);
|
|
|
|
cairo_line_to (cr, _width, y);
|
2009-05-03 10:31:42 -04:00
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
2009-01-20 09:46:00 -05:00
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
} else {
|
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
y += grid_spacing ();
|
2009-07-17 09:18:58 -04:00
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-07-17 09:18:58 -04:00
|
|
|
++N;
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-08-13 16:19:39 -04:00
|
|
|
if (_matrix->show_only_bundles ()) {
|
|
|
|
cairo_move_to (cr, 0, y);
|
|
|
|
cairo_line_to (cr, _width, y);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2010-07-21 19:20:56 -04:00
|
|
|
/* 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)
|
|
|
|
*/
|
2009-07-17 18:54:45 -04:00
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
uint32_t bx = 0;
|
|
|
|
uint32_t by = 0;
|
2009-01-20 09:46:00 -05:00
|
|
|
|
2009-05-03 10:31:42 -04:00
|
|
|
if (_matrix->show_only_bundles()) {
|
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
for (PortGroup::BundleList::const_iterator i = column_bundles.begin(); i != column_bundles.end(); ++i) {
|
2009-11-18 08:35:31 -05:00
|
|
|
by = 0;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
for (PortGroup::BundleList::const_iterator j = row_bundles.begin(); j != row_bundles.end(); ++j) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-12-10 12:27:13 -05:00
|
|
|
PortMatrixNode::State s = _matrix->get_association (PortMatrixNode (
|
2011-01-29 07:41:10 -05:00
|
|
|
ARDOUR::BundleChannel ((*j)->bundle, 0),
|
|
|
|
ARDOUR::BundleChannel ((*i)->bundle, 0)
|
2009-07-19 16:36:46 -04:00
|
|
|
));
|
2009-05-03 10:31:42 -04:00
|
|
|
switch (s) {
|
|
|
|
case PortMatrixNode::ASSOCIATED:
|
|
|
|
draw_association_indicator (cr, bx, by);
|
|
|
|
break;
|
|
|
|
case PortMatrixNode::PARTIAL:
|
|
|
|
draw_association_indicator (cr, bx, by, 0.5);
|
|
|
|
break;
|
2009-05-13 17:34:09 -04:00
|
|
|
default:
|
|
|
|
break;
|
2009-05-03 10:31:42 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-07-17 22:10:15 -04:00
|
|
|
by += grid_spacing();
|
2009-05-03 10:31:42 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-07-17 22:10:15 -04:00
|
|
|
bx += grid_spacing();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-05-03 10:31:42 -04:00
|
|
|
}
|
2009-01-20 09:46:00 -05:00
|
|
|
|
2009-05-03 10:31:42 -04:00
|
|
|
} else {
|
2009-01-30 10:08:09 -05:00
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
for (PortGroup::BundleList::const_iterator i = column_bundles.begin(); i != column_bundles.end(); ++i) {
|
2009-11-18 08:35:31 -05:00
|
|
|
by = 0;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
for (PortGroup::BundleList::const_iterator j = row_bundles.begin(); j != row_bundles.end(); ++j) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
x = bx;
|
2011-08-13 16:19:39 -04:00
|
|
|
for (uint32_t k = 0; k < _matrix->count_of_our_type ((*i)->bundle->nchannels()); ++k) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
y = by;
|
2011-08-13 16:19:39 -04:00
|
|
|
for (uint32_t l = 0; l < _matrix->count_of_our_type ((*j)->bundle->nchannels()); ++l) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-05-03 10:31:42 -04:00
|
|
|
ARDOUR::BundleChannel c[2];
|
2011-11-07 21:10:56 -05:00
|
|
|
|
|
|
|
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)
|
|
|
|
);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-07-21 19:20:56 -04:00
|
|
|
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);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-07-21 19:20:56 -04:00
|
|
|
switch (s) {
|
|
|
|
case PortMatrixNode::ASSOCIATED:
|
|
|
|
draw_association_indicator (cr, x, y);
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-07-21 19:20:56 -04:00
|
|
|
case PortMatrixNode::NOT_ASSOCIATED:
|
|
|
|
break;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-07-21 19:20:56 -04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-05-03 10:31:42 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
y += grid_spacing();
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-08-14 14:12:33 -04:00
|
|
|
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.
|
|
|
|
*/
|
2011-08-13 16:19:39 -04:00
|
|
|
draw_non_connectable_indicator (cr, x, y);
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
x += grid_spacing();
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-08-14 14:12:33 -04:00
|
|
|
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 ();
|
|
|
|
}
|
2011-08-13 16:19:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
by += _matrix->count_of_our_type_min_1 ((*j)->bundle->nchannels()) * grid_spacing();
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-08-13 16:19:39 -04:00
|
|
|
bx += _matrix->count_of_our_type_min_1 ((*i)->bundle->nchannels()) * grid_spacing();
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-03 10:31:42 -04:00
|
|
|
void
|
|
|
|
PortMatrixGrid::draw_association_indicator (cairo_t* cr, uint32_t x, uint32_t y, double p)
|
|
|
|
{
|
|
|
|
set_source_rgba (cr, association_colour(), 0.5);
|
2009-07-17 22:10:15 -04:00
|
|
|
|
2009-05-03 10:31:42 -04:00
|
|
|
cairo_arc (
|
|
|
|
cr,
|
2009-07-17 22:10:15 -04:00
|
|
|
x + grid_spacing() / 2,
|
|
|
|
y + grid_spacing() / 2,
|
|
|
|
(grid_spacing() - (2 * connection_indicator_pad())) / 2,
|
2009-05-03 10:31:42 -04:00
|
|
|
0,
|
|
|
|
p * 2 * M_PI
|
|
|
|
);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-05-03 10:31:42 -04:00
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
|
|
|
|
2009-07-19 16:36:46 -04:00
|
|
|
void
|
|
|
|
PortMatrixGrid::draw_empty_square (cairo_t* cr, uint32_t x, uint32_t y)
|
|
|
|
{
|
|
|
|
set_source_rgb (cr, background_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()
|
2010-07-21 19:20:56 -04:00
|
|
|
);
|
|
|
|
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()
|
2009-07-19 16:36:46 -04:00
|
|
|
);
|
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
|
|
|
|
2009-01-26 23:21:13 -05:00
|
|
|
PortMatrixNode
|
2009-11-16 19:30:42 -05:00
|
|
|
PortMatrixGrid::position_to_node (double x, double y) const
|
2009-01-20 09:46:00 -05:00
|
|
|
{
|
2009-01-26 23:21:13 -05:00
|
|
|
return PortMatrixNode (
|
2009-11-18 08:35:31 -05:00
|
|
|
position_to_channel (y, x, _matrix->visible_rows()),
|
|
|
|
position_to_channel (x, y, _matrix->visible_columns())
|
2009-01-26 23:21:13 -05:00
|
|
|
);
|
|
|
|
}
|
2009-01-20 09:46:00 -05:00
|
|
|
|
2009-07-17 22:10:15 -04:00
|
|
|
void
|
2011-12-06 20:44:47 -05:00
|
|
|
PortMatrixGrid::button_press (double x, double y, GdkEventButton* ev)
|
2009-01-26 23:21:13 -05:00
|
|
|
{
|
2009-11-18 08:35:31 -05:00
|
|
|
ARDOUR::BundleChannel const px = position_to_channel (x, y, _matrix->visible_columns());
|
|
|
|
ARDOUR::BundleChannel const py = position_to_channel (y, x, _matrix->visible_rows());
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-12-06 20:44:47 -05:00
|
|
|
if (ev->button == 1) {
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-07-17 22:10:15 -04:00
|
|
|
_dragging = true;
|
2009-11-18 08:35:31 -05:00
|
|
|
_drag_valid = (px.bundle && py.bundle);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-07-17 22:10:15 -04:00
|
|
|
_moved = false;
|
|
|
|
_drag_start_x = x / grid_spacing ();
|
|
|
|
_drag_start_y = y / grid_spacing ();
|
2009-07-17 18:54:45 -04:00
|
|
|
|
2011-12-06 20:44:47 -05:00
|
|
|
} else if (ev->button == 3) {
|
2009-07-17 18:54:45 -04:00
|
|
|
|
2011-12-06 20:44:47 -05:00
|
|
|
_matrix->popup_menu (px, py, ev->time);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
2009-01-26 23:21:13 -05:00
|
|
|
}
|
|
|
|
|
2009-07-17 22:27:36 -04:00
|
|
|
void
|
2009-07-19 16:36:46 -04:00
|
|
|
PortMatrixGrid::set_association (PortMatrixNode node, bool s)
|
2009-07-17 22:27:36 -04:00
|
|
|
{
|
|
|
|
if (_matrix->show_only_bundles()) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-06-29 22:59:13 -04:00
|
|
|
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) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-06-30 21:14:14 -04:00
|
|
|
if (!_matrix->should_show (node.column.bundle->channel_type(i)) || !_matrix->should_show (node.row.bundle->channel_type(j))) {
|
2010-06-29 22:59:13 -04:00
|
|
|
continue;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-07-17 22:27:36 -04:00
|
|
|
ARDOUR::BundleChannel c[2];
|
|
|
|
c[_matrix->column_index()] = ARDOUR::BundleChannel (node.column.bundle, i);
|
|
|
|
c[_matrix->row_index()] = ARDOUR::BundleChannel (node.row.bundle, j);
|
2009-07-19 16:36:46 -04:00
|
|
|
_matrix->set_state (c, s && (i == j));
|
2009-07-17 22:27:36 -04:00
|
|
|
}
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-07-17 22:27:36 -04:00
|
|
|
} else {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-07-17 22:27:36 -04:00
|
|
|
if (node.row.bundle && node.column.bundle) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-07-17 22:27:36 -04:00
|
|
|
ARDOUR::BundleChannel c[2];
|
|
|
|
c[_matrix->row_index()] = node.row;
|
|
|
|
c[_matrix->column_index()] = node.column;
|
2011-11-07 21:10:56 -05:00
|
|
|
|
2009-07-19 16:36:46 -04:00
|
|
|
_matrix->set_state (c, s);
|
2009-07-17 22:27:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-17 22:10:15 -04:00
|
|
|
void
|
2011-12-06 20:44:47 -05:00
|
|
|
PortMatrixGrid::button_release (double x, double y, GdkEventButton* ev)
|
2009-01-26 23:21:13 -05:00
|
|
|
{
|
2011-12-06 20:44:47 -05:00
|
|
|
if (ev->button == 1) {
|
2009-05-03 10:31:42 -04:00
|
|
|
|
2009-11-18 09:53:55 -05:00
|
|
|
if (x != -1) {
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-11-18 09:53:55 -05:00
|
|
|
if (_dragging && _moved) {
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-11-18 09:53:55 -05:00
|
|
|
if (_drag_valid) {
|
|
|
|
list<PortMatrixNode> const p = nodes_on_line (_drag_start_x, _drag_start_y, _drag_x, _drag_y);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-11-18 09:53:55 -05:00
|
|
|
if (!p.empty()) {
|
2010-12-10 12:27:13 -05:00
|
|
|
PortMatrixNode::State const s = _matrix->get_association (p.front());
|
2009-11-18 09:53:55 -05:00
|
|
|
for (list<PortMatrixNode>::const_iterator i = p.begin(); i != p.end(); ++i) {
|
|
|
|
set_association (*i, toggle_state (s));
|
|
|
|
}
|
2009-07-19 17:57:51 -04:00
|
|
|
}
|
2009-07-19 16:36:46 -04:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-11-18 09:53:55 -05:00
|
|
|
} else {
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-12-06 20:44:47 -05:00
|
|
|
if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
|
2009-11-18 10:16:28 -05:00
|
|
|
/* 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) {
|
2010-12-10 12:27:13 -05:00
|
|
|
s = _matrix->get_association (n);
|
2009-11-18 10:16:28 -05:00
|
|
|
}
|
|
|
|
set_association (n, toggle_state (s));
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
x += grid_spacing ();
|
|
|
|
y += grid_spacing ();
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-11-18 10:16:28 -05:00
|
|
|
} else {
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-11-18 10:16:28 -05:00
|
|
|
PortMatrixNode const n = position_to_node (x, y);
|
|
|
|
if (n.row.bundle && n.column.bundle) {
|
2010-12-10 12:27:13 -05:00
|
|
|
PortMatrixNode::State const s = _matrix->get_association (n);
|
2009-11-18 10:16:28 -05:00
|
|
|
set_association (n, toggle_state (s));
|
|
|
|
}
|
2009-11-18 09:53:55 -05:00
|
|
|
}
|
2009-07-17 18:54:45 -04:00
|
|
|
}
|
2009-07-17 22:10:15 -04:00
|
|
|
|
2009-11-18 09:53:55 -05:00
|
|
|
require_render ();
|
2009-01-23 20:17:26 -05:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-07-17 22:27:36 -04:00
|
|
|
_body->queue_draw ();
|
2009-07-17 18:54:45 -04:00
|
|
|
}
|
2009-07-17 22:10:15 -04:00
|
|
|
|
|
|
|
_dragging = false;
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
|
|
|
|
2009-07-17 22:10:15 -04:00
|
|
|
|
2009-01-26 23:21:13 -05:00
|
|
|
void
|
|
|
|
PortMatrixGrid::draw_extra (cairo_t* cr)
|
|
|
|
{
|
|
|
|
set_source_rgba (cr, mouseover_line_colour(), 0.3);
|
|
|
|
cairo_set_line_width (cr, mouseover_line_width());
|
|
|
|
|
2009-11-16 19:30:42 -05:00
|
|
|
list<PortMatrixNode> const m = _body->mouseover ();
|
2009-07-19 16:42:14 -04:00
|
|
|
|
2009-11-16 19:30:42 -05:00
|
|
|
for (list<PortMatrixNode>::const_iterator i = m.begin(); i != m.end(); ++i) {
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
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;
|
2009-01-26 23:21:13 -05:00
|
|
|
|
2011-08-13 16:19:39 -04:00
|
|
|
if (PortMatrix::bundle_with_channels (i->row.bundle) && PortMatrix::bundle_with_channels (i->column.bundle)) {
|
2009-01-26 23:21:13 -05:00
|
|
|
|
2009-11-16 19:30:42 -05:00
|
|
|
cairo_move_to (cr, x, y);
|
|
|
|
if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
|
|
|
|
cairo_line_to (cr, component_to_parent_x (0), y);
|
|
|
|
} else if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
|
|
|
|
cairo_line_to (cr, _parent_rectangle.get_x() + _parent_rectangle.get_width(), y);
|
|
|
|
}
|
|
|
|
cairo_stroke (cr);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-11-16 19:30:42 -05:00
|
|
|
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());
|
|
|
|
} else if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
|
|
|
|
cairo_line_to (cr, x, component_to_parent_y (0));
|
|
|
|
}
|
|
|
|
cairo_stroke (cr);
|
2009-01-27 13:56:06 -05:00
|
|
|
}
|
2009-01-26 23:21:13 -05:00
|
|
|
}
|
2009-07-17 22:10:15 -04:00
|
|
|
|
2009-07-19 17:57:51 -04:00
|
|
|
if (_dragging && _drag_valid && _moved) {
|
2009-07-19 16:36:46 -04:00
|
|
|
|
|
|
|
list<PortMatrixNode> const p = nodes_on_line (_drag_start_x, _drag_start_y, _drag_x, _drag_y);
|
|
|
|
|
|
|
|
if (!p.empty()) {
|
|
|
|
|
2010-12-10 12:27:13 -05:00
|
|
|
bool const s = toggle_state (_matrix->get_association (p.front()));
|
2009-07-19 16:36:46 -04:00
|
|
|
|
|
|
|
for (list<PortMatrixNode>::const_iterator i = p.begin(); i != p.end(); ++i) {
|
|
|
|
if (s) {
|
|
|
|
draw_association_indicator (
|
|
|
|
cr,
|
2009-11-18 08:35:31 -05:00
|
|
|
component_to_parent_x (channel_to_position (i->column, _matrix->visible_columns()) * grid_spacing ()),
|
|
|
|
component_to_parent_y (channel_to_position (i->row, _matrix->visible_rows()) * grid_spacing ())
|
2009-07-19 16:36:46 -04:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
draw_empty_square (
|
|
|
|
cr,
|
2009-11-18 08:35:31 -05:00
|
|
|
component_to_parent_x (channel_to_position (i->column, _matrix->visible_columns()) * grid_spacing ()),
|
|
|
|
component_to_parent_y (channel_to_position (i->row, _matrix->visible_rows()) * grid_spacing ())
|
2009-07-19 16:36:46 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
|
|
|
|
2009-07-17 22:10:15 -04:00
|
|
|
set_source_rgba (cr, association_colour (), 0.3);
|
|
|
|
|
|
|
|
cairo_move_to (
|
|
|
|
cr,
|
|
|
|
component_to_parent_x (_drag_start_x * grid_spacing() + grid_spacing() / 2),
|
|
|
|
component_to_parent_y (_drag_start_y * grid_spacing() + grid_spacing() / 2)
|
|
|
|
);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-07-17 22:10:15 -04:00
|
|
|
cairo_line_to (
|
|
|
|
cr,
|
|
|
|
component_to_parent_x (_drag_x * grid_spacing() + grid_spacing() / 2),
|
|
|
|
component_to_parent_y (_drag_y * grid_spacing() + grid_spacing() / 2)
|
|
|
|
);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-07-17 22:10:15 -04:00
|
|
|
cairo_stroke (cr);
|
|
|
|
|
|
|
|
}
|
2009-01-26 23:21:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-11-16 19:30:42 -05:00
|
|
|
PortMatrixGrid::mouseover_changed (list<PortMatrixNode> const & old)
|
2009-01-26 23:21:13 -05:00
|
|
|
{
|
|
|
|
queue_draw_for (old);
|
|
|
|
queue_draw_for (_body->mouseover());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-07-17 22:10:15 -04:00
|
|
|
PortMatrixGrid::motion (double x, double y)
|
2009-01-26 23:21:13 -05:00
|
|
|
{
|
2009-11-16 19:30:42 -05:00
|
|
|
_body->set_mouseover (position_to_node (x, y));
|
2009-07-17 22:10:15 -04:00
|
|
|
|
|
|
|
int const px = x / grid_spacing ();
|
|
|
|
int const py = y / grid_spacing ();
|
|
|
|
|
|
|
|
if (_dragging && !_moved && ( (px != _drag_start_x || py != _drag_start_x) )) {
|
|
|
|
_moved = true;
|
|
|
|
}
|
|
|
|
|
2009-07-19 17:57:51 -04:00
|
|
|
if (_dragging && _drag_valid && _moved) {
|
2009-07-17 22:10:15 -04:00
|
|
|
_drag_x = px;
|
|
|
|
_drag_y = py;
|
|
|
|
_body->queue_draw ();
|
|
|
|
}
|
2009-01-26 23:21:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-11-16 19:30:42 -05:00
|
|
|
PortMatrixGrid::queue_draw_for (list<PortMatrixNode> const &n)
|
2009-01-26 23:21:13 -05:00
|
|
|
{
|
2009-11-16 19:30:42 -05:00
|
|
|
for (list<PortMatrixNode>::const_iterator i = n.begin(); i != n.end(); ++i) {
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-11-16 19:30:42 -05:00
|
|
|
if (i->row.bundle) {
|
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
double const y = channel_to_position (i->row, _matrix->visible_rows()) * grid_spacing ();
|
2009-11-16 19:30:42 -05:00
|
|
|
_body->queue_draw_area (
|
|
|
|
_parent_rectangle.get_x(),
|
|
|
|
component_to_parent_y (y),
|
|
|
|
_parent_rectangle.get_width(),
|
|
|
|
grid_spacing()
|
|
|
|
);
|
|
|
|
}
|
2009-01-26 23:21:13 -05:00
|
|
|
|
2009-11-16 19:30:42 -05:00
|
|
|
if (i->column.bundle) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
double const x = channel_to_position (i->column, _matrix->visible_columns()) * grid_spacing ();
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-11-16 19:30:42 -05:00
|
|
|
_body->queue_draw_area (
|
|
|
|
component_to_parent_x (x),
|
|
|
|
_parent_rectangle.get_y(),
|
|
|
|
grid_spacing(),
|
|
|
|
_parent_rectangle.get_height()
|
|
|
|
);
|
|
|
|
}
|
2009-01-26 23:21:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
PortMatrixGrid::component_to_parent_x (double x) const
|
|
|
|
{
|
|
|
|
return x - _body->xoffset() + _parent_rectangle.get_x();
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
PortMatrixGrid::parent_to_component_x (double x) const
|
|
|
|
{
|
|
|
|
return x + _body->xoffset() - _parent_rectangle.get_x();
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
PortMatrixGrid::component_to_parent_y (double y) const
|
|
|
|
{
|
|
|
|
return y - _body->yoffset() + _parent_rectangle.get_y();
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
PortMatrixGrid::parent_to_component_y (double y) const
|
|
|
|
{
|
|
|
|
return y + _body->yoffset() - _parent_rectangle.get_y();
|
|
|
|
}
|
2009-01-20 09:46:00 -05:00
|
|
|
|
2009-07-17 22:10:15 -04:00
|
|
|
list<PortMatrixNode>
|
|
|
|
PortMatrixGrid::nodes_on_line (int x0, int y0, int x1, int y1) const
|
|
|
|
{
|
|
|
|
list<PortMatrixNode> p;
|
|
|
|
|
|
|
|
bool const steep = abs (y1 - y0) > abs (x1 - x0);
|
|
|
|
if (steep) {
|
|
|
|
int tmp = x0;
|
|
|
|
x0 = y0;
|
|
|
|
y0 = tmp;
|
|
|
|
|
|
|
|
tmp = y1;
|
|
|
|
y1 = x1;
|
|
|
|
x1 = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x0 > x1) {
|
|
|
|
int tmp = x0;
|
|
|
|
x0 = x1;
|
|
|
|
x1 = tmp;
|
|
|
|
|
|
|
|
tmp = y0;
|
|
|
|
y0 = y1;
|
|
|
|
y1 = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dx = x1 - x0;
|
|
|
|
int dy = abs (y1 - y0);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-07-17 22:10:15 -04:00
|
|
|
double err = 0;
|
|
|
|
double derr = double (dy) / dx;
|
|
|
|
|
|
|
|
int y = y0;
|
|
|
|
int const ystep = y0 < y1 ? 1 : -1;
|
|
|
|
|
|
|
|
for (int x = x0; x <= x1; ++x) {
|
|
|
|
if (steep) {
|
2009-11-16 19:30:42 -05:00
|
|
|
PortMatrixNode n = position_to_node (y * grid_spacing (), x * grid_spacing ());
|
2009-07-19 17:23:16 -04:00
|
|
|
if (n.row.bundle && n.column.bundle) {
|
|
|
|
p.push_back (n);
|
|
|
|
}
|
2009-07-17 22:10:15 -04:00
|
|
|
} else {
|
2009-11-16 19:30:42 -05:00
|
|
|
PortMatrixNode n = position_to_node (x * grid_spacing (), y * grid_spacing ());
|
2009-07-19 17:23:16 -04:00
|
|
|
if (n.row.bundle && n.column.bundle) {
|
|
|
|
p.push_back (n);
|
|
|
|
}
|
2009-07-17 22:10:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
err += derr;
|
|
|
|
|
|
|
|
if (err >= 0.5) {
|
|
|
|
y += ystep;
|
|
|
|
err -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
2009-07-19 16:36:46 -04:00
|
|
|
|
|
|
|
bool
|
|
|
|
PortMatrixGrid::toggle_state (PortMatrixNode::State s) const
|
|
|
|
{
|
|
|
|
return (s == PortMatrixNode::NOT_ASSOCIATED || s == PortMatrixNode::PARTIAL);
|
|
|
|
}
|