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