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