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