2 * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
3 * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
4 * Copyright (C) 2009-2016 Paul Davis <paul@linuxaudiosystems.com>
5 * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <boost/foreach.hpp>
24 #include "gtkmm2ext/utils.h"
26 #include "ardour/route_group.h"
28 #include "gtkmm2ext/colors.h"
30 #include "mixer_group_tabs.h"
31 #include "mixer_strip.h"
33 #include "rgb_macros.h"
34 #include "route_group_dialog.h"
35 #include "ui_config.h"
42 using namespace ARDOUR;
43 using namespace ARDOUR_UI_UTILS;
46 MixerGroupTabs::MixerGroupTabs (Mixer_UI* m)
54 MixerGroupTabs::compute_tabs () const
63 TreeModel::Children rows = _mixer->track_model->children ();
64 for (TreeModel::Children::iterator i = rows.begin(); i != rows.end(); ++i) {
66 AxisView* av = (*i)[_mixer->stripable_columns.strip];
67 MixerStrip* s = dynamic_cast<MixerStrip*> (av);
73 if (s->route()->is_master() || s->route()->is_monitor() || !s->marked_for_display()) {
77 if (s->route()->mixbus()) {
82 RouteGroup* g = s->route_group ();
94 tab.color = group_color (g);
99 s->get_size_request (ww, wh); // widget may not be realized, get_width() is invalid.
105 tabs.push_back (tab);
112 MixerGroupTabs::draw_tab (cairo_t* cr, Tab const & tab)
114 double const arc_radius = get_height();
117 if (tab.group && tab.group->is_active()) {
118 Gtkmm2ext::color_to_rgba (tab.color, r, g, b, a);
120 Gtkmm2ext::color_to_rgba (UIConfiguration::instance().color ("inactive group tab"), r, g, b, a);
125 cairo_set_source_rgba (cr, r, g, b, a);
126 cairo_arc (cr, tab.from + arc_radius, get_height(), arc_radius, M_PI, 3 * M_PI / 2);
127 cairo_line_to (cr, tab.to - arc_radius, 0);
128 cairo_arc (cr, tab.to - arc_radius, get_height(), arc_radius, 3 * M_PI / 2, 2 * M_PI);
129 cairo_line_to (cr, tab.from, get_height());
132 if (tab.group && (tab.to - tab.from) > arc_radius) {
133 int text_width, text_height;
135 Glib::RefPtr<Pango::Layout> layout;
136 layout = Pango::Layout::create (get_pango_context ());
137 layout->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
139 layout->set_text (tab.group->name ());
140 layout->set_width ((tab.to - tab.from - arc_radius) * PANGO_SCALE);
141 layout->get_pixel_size (text_width, text_height);
143 cairo_move_to (cr, tab.from + (tab.to - tab.from - text_width) * .5, (get_height () - text_height) * .5);
145 Gtkmm2ext::Color c = Gtkmm2ext::contrasting_text_color (Gtkmm2ext::rgba_to_color (r, g, b, a));
146 Gtkmm2ext::color_to_rgba (c, r, g, b, a);
147 cairo_set_source_rgb (cr, r, g, b);
149 pango_cairo_show_layout (cr, layout->gobj ());
154 MixerGroupTabs::primary_coordinate (double x, double) const
160 MixerGroupTabs::routes_for_tab (Tab const * t) const
165 TreeModel::Children rows = _mixer->track_model->children ();
166 for (TreeModel::Children::iterator i = rows.begin(); i != rows.end(); ++i) {
168 AxisView* av = (*i)[_mixer->stripable_columns.strip];
169 MixerStrip* s = dynamic_cast<MixerStrip*> (av);
175 if (s->route()->is_master() || s->route()->is_monitor() || !s->marked_for_display()) {
180 /* tab finishes before this track starts */
184 double const h = x + s->get_width() / 2;
186 if (t->from < h && t->to > h) {
187 routes.push_back (s->route ());
190 x += s->get_width ();
197 MixerGroupTabs::selected_routes () const
200 BOOST_FOREACH (AxisView* r, _mixer->selection().axes) {
201 boost::shared_ptr<Route> rp = boost::dynamic_pointer_cast<Route> (r->stripable());