2 Copyright (C) 2002-2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "port_matrix_component.h"
21 #include "port_matrix.h"
22 #include "port_matrix_body.h"
27 * @param p Port matrix that we're in.
29 PortMatrixComponent::PortMatrixComponent (PortMatrix* m, PortMatrixBody* b)
33 _render_required (true),
34 _dimension_computation_required (true)
40 PortMatrixComponent::~PortMatrixComponent ()
43 gdk_pixmap_unref (_pixmap);
48 PortMatrixComponent::setup ()
50 _dimension_computation_required = true;
51 _render_required = true;
55 PortMatrixComponent::get_pixmap (GdkDrawable *drawable)
57 if (_render_required) {
59 if (_dimension_computation_required) {
60 compute_dimensions ();
61 _dimension_computation_required = false;
62 _body->component_size_changed ();
65 /* we may be zero width or height; if so, just
66 use the smallest allowable pixmap */
74 /* make a pixmap of the right size */
76 gdk_pixmap_unref (_pixmap);
78 _pixmap = gdk_pixmap_new (drawable, _width, _height, -1);
81 cairo_t* cr = gdk_cairo_create (_pixmap);
85 _render_required = false;
92 PortMatrixComponent::set_source_rgb (cairo_t *cr, Gdk::Color const & c)
94 cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
98 PortMatrixComponent::set_source_rgba (cairo_t *cr, Gdk::Color const & c, double a)
100 cairo_set_source_rgba (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p(), a);
103 pair<uint32_t, uint32_t>
104 PortMatrixComponent::dimensions ()
106 if (_dimension_computation_required) {
107 compute_dimensions ();
108 _dimension_computation_required = false;
109 _body->component_size_changed ();
112 return make_pair (_width, _height);
116 PortMatrixComponent::background_colour ()
118 return _matrix->get_style()->get_bg (Gtk::STATE_NORMAL);
122 * @return Visible size of the group in grid units, taking visibility and show_only_bundles into account.
125 PortMatrixComponent::group_size (boost::shared_ptr<const PortGroup> g) const
130 PortGroup::BundleList const & bundles = g->bundles ();
131 if (_matrix->show_only_bundles()) {
134 for (PortGroup::BundleList::const_iterator i = bundles.begin(); i != bundles.end(); ++i) {
135 s += i->bundle->nchannels();
145 /** @param bc Channel.
146 * @param groups List of groups.
147 * @return Position of bc in groups in grid units, taking visibility and show_only_bundles into account.
150 PortMatrixComponent::channel_to_position (ARDOUR::BundleChannel bc, PortGroupList const * groups) const
154 for (PortGroupList::List::const_iterator i = groups->begin(); i != groups->end(); ++i) {
156 PortGroup::BundleList const & bundles = (*i)->bundles ();
158 for (PortGroup::BundleList::const_iterator j = bundles.begin(); j != bundles.end(); ++j) {
160 if (j->bundle == bc.bundle) {
162 /* found the bundle */
164 if (_matrix->show_only_bundles() || !(*i)->visible()) {
167 return p + bc.channel;
172 if ((*i)->visible()) {
174 /* move past this bundle */
176 if (_matrix->show_only_bundles()) {
179 p += j->bundle->nchannels ();
184 if (!(*i)->visible()) {
185 /* if this group isn't visible we won't have updated p, so do it now */
194 pair<boost::shared_ptr<PortGroup>, ARDOUR::BundleChannel>
195 PortMatrixComponent::position_to_group_and_channel (uint32_t p, PortGroupList const * groups) const
197 PortGroupList::List::const_iterator i = groups->begin ();
199 while (i != groups->end()) {
201 uint32_t const gs = group_size (*i);
205 /* it's in this group */
207 if (!(*i)->visible()) {
208 return make_pair (*i, ARDOUR::BundleChannel (boost::shared_ptr<ARDOUR::Bundle> (), 0));
211 PortGroup::BundleList const & bundles = (*i)->bundles ();
212 for (PortGroup::BundleList::const_iterator j = bundles.begin(); j != bundles.end(); ++j) {
214 if (_matrix->show_only_bundles()) {
217 return make_pair (*i, ARDOUR::BundleChannel (j->bundle, 0));
224 uint32_t const s = j->bundle->nchannels ();
226 return make_pair (*i, ARDOUR::BundleChannel (j->bundle, p));
244 return make_pair (boost::shared_ptr<PortGroup> (), ARDOUR::BundleChannel (boost::shared_ptr<ARDOUR::Bundle> (), 0));