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