2009-01-20 09:46:00 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2002-2009 Paul Davis
|
|
|
|
|
|
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <cairo/cairo.h>
|
|
|
|
#include "ardour/bundle.h"
|
2009-01-25 01:47:11 -05:00
|
|
|
#include "ardour/types.h"
|
2009-01-20 09:46:00 -05:00
|
|
|
#include "port_matrix_grid.h"
|
|
|
|
#include "port_matrix.h"
|
2009-02-04 12:05:26 -05:00
|
|
|
#include "port_matrix_body.h"
|
2009-01-20 09:46:00 -05:00
|
|
|
|
2009-01-30 10:08:09 -05:00
|
|
|
PortMatrixGrid::PortMatrixGrid (PortMatrix* m, PortMatrixBody* b)
|
|
|
|
: PortMatrixComponent (m, b)
|
2009-01-20 09:46:00 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PortMatrixGrid::compute_dimensions ()
|
|
|
|
{
|
|
|
|
_width = 0;
|
2009-01-30 10:08:09 -05:00
|
|
|
ARDOUR::BundleList const c = _matrix->columns()->bundles();
|
2009-01-25 01:47:11 -05:00
|
|
|
for (ARDOUR::BundleList::const_iterator i = c.begin(); i != c.end(); ++i) {
|
|
|
|
_width += (*i)->nchannels() * column_width();
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
_height = 0;
|
2009-01-30 10:08:09 -05:00
|
|
|
ARDOUR::BundleList const r = _matrix->rows()->bundles();
|
2009-01-25 01:47:11 -05:00
|
|
|
for (ARDOUR::BundleList::const_iterator i = r.begin(); i != r.end(); ++i) {
|
|
|
|
_height += (*i)->nchannels() * row_height();
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PortMatrixGrid::render (cairo_t* cr)
|
|
|
|
{
|
|
|
|
/* BACKGROUND */
|
|
|
|
|
|
|
|
set_source_rgb (cr, background_colour());
|
|
|
|
cairo_rectangle (cr, 0, 0, _width, _height);
|
|
|
|
cairo_fill (cr);
|
|
|
|
|
|
|
|
/* VERTICAL GRID LINES */
|
|
|
|
|
|
|
|
set_source_rgb (cr, grid_colour());
|
|
|
|
uint32_t x = 0;
|
2009-01-30 10:08:09 -05:00
|
|
|
ARDOUR::BundleList const c = _matrix->columns()->bundles();
|
2009-01-25 01:47:11 -05:00
|
|
|
for (ARDOUR::BundleList::size_type i = 0; i < c.size(); ++i) {
|
2009-01-20 09:46:00 -05:00
|
|
|
|
|
|
|
cairo_set_line_width (cr, thin_grid_line_width());
|
2009-01-25 01:47:11 -05:00
|
|
|
for (uint32_t j = 1; j < c[i]->nchannels(); ++j) {
|
2009-01-20 09:46:00 -05:00
|
|
|
x += column_width();
|
|
|
|
cairo_move_to (cr, x, 0);
|
|
|
|
cairo_line_to (cr, x, _height);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
|
2009-01-25 01:47:11 -05:00
|
|
|
if (i < (c.size() - 1)) {
|
2009-01-20 09:46:00 -05:00
|
|
|
x += column_width();
|
|
|
|
cairo_set_line_width (cr, thick_grid_line_width());
|
|
|
|
cairo_move_to (cr, x, 0);
|
|
|
|
cairo_line_to (cr, x, _height);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t grid_width = x + column_width();
|
|
|
|
|
|
|
|
/* HORIZONTAL GRID LINES */
|
|
|
|
|
|
|
|
uint32_t y = 0;
|
2009-01-30 10:08:09 -05:00
|
|
|
ARDOUR::BundleList const r = _matrix->rows()->bundles();
|
2009-01-25 01:47:11 -05:00
|
|
|
for (ARDOUR::BundleList::size_type i = 0; i < r.size(); ++i) {
|
2009-01-20 09:46:00 -05:00
|
|
|
|
|
|
|
cairo_set_line_width (cr, thin_grid_line_width());
|
2009-01-25 01:47:11 -05:00
|
|
|
for (uint32_t j = 1; j < r[i]->nchannels(); ++j) {
|
2009-01-20 09:46:00 -05:00
|
|
|
y += row_height();
|
|
|
|
cairo_move_to (cr, 0, y);
|
|
|
|
cairo_line_to (cr, grid_width, y);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
|
2009-01-25 01:47:11 -05:00
|
|
|
if (i < (r.size() - 1)) {
|
2009-01-20 09:46:00 -05:00
|
|
|
y += row_height();
|
|
|
|
cairo_set_line_width (cr, thick_grid_line_width());
|
|
|
|
cairo_move_to (cr, 0, y);
|
|
|
|
cairo_line_to (cr, grid_width, y);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ASSOCIATION INDICATORS */
|
|
|
|
|
|
|
|
uint32_t bx = 0;
|
|
|
|
uint32_t by = 0;
|
|
|
|
|
2009-01-25 01:47:11 -05:00
|
|
|
for (ARDOUR::BundleList::const_iterator i = c.begin(); i < c.end(); ++i) {
|
2009-01-20 09:46:00 -05:00
|
|
|
by = 0;
|
|
|
|
|
2009-01-25 01:47:11 -05:00
|
|
|
for (ARDOUR::BundleList::const_iterator j = r.begin(); j < r.end(); ++j) {
|
2009-01-20 09:46:00 -05:00
|
|
|
|
|
|
|
x = bx;
|
|
|
|
for (uint32_t k = 0; k < (*i)->nchannels (); k++) {
|
|
|
|
|
|
|
|
y = by;
|
|
|
|
for (uint32_t l = 0; l < (*j)->nchannels (); ++l) {
|
2009-01-30 10:08:09 -05:00
|
|
|
|
|
|
|
ARDOUR::BundleChannel c[2];
|
|
|
|
c[_matrix->column_index()] = ARDOUR::BundleChannel (*i, k);
|
|
|
|
c[_matrix->row_index()] = ARDOUR::BundleChannel (*j, l);
|
2009-01-20 09:46:00 -05:00
|
|
|
|
2009-01-30 10:08:09 -05:00
|
|
|
PortMatrix::State const s = _matrix->get_state (c);
|
2009-01-20 09:46:00 -05:00
|
|
|
|
2009-01-23 16:24:11 -05:00
|
|
|
switch (s) {
|
|
|
|
case PortMatrix::ASSOCIATED:
|
2009-01-20 09:46:00 -05:00
|
|
|
set_source_rgba (cr, association_colour(), 0.5);
|
|
|
|
cairo_arc (
|
|
|
|
cr,
|
|
|
|
x + column_width() / 2,
|
|
|
|
y + column_width() / 2,
|
|
|
|
(column_width() - (2 * connection_indicator_pad())) / 2,
|
|
|
|
0,
|
|
|
|
2 * M_PI
|
|
|
|
);
|
|
|
|
|
|
|
|
cairo_fill (cr);
|
2009-01-23 16:24:11 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PortMatrix::UNKNOWN:
|
|
|
|
set_source_rgba (cr, unknown_colour(), 0.5);
|
|
|
|
cairo_rectangle (
|
|
|
|
cr,
|
|
|
|
x + thick_grid_line_width(),
|
|
|
|
y + thick_grid_line_width(),
|
|
|
|
column_width() - 2 * thick_grid_line_width(),
|
|
|
|
row_height() - 2 * thick_grid_line_width()
|
|
|
|
);
|
|
|
|
cairo_fill (cr);
|
|
|
|
break;
|
2009-01-20 09:46:00 -05:00
|
|
|
|
2009-01-23 16:24:11 -05:00
|
|
|
case PortMatrix::NOT_ASSOCIATED:
|
|
|
|
break;
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
2009-01-23 16:24:11 -05:00
|
|
|
|
2009-01-20 09:46:00 -05:00
|
|
|
y += row_height();
|
|
|
|
}
|
|
|
|
x += column_width();
|
|
|
|
}
|
|
|
|
|
|
|
|
by += (*j)->nchannels () * row_height();
|
|
|
|
}
|
|
|
|
|
|
|
|
bx += (*i)->nchannels () * column_width();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-26 23:21:13 -05:00
|
|
|
PortMatrixNode
|
|
|
|
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-01-30 10:08:09 -05:00
|
|
|
position_to_channel (y, _matrix->rows()->bundles(), row_height()),
|
|
|
|
position_to_channel (x, _matrix->columns()->bundles(), column_width())
|
2009-01-26 23:21:13 -05:00
|
|
|
);
|
|
|
|
}
|
2009-01-20 09:46:00 -05:00
|
|
|
|
|
|
|
|
2009-01-30 10:08:09 -05:00
|
|
|
ARDOUR::BundleChannel
|
2009-01-26 23:21:13 -05:00
|
|
|
PortMatrixGrid::position_to_channel (double p, ARDOUR::BundleList const& bundles, double inc) const
|
|
|
|
{
|
|
|
|
uint32_t pos = p / inc;
|
|
|
|
|
|
|
|
for (ARDOUR::BundleList::const_iterator i = bundles.begin(); i != bundles.end(); ++i) {
|
|
|
|
if (pos < (*i)->nchannels()) {
|
2009-01-30 10:08:09 -05:00
|
|
|
return ARDOUR::BundleChannel (*i, pos);
|
2009-01-20 09:46:00 -05:00
|
|
|
} else {
|
2009-01-26 23:21:13 -05:00
|
|
|
pos -= (*i)->nchannels();
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
|
|
|
}
|
2009-01-26 23:21:13 -05:00
|
|
|
|
2009-01-30 10:08:09 -05:00
|
|
|
return ARDOUR::BundleChannel (boost::shared_ptr<ARDOUR::Bundle> (), 0);
|
2009-01-26 23:21:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double
|
|
|
|
PortMatrixGrid::channel_position (
|
2009-01-30 10:08:09 -05:00
|
|
|
ARDOUR::BundleChannel bc,
|
2009-01-26 23:21:13 -05:00
|
|
|
ARDOUR::BundleList const& bundles,
|
|
|
|
double inc) const
|
|
|
|
{
|
|
|
|
double p = 0;
|
|
|
|
|
|
|
|
ARDOUR::BundleList::const_iterator i = bundles.begin ();
|
|
|
|
while (i != bundles.end() && *i != bc.bundle) {
|
|
|
|
p += inc * (*i)->nchannels();
|
|
|
|
++i;
|
|
|
|
}
|
2009-01-20 09:46:00 -05:00
|
|
|
|
2009-01-26 23:21:13 -05:00
|
|
|
if (i == bundles.end()) {
|
|
|
|
return 0;
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
|
|
|
|
2009-01-26 23:21:13 -05:00
|
|
|
p += inc * bc.channel;
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PortMatrixGrid::button_press (double x, double y, int b)
|
|
|
|
{
|
|
|
|
PortMatrixNode const node = position_to_node (x, y);
|
2009-01-23 20:17:26 -05:00
|
|
|
|
2009-01-26 23:21:13 -05:00
|
|
|
if (node.row.bundle && node.column.bundle) {
|
2009-01-23 20:46:13 -05:00
|
|
|
|
2009-01-30 10:08:09 -05:00
|
|
|
ARDOUR::BundleChannel c[2];
|
|
|
|
c[_matrix->row_index()] = node.row;
|
|
|
|
c[_matrix->column_index()] = node.column;
|
|
|
|
|
|
|
|
PortMatrix::State const s = _matrix->get_state (c);
|
2009-01-26 23:21:13 -05:00
|
|
|
|
2009-01-23 20:17:26 -05:00
|
|
|
if (s == PortMatrix::ASSOCIATED || s == PortMatrix::NOT_ASSOCIATED) {
|
|
|
|
|
|
|
|
bool const n = !(s == PortMatrix::ASSOCIATED);
|
2009-01-30 10:08:09 -05:00
|
|
|
|
|
|
|
ARDOUR::BundleChannel c[2];
|
|
|
|
c[_matrix->row_index()] = node.row;
|
|
|
|
c[_matrix->column_index()] = node.column;
|
2009-01-23 20:17:26 -05:00
|
|
|
|
2009-01-30 10:08:09 -05:00
|
|
|
_matrix->set_state (c, n);
|
2009-01-23 20:17:26 -05:00
|
|
|
}
|
2009-01-20 09:46:00 -05:00
|
|
|
|
|
|
|
require_render ();
|
|
|
|
_body->queue_draw ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-01-27 13:56:06 -05:00
|
|
|
double const x = component_to_parent_x (
|
2009-01-30 10:08:09 -05:00
|
|
|
channel_position (_body->mouseover().column, _matrix->columns()->bundles(), column_width()) + column_width() / 2
|
2009-01-27 13:56:06 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
double const y = component_to_parent_y (
|
2009-01-30 10:08:09 -05:00
|
|
|
channel_position (_body->mouseover().row, _matrix->rows()->bundles(), row_height()) + row_height() / 2
|
2009-01-27 13:56:06 -05:00
|
|
|
);
|
|
|
|
|
2009-01-26 23:21:13 -05:00
|
|
|
if (_body->mouseover().row.bundle) {
|
|
|
|
|
2009-01-27 13:56:06 -05:00
|
|
|
cairo_move_to (cr, x, y);
|
2009-01-30 10:08:09 -05:00
|
|
|
if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
|
2009-01-27 13:56:06 -05:00
|
|
|
cairo_line_to (cr, component_to_parent_x (0), y);
|
2009-01-30 10:08:09 -05:00
|
|
|
} else if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
|
2009-01-27 13:56:06 -05:00
|
|
|
cairo_line_to (cr, _parent_rectangle.get_x() + _parent_rectangle.get_width(), y);
|
|
|
|
}
|
2009-01-26 23:21:13 -05:00
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_body->mouseover().column.bundle) {
|
|
|
|
|
2009-01-27 13:56:06 -05:00
|
|
|
cairo_move_to (cr, x, y);
|
2009-01-30 10:08:09 -05:00
|
|
|
if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
|
2009-01-27 13:56:06 -05:00
|
|
|
cairo_line_to (cr, x, _parent_rectangle.get_y() + _parent_rectangle.get_height());
|
2009-01-30 10:08:09 -05:00
|
|
|
} else if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
|
2009-01-27 13:56:06 -05:00
|
|
|
cairo_line_to (cr, x, component_to_parent_y (0));
|
|
|
|
}
|
2009-01-26 23:21:13 -05:00
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PortMatrixGrid::mouseover_changed (PortMatrixNode const& old)
|
|
|
|
{
|
|
|
|
queue_draw_for (old);
|
|
|
|
queue_draw_for (_body->mouseover());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PortMatrixGrid::mouseover_event (double x, double y)
|
|
|
|
{
|
|
|
|
_body->set_mouseover (position_to_node (x, y));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PortMatrixGrid::queue_draw_for (PortMatrixNode const &n)
|
|
|
|
{
|
|
|
|
if (n.row.bundle) {
|
|
|
|
|
2009-01-30 10:08:09 -05:00
|
|
|
double const y = channel_position (n.row, _matrix->rows()->bundles(), row_height());
|
2009-01-26 23:21:13 -05:00
|
|
|
_body->queue_draw_area (
|
|
|
|
_parent_rectangle.get_x(),
|
|
|
|
component_to_parent_y (y),
|
|
|
|
_parent_rectangle.get_width(),
|
|
|
|
row_height()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n.column.bundle) {
|
|
|
|
|
2009-01-30 10:08:09 -05:00
|
|
|
double const x = channel_position (n.column, _matrix->columns()->bundles(), column_width());
|
2009-01-26 23:21:13 -05:00
|
|
|
|
|
|
|
_body->queue_draw_area (
|
|
|
|
component_to_parent_x (x),
|
|
|
|
_parent_rectangle.get_y(),
|
|
|
|
column_width(),
|
|
|
|
_parent_rectangle.get_height()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|