X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fport_matrix_component.cc;h=b2425dcef45ddd9e768dd1154bf57b518e70a9c1;hb=87e332fd1c89d74a67b173fc7bc3f7136605ce46;hp=02d754f5cefa8a323fba87edf1f42bdd3dec5cd5;hpb=a384dab13095f3d909e52eff9e6170ae55416601;p=ardour.git diff --git a/gtk2_ardour/port_matrix_component.cc b/gtk2_ardour/port_matrix_component.cc index 02d754f5ce..b2425dcef4 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,11 +17,15 @@ */ -#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 (PortMatrix* m, PortMatrixBody* b) : _matrix (m), @@ -30,14 +34,14 @@ PortMatrixComponent::PortMatrixComponent (PortMatrix* m, PortMatrixBody* b) _render_required (true), _dimension_computation_required (true) { - + } /** Destructor */ PortMatrixComponent::~PortMatrixComponent () { if (_pixmap) { - gdk_pixmap_unref (_pixmap); + g_object_unref (_pixmap); } } @@ -56,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 @@ -69,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); @@ -96,45 +101,110 @@ 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 std::make_pair (_width, _height); + return make_pair (_width, _height); } -std::pair -PortMatrixComponent::display_port_name (cairo_t* cr, std::string const &n, double avail) const +Gdk::Color +PortMatrixComponent::background_colour () { - /* XXX hopefully there exists a more efficient way of doing this */ - - Glib::ustring name = Glib::ustring (n).uppercase (); - bool abbreviated = false; - uint32_t width = 0; - - while (1) { - if (name.length() <= 2) { - break; + 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 ((*i)->bundle->nchannels()); } + } + + return s; +} + +/** @param bc Channel. + * @param groups List of groups. + * @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 */ - cairo_text_extents_t ext; - cairo_text_extents (cr, name.c_str(), &ext); - if (ext.width < avail) { - width = ext.width; - break; - } + if (_matrix->show_only_bundles()) { + return p; + } else { + return p + bc.channel; + } - if (abbreviated) { - name = name.substr (0, name.length() - 2) + "."; + } + + /* move past this bundle */ + + if (_matrix->show_only_bundles()) { + p += 1; } else { - name = name.substr (0, name.length() - 1) + "."; - abbreviated = true; + p += _matrix->count_of_our_type ((*i)->bundle->nchannels()); } } - return std::make_pair (name, width); + 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 { + + uint32_t const s = _matrix->count_of_our_type ((*j)->bundle->nchannels()); + if (p < s) { + return ARDOUR::BundleChannel ((*j)->bundle, p); + } else { + p -= s; + } + + } + + } + + return ARDOUR::BundleChannel (boost::shared_ptr (), -1); }