VKeybd: Pass on primary (Ctrl/Cmd) shortcuts
[ardour.git] / gtk2_ardour / mixer_group_tabs.cc
1 /*
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>
6  *
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.
11  *
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.
16  *
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.
20  */
21
22 #include <boost/foreach.hpp>
23
24 #include "gtkmm2ext/utils.h"
25
26 #include "ardour/route_group.h"
27
28 #include "gtkmm2ext/colors.h"
29
30 #include "mixer_group_tabs.h"
31 #include "mixer_strip.h"
32 #include "mixer_ui.h"
33 #include "rgb_macros.h"
34 #include "route_group_dialog.h"
35 #include "ui_config.h"
36 #include "utils.h"
37
38 #include "pbd/i18n.h"
39
40 using namespace std;
41 using namespace Gtk;
42 using namespace ARDOUR;
43 using namespace ARDOUR_UI_UTILS;
44 using namespace PBD;
45
46 MixerGroupTabs::MixerGroupTabs (Mixer_UI* m)
47         : _mixer (m)
48 {
49
50 }
51
52
53 list<GroupTabs::Tab>
54 MixerGroupTabs::compute_tabs () const
55 {
56         list<Tab> tabs;
57
58         Tab tab;
59         tab.from = 0;
60         tab.group = 0;
61
62         int32_t x = 0;
63         TreeModel::Children rows = _mixer->track_model->children ();
64         for (TreeModel::Children::iterator i = rows.begin(); i != rows.end(); ++i) {
65
66                 AxisView* av = (*i)[_mixer->stripable_columns.strip];
67                 MixerStrip* s = dynamic_cast<MixerStrip*> (av);
68
69                 if (!s) {
70                         continue;
71                 }
72
73                 if (s->route()->is_master() || s->route()->is_monitor() || !s->marked_for_display()) {
74                         continue;
75                 }
76 #ifdef MIXBUS
77                 if (s->route()->mixbus()) {
78                         continue;
79                 }
80 #endif
81
82                 RouteGroup* g = s->route_group ();
83
84                 if (g != tab.group) {
85                         if (tab.group) {
86                                 tab.to = x;
87                                 tabs.push_back (tab);
88                         }
89
90                         tab.from = x;
91                         tab.group = g;
92
93                         if (g) {
94                                 tab.color = group_color (g);
95                         }
96                 }
97
98                 int ww = 0, wh = 0;
99                 s->get_size_request (ww, wh); // widget may not be realized, get_width() is invalid.
100                 x += ww;
101         }
102
103         if (tab.group) {
104                 tab.to = x;
105                 tabs.push_back (tab);
106         }
107
108         return tabs;
109 }
110
111 void
112 MixerGroupTabs::draw_tab (cairo_t* cr, Tab const & tab)
113 {
114         double const arc_radius = get_height();
115         double r, g, b, a;
116
117         if (tab.group && tab.group->is_active()) {
118                 Gtkmm2ext::color_to_rgba (tab.color, r, g, b, a);
119         } else {
120                 Gtkmm2ext::color_to_rgba (UIConfiguration::instance().color ("inactive group tab"), r, g, b, a);
121         }
122
123         a = 1.0;
124
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());
130         cairo_fill (cr);
131
132         if (tab.group && (tab.to - tab.from) > arc_radius) {
133                 int text_width, text_height;
134
135                 Glib::RefPtr<Pango::Layout> layout;
136                 layout = Pango::Layout::create (get_pango_context ());
137                 layout->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
138
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);
142
143                 cairo_move_to (cr, tab.from + (tab.to - tab.from - text_width) * .5, (get_height () - text_height) * .5);
144
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);
148
149                 pango_cairo_show_layout (cr, layout->gobj ());
150         }
151 }
152
153 double
154 MixerGroupTabs::primary_coordinate (double x, double) const
155 {
156         return x;
157 }
158
159 RouteList
160 MixerGroupTabs::routes_for_tab (Tab const * t) const
161 {
162         RouteList routes;
163         int32_t x = 0;
164
165         TreeModel::Children rows = _mixer->track_model->children ();
166         for (TreeModel::Children::iterator i = rows.begin(); i != rows.end(); ++i) {
167
168                 AxisView* av = (*i)[_mixer->stripable_columns.strip];
169                 MixerStrip* s = dynamic_cast<MixerStrip*> (av);
170
171                 if (!s) {
172                         continue;
173                 }
174
175                 if (s->route()->is_master() || s->route()->is_monitor() || !s->marked_for_display()) {
176                         continue;
177                 }
178
179                 if (x >= t->to) {
180                         /* tab finishes before this track starts */
181                         break;
182                 }
183
184                 double const h = x + s->get_width() / 2;
185
186                 if (t->from < h && t->to > h) {
187                         routes.push_back (s->route ());
188                 }
189
190                 x += s->get_width ();
191         }
192
193         return routes;
194 }
195
196 RouteList
197 MixerGroupTabs::selected_routes () const
198 {
199         RouteList rl;
200         BOOST_FOREACH (AxisView* r, _mixer->selection().axes) {
201                 boost::shared_ptr<Route> rp = boost::dynamic_pointer_cast<Route> (r->stripable());
202                 if (rp) {
203                         rl.push_back (rp);
204                 }
205         }
206         return rl;
207 }
208