somewhat illogical and temporary workaround to the problems with consolidate & bounce...
[ardour2.git] / gtk2_ardour / port_matrix_component.cc
blobb2425dcef45ddd9e768dd1154bf57b518e70a9c1
1 /*
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"
24 using namespace std;
26 /** Constructor.
27 * @param m Port matrix that we're in.
28 * @param b Port matrix body that we're in.
30 PortMatrixComponent::PortMatrixComponent (PortMatrix* m, PortMatrixBody* b)
31 : _matrix (m),
32 _body (b),
33 _pixmap (0),
34 _render_required (true),
35 _dimension_computation_required (true)
40 /** Destructor */
41 PortMatrixComponent::~PortMatrixComponent ()
43 if (_pixmap) {
44 g_object_unref (_pixmap);
48 void
49 PortMatrixComponent::setup ()
51 _dimension_computation_required = true;
52 _render_required = true;
55 GdkPixmap *
56 PortMatrixComponent::get_pixmap (GdkDrawable *drawable)
58 if (_render_required) {
60 if (_dimension_computation_required) {
61 compute_dimensions ();
62 _dimension_computation_required = false;
63 _body->component_size_changed ();
66 /* we may be zero width or height; if so, just
67 use the smallest allowable pixmap */
68 if (_width == 0) {
69 _width = 1;
71 if (_height == 0) {
72 _height = 1;
75 /* make a pixmap of the right size */
76 if (_pixmap) {
77 g_object_unref (_pixmap);
79 _pixmap = gdk_pixmap_new (drawable, _width, _height, -1);
81 /* render */
82 cairo_t* cr = gdk_cairo_create (_pixmap);
83 render (cr);
84 cairo_destroy (cr);
86 _render_required = false;
89 return _pixmap;
92 void
93 PortMatrixComponent::set_source_rgb (cairo_t *cr, Gdk::Color const & c)
95 cairo_set_source_rgb (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p());
98 void
99 PortMatrixComponent::set_source_rgba (cairo_t *cr, Gdk::Color const & c, double a)
101 cairo_set_source_rgba (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p(), a);
104 pair<uint32_t, uint32_t>
105 PortMatrixComponent::dimensions ()
107 if (_dimension_computation_required) {
108 compute_dimensions ();
109 _dimension_computation_required = false;
110 _body->component_size_changed ();
113 return make_pair (_width, _height);
116 Gdk::Color
117 PortMatrixComponent::background_colour ()
119 return _matrix->get_style()->get_bg (Gtk::STATE_NORMAL);
122 /** @param g Group.
123 * @return Visible size of the group in grid units, taking visibility and show_only_bundles into account.
125 uint32_t
126 PortMatrixComponent::group_size (boost::shared_ptr<const PortGroup> g) const
128 uint32_t s = 0;
130 PortGroup::BundleList const & bundles = g->bundles ();
131 if (_matrix->show_only_bundles()) {
132 s = bundles.size();
133 } else {
134 for (PortGroup::BundleList::const_iterator i = bundles.begin(); i != bundles.end(); ++i) {
135 s += _matrix->count_of_our_type ((*i)->bundle->nchannels());
139 return s;
142 /** @param bc Channel.
143 * @param groups List of groups.
144 * @return Position of bc in groups in grid units, taking show_only_bundles into account.
146 uint32_t
147 PortMatrixComponent::channel_to_position (ARDOUR::BundleChannel bc, boost::shared_ptr<const PortGroup> group) const
149 uint32_t p = 0;
151 PortGroup::BundleList const & bundles = group->bundles ();
153 for (PortGroup::BundleList::const_iterator i = bundles.begin(); i != bundles.end(); ++i) {
155 if ((*i)->bundle == bc.bundle) {
157 /* found the bundle */
159 if (_matrix->show_only_bundles()) {
160 return p;
161 } else {
162 return p + bc.channel;
167 /* move past this bundle */
169 if (_matrix->show_only_bundles()) {
170 p += 1;
171 } else {
172 p += _matrix->count_of_our_type ((*i)->bundle->nchannels());
176 return 0;
180 ARDOUR::BundleChannel
181 PortMatrixComponent::position_to_channel (double p, double, boost::shared_ptr<const PortGroup> group) const
183 p /= grid_spacing ();
185 PortGroup::BundleList const & bundles = group->bundles ();
186 for (PortGroup::BundleList::const_iterator j = bundles.begin(); j != bundles.end(); ++j) {
188 if (_matrix->show_only_bundles()) {
190 if (p < 1) {
191 return ARDOUR::BundleChannel ((*j)->bundle, -1);
192 } else {
193 p -= 1;
196 } else {
198 uint32_t const s = _matrix->count_of_our_type ((*j)->bundle->nchannels());
199 if (p < s) {
200 return ARDOUR::BundleChannel ((*j)->bundle, p);
201 } else {
202 p -= s;
209 return ARDOUR::BundleChannel (boost::shared_ptr<ARDOUR::Bundle> (), -1);