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