missing piece of previous panner UI commit
[ardour.git] / gtk2_ardour / mixer_group_tabs.cc
1 /*
2     Copyright (C) 2009 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #include "ardour/route_group.h"
21 #include "ardour/session.h"
22 #include "mixer_group_tabs.h"
23 #include "mixer_strip.h"
24 #include "mixer_ui.h"
25 #include "utils.h"
26 #include "i18n.h"
27 #include "route_group_dialog.h"
28
29 using namespace std;
30 using namespace Gtk;
31 using namespace ARDOUR;
32 using namespace PBD;
33
34 MixerGroupTabs::MixerGroupTabs (Mixer_UI* m)
35         : _mixer (m)
36 {
37
38 }
39
40
41 list<GroupTabs::Tab>
42 MixerGroupTabs::compute_tabs () const
43 {
44         list<Tab> tabs;
45
46         Tab tab;
47         tab.from = 0;
48         tab.group = 0;
49
50         int32_t x = 0;
51         TreeModel::Children rows = _mixer->track_model->children ();
52         for (TreeModel::Children::iterator i = rows.begin(); i != rows.end(); ++i) {
53
54                 MixerStrip* s = (*i)[_mixer->track_columns.strip];
55
56                 if (s->route()->is_master() || s->route()->is_monitor() || !s->marked_for_display()) {
57                         continue;
58                 }
59
60                 RouteGroup* g = s->route_group ();
61
62                 if (g != tab.group) {
63                         if (tab.group) {
64                                 tab.to = x;
65                                 tabs.push_back (tab);
66                         }
67
68                         tab.from = x;
69                         tab.group = g;
70
71                         if (g) {
72                                 tab.color = group_color (g);
73                         }
74                 }
75
76                 x += s->get_width ();
77         }
78
79         if (tab.group) {
80                 tab.to = x;
81                 tabs.push_back (tab);
82         }
83
84         return tabs;
85 }
86
87 void
88 MixerGroupTabs::draw_tab (cairo_t* cr, Tab const & tab) const
89 {
90         double const arc_radius = _height;
91
92         if (tab.group && tab.group->is_active()) {
93                 cairo_set_source_rgba (cr, tab.color.get_red_p (), tab.color.get_green_p (), tab.color.get_blue_p (), 1);
94         } else {
95                 cairo_set_source_rgba (cr, 1, 1, 1, 0.2);
96         }
97
98         cairo_arc (cr, tab.from + arc_radius, _height, arc_radius, M_PI, 3 * M_PI / 2);
99         cairo_line_to (cr, tab.to - arc_radius, 0);
100         cairo_arc (cr, tab.to - arc_radius, _height, arc_radius, 3 * M_PI / 2, 2 * M_PI);
101         cairo_line_to (cr, tab.from, _height);
102         cairo_fill (cr);
103
104         if (tab.group) {
105                 pair<string, double> const f = fit_to_pixels (cr, tab.group->name(), tab.to - tab.from - arc_radius * 2);
106
107                 cairo_text_extents_t ext;
108                 cairo_text_extents (cr, tab.group->name().c_str(), &ext);
109
110                 cairo_set_source_rgb (cr, 1, 1, 1);
111                 cairo_move_to (cr, tab.from + (tab.to - tab.from - f.second) / 2, _height - ext.height / 2);
112                 cairo_save (cr);
113                 cairo_show_text (cr, f.first.c_str());
114                 cairo_restore (cr);
115         }
116 }
117
118 double
119 MixerGroupTabs::primary_coordinate (double x, double) const
120 {
121         return x;
122 }
123
124 RouteList
125 MixerGroupTabs::routes_for_tab (Tab const * t) const
126 {
127         RouteList routes;
128         int32_t x = 0;
129
130         TreeModel::Children rows = _mixer->track_model->children ();
131         for (TreeModel::Children::iterator i = rows.begin(); i != rows.end(); ++i) {
132
133                 MixerStrip* s = (*i)[_mixer->track_columns.strip];
134
135                 if (s->route()->is_master() || s->route()->is_monitor() || !s->marked_for_display()) {
136                         continue;
137                 }
138
139                 if (x >= t->to) {
140                         /* tab finishes before this track starts */
141                         break;
142                 }
143
144                 double const h = x + s->get_width() / 2;
145
146                 if (t->from < h && t->to > h) {
147                         routes.push_back (s->route ());
148                 }
149
150                 x += s->get_width ();
151         }
152
153         return routes;
154 }
155
156 PropertyList
157 MixerGroupTabs::default_properties () const
158 {
159         PropertyList plist;
160
161         plist.add (Properties::active, true);
162         plist.add (Properties::mute, true);
163         plist.add (Properties::solo, true);
164         plist.add (Properties::gain, true);
165         plist.add (Properties::recenable, true);
166
167         return plist;
168 }
169
170 string
171 MixerGroupTabs::order_key () const
172 {
173         return X_("signal");
174 }
175
176 RouteList
177 MixerGroupTabs::selected_routes () const
178 {
179         return _mixer->selection().routes;
180 }
181
182 void
183 MixerGroupTabs::sync_order_keys ()
184 {
185         _mixer->sync_order_keys ("");
186 }