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