enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / editor_mixer.cc
1 /*
2     Copyright (C) 2003-2004 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 #ifdef WAF_BUILD
21 #include "gtk2ardour-config.h"
22 #endif
23
24 #include <glibmm/miscutils.h>
25 #include <gtkmm/messagedialog.h>
26 #include <gtkmm2ext/utils.h>
27 #include <gtkmm2ext/window_title.h>
28
29 #include "pbd/enumwriter.h"
30
31 #include "ardour/rc_configuration.h"
32
33 #include "control_protocol/control_protocol.h"
34
35 #include "actions.h"
36 #include "ardour_ui.h"
37 #include "audio_time_axis.h"
38 #include "automation_time_axis.h"
39 #include "editor.h"
40 #include "editor_route_groups.h"
41 #include "editor_regions.h"
42 #include "gui_thread.h"
43 #include "midi_time_axis.h"
44 #include "mixer_strip.h"
45 #include "mixer_ui.h"
46 #include "selection.h"
47 #include "ui_config.h"
48
49 #include "pbd/i18n.h"
50
51 using namespace std;
52 using namespace Gtkmm2ext;
53 using namespace PBD;
54
55 void
56 Editor::editor_mixer_button_toggled ()
57 {
58         Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
59         if (act) {
60                 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
61                 show_editor_mixer (tact->get_active());
62         }
63 }
64
65 void
66 Editor::editor_list_button_toggled ()
67 {
68         Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-list"));
69         if (act) {
70                 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
71                 show_editor_list (tact->get_active());
72         }
73 }
74
75 void
76 Editor::show_editor_mixer (bool yn)
77 {
78         boost::shared_ptr<ARDOUR::Route> r;
79
80         show_editor_mixer_when_tracks_arrive = false;
81
82         if (yn) {
83                 Gtk::Window* toplevel = current_toplevel();
84                 Glib::RefPtr<Gdk::Window> win;
85                 Glib::RefPtr<Gdk::Screen> screen;
86
87                 if (toplevel) {
88                         win = toplevel->get_window();
89                 }
90
91                 if (win) {
92                         screen = win->get_screen();
93                 } else {
94                         screen = Gdk::Screen::get_default();
95                 }
96
97                 if (g_getenv ("ARDOUR_LOVES_STUPID_TINY_SCREENS") == 0 && screen && screen->get_height() < 700) {
98                         Gtk::MessageDialog msg (_("This screen is not tall enough to display the editor mixer"));
99                         msg.run ();
100                         return;
101                 }
102         }
103
104         if (!_session) {
105                 show_editor_mixer_when_tracks_arrive = yn;
106                 return;
107         }
108
109         if (yn) {
110
111                 if (selection->tracks.empty()) {
112
113                         if (track_views.empty()) {
114                                 show_editor_mixer_when_tracks_arrive = true;
115                                 return;
116                         }
117
118                         for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
119                                 RouteTimeAxisView* atv;
120
121                                 if ((atv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
122                                         r = atv->route();
123                                         break;
124                                 }
125                         }
126
127                 } else {
128                         sort_track_selection (selection->tracks);
129
130                         for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
131                                 RouteTimeAxisView* atv;
132
133                                 if ((atv = dynamic_cast<RouteTimeAxisView*> (*i)) != 0) {
134                                         r = atv->route();
135                                         break;
136                                 }
137                         }
138                 }
139
140                 if (r) {
141                         if (current_mixer_strip == 0) {
142                                 create_editor_mixer ();
143                         }
144                 }
145
146                 if (current_mixer_strip && current_mixer_strip->get_parent() == 0) {
147                         global_hpacker.pack_start (*current_mixer_strip, Gtk::PACK_SHRINK );
148                         global_hpacker.reorder_child (*current_mixer_strip, 0);
149                         current_mixer_strip->show ();
150                 }
151
152                 if (r) {
153                         current_mixer_strip->set_route (r);
154                         current_mixer_strip->set_width_enum (editor_mixer_strip_width, (void*) this);
155                 }
156
157         } else {
158
159                 if (current_mixer_strip) {
160                         if (current_mixer_strip->get_parent() != 0) {
161                                 global_hpacker.remove (*current_mixer_strip);
162                         }
163                 }
164         }
165
166 #ifdef __APPLE__
167         /* XXX gtk problem here */
168         ensure_all_elements_drawn();
169 #endif
170 }
171
172 #ifdef __APPLE__
173 void
174 Editor::ensure_all_elements_drawn ()
175 {
176         controls_layout.queue_draw ();
177         time_bars_event_box.queue_draw ();
178 }
179 #endif
180
181 void
182 Editor::create_editor_mixer ()
183 {
184         current_mixer_strip = new MixerStrip (*ARDOUR_UI::instance()->the_mixer(), _session, false);
185         current_mixer_strip->Hiding.connect (sigc::mem_fun(*this, &Editor::current_mixer_strip_hidden));
186         current_mixer_strip->WidthChanged.connect (sigc::mem_fun (*this, &Editor::mixer_strip_width_changed));
187
188 #ifdef __APPLE__
189         current_mixer_strip->WidthChanged.connect (sigc::mem_fun(*this, &Editor::ensure_all_elements_drawn));
190 #endif
191         current_mixer_strip->set_embedded (true);
192
193 }
194
195 void
196 Editor::set_selected_mixer_strip (TimeAxisView& view)
197 {
198         if (!_session) {
199                 return;
200         }
201
202         // if this is an automation track, then we shold the mixer strip should
203         // show the parent
204
205         boost::shared_ptr<ARDOUR::Route> route;
206         AutomationTimeAxisView* atv;
207
208         if ((atv = dynamic_cast<AutomationTimeAxisView*>(&view)) != 0) {
209
210                 AudioTimeAxisView *parent = dynamic_cast<AudioTimeAxisView*>(view.get_parent());
211
212                 if (parent) {
213                         route = parent->route ();
214                 }
215
216         } else {
217
218                 AudioTimeAxisView* at = dynamic_cast<AudioTimeAxisView*> (&view);
219
220                 if (at) {
221                         route = at->route();
222                 } else {
223                         MidiTimeAxisView* mt = dynamic_cast<MidiTimeAxisView*> (&view);
224                         if (mt) {
225                                 route = mt->route();
226                         }
227                 }
228         }
229
230         /* Typically this is set by changing the TAV selection but if for any
231            reason we decide to show a different strip for some reason, make
232            sure that control surfaces can find it.
233         */
234         ARDOUR::ControlProtocol::set_first_selected_stripable (route);
235
236         Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
237
238         if (act) {
239                 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
240                 if (!tact || !tact->get_active()) {
241                         /* not showing mixer strip presently */
242                         return;
243                 }
244         }
245
246         if (current_mixer_strip == 0) {
247                 create_editor_mixer ();
248         }
249
250         if (current_mixer_strip->route() == route) {
251                 return;
252         }
253
254         if (route) {
255                 current_mixer_strip->set_route (route);
256                 current_mixer_strip->set_width_enum (editor_mixer_strip_width, (void*) this);
257         }
258 }
259
260 void
261 Editor::current_mixer_strip_hidden ()
262 {
263         Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (X_("Editor"), X_("show-editor-mixer"));
264         if (act) {
265                 Glib::RefPtr<Gtk::ToggleAction> tact = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(act);
266                 tact->set_active (false);
267         }
268 }
269
270 void
271 Editor::maybe_add_mixer_strip_width (XMLNode& node)
272 {
273         if (current_mixer_strip) {
274                 node.add_property ("mixer-width", enum_2_string (editor_mixer_strip_width));
275         }
276 }
277
278 void
279 Editor::mixer_strip_width_changed ()
280 {
281 #ifdef __APPLE__
282         ensure_all_elements_drawn ();
283 #endif
284
285         editor_mixer_strip_width = current_mixer_strip->get_width_enum ();
286 }
287
288 void
289 Editor::track_mixer_selection ()
290 {
291         Mixer_UI::instance()->selection().RoutesChanged.connect (sigc::mem_fun (*this, &Editor::follow_mixer_selection));
292 }
293
294 void
295 Editor::follow_mixer_selection ()
296 {
297         if (_following_mixer_selection) {
298                 return;
299         }
300
301         _following_mixer_selection = true;
302         selection->block_tracks_changed (true);
303
304         AxisViewSelection& s (Mixer_UI::instance()->selection().axes);
305
306         selection->clear_tracks ();
307
308         for (AxisViewSelection::iterator i = s.begin(); i != s.end(); ++i) {
309                 TimeAxisView* tav = axis_view_from_stripable ((*i)->stripable());
310                 if (tav) {
311                         selection->add (tav);
312                 }
313         }
314
315         _following_mixer_selection = false;
316         selection->block_tracks_changed (false);
317         selection->TracksChanged (); /* EMIT SIGNAL */
318 }