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