rename ArdourStartup to NewUserWizard and rename source file(s)
[ardour.git] / gtk2_ardour / ardour_ui_ed.cc
1 /*
2  * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
3  * Copyright (C) 2005-2016 Tim Mayberry <mojofunk@gmail.com>
4  * Copyright (C) 2005-2019 Paul Davis <paul@linuxaudiosystems.com>
5  * Copyright (C) 2006-2007 Doug McLain <doug@nostar.net>
6  * Copyright (C) 2006-2012 David Robillard <d@drobilla.net>
7  * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
8  * Copyright (C) 2008 Hans Baier <hansfbaier@googlemail.com>
9  * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
10  * Copyright (C) 2014-2019 Ben Loftis <ben@harrisonconsoles.com>
11  * Copyright (C) 2015 AndrĂ© Nusser <andre.nusser@googlemail.com>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with this program; if not, write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26  */
27
28 #ifdef WAF_BUILD
29 #include "gtk2ardour-config.h"
30 #endif
31
32 /* This file contains any ARDOUR_UI methods that require knowledge of
33    the editor, and exists so that no compilation dependency exists
34    between the main ARDOUR_UI modules and the PublicEditor class. This
35    is to cut down on the nasty compile times for both these classes.
36 */
37
38 #include <cmath>
39
40 #include <glibmm/miscutils.h>
41 #include <gtkmm/accelmap.h>
42 #include <gtk/gtk.h>
43
44 #include "pbd/file_utils.h"
45 #include "pbd/fpu.h"
46 #include "pbd/convert.h"
47
48 #include "gtkmm2ext/cairo_packer.h"
49 #include "gtkmm2ext/utils.h"
50 #include "gtkmm2ext/window_title.h"
51
52 #include "widgets/tearoff.h"
53
54 #include "ardour_ui.h"
55 #include "public_editor.h"
56 #include "audio_clock.h"
57 #include "keyboard.h"
58 #include "monitor_section.h"
59 #include "engine_dialog.h"
60 #include "editor.h"
61 #include "editing.h"
62 #include "actions.h"
63 #include "meterbridge.h"
64 #include "luawindow.h"
65 #include "mixer_ui.h"
66 #include "window_manager.h"
67 #include "global_port_matrix.h"
68 #include "location_ui.h"
69 #include "main_clock.h"
70 #include "rc_option_editor.h"
71
72 #include <gtkmm2ext/application.h>
73
74 #include "ardour/session.h"
75 #include "ardour/profile.h"
76 #include "ardour/audioengine.h"
77 #include "ardour/lv2_plugin.h"
78
79 #include "control_protocol/control_protocol.h"
80
81 #include "pbd/i18n.h"
82
83 using namespace std;
84 using namespace ARDOUR;
85 using namespace PBD;
86 using namespace Gtkmm2ext;
87 using namespace Gtk;
88 using namespace Glib;
89
90 int
91 ARDOUR_UI::create_editor ()
92 {
93         try {
94                 editor = new Editor ();
95                 editor->StateChange.connect (sigc::mem_fun (*this, &ARDOUR_UI::tabbable_state_change));
96         }
97
98         catch (failed_constructor& err) {
99                 return -1;
100         }
101
102         // editor->signal_event().connect (sigc::bind (sigc::ptr_fun (&Keyboard::catch_user_event_for_pre_dialog_focus), editor));
103
104         return 0;
105 }
106
107 int
108 ARDOUR_UI::create_luawindow ()
109
110 {
111         try {
112                 luawindow = LuaWindow::instance ();
113         }
114         catch (failed_constructor& err) {
115                 return -1;
116         }
117
118         return 0;
119 }
120
121 void
122 ARDOUR_UI::escape ()
123 {
124         Escape (); /* EMIT SIGNAL */
125 }
126
127 void
128 ARDOUR_UI::close_current_dialog ()
129 {
130         Keyboard::close_current_dialog ();
131 }
132
133 void
134 ARDOUR_UI::install_actions ()
135 {
136         Glib::RefPtr<ActionGroup> main_actions = ActionManager::create_action_group (global_bindings, X_("Main"));
137         Glib::RefPtr<ActionGroup> main_menu_actions = ActionManager::create_action_group (global_bindings, X_("Main Menu"));
138         Glib::RefPtr<Action> act;
139
140         ActionManager::register_action (main_actions, X_("Escape"), _("Escape (deselect all)"), sigc::mem_fun (*this, &ARDOUR_UI::escape));
141         /* This is hard-wired into the Keyboard code as "Primary-w". Maybe it
142            doesn't need to be. This action makes it possible to do this from a
143            control surface.
144         */
145         ActionManager::register_action (main_actions, X_("close-current-dialog"), _("Close Current Dialog"), sigc::mem_fun (*this, &ARDOUR_UI::close_current_dialog));
146
147         /* menus + submenus that need action items */
148
149         ActionManager::register_action (main_menu_actions, X_("Session"), _("Session"));
150         act = ActionManager::register_action (main_menu_actions, X_("Cleanup"), _("Clean-up"));
151         ActionManager::write_sensitive_actions.push_back (act);
152         ActionManager::register_action (main_menu_actions, X_("Sync"), _("Sync"));
153         ActionManager::register_action (main_menu_actions, X_("TransportOptions"), _("Options"));
154         ActionManager::register_action (main_menu_actions, X_("WindowMenu"), _("Window"));
155         ActionManager::register_action (main_menu_actions, X_("MixerMenu"), _("Mixer"));
156         ActionManager::register_action (main_menu_actions, X_("EditorMenu"), _("Editor"));
157         ActionManager::register_action (main_menu_actions, X_("PrefsMenu"), _("Preferences"));
158         ActionManager::register_action (main_menu_actions, X_("DetachMenu"), _("Detach"));
159         ActionManager::register_action (main_menu_actions, X_("Help"), _("Help"));
160         ActionManager::register_action (main_menu_actions, X_("KeyMouseActions"), _("Misc. Shortcuts"));
161         ActionManager::register_action (main_menu_actions, X_("AudioFileFormat"), _("Audio File Format"));
162         ActionManager::register_action (main_menu_actions, X_("AudioFileFormatHeader"), _("File Type"));
163         ActionManager::register_action (main_menu_actions, X_("AudioFileFormatData"), _("Sample Format"));
164         ActionManager::register_action (main_menu_actions, X_("ControlSurfaces"), _("Control Surfaces"));
165         ActionManager::register_action (main_menu_actions, X_("Plugins"), _("Plugins"));
166         ActionManager::register_action (main_menu_actions, X_("Metering"), _("Metering"));
167         ActionManager::register_action (main_menu_actions, X_("MeteringFallOffRate"), _("Fall Off Rate"));
168         ActionManager::register_action (main_menu_actions, X_("MeteringHoldTime"), _("Hold Time"));
169         ActionManager::register_action (main_menu_actions, X_("Denormals"), _("Denormal Handling"));
170
171         /* the real actions */
172
173         act = ActionManager::register_action (main_actions, X_("New"), _("New..."),  hide_return (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::get_session_parameters), false, true, "")));
174
175         ActionManager::register_action (main_actions, X_("Open"), _("Open..."),  sigc::mem_fun(*this, &ARDOUR_UI::open_session));
176         ActionManager::register_action (main_actions, X_("Recent"), _("Recent..."),  sigc::mem_fun(*this, &ARDOUR_UI::open_recent_session));
177         act = ActionManager::register_action (main_actions, X_("Close"), _("Close"),  sigc::mem_fun(*this, &ARDOUR_UI::close_session));
178         ActionManager::session_sensitive_actions.push_back (act);
179
180         act = ActionManager::register_action (main_actions, X_("AddTrackBus"), _("Add Track, Bus or VCA..."), sigc::mem_fun(*this, &ARDOUR_UI::add_route));
181         ActionManager::session_sensitive_actions.push_back (act);
182         ActionManager::write_sensitive_actions.push_back (act);
183         ActionManager::rec_sensitive_actions.push_back (act);
184
185         act = ActionManager::register_action (main_actions, X_("duplicate-routes"), _("Duplicate Tracks/Busses..."),
186                                               sigc::mem_fun(*this, &ARDOUR_UI::start_duplicate_routes));
187         ActionManager::session_sensitive_actions.push_back (act);
188         ActionManager::write_sensitive_actions.push_back (act);
189         ActionManager::route_selection_sensitive_actions.push_back (act);
190
191         act = ActionManager::register_action (main_actions, X_("cancel-solo"), _("Cancel Solo"), sigc::mem_fun(*this, &ARDOUR_UI::cancel_solo));
192         ActionManager::session_sensitive_actions.push_back (act);
193         ActionManager::write_sensitive_actions.push_back (act);
194
195         act = ActionManager::register_action (main_actions, X_("Scripting"), S_("Session|Scripting"));
196         ActionManager::session_sensitive_actions.push_back (act);
197
198         act = ActionManager::register_action (main_actions, X_("OpenVideo"), _("Open Video..."),
199                                               sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::add_video), (Gtk::Window*) 0));
200         ActionManager::session_sensitive_actions.push_back (act);
201         act = ActionManager::register_action (main_actions, X_("CloseVideo"), _("Remove Video"),
202                                               sigc::mem_fun (*this, &ARDOUR_UI::remove_video));
203         act->set_sensitive (false);
204         act = ActionManager::register_action (main_actions, X_("ExportVideo"), _("Export to Video File..."),
205                                               hide_return (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::export_video), false)));
206         ActionManager::session_sensitive_actions.push_back (act);
207
208         act = ActionManager::register_action (main_actions, X_("SnapshotStay"), _("Snapshot (& keep working on current version) ..."), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::snapshot_session), false));
209         ActionManager::session_sensitive_actions.push_back (act);
210
211         act = ActionManager::register_action (main_actions, X_("SnapshotSwitch"), _("Snapshot (& switch to new version) ..."), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::snapshot_session), true));
212         ActionManager::session_sensitive_actions.push_back (act);
213
214         act = ActionManager::register_action (main_actions, X_("QuickSnapshotStay"), _("Quick Snapshot (& keep working on current version) ..."), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::quick_snapshot_session), false));
215         ActionManager::session_sensitive_actions.push_back (act);
216
217         act = ActionManager::register_action (main_actions, X_("QuickSnapshotSwitch"), _("Quick Snapshot (& switch to new version) ..."), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::quick_snapshot_session), true));
218         ActionManager::session_sensitive_actions.push_back (act);
219         ActionManager::write_sensitive_actions.push_back (act);
220
221         act = ActionManager::register_action (main_actions, X_("SaveAs"), _("Save As..."), sigc::mem_fun(*this, &ARDOUR_UI::save_session_as));
222         ActionManager::session_sensitive_actions.push_back (act);
223
224         act = ActionManager::register_action (main_actions, X_("Archive"), _("Archive..."), sigc::mem_fun(*this, &ARDOUR_UI::archive_session));
225         ActionManager::session_sensitive_actions.push_back (act);
226
227         act = ActionManager::register_action (main_actions, X_("Rename"), _("Rename..."), sigc::mem_fun(*this, &ARDOUR_UI::rename_session));
228         ActionManager::session_sensitive_actions.push_back (act);
229         ActionManager::write_sensitive_actions.push_back (act);
230
231         act = ActionManager::register_action (main_actions, X_("SaveTemplate"), _("Save Template..."),  sigc::mem_fun(*this, &ARDOUR_UI::save_template));
232         ActionManager::session_sensitive_actions.push_back (act);
233
234         act = ActionManager::register_action (main_actions, X_("ManageTemplates"), _("Templates"), sigc::mem_fun(*this, &ARDOUR_UI::manage_templates));
235         ActionManager::session_sensitive_actions.push_back (act);
236
237         act = ActionManager::register_action (main_actions, X_("Metadata"), _("Metadata"));
238         ActionManager::session_sensitive_actions.push_back (act);
239
240         act = ActionManager::register_action (main_actions, X_("EditMetadata"), _("Edit Metadata..."),  sigc::mem_fun(*this, &ARDOUR_UI::edit_metadata));
241         ActionManager::session_sensitive_actions.push_back (act);
242
243         act = ActionManager::register_action (main_actions, X_("ImportMetadata"), _("Import Metadata..."),  sigc::mem_fun(*this, &ARDOUR_UI::import_metadata));
244         ActionManager::session_sensitive_actions.push_back (act);
245
246         act = ActionManager::register_action (main_actions, X_("Export"), _("Export"));
247         ActionManager::session_sensitive_actions.push_back (act);
248
249         act = ActionManager::register_action (main_actions, X_("FlushWastebasket"), _("Flush Wastebasket"),  sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::flush_trash));
250
251         ActionManager::write_sensitive_actions.push_back (act);
252         ActionManager::session_sensitive_actions.push_back (act);
253
254         /* these actions are intended to be shared across all windows */
255
256         common_actions = ActionManager::create_action_group (global_bindings, X_("Common"));
257         ActionManager::register_action (common_actions, X_("Quit"), _("Quit"), (hide_return (sigc::mem_fun(*this, &ARDOUR_UI::finish))));
258         ActionManager::register_action (common_actions, X_("Hide"), _("Hide"), sigc::mem_fun (*this, &ARDOUR_UI::hide_application));
259
260         if (Profile->get_mixbus()) {
261                 ActionManager::register_action (common_actions, X_("show-ui-prefs"), _("Show more UI preferences"), sigc::mem_fun (*this, &ARDOUR_UI::show_ui_prefs));
262         }
263
264         ActionManager::register_action (common_actions, X_("toggle-luawindow"), S_("Window|Scripting"),  sigc::mem_fun(*this, &ARDOUR_UI::toggle_luawindow));
265         ActionManager::register_action (common_actions, X_("toggle-meterbridge"), S_("Window|Meterbridge"),  sigc::mem_fun(*this, &ARDOUR_UI::toggle_meterbridge));
266
267         act = ActionManager::register_action (common_actions, X_("NewMIDITracer"), _("MIDI Tracer"), sigc::mem_fun(*this, &ARDOUR_UI::new_midi_tracer_window));
268         ActionManager::session_sensitive_actions.push_back (act);
269
270         ActionManager::register_action (common_actions, X_("chat"), _("Chat"),  sigc::mem_fun(*this, &ARDOUR_UI::launch_chat));
271         /** TRANSLATORS: This is `Manual' in the sense of an instruction book that tells a user how to use Ardour */
272         ActionManager::register_action (common_actions, X_("manual"), S_("Help|Manual"),  mem_fun(*this, &ARDOUR_UI::launch_manual));
273         ActionManager::register_action (common_actions, X_("reference"), S_("Manual|Reference"),  mem_fun(*this, &ARDOUR_UI::launch_reference));
274         ActionManager::register_action (common_actions, X_("tracker"), _("Report a Bug"), mem_fun(*this, &ARDOUR_UI::launch_tracker));
275         ActionManager::register_action (common_actions, X_("cheat-sheet"), _("Cheat Sheet"), mem_fun(*this, &ARDOUR_UI::launch_cheat_sheet));
276         ActionManager::register_action (common_actions, X_("website"), _("Website"), mem_fun(*this, &ARDOUR_UI::launch_website));
277         ActionManager::register_action (common_actions, X_("website-dev"), _("Development"), mem_fun(*this, &ARDOUR_UI::launch_website_dev));
278         ActionManager::register_action (common_actions, X_("forums"), _("User Forums"), mem_fun(*this, &ARDOUR_UI::launch_forums));
279         ActionManager::register_action (common_actions, X_("howto-report"), _("How to Report a Bug"), mem_fun(*this, &ARDOUR_UI::launch_howto_report));
280
281         act = ActionManager::register_action (common_actions, X_("Save"), _("Save"),  sigc::hide_return (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::save_state), string(""), false)));
282         ActionManager::session_sensitive_actions.push_back (act);
283         ActionManager::write_sensitive_actions.push_back (act);
284
285         /* this is used by the monitor section to create global equivalents of
286          * some of its "local" actions. It will be used when Monitor/... actions
287          * are created.
288          */
289
290         (void) ActionManager::create_action_group (global_bindings, X_("Monitor Section"));
291
292         Glib::RefPtr<ActionGroup> transport_actions = ActionManager::create_action_group (global_bindings, X_("Transport"));
293
294         /* do-nothing action for the "transport" menu bar item */
295
296         ActionManager::register_action (transport_actions, X_("Transport"), _("Transport"));
297
298         /* these two are not used by key bindings, instead use ToggleRoll for that. these two do show up in
299            menus and via button proxies.
300         */
301
302         act = ActionManager::register_action (transport_actions, X_("Stop"), _("Stop"), sigc::mem_fun(*this, &ARDOUR_UI::transport_stop));
303         ActionManager::session_sensitive_actions.push_back (act);
304         ActionManager::transport_sensitive_actions.push_back (act);
305         act = ActionManager::register_action (transport_actions, X_("Roll"), _("Roll"), sigc::mem_fun(*this, &ARDOUR_UI::transport_roll));
306         ActionManager::session_sensitive_actions.push_back (act);
307         ActionManager::transport_sensitive_actions.push_back (act);
308
309         act = ActionManager::register_action (transport_actions, X_("ToggleRoll"), _("Start/Stop"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::toggle_roll), false, false));
310         ActionManager::session_sensitive_actions.push_back (act);
311         ActionManager::transport_sensitive_actions.push_back (act);
312         act = ActionManager::register_action (transport_actions, X_("alternate-ToggleRoll"), _("Start/Stop"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::toggle_roll), false, false));
313         ActionManager::session_sensitive_actions.push_back (act);
314         ActionManager::transport_sensitive_actions.push_back (act);
315         act = ActionManager::register_action (transport_actions, X_("ToggleRollMaybe"), _("Start/Continue/Stop"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::toggle_roll), false, true));
316         ActionManager::session_sensitive_actions.push_back (act);
317         ActionManager::transport_sensitive_actions.push_back (act);
318         act = ActionManager::register_action (transport_actions, X_("ToggleRollForgetCapture"), _("Stop and Forget Capture"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::toggle_roll), true, false));
319         ActionManager::session_sensitive_actions.push_back (act);
320         ActionManager::transport_sensitive_actions.push_back (act);
321
322         act = ActionManager::register_action (transport_actions, X_("Loop"), _("Play Loop Range"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_session_auto_loop));
323         ActionManager::session_sensitive_actions.push_back (act);
324         ActionManager::transport_sensitive_actions.push_back (act);
325         act = ActionManager::register_action (transport_actions, X_("PlaySelection"), _("Play Selection"), sigc::mem_fun(*this, &ARDOUR_UI::transport_play_selection));
326         ActionManager::session_sensitive_actions.push_back (act);
327         ActionManager::transport_sensitive_actions.push_back (act);
328         act = ActionManager::register_action (transport_actions, X_("PlayPreroll"), _("Play w/Preroll"), sigc::mem_fun(*this, &ARDOUR_UI::transport_play_preroll));
329         ActionManager::session_sensitive_actions.push_back (act);
330         ActionManager::transport_sensitive_actions.push_back (act);
331
332
333         act = ActionManager::register_action (transport_actions, X_("RecordPreroll"), _("Record w/Preroll"), sigc::mem_fun(*this, &ARDOUR_UI::transport_rec_preroll));
334         ActionManager::session_sensitive_actions.push_back (act);
335         ActionManager::write_sensitive_actions.push_back (act);
336
337         act = ActionManager::register_action (transport_actions, X_("RecordCountIn"), _("Record w/Count-In"), sigc::mem_fun(*this, &ARDOUR_UI::transport_rec_count_in));
338         ActionManager::session_sensitive_actions.push_back (act);
339         ActionManager::write_sensitive_actions.push_back (act);
340
341         act = ActionManager::register_action (transport_actions, X_("Record"), _("Enable Record"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_record), false));
342         ActionManager::session_sensitive_actions.push_back (act);
343         ActionManager::write_sensitive_actions.push_back (act);
344         act = ActionManager::register_action (transport_actions, X_("record-roll"), _("Start Recording"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_record), true));
345         ActionManager::session_sensitive_actions.push_back (act);
346         ActionManager::write_sensitive_actions.push_back (act);
347         ActionManager::transport_sensitive_actions.push_back (act);
348         act = ActionManager::register_action (transport_actions, X_("alternate-record-roll"), _("Start Recording"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_record), true));
349         ActionManager::session_sensitive_actions.push_back (act);
350         ActionManager::write_sensitive_actions.push_back (act);
351         ActionManager::transport_sensitive_actions.push_back (act);
352         act = ActionManager::register_action (transport_actions, X_("Rewind"), _("Rewind"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_rewind), 0));
353         ActionManager::session_sensitive_actions.push_back (act);
354         ActionManager::transport_sensitive_actions.push_back (act);
355         act = ActionManager::register_action (transport_actions, X_("RewindSlow"), _("Rewind (Slow)"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_rewind), -1));
356         ActionManager::session_sensitive_actions.push_back (act);
357         ActionManager::transport_sensitive_actions.push_back (act);
358         act = ActionManager::register_action (transport_actions, X_("RewindFast"), _("Rewind (Fast)"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_rewind), 1));
359         ActionManager::session_sensitive_actions.push_back (act);
360         ActionManager::transport_sensitive_actions.push_back (act);
361         act = ActionManager::register_action (transport_actions, X_("Forward"), _("Forward"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_forward), 0));
362         ActionManager::session_sensitive_actions.push_back (act);
363         ActionManager::transport_sensitive_actions.push_back (act);
364         act = ActionManager::register_action (transport_actions, X_("ForwardSlow"), _("Forward (Slow)"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_forward), -1));
365         ActionManager::session_sensitive_actions.push_back (act);
366         ActionManager::transport_sensitive_actions.push_back (act);
367         act = ActionManager::register_action (transport_actions, X_("ForwardFast"), _("Forward (Fast)"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_forward), 1));
368         ActionManager::session_sensitive_actions.push_back (act);
369         ActionManager::transport_sensitive_actions.push_back (act);
370         act = ActionManager::register_action (transport_actions, X_("GotoZero"), _("Go to Zero"), sigc::mem_fun(*this, &ARDOUR_UI::transport_goto_zero));
371         ActionManager::session_sensitive_actions.push_back (act);
372         ActionManager::transport_sensitive_actions.push_back (act);
373         act = ActionManager::register_action (transport_actions, X_("GotoStart"), _("Go to Start"), sigc::mem_fun(*this, &ARDOUR_UI::transport_goto_start));
374         ActionManager::session_sensitive_actions.push_back (act);
375         ActionManager::transport_sensitive_actions.push_back (act);
376         act = ActionManager::register_action (transport_actions, X_("alternate-GotoStart"), _("Go to Start"), sigc::mem_fun(*this, &ARDOUR_UI::transport_goto_start));
377         ActionManager::session_sensitive_actions.push_back (act);
378         ActionManager::transport_sensitive_actions.push_back (act);
379         act = ActionManager::register_action (transport_actions, X_("GotoEnd"), _("Go to End"), sigc::mem_fun(*this, &ARDOUR_UI::transport_goto_end));
380         ActionManager::session_sensitive_actions.push_back (act);
381         ActionManager::transport_sensitive_actions.push_back (act);
382         act = ActionManager::register_action (transport_actions, X_("GotoWallClock"), _("Go to Wall Clock"), sigc::mem_fun(*this, &ARDOUR_UI::transport_goto_wallclock));
383         ActionManager::session_sensitive_actions.push_back (act);
384         ActionManager::transport_sensitive_actions.push_back (act);
385
386         //these actions handle the numpad events, ProTools style
387         act = ActionManager::register_action (transport_actions, X_("numpad-decimal"), _("Numpad Decimal"), mem_fun(*this, &ARDOUR_UI::transport_numpad_decimal));
388         ActionManager::session_sensitive_actions.push_back (act);
389         ActionManager::transport_sensitive_actions.push_back (act);
390         act = ActionManager::register_action (transport_actions, X_("alternate-numpad-decimal"), _("Numpad Decimal"), mem_fun(*this, &ARDOUR_UI::transport_numpad_decimal));
391         ActionManager::session_sensitive_actions.push_back (act);
392         ActionManager::transport_sensitive_actions.push_back (act);
393         act = ActionManager::register_action (transport_actions, X_("numpad-0"), _("Numpad 0"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 0));
394         ActionManager::session_sensitive_actions.push_back (act);
395         ActionManager::transport_sensitive_actions.push_back (act);
396         act = ActionManager::register_action (transport_actions, X_("numpad-1"), _("Numpad 1"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 1));
397         ActionManager::session_sensitive_actions.push_back (act);
398         ActionManager::transport_sensitive_actions.push_back (act);
399         act = ActionManager::register_action (transport_actions, X_("numpad-2"), _("Numpad 2"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 2));
400         ActionManager::session_sensitive_actions.push_back (act);
401         ActionManager::transport_sensitive_actions.push_back (act);
402         act = ActionManager::register_action (transport_actions, X_("numpad-3"), _("Numpad 3"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 3));
403         ActionManager::session_sensitive_actions.push_back (act);
404         ActionManager::transport_sensitive_actions.push_back (act);
405         act = ActionManager::register_action (transport_actions, X_("numpad-4"), _("Numpad 4"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 4));
406         ActionManager::session_sensitive_actions.push_back (act);
407         ActionManager::transport_sensitive_actions.push_back (act);
408         act = ActionManager::register_action (transport_actions, X_("numpad-5"), _("Numpad 5"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 5));
409         ActionManager::session_sensitive_actions.push_back (act);
410         ActionManager::transport_sensitive_actions.push_back (act);
411         act = ActionManager::register_action (transport_actions, X_("numpad-6"), _("Numpad 6"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 6));
412         ActionManager::session_sensitive_actions.push_back (act);
413         ActionManager::transport_sensitive_actions.push_back (act);
414         act = ActionManager::register_action (transport_actions, X_("numpad-7"), _("Numpad 7"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 7));
415         ActionManager::session_sensitive_actions.push_back (act);
416         ActionManager::transport_sensitive_actions.push_back (act);
417         act = ActionManager::register_action (transport_actions, X_("numpad-8"), _("Numpad 8"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 8));
418         ActionManager::session_sensitive_actions.push_back (act);
419         ActionManager::transport_sensitive_actions.push_back (act);
420         act = ActionManager::register_action (transport_actions, X_("numpad-9"), _("Numpad 9"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 9));
421         ActionManager::session_sensitive_actions.push_back (act);
422         ActionManager::transport_sensitive_actions.push_back (act);
423
424         act = ActionManager::register_action (transport_actions, X_("focus-on-clock"), _("Focus On Clock"), sigc::mem_fun(*this, &ARDOUR_UI::focus_on_clock));
425         ActionManager::session_sensitive_actions.push_back (act);
426         ActionManager::transport_sensitive_actions.push_back (act);
427
428         act = ActionManager::register_action (transport_actions, X_("primary-clock-timecode"), _("Timecode"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::Timecode, false));
429         ActionManager::session_sensitive_actions.push_back (act);
430         act = ActionManager::register_action (transport_actions, X_("primary-clock-bbt"), _("Bars & Beats"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::BBT, false));
431         ActionManager::session_sensitive_actions.push_back (act);
432         act = ActionManager::register_action (transport_actions, X_("primary-clock-minsec"), _("Minutes & Seconds"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::MinSec, false));
433         ActionManager::session_sensitive_actions.push_back (act);
434         act = ActionManager::register_action (transport_actions, X_("primary-clock-seconds"), _("Seconds"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::Seconds, false));
435         ActionManager::session_sensitive_actions.push_back (act);
436         act = ActionManager::register_action (transport_actions, X_("primary-clock-samples"), _("Samples"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::Samples, false));
437         ActionManager::session_sensitive_actions.push_back (act);
438
439         act = ActionManager::register_action (transport_actions, X_("secondary-clock-timecode"), _("Timecode"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::Timecode, false));
440         ActionManager::session_sensitive_actions.push_back (act);
441         act = ActionManager::register_action (transport_actions, X_("secondary-clock-bbt"), _("Bars & Beats"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::BBT, false));
442         ActionManager::session_sensitive_actions.push_back (act);
443         act = ActionManager::register_action (transport_actions, X_("secondary-clock-minsec"), _("Minutes & Seconds"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::MinSec, false));
444         ActionManager::session_sensitive_actions.push_back (act);
445         act = ActionManager::register_action (transport_actions, X_("secondary-clock-seconds"), _("Seconds"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::Seconds, false));
446         ActionManager::session_sensitive_actions.push_back (act);
447         act = ActionManager::register_action (transport_actions, X_("secondary-clock-samples"), _("Samples"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::Samples, false));
448         ActionManager::session_sensitive_actions.push_back (act);
449
450         act = ActionManager::register_toggle_action (transport_actions, X_("SessionMonitorIn"), _("All Input"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_session_monitoring_in));
451         act->set_short_label (_("All In"));
452         ActionManager::session_sensitive_actions.push_back (act);
453         act = ActionManager::register_toggle_action (transport_actions, X_("SessionMonitorDisk"), _("All Disk"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_session_monitoring_disk));
454         act->set_short_label (_("All Disk"));
455         ActionManager::session_sensitive_actions.push_back (act);
456
457         act = ActionManager::register_toggle_action (transport_actions, X_("TogglePunchIn"), _("Punch In"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_punch_in));
458         act->set_short_label (_("In"));
459         ActionManager::session_sensitive_actions.push_back (act);
460         ActionManager::transport_sensitive_actions.push_back (act);
461         act = ActionManager::register_toggle_action (transport_actions, X_("TogglePunchOut"), _("Punch Out"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_punch_out));
462         act->set_short_label (_("Out"));
463         ActionManager::session_sensitive_actions.push_back (act);
464         ActionManager::transport_sensitive_actions.push_back (act);
465         act = ActionManager::register_toggle_action (transport_actions, X_("TogglePunch"), _("Punch In/Out"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_punch));
466         act->set_short_label (_("In/Out"));
467         ActionManager::session_sensitive_actions.push_back (act);
468         ActionManager::transport_sensitive_actions.push_back (act);
469         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleClick"), _("Click"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_click));
470         ActionManager::session_sensitive_actions.push_back (act);
471         ActionManager::transport_sensitive_actions.push_back (act);
472         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleAutoInput"), _("Auto Input"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_auto_input));
473         ActionManager::session_sensitive_actions.push_back (act);
474         ActionManager::transport_sensitive_actions.push_back (act);
475         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleAutoPlay"), _("Auto Play"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_auto_play));
476         ActionManager::session_sensitive_actions.push_back (act);
477         ActionManager::transport_sensitive_actions.push_back (act);
478         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleAutoReturn"), _("Auto Return"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_auto_return));
479         ActionManager::session_sensitive_actions.push_back (act);
480         ActionManager::transport_sensitive_actions.push_back (act);
481         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleFollowEdits"), _("Follow Range"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_follow_edits));
482         ActionManager::session_sensitive_actions.push_back (act);
483         ActionManager::transport_sensitive_actions.push_back (act);
484
485         act = ActionManager::register_toggle_action (main_actions, X_("ToggleLatencyCompensation"), _("Disable Latency Compensation"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_latency_switch));
486
487         act = ActionManager::register_action (main_actions, X_("MonitorMenu"), _("Monitor Section")); /* just the submenu item */
488         ActionManager::session_sensitive_actions.push_back (act);
489
490         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleVideoSync"), _("Sync Startup to Video"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_video_sync));
491         ActionManager::session_sensitive_actions.push_back (act);
492         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleTimeMaster"), _("Time Master"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_time_master));
493         ActionManager::session_sensitive_actions.push_back (act);
494         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleExternalSync"), _("Use External Positional Sync Source"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_external_sync));
495         ActionManager::session_sensitive_actions.push_back (act);
496
497         for (int i = 1; i <= 32; ++i) {
498                 string const a = string_compose (X_("ToggleRecordEnableTrack%1"), i);
499                 string const n = string_compose (_("Toggle Record Enable Track %1"), i);
500                 act = ActionManager::register_action (common_actions, a.c_str(), n.c_str(), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::toggle_record_enable), i - 1));
501                 ActionManager::session_sensitive_actions.push_back (act);
502         }
503
504         Glib::RefPtr<ActionGroup> shuttle_actions = ActionManager::create_action_group (global_bindings, "ShuttleActions");
505
506         shuttle_actions->add (Action::create (X_("SetShuttleUnitsPercentage"), _("Percentage")), hide_return (sigc::bind (sigc::mem_fun (*Config, &RCConfiguration::set_shuttle_units), Percentage)));
507         shuttle_actions->add (Action::create (X_("SetShuttleUnitsSemitones"), _("Semitones")), hide_return (sigc::bind (sigc::mem_fun (*Config, &RCConfiguration::set_shuttle_units), Semitones)));
508
509         Glib::RefPtr<ActionGroup> option_actions = ActionManager::create_action_group (global_bindings, "Options");
510
511         act = ActionManager::register_toggle_action (option_actions, X_("SendMTC"), _("Send MTC"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_send_mtc));
512         ActionManager::session_sensitive_actions.push_back (act);
513         act = ActionManager::register_toggle_action (option_actions, X_("SendMMC"), _("Send MMC"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_send_mmc));
514         ActionManager::session_sensitive_actions.push_back (act);
515         act = ActionManager::register_toggle_action (option_actions, X_("UseMMC"), _("Use MMC"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_use_mmc));
516         ActionManager::session_sensitive_actions.push_back (act);
517         act = ActionManager::register_toggle_action (option_actions, X_("SendMidiClock"), _("Send MIDI Clock"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_send_midi_clock));
518         ActionManager::session_sensitive_actions.push_back (act);
519
520         /* MIDI */
521
522         Glib::RefPtr<ActionGroup> midi_actions = ActionManager::create_action_group (global_bindings, X_("MIDI"));
523         act = ActionManager::register_action (midi_actions, X_("panic"), _("Panic (Send MIDI all-notes-off)"), sigc::mem_fun(*this, &ARDOUR_UI::midi_panic));
524         ActionManager::session_sensitive_actions.push_back (act);
525         ActionManager::transport_sensitive_actions.push_back (act);
526 }
527
528 void
529 ARDOUR_UI::install_dependent_actions ()
530 {
531         using namespace Glib;
532         using namespace Gtk;
533
534         RefPtr<ActionGroup> main_actions = ActionManager::get_action_group (X_("Main"));
535         assert (main_actions);
536         RefPtr<ActionGroup> common_actions = ActionManager::get_action_group (X_("Common"));
537         assert (common_actions);
538         RefPtr<ActionGroup> transport_actions = ActionManager::get_action_group (X_("Transport"));
539         assert (transport_actions);
540
541         RefPtr<Action> act;
542
543         /* these two behave as follows:
544
545            - if transport speed != 1.0 or != -1.0, change speed to 1.0 or -1.0 (respectively)
546            - otherwise do nothing
547         */
548
549         act = ActionManager::register_action (transport_actions, X_("TransitionToRoll"), _("Transition to Roll"), sigc::bind (sigc::mem_fun (*editor, &PublicEditor::transition_to_rolling), true));
550         ActionManager::session_sensitive_actions.push_back (act);
551         ActionManager::transport_sensitive_actions.push_back (act);
552
553         act = ActionManager::register_action (transport_actions, X_("TransitionToReverse"), _("Transition to Reverse"), sigc::bind (sigc::mem_fun (*editor, &PublicEditor::transition_to_rolling), false));
554         ActionManager::session_sensitive_actions.push_back (act);
555         ActionManager::transport_sensitive_actions.push_back (act);
556
557         act = ActionManager::register_action (common_actions, "jump-backward-to-mark", _("Jump to Previous Mark"), sigc::mem_fun(*editor, &PublicEditor::jump_backward_to_mark));
558         ActionManager::session_sensitive_actions.push_back (act);
559
560         act = ActionManager::register_action (common_actions, "jump-forward-to-mark", _("Jump to Next Mark"), sigc::mem_fun(*editor, &PublicEditor::jump_forward_to_mark));
561         ActionManager::session_sensitive_actions.push_back (act);
562
563         act = ActionManager::register_action (common_actions, X_("addExistingAudioFiles"), _("Import"), sigc::mem_fun (*editor, &PublicEditor::external_audio_dialog));
564         ActionManager::session_sensitive_actions.push_back (act);
565         ActionManager::write_sensitive_actions.push_back (act);
566
567         act = ActionManager::register_action (main_actions, X_("StemExport"), _("Stem export..."),  sigc::mem_fun (*editor, &PublicEditor::stem_export));
568         ActionManager::session_sensitive_actions.push_back (act);
569
570         act = ActionManager::register_action (main_actions, X_("ExportAudio"), _("Export to Audio File(s)..."),  sigc::mem_fun (*editor, &PublicEditor::export_audio));
571         ActionManager::session_sensitive_actions.push_back (act);
572
573         act = ActionManager::register_action (main_actions, X_("CleanupUnusedSources"), _("Clean-up Unused Sources..."),  sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::cleanup));
574         ActionManager::session_sensitive_actions.push_back (act);
575         ActionManager::write_sensitive_actions.push_back (act);
576
577         act = ActionManager::register_action (main_actions, X_("CleanupUnusedRegions"), _("Clean-up Unused Regions..."),  sigc::mem_fun (*editor, &PublicEditor::cleanup_regions));
578         ActionManager::session_sensitive_actions.push_back (act);
579         ActionManager::write_sensitive_actions.push_back (act);
580
581         act = ActionManager::register_action (main_actions, X_("CleanupPeakFiles"), _("Reset Peak Files"),  sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::cleanup_peakfiles));
582         ActionManager::session_sensitive_actions.push_back (act);
583         ActionManager::write_sensitive_actions.push_back (act);
584
585         /* these actions are all currently implemented by the Editor, but need
586          * to be accessible from anywhere as actions.
587          */
588
589         act = ActionManager::register_action (common_actions, "alternate-jump-forward-to-mark", _("Jump to Next Mark"), sigc::mem_fun(editor, &PublicEditor::jump_forward_to_mark));
590         ActionManager::session_sensitive_actions.push_back (act);
591         act = ActionManager::register_action (common_actions, "alternate-jump-backward-to-mark", _("Jump to Previous Mark"), sigc::mem_fun(editor, &PublicEditor::jump_backward_to_mark));
592         ActionManager::session_sensitive_actions.push_back (act);
593
594         act = ActionManager::register_action (common_actions, "set-session-start-from-playhead", _("Set Session Start from Playhead"), sigc::mem_fun(editor, &PublicEditor::set_session_start_from_playhead));
595         ActionManager::session_sensitive_actions.push_back (act);
596         act = ActionManager::register_action (common_actions, "set-session-end-from-playhead", _("Set Session End from Playhead"), sigc::mem_fun(editor, &PublicEditor::set_session_end_from_playhead));
597         ActionManager::session_sensitive_actions.push_back (act);
598
599         act = ActionManager::register_action (common_actions, "toggle-location-at-playhead", _("Toggle Mark at Playhead"), sigc::mem_fun(editor, &PublicEditor::toggle_location_at_playhead_cursor));
600         ActionManager::session_sensitive_actions.push_back (act);
601         act = ActionManager::register_action (common_actions, "add-location-from-playhead", _("Add Mark from Playhead"), sigc::mem_fun(editor, &PublicEditor::add_location_from_playhead_cursor));
602         ActionManager::session_sensitive_actions.push_back (act);
603         act = ActionManager::register_action (common_actions, "alternate-add-location-from-playhead", _("Add Mark from Playhead"), sigc::mem_fun(editor, &PublicEditor::add_location_from_playhead_cursor));
604         ActionManager::session_sensitive_actions.push_back (act);
605
606         act = ActionManager::register_action (common_actions, "remove-location-from-playhead", _("Remove Mark at Playhead"), sigc::mem_fun(editor, &PublicEditor::remove_location_at_playhead_cursor));
607         ActionManager::session_sensitive_actions.push_back (act);
608         act = ActionManager::register_action (common_actions, "alternate-remove-location-from-playhead", _("Remove Mark at Playhead"), sigc::mem_fun(editor, &PublicEditor::remove_location_at_playhead_cursor));
609         ActionManager::session_sensitive_actions.push_back (act);
610
611         act = ActionManager::register_action (common_actions, "nudge-next-forward", _("Nudge Next Later"), sigc::bind (sigc::mem_fun(editor, &PublicEditor::nudge_forward), true, false));
612         ActionManager::session_sensitive_actions.push_back (act);
613         act = ActionManager::register_action (common_actions, "nudge-next-backward", _("Nudge Next Earlier"), sigc::bind (sigc::mem_fun(editor, &PublicEditor::nudge_backward), true, false));
614         ActionManager::session_sensitive_actions.push_back (act);
615
616         act = ActionManager::register_action (common_actions, "nudge-playhead-forward", _("Nudge Playhead Forward"), sigc::bind (sigc::mem_fun(editor, &PublicEditor::nudge_forward), false, true));
617         ActionManager::session_sensitive_actions.push_back (act);
618         act = ActionManager::register_action (common_actions, "nudge-playhead-backward", _("Nudge Playhead Backward"), sigc::bind (sigc::mem_fun(editor, &PublicEditor::nudge_backward), false, true));
619         ActionManager::session_sensitive_actions.push_back (act);
620         act = ActionManager::register_action (common_actions, "playhead-forward-to-grid", _("Playhead to Next Grid"), sigc::mem_fun(editor, &PublicEditor::playhead_forward_to_grid));
621         ActionManager::session_sensitive_actions.push_back (act);
622         act = ActionManager::register_action (common_actions, "playhead-backward-to-grid", _("Playhead to Previous Grid"), sigc::mem_fun(editor, &PublicEditor::playhead_backward_to_grid));
623         ActionManager::session_sensitive_actions.push_back (act);
624
625         act = ActionManager::register_action (common_actions, "start-range-from-playhead", _("Start Range from Playhead"), sigc::bind (sigc::mem_fun(editor, &PublicEditor::keyboard_selection_begin), Editing::EDIT_IGNORE_MOUSE ));
626         ActionManager::session_sensitive_actions.push_back (act);
627         act = ActionManager::register_action (common_actions, "finish-range-from-playhead", _("Finish Range from Playhead"), sigc::bind (sigc::mem_fun(editor, &PublicEditor::keyboard_selection_finish), false, Editing::EDIT_IGNORE_MOUSE ));
628         ActionManager::session_sensitive_actions.push_back (act);
629         act = ActionManager::register_action (common_actions, "start-range", _("Start Range"), sigc::bind (sigc::mem_fun(editor, &PublicEditor::keyboard_selection_begin), Editing::EDIT_IGNORE_NONE));
630         ActionManager::session_sensitive_actions.push_back (act);
631         act = ActionManager::register_action (common_actions, "finish-range", _("Finish Range"), sigc::bind (sigc::mem_fun(editor, &PublicEditor::keyboard_selection_finish), false, Editing::EDIT_IGNORE_NONE));
632         ActionManager::session_sensitive_actions.push_back (act);
633         act = ActionManager::register_action (common_actions, "start-punch-range", _("Start Punch Range"), sigc::mem_fun(editor, &PublicEditor::set_punch_start_from_edit_point));
634         ActionManager::session_sensitive_actions.push_back (act);
635         act = ActionManager::register_action (common_actions, "finish-punch-range", _("Finish Punch Range"), sigc::mem_fun(editor, &PublicEditor::set_punch_end_from_edit_point));
636         ActionManager::session_sensitive_actions.push_back (act);
637         act = ActionManager::register_action (common_actions, "start-loop-range", _("Start Loop Range"), sigc::mem_fun(editor, &PublicEditor::set_loop_start_from_edit_point));
638         ActionManager::session_sensitive_actions.push_back (act);
639         act = ActionManager::register_action (common_actions, "finish-loop-range", _("Finish Loop Range"), sigc::mem_fun(editor, &PublicEditor::set_loop_end_from_edit_point));
640         ActionManager::session_sensitive_actions.push_back (act);
641         act = ActionManager::register_action (common_actions, "alt-start-range", _("Start Range"), sigc::bind (sigc::mem_fun(editor, &PublicEditor::keyboard_selection_begin), Editing::EDIT_IGNORE_NONE));
642         ActionManager::session_sensitive_actions.push_back (act);
643         act = ActionManager::register_action (common_actions, "alt-finish-range", _("Finish Range"), sigc::bind (sigc::mem_fun(editor, &PublicEditor::keyboard_selection_finish), false, Editing::EDIT_IGNORE_NONE));
644         ActionManager::session_sensitive_actions.push_back (act);
645
646         act = ActionManager::register_action (common_actions, "select-all-tracks", _("Select All Tracks"), sigc::mem_fun(editor, &PublicEditor::select_all_tracks));
647         ActionManager::session_sensitive_actions.push_back (act);
648         act = ActionManager::register_action (common_actions, "deselect-all", _("Deselect All"), sigc::mem_fun(editor, &PublicEditor::deselect_all));
649         ActionManager::session_sensitive_actions.push_back (act);
650         act = ActionManager::register_action (common_actions, "invert-selection", _("Invert Selection"), sigc::mem_fun(editor, &PublicEditor::invert_selection));
651         ActionManager::session_sensitive_actions.push_back (act);
652
653         act = ActionManager::register_action (transport_actions, X_("solo-selection"), _("Solo Selection"), sigc::bind (sigc::mem_fun(*editor, &PublicEditor::play_solo_selection), true));
654         ActionManager::session_sensitive_actions.push_back (act);
655         ActionManager::transport_sensitive_actions.push_back (act);
656
657         /* XXX */
658
659         ActionManager::register_action (common_actions, X_("show-preferences"), _("Show"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::show_tabbable), rc_option_editor));
660         ActionManager::register_action (common_actions, X_("menu-show-preferences"), _("Preferences"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::show_tabbable), rc_option_editor));
661
662         ActionManager::register_action (common_actions, X_("hide-editor"), _("Hide"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::hide_tabbable), editor));
663         ActionManager::register_action (common_actions, X_("hide-mixer"), _("Hide"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::hide_tabbable), mixer));
664         ActionManager::register_action (common_actions, X_("hide-preferences"), _("Hide"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::hide_tabbable), rc_option_editor));
665
666         ActionManager::register_action (common_actions, X_("attach-editor"), _("Attach"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::attach_tabbable), editor));
667         ActionManager::register_action (common_actions, X_("attach-mixer"), _("Attach"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::attach_tabbable), mixer));
668         ActionManager::register_action (common_actions, X_("attach-preferences"), _("Attach"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::attach_tabbable), rc_option_editor));
669
670         ActionManager::register_action (common_actions, X_("detach-editor"), _("Detach"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::detach_tabbable), editor));
671         ActionManager::register_action (common_actions, X_("detach-mixer"), _("Detach"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::detach_tabbable), mixer));
672         ActionManager::register_action (common_actions, X_("detach-preferences"), _("Detach"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::detach_tabbable), rc_option_editor));
673
674         ActionManager::register_action (common_actions, X_("show-mixer"), _("Show Mixer"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::show_tabbable), mixer));
675         ActionManager::register_action (common_actions, X_("show-editor"), _("Show Editor"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::show_tabbable), editor));
676
677         /* These "change" actions are not intended to be used inside menus, but
678            are for the tab/window control buttons, which have somewhat odd
679            semantics.
680         */
681         ActionManager::register_action (common_actions, X_("change-editor-visibility"), _("Change"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::button_change_tabbable_visibility), editor));
682         ActionManager::register_action (common_actions, X_("change-mixer-visibility"), _("Change"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::button_change_tabbable_visibility), mixer));
683         ActionManager::register_action (common_actions, X_("change-preferences-visibility"), _("Change"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::button_change_tabbable_visibility), rc_option_editor));
684
685         /* These "change" actions are not intended to be used inside menus, but
686            are for the tab/window control key bindings, which have somewhat odd
687            semantics.
688         */
689         ActionManager::register_action (common_actions, X_("key-change-editor-visibility"), _("Change"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::key_change_tabbable_visibility), editor));
690         ActionManager::register_action (common_actions, X_("key-change-mixer-visibility"), _("Change"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::key_change_tabbable_visibility), mixer));
691         ActionManager::register_action (common_actions, X_("key-change-preferences-visibility"), _("Change"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::key_change_tabbable_visibility), rc_option_editor));
692
693         ActionManager::register_action (common_actions, X_("previous-tab"), _("Previous Tab"), sigc::mem_fun (*this, &ARDOUR_UI::step_up_through_tabs));
694         ActionManager::register_action (common_actions, X_("next-tab"), _("Next Tab"), sigc::mem_fun (*this, &ARDOUR_UI::step_down_through_tabs));
695
696         ActionManager::register_action (common_actions, X_("toggle-editor-and-mixer"), _("Toggle Editor & Mixer"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_editor_and_mixer));
697
698         /* windows visibility actions */
699
700         ActionManager::register_toggle_action (common_actions, X_("ToggleMaximalEditor"), _("Maximise Editor Space"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_editing_space));
701         ActionManager::register_toggle_action (common_actions, X_("ToggleMaximalMixer"), _("Maximise Mixer Space"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_mixer_space));
702         ActionManager::session_sensitive_actions.push_back (act);
703 }
704
705 void
706 ARDOUR_UI::build_menu_bar ()
707 {
708         menu_bar = dynamic_cast<MenuBar*> (ActionManager::get_widget (X_("/Main")));
709         menu_bar->set_name ("MainMenuBar");
710
711         EventBox* ev = manage (new EventBox);
712         ev->set_name ("MainMenuBar");
713         ev->show ();
714
715         Gtk::HBox* hbox = manage (new Gtk::HBox);
716         hbox->show ();
717         hbox->set_border_width (2);
718         ev->add (*hbox);
719
720         wall_clock_label.set_name ("WallClock");
721         wall_clock_label.set_use_markup ();
722         timecode_format_label.set_name ("WallClock");
723         timecode_format_label.set_use_markup ();
724         peak_thread_work_label.set_name ("PeakThreadWork");
725         peak_thread_work_label.set_use_markup ();
726         sample_rate_label.set_name ("SampleRate");
727         sample_rate_label.set_use_markup ();
728         format_label.set_name ("Format");
729         format_label.set_use_markup ();
730
731 #ifdef __APPLE__
732         use_menubar_as_top_menubar ();
733 #else
734         menu_hbox.pack_start (*menu_bar, false, false);
735 #endif
736
737         hbox->pack_end (error_alert_button, false, false, 2);
738         hbox->pack_end (dsp_load_label, false, false, 4);
739         hbox->pack_end (disk_space_label, false, false, 4);
740         hbox->pack_end (sample_rate_label, false, false, 4);
741         hbox->pack_end (timecode_format_label, false, false, 4);
742         hbox->pack_end (format_label, false, false, 4);
743         hbox->pack_end (peak_thread_work_label, false, false, 4);
744         hbox->pack_end (wall_clock_label, false, false, 2);
745
746         menu_hbox.pack_end (*ev, true, true, 2);
747
748         menu_bar_base.set_name ("MainMenuBar");
749         menu_bar_base.add (menu_hbox);
750
751 #ifndef __APPLE__
752         // OSX provides its own wallclock, thank you very much
753         _status_bar_visibility.add (&wall_clock_label,      X_("WallClock"), _("Wall Clock"), false);
754 #endif
755         _status_bar_visibility.add (&peak_thread_work_label,X_("Peakfile"),  _("Active Peak-file Work"), false);
756         _status_bar_visibility.add (&format_label,          X_("Format"),    _("File Format"), false);
757         _status_bar_visibility.add (&timecode_format_label, X_("TCFormat"),  _("Timecode Format"), false);
758         _status_bar_visibility.add (&sample_rate_label,     X_("Audio"),     _("Audio"), true);
759         _status_bar_visibility.add (&disk_space_label,      X_("Disk"),      _("Disk Space"), !Profile->get_small_screen());
760         _status_bar_visibility.add (&dsp_load_label,        X_("DSP"),       _("DSP"), true);
761
762         ev->signal_button_press_event().connect (sigc::mem_fun (_status_bar_visibility, &VisibilityGroup::button_press_event));
763         ev->signal_button_release_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::xrun_button_release));
764 }
765
766 void
767 ARDOUR_UI::use_menubar_as_top_menubar ()
768 {
769         Gtk::Widget* widget;
770         Application* app = Application::instance ();
771
772         /* the addresses ("/ui/Main...") used below are based on the menu definitions in the menus file
773         */
774
775         /* Quit will be taken care of separately */
776
777         if ((widget = ActionManager::get_widget ("/ui/Main/Session/Quit"))) {
778                 widget->hide ();
779         }
780
781         /* Put items for About and Preferences into App menu (the
782          * ardour.menus.in file does not list them for OS X)
783          */
784
785         GtkApplicationMenuGroup* group = app->add_app_menu_group ();
786
787         if ((widget = ActionManager::get_widget ("/ui/Main/Session/toggle-about"))) {
788                 app->add_app_menu_item (group, dynamic_cast<MenuItem*>(widget));
789         }
790
791         if ((widget = ActionManager::get_widget ("/ui/Main/Edit/menu-show-preferences"))) {
792                 app->add_app_menu_item (group, dynamic_cast<MenuItem*>(widget));
793         }
794
795         app->set_menu_bar (*menu_bar);
796 }
797
798 void
799 ARDOUR_UI::save_ardour_state ()
800 {
801         if (!keyboard || !mixer || !editor || !meterbridge) {
802                 return;
803         }
804
805         /* XXX this is all a bit dubious. add_extra_xml() uses
806            a different lifetime model from add_instant_xml().
807         */
808
809         XMLNode* node = new XMLNode (keyboard->get_state());
810         Config->add_extra_xml (*node);
811
812         XMLNode* window_node = new XMLNode (X_("UI"));
813         window_node->set_property (_status_bar_visibility.get_state_name().c_str(), _status_bar_visibility.get_state_value ());
814
815         /* main window */
816
817         gint mx, my, mw, mh;
818         _main_window.get_position (mx, my);
819         _main_window.get_size (mw, mh);
820
821         XMLNode main_window_node (X_("Main"));
822         main_window_node.set_property (X_("x"), mx);
823         main_window_node.set_property (X_("y"), my);
824         main_window_node.set_property (X_("w"), mw);
825         main_window_node.set_property (X_("h"), mh);
826
827         string current_tab;
828         int current_page_number = _tabs.get_current_page ();
829         if (current_page_number == _tabs.page_num (editor->contents())) {
830                 current_tab = "editor";
831         } else if (current_page_number == _tabs.page_num (mixer->contents())) {
832                 current_tab = "mixer";
833         } else if (current_page_number == _tabs.page_num (rc_option_editor->contents())) {
834                 current_tab = "preferences";
835         }
836
837         main_window_node.set_property (X_("current-tab"), current_tab);
838
839         /* Windows */
840
841         WM::Manager::instance().add_state (*window_node);
842
843         XMLNode* tearoff_node = new XMLNode (X_("Tearoffs"));
844
845         XMLNode* t = new XMLNode (X_("monitor-section"));
846         mixer->monitor_section().tearoff().add_state (*t);
847         tearoff_node->add_child_nocopy (*t);
848
849         window_node->add_child_nocopy (*tearoff_node);
850
851         XMLNode& enode (editor->get_state());
852         XMLNode& mnode (mixer->get_state());
853         XMLNode& bnode (meterbridge->get_state());
854         XMLNode& pnode (rc_option_editor->get_state());
855
856         Config->add_extra_xml (*window_node);
857         Config->add_extra_xml (audio_midi_setup->get_state());
858
859         Config->save_state();
860
861         mixer->save_plugin_order_file();
862
863         UIConfiguration::instance().save_state ();
864
865         if (_session) {
866                 _session->add_instant_xml (main_window_node);
867                 _session->add_instant_xml (enode);
868                 _session->add_instant_xml (mnode);
869                 _session->add_instant_xml (pnode);
870                 _session->add_instant_xml (bnode);
871                 if (location_ui) {
872                         _session->add_instant_xml (location_ui->ui().get_state ());
873                 }
874         } else {
875                 Config->add_instant_xml (main_window_node);
876                 Config->add_instant_xml (enode);
877                 Config->add_instant_xml (mnode);
878                 Config->add_instant_xml (pnode);
879                 Config->add_instant_xml (bnode);
880                 if (location_ui) {
881                         Config->add_instant_xml (location_ui->ui().get_state ());
882                 }
883         }
884
885         delete &enode;
886         delete &mnode;
887         delete &bnode;
888         delete &pnode;
889
890         Keyboard::save_keybindings ();
891 }
892
893 void
894 ARDOUR_UI::on_theme_changed ()
895 {
896         LV2Plugin::set_global_ui_background_color (UIConfiguration::instance().color ("gtk_background"));
897         LV2Plugin::set_global_ui_foreground_color (UIConfiguration::instance().color ("gtk_foreground"));
898         LV2Plugin::set_global_ui_scale_factor (UIConfiguration::instance().get_ui_scale());
899 }
900
901 void
902 ARDOUR_UI::focus_on_clock ()
903 {
904         if (primary_clock) {
905                 primary_clock->focus ();
906         }
907 }
908
909 bool
910 ARDOUR_UI::xrun_button_release (GdkEventButton* ev)
911 {
912         if (ev->button != 1 || !Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
913                 return false;
914         }
915
916         if (_session) {
917                 _session->reset_xrun_count ();
918                 update_cpu_load ();
919         }
920         return true;
921 }
922
923 Gtk::Notebook&
924 ARDOUR_UI::tabs()
925 {
926         return _tabs;
927 }
928
929 bool
930 ARDOUR_UI::tabbable_visibility_button_press (GdkEventButton* ev, string const& tabbable_name)
931 {
932         if (ev->button != 3) {
933                 return false;
934         }
935
936         /* context menu is defined in *.menus.in
937          */
938
939         string menu_name = string ("/ui/") + tabbable_name + X_("TabbableButtonMenu");
940         Gtk::Menu* menu = dynamic_cast<Gtk::Menu*> (ActionManager::get_widget (menu_name.c_str()));
941         if (menu) {
942                 menu->popup (3, ev->time);
943         }
944         return true;
945 }