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"
24 #include "ui_config.h"
29 * @param m Port matrix that we're in.
30 * @param b Port matrix body that we're in.
32 PortMatrixComponent::PortMatrixComponent (PortMatrix* m, PortMatrixBody* b)
36 _render_required (true),
37 _dimension_computation_required (true)
43 PortMatrixComponent::~PortMatrixComponent ()
46 g_object_unref (_pixmap);
51 PortMatrixComponent::setup ()
53 _dimension_computation_required = true;
54 _render_required = true;
58 PortMatrixComponent::get_pixmap (GdkDrawable *drawable)
60 if (_render_required) {
62 if (_dimension_computation_required) {
63 compute_dimensions ();
64 _dimension_computation_required = false;
65 _body->component_size_changed ();
68 /* we may be zero width or height; if so, just
69 use the smallest allowable pixmap */
77 /* make a pixmap of the right size */
79 g_object_unref (_pixmap);
81 _pixmap = gdk_pixmap_new (drawable, _width, _height, -1);
84 cairo_t* cr = gdk_cairo_create (_pixmap);
85 cairo_set_font_size (cr, UIConfiguration::instance().get_ui_scale() * 10);
89 _render_required = false;
96 PortMatrixComponent::set_source_rgb (cairo_t *cr, Gdk::Color const & c)
98 cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
102 PortMatrixComponent::set_source_rgba (cairo_t *cr, Gdk::Color const & c, double a)
104 cairo_set_source_rgba (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p(), a);
107 pair<uint32_t, uint32_t>
108 PortMatrixComponent::dimensions ()
110 if (_dimension_computation_required) {
111 compute_dimensions ();
112 _dimension_computation_required = false;
113 _body->component_size_changed ();
116 return make_pair (_width, _height);
120 PortMatrixComponent::background_colour ()
122 return _matrix->get_style()->get_bg (Gtk::STATE_NORMAL);
126 * @return Visible size of the group in grid units, taking visibility and show_only_bundles into account.
129 PortMatrixComponent::group_size (boost::shared_ptr<const PortGroup> g) const
133 PortGroup::BundleList const & bundles = g->bundles ();
134 if (_matrix->show_only_bundles()) {
137 for (PortGroup::BundleList::const_iterator i = bundles.begin(); i != bundles.end(); ++i) {
138 s += _matrix->count_of_our_type_min_1 ((*i)->bundle->nchannels());
145 /** @param bc Channel.
146 * @param group Group.
147 * @return Position of bc in groups in grid units, taking show_only_bundles into account.
150 PortMatrixComponent::channel_to_position (ARDOUR::BundleChannel bc, boost::shared_ptr<const PortGroup> group) const
154 PortGroup::BundleList const & bundles = group->bundles ();
156 for (PortGroup::BundleList::const_iterator i = bundles.begin(); i != bundles.end(); ++i) {
158 if ((*i)->bundle == bc.bundle) {
160 /* found the bundle */
162 if (_matrix->show_only_bundles()) {
165 return p + bc.bundle->overall_channel_to_type (_matrix->type (), bc.channel);
170 /* move past this bundle */
172 if (_matrix->show_only_bundles()) {
175 p += _matrix->count_of_our_type_min_1 ((*i)->bundle->nchannels());
183 ARDOUR::BundleChannel
184 PortMatrixComponent::position_to_channel (double p, double, boost::shared_ptr<const PortGroup> group) const
186 p /= grid_spacing ();
188 PortGroup::BundleList const & bundles = group->bundles ();
189 for (PortGroup::BundleList::const_iterator j = bundles.begin(); j != bundles.end(); ++j) {
191 if (_matrix->show_only_bundles()) {
194 return ARDOUR::BundleChannel ((*j)->bundle, -1);
201 ARDOUR::ChanCount const N = (*j)->bundle->nchannels ();
203 uint32_t const s = _matrix->count_of_our_type_min_1 (N);
205 if (p < _matrix->count_of_our_type (N)) {
206 return ARDOUR::BundleChannel ((*j)->bundle, (*j)->bundle->type_channel_to_overall (_matrix->type (), p));
208 return ARDOUR::BundleChannel (boost::shared_ptr<ARDOUR::Bundle> (), -1);
218 return ARDOUR::BundleChannel (boost::shared_ptr<ARDOUR::Bundle> (), -1);
222 PortMatrixComponent::grid_spacing ()
224 return UIConfiguration::instance().get_ui_scale() * 24;