2 Copyright (C) 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 <boost/foreach.hpp>
22 #include "gtkmm2ext/utils.h"
24 #include "ardour/route_group.h"
26 #include "gtkmm2ext/colors.h"
28 #include "mixer_group_tabs.h"
29 #include "mixer_strip.h"
31 #include "rgb_macros.h"
32 #include "route_group_dialog.h"
33 #include "ui_config.h"
40 using namespace ARDOUR;
41 using namespace ARDOUR_UI_UTILS;
44 MixerGroupTabs::MixerGroupTabs (Mixer_UI* m)
52 MixerGroupTabs::compute_tabs () const
61 TreeModel::Children rows = _mixer->track_model->children ();
62 for (TreeModel::Children::iterator i = rows.begin(); i != rows.end(); ++i) {
64 AxisView* av = (*i)[_mixer->stripable_columns.strip];
65 MixerStrip* s = dynamic_cast<MixerStrip*> (av);
71 if (s->route()->is_master() || s->route()->is_monitor() || !s->marked_for_display()) {
75 if (s->route()->mixbus()) {
80 RouteGroup* g = s->route_group ();
92 tab.color = group_color (g);
97 s->get_size_request (ww, wh); // widget may not be realized, get_width() is invalid.
103 tabs.push_back (tab);
110 MixerGroupTabs::draw_tab (cairo_t* cr, Tab const & tab)
112 double const arc_radius = get_height();
115 if (tab.group && tab.group->is_active()) {
116 Gtkmm2ext::color_to_rgba (tab.color, r, g, b, a);
118 Gtkmm2ext::color_to_rgba (UIConfiguration::instance().color ("inactive group tab"), r, g, b, a);
123 cairo_set_source_rgba (cr, r, g, b, a);
124 cairo_arc (cr, tab.from + arc_radius, get_height(), arc_radius, M_PI, 3 * M_PI / 2);
125 cairo_line_to (cr, tab.to - arc_radius, 0);
126 cairo_arc (cr, tab.to - arc_radius, get_height(), arc_radius, 3 * M_PI / 2, 2 * M_PI);
127 cairo_line_to (cr, tab.from, get_height());
130 if (tab.group && (tab.to - tab.from) > arc_radius) {
131 int text_width, text_height;
133 Glib::RefPtr<Pango::Layout> layout;
134 layout = Pango::Layout::create (get_pango_context ());
135 layout->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
137 layout->set_text (tab.group->name ());
138 layout->set_width ((tab.to - tab.from - arc_radius) * PANGO_SCALE);
139 layout->get_pixel_size (text_width, text_height);
141 cairo_move_to (cr, tab.from + (tab.to - tab.from - text_width) * .5, (get_height () - text_height) * .5);
143 Gtkmm2ext::Color c = Gtkmm2ext::contrasting_text_color (Gtkmm2ext::rgba_to_color (r, g, b, a));
144 Gtkmm2ext::color_to_rgba (c, r, g, b, a);
145 cairo_set_source_rgb (cr, r, g, b);
147 pango_cairo_show_layout (cr, layout->gobj ());
152 MixerGroupTabs::primary_coordinate (double x, double) const
158 MixerGroupTabs::routes_for_tab (Tab const * t) const
163 TreeModel::Children rows = _mixer->track_model->children ();
164 for (TreeModel::Children::iterator i = rows.begin(); i != rows.end(); ++i) {
166 AxisView* av = (*i)[_mixer->stripable_columns.strip];
167 MixerStrip* s = dynamic_cast<MixerStrip*> (av);
173 if (s->route()->is_master() || s->route()->is_monitor() || !s->marked_for_display()) {
178 /* tab finishes before this track starts */
182 double const h = x + s->get_width() / 2;
184 if (t->from < h && t->to > h) {
185 routes.push_back (s->route ());
188 x += s->get_width ();
195 MixerGroupTabs::selected_routes () const
198 BOOST_FOREACH (AxisView* r, _mixer->selection().axes) {
199 boost::shared_ptr<Route> rp = boost::dynamic_pointer_cast<Route> (r->stripable());