2 * Copyright (C) 2009-2010 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
4 * Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "port_matrix_component.h"
22 #include "port_matrix.h"
23 #include "port_matrix_body.h"
28 * @param m Port matrix that we're in.
29 * @param b Port matrix body that we're in.
31 PortMatrixComponent::PortMatrixComponent (PortMatrix* m, PortMatrixBody* b)
35 _render_required (true),
36 _dimension_computation_required (true)
42 PortMatrixComponent::~PortMatrixComponent ()
45 g_object_unref (_pixmap);
50 PortMatrixComponent::setup ()
52 _dimension_computation_required = true;
53 _render_required = true;
57 PortMatrixComponent::get_pixmap (GdkDrawable *drawable)
59 if (_render_required) {
61 if (_dimension_computation_required) {
62 compute_dimensions ();
63 _dimension_computation_required = false;
64 _body->component_size_changed ();
67 /* we may be zero width or height; if so, just
68 use the smallest allowable pixmap */
76 /* make a pixmap of the right size */
78 g_object_unref (_pixmap);
80 _pixmap = gdk_pixmap_new (drawable, _width, _height, -1);
83 cairo_t* cr = gdk_cairo_create (_pixmap);
87 _render_required = false;
94 PortMatrixComponent::set_source_rgb (cairo_t *cr, Gdk::Color const & c)
96 cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
100 PortMatrixComponent::set_source_rgba (cairo_t *cr, Gdk::Color const & c, double a)
102 cairo_set_source_rgba (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p(), a);
105 pair<uint32_t, uint32_t>
106 PortMatrixComponent::dimensions ()
108 if (_dimension_computation_required) {
109 compute_dimensions ();
110 _dimension_computation_required = false;
111 _body->component_size_changed ();
114 return make_pair (_width, _height);
118 PortMatrixComponent::background_colour ()
120 return _matrix->get_style()->get_bg (Gtk::STATE_NORMAL);
124 * @return Visible size of the group in grid units, taking visibility and show_only_bundles into account.
127 PortMatrixComponent::group_size (boost::shared_ptr<const PortGroup> g) const
131 PortGroup::BundleList const & bundles = g->bundles ();
132 if (_matrix->show_only_bundles()) {
135 for (PortGroup::BundleList::const_iterator i = bundles.begin(); i != bundles.end(); ++i) {
136 s += _matrix->count_of_our_type_min_1 ((*i)->bundle->nchannels());
143 /** @param bc Channel.
144 * @param group Group.
145 * @return Position of bc in groups in grid units, taking show_only_bundles into account.
148 PortMatrixComponent::channel_to_position (ARDOUR::BundleChannel bc, boost::shared_ptr<const PortGroup> group) const
152 PortGroup::BundleList const & bundles = group->bundles ();
154 for (PortGroup::BundleList::const_iterator i = bundles.begin(); i != bundles.end(); ++i) {
156 if ((*i)->bundle == bc.bundle) {
158 /* found the bundle */
160 if (_matrix->show_only_bundles()) {
163 return p + bc.bundle->overall_channel_to_type (_matrix->type (), bc.channel);
168 /* move past this bundle */
170 if (_matrix->show_only_bundles()) {
173 p += _matrix->count_of_our_type_min_1 ((*i)->bundle->nchannels());
181 ARDOUR::BundleChannel
182 PortMatrixComponent::position_to_channel (double p, double, boost::shared_ptr<const PortGroup> group) const
184 p /= grid_spacing ();
186 PortGroup::BundleList const & bundles = group->bundles ();
187 for (PortGroup::BundleList::const_iterator j = bundles.begin(); j != bundles.end(); ++j) {
189 if (_matrix->show_only_bundles()) {
192 return ARDOUR::BundleChannel ((*j)->bundle, -1);
199 ARDOUR::ChanCount const N = (*j)->bundle->nchannels ();
201 uint32_t const s = _matrix->count_of_our_type_min_1 (N);
203 if (p < _matrix->count_of_our_type (N)) {
204 return ARDOUR::BundleChannel ((*j)->bundle, (*j)->bundle->type_channel_to_overall (_matrix->type (), p));
206 return ARDOUR::BundleChannel (boost::shared_ptr<ARDOUR::Bundle> (), -1);
216 return ARDOUR::BundleChannel (boost::shared_ptr<ARDOUR::Bundle> (), -1);