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