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