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