2009-01-20 09:46:00 -05:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2009-2010 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
|
|
|
|
*
|
|
|
|
* 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 "port_matrix_component.h"
|
2009-02-05 07:56:12 -05:00
|
|
|
#include "port_matrix.h"
|
|
|
|
#include "port_matrix_body.h"
|
2009-01-20 09:46:00 -05:00
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
using namespace std;
|
|
|
|
|
2009-01-20 09:46:00 -05:00
|
|
|
/** Constructor.
|
2010-03-31 21:07:24 -04:00
|
|
|
* @param m Port matrix that we're in.
|
|
|
|
* @param b Port matrix body that we're in.
|
2009-01-20 09:46:00 -05:00
|
|
|
*/
|
2009-01-30 10:08:09 -05:00
|
|
|
PortMatrixComponent::PortMatrixComponent (PortMatrix* m, PortMatrixBody* b)
|
|
|
|
: _matrix (m),
|
|
|
|
_body (b),
|
2009-01-20 09:46:00 -05:00
|
|
|
_pixmap (0),
|
|
|
|
_render_required (true),
|
|
|
|
_dimension_computation_required (true)
|
|
|
|
{
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Destructor */
|
|
|
|
PortMatrixComponent::~PortMatrixComponent ()
|
|
|
|
{
|
|
|
|
if (_pixmap) {
|
2010-05-28 11:20:39 -04:00
|
|
|
g_object_unref (_pixmap);
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PortMatrixComponent::setup ()
|
|
|
|
{
|
|
|
|
_dimension_computation_required = true;
|
|
|
|
_render_required = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
GdkPixmap *
|
|
|
|
PortMatrixComponent::get_pixmap (GdkDrawable *drawable)
|
|
|
|
{
|
|
|
|
if (_render_required) {
|
|
|
|
|
|
|
|
if (_dimension_computation_required) {
|
|
|
|
compute_dimensions ();
|
|
|
|
_dimension_computation_required = false;
|
2009-02-05 07:56:12 -05:00
|
|
|
_body->component_size_changed ();
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we may be zero width or height; if so, just
|
|
|
|
use the smallest allowable pixmap */
|
|
|
|
if (_width == 0) {
|
|
|
|
_width = 1;
|
|
|
|
}
|
|
|
|
if (_height == 0) {
|
|
|
|
_height = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make a pixmap of the right size */
|
|
|
|
if (_pixmap) {
|
2010-05-28 11:20:39 -04:00
|
|
|
g_object_unref (_pixmap);
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
|
|
|
_pixmap = gdk_pixmap_new (drawable, _width, _height, -1);
|
|
|
|
|
|
|
|
/* render */
|
|
|
|
cairo_t* cr = gdk_cairo_create (_pixmap);
|
|
|
|
render (cr);
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
_render_required = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _pixmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PortMatrixComponent::set_source_rgb (cairo_t *cr, Gdk::Color const & c)
|
|
|
|
{
|
|
|
|
cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PortMatrixComponent::set_source_rgba (cairo_t *cr, Gdk::Color const & c, double a)
|
|
|
|
{
|
|
|
|
cairo_set_source_rgba (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p(), a);
|
|
|
|
}
|
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
pair<uint32_t, uint32_t>
|
2009-01-20 09:46:00 -05:00
|
|
|
PortMatrixComponent::dimensions ()
|
|
|
|
{
|
|
|
|
if (_dimension_computation_required) {
|
|
|
|
compute_dimensions ();
|
|
|
|
_dimension_computation_required = false;
|
2009-02-05 07:56:12 -05:00
|
|
|
_body->component_size_changed ();
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
return make_pair (_width, _height);
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
2009-01-25 01:47:11 -05:00
|
|
|
|
2009-07-17 09:57:10 -04:00
|
|
|
Gdk::Color
|
|
|
|
PortMatrixComponent::background_colour ()
|
|
|
|
{
|
|
|
|
return _matrix->get_style()->get_bg (Gtk::STATE_NORMAL);
|
|
|
|
}
|
2009-07-17 18:54:45 -04:00
|
|
|
|
2009-07-17 22:10:15 -04:00
|
|
|
/** @param g Group.
|
|
|
|
* @return Visible size of the group in grid units, taking visibility and show_only_bundles into account.
|
|
|
|
*/
|
2009-07-17 18:54:45 -04:00
|
|
|
uint32_t
|
2009-07-17 22:10:15 -04:00
|
|
|
PortMatrixComponent::group_size (boost::shared_ptr<const PortGroup> g) const
|
2009-07-17 18:54:45 -04:00
|
|
|
{
|
2009-07-17 22:10:15 -04:00
|
|
|
uint32_t s = 0;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
PortGroup::BundleList const & bundles = g->bundles ();
|
|
|
|
if (_matrix->show_only_bundles()) {
|
|
|
|
s = bundles.size();
|
2009-07-17 18:54:45 -04:00
|
|
|
} else {
|
2009-11-18 08:35:31 -05:00
|
|
|
for (PortGroup::BundleList::const_iterator i = bundles.begin(); i != bundles.end(); ++i) {
|
2011-08-13 16:19:39 -04:00
|
|
|
s += _matrix->count_of_our_type_min_1 ((*i)->bundle->nchannels());
|
2009-11-18 08:35:31 -05:00
|
|
|
}
|
2009-07-17 18:54:45 -04:00
|
|
|
}
|
|
|
|
|
2009-07-17 22:10:15 -04:00
|
|
|
return s;
|
2009-07-17 18:54:45 -04:00
|
|
|
}
|
|
|
|
|
2009-07-17 22:10:15 -04:00
|
|
|
/** @param bc Channel.
|
2011-11-08 09:15:28 -05:00
|
|
|
* @param group Group.
|
2009-11-18 08:35:31 -05:00
|
|
|
* @return Position of bc in groups in grid units, taking show_only_bundles into account.
|
2009-07-17 22:10:15 -04:00
|
|
|
*/
|
2009-07-17 18:54:45 -04:00
|
|
|
uint32_t
|
2009-11-18 08:35:31 -05:00
|
|
|
PortMatrixComponent::channel_to_position (ARDOUR::BundleChannel bc, boost::shared_ptr<const PortGroup> group) const
|
2009-07-17 18:54:45 -04:00
|
|
|
{
|
2009-07-17 22:10:15 -04:00
|
|
|
uint32_t p = 0;
|
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
PortGroup::BundleList const & bundles = group->bundles ();
|
2009-07-17 22:10:15 -04:00
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
for (PortGroup::BundleList::const_iterator i = bundles.begin(); i != bundles.end(); ++i) {
|
2009-07-17 22:10:15 -04:00
|
|
|
|
2009-12-17 13:24:23 -05:00
|
|
|
if ((*i)->bundle == bc.bundle) {
|
2009-07-17 18:54:45 -04:00
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
/* found the bundle */
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
if (_matrix->show_only_bundles()) {
|
|
|
|
return p;
|
|
|
|
} else {
|
2011-11-08 09:15:28 -05:00
|
|
|
return p + bc.bundle->overall_channel_to_type (_matrix->type (), bc.channel);
|
2009-07-17 22:10:15 -04:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
}
|
2009-07-17 22:10:15 -04:00
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
/* move past this bundle */
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
if (_matrix->show_only_bundles()) {
|
2009-07-17 22:10:15 -04:00
|
|
|
p += 1;
|
2009-11-18 08:35:31 -05:00
|
|
|
} else {
|
2011-08-13 16:19:39 -04:00
|
|
|
p += _matrix->count_of_our_type_min_1 ((*i)->bundle->nchannels());
|
2009-07-17 22:10:15 -04:00
|
|
|
}
|
2009-07-17 18:54:45 -04:00
|
|
|
}
|
|
|
|
|
2009-07-17 22:10:15 -04:00
|
|
|
return 0;
|
2009-07-17 18:54:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
ARDOUR::BundleChannel
|
|
|
|
PortMatrixComponent::position_to_channel (double p, double, boost::shared_ptr<const PortGroup> group) const
|
2009-07-17 18:54:45 -04:00
|
|
|
{
|
2009-11-16 19:30:42 -05:00
|
|
|
p /= grid_spacing ();
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
PortGroup::BundleList const & bundles = group->bundles ();
|
|
|
|
for (PortGroup::BundleList::const_iterator j = bundles.begin(); j != bundles.end(); ++j) {
|
2009-07-17 18:54:45 -04:00
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
if (_matrix->show_only_bundles()) {
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-12-07 12:39:13 -05:00
|
|
|
if (p < 1) {
|
2009-12-17 13:24:23 -05:00
|
|
|
return ARDOUR::BundleChannel ((*j)->bundle, -1);
|
2009-11-18 08:35:31 -05:00
|
|
|
} else {
|
|
|
|
p -= 1;
|
2009-07-17 18:54:45 -04:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
} else {
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-11-08 09:15:28 -05:00
|
|
|
ARDOUR::ChanCount const N = (*j)->bundle->nchannels ();
|
|
|
|
|
|
|
|
uint32_t const s = _matrix->count_of_our_type_min_1 (N);
|
2009-11-18 08:35:31 -05:00
|
|
|
if (p < s) {
|
2011-11-08 09:15:28 -05:00
|
|
|
if (p < _matrix->count_of_our_type (N)) {
|
|
|
|
return ARDOUR::BundleChannel ((*j)->bundle, (*j)->bundle->type_channel_to_overall (_matrix->type (), p));
|
|
|
|
} else {
|
|
|
|
return ARDOUR::BundleChannel (boost::shared_ptr<ARDOUR::Bundle> (), -1);
|
|
|
|
}
|
2009-11-18 08:35:31 -05:00
|
|
|
} else {
|
|
|
|
p -= s;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-07-17 18:54:45 -04:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-12-14 11:44:20 -05:00
|
|
|
return ARDOUR::BundleChannel (boost::shared_ptr<ARDOUR::Bundle> (), -1);
|
2009-07-17 18:54:45 -04:00
|
|
|
}
|