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