X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=gtk2_ardour%2Fport_matrix_component.cc;h=5e11527d299fefc4f4369d7021905a0541320979;hb=cef341631b55526e4b2bad940064491922c07701;hp=e2d1e07027538e1358e02e5c8f1f6f8fa53ca601;hpb=61db2175eb8b8fffd0c1796ace78ac33c9e1adf0;p=ardour.git diff --git a/gtk2_ardour/port_matrix_component.cc b/gtk2_ardour/port_matrix_component.cc index e2d1e07027..5e11527d29 100644 --- a/gtk2_ardour/port_matrix_component.cc +++ b/gtk2_ardour/port_matrix_component.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2009 Paul Davis + Copyright (C) 2002-2009 Paul Davis 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 @@ -17,26 +17,31 @@ */ -#include #include "port_matrix_component.h" +#include "port_matrix.h" +#include "port_matrix_body.h" + +using namespace std; /** Constructor. - * @param p Port matrix that we're in. + * @param m Port matrix that we're in. + * @param b Port matrix body that we're in. */ -PortMatrixComponent::PortMatrixComponent (PortMatrixBody* b) - : _body (b), +PortMatrixComponent::PortMatrixComponent (PortMatrix* m, PortMatrixBody* b) + : _matrix (m), + _body (b), _pixmap (0), _render_required (true), _dimension_computation_required (true) { - + } /** Destructor */ PortMatrixComponent::~PortMatrixComponent () { if (_pixmap) { - gdk_pixmap_unref (_pixmap); + g_object_unref (_pixmap); } } @@ -55,6 +60,7 @@ PortMatrixComponent::get_pixmap (GdkDrawable *drawable) if (_dimension_computation_required) { compute_dimensions (); _dimension_computation_required = false; + _body->component_size_changed (); } /* we may be zero width or height; if so, just @@ -68,7 +74,7 @@ PortMatrixComponent::get_pixmap (GdkDrawable *drawable) /* make a pixmap of the right size */ if (_pixmap) { - gdk_pixmap_unref (_pixmap); + g_object_unref (_pixmap); } _pixmap = gdk_pixmap_new (drawable, _width, _height, -1); @@ -95,13 +101,116 @@ PortMatrixComponent::set_source_rgba (cairo_t *cr, Gdk::Color const & c, double cairo_set_source_rgba (cr, c.get_red_p(), c.get_green_p(), c.get_blue_p(), a); } -std::pair +pair PortMatrixComponent::dimensions () { if (_dimension_computation_required) { compute_dimensions (); _dimension_computation_required = false; + _body->component_size_changed (); + } + + return make_pair (_width, _height); +} + +Gdk::Color +PortMatrixComponent::background_colour () +{ + return _matrix->get_style()->get_bg (Gtk::STATE_NORMAL); +} + +/** @param g Group. + * @return Visible size of the group in grid units, taking visibility and show_only_bundles into account. + */ +uint32_t +PortMatrixComponent::group_size (boost::shared_ptr g) const +{ + uint32_t s = 0; + + PortGroup::BundleList const & bundles = g->bundles (); + if (_matrix->show_only_bundles()) { + s = bundles.size(); + } else { + for (PortGroup::BundleList::const_iterator i = bundles.begin(); i != bundles.end(); ++i) { + s += _matrix->count_of_our_type_min_1 ((*i)->bundle->nchannels()); + } + } + + return s; +} + +/** @param bc Channel. + * @param group Group. + * @return Position of bc in groups in grid units, taking show_only_bundles into account. + */ +uint32_t +PortMatrixComponent::channel_to_position (ARDOUR::BundleChannel bc, boost::shared_ptr group) const +{ + uint32_t p = 0; + + PortGroup::BundleList const & bundles = group->bundles (); + + for (PortGroup::BundleList::const_iterator i = bundles.begin(); i != bundles.end(); ++i) { + + if ((*i)->bundle == bc.bundle) { + + /* found the bundle */ + + if (_matrix->show_only_bundles()) { + return p; + } else { + return p + bc.bundle->overall_channel_to_type (_matrix->type (), bc.channel); + } + + } + + /* move past this bundle */ + + if (_matrix->show_only_bundles()) { + p += 1; + } else { + p += _matrix->count_of_our_type_min_1 ((*i)->bundle->nchannels()); + } + } + + return 0; +} + + +ARDOUR::BundleChannel +PortMatrixComponent::position_to_channel (double p, double, boost::shared_ptr group) const +{ + p /= grid_spacing (); + + PortGroup::BundleList const & bundles = group->bundles (); + for (PortGroup::BundleList::const_iterator j = bundles.begin(); j != bundles.end(); ++j) { + + if (_matrix->show_only_bundles()) { + + if (p < 1) { + return ARDOUR::BundleChannel ((*j)->bundle, -1); + } else { + p -= 1; + } + + } else { + + ARDOUR::ChanCount const N = (*j)->bundle->nchannels (); + + uint32_t const s = _matrix->count_of_our_type_min_1 (N); + if (p < s) { + 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 (), -1); + } + } else { + p -= s; + } + + } + } - return std::make_pair (_width, _height); + return ARDOUR::BundleChannel (boost::shared_ptr (), -1); }