Add more menu entries to the 'Help' menu.
[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         act = ActionManager::register_action (main_actions, X_("duplicate-routes"), _("Duplicate Tracks/Busses"),
136                                               sigc::mem_fun(*this, &ARDOUR_UI::start_duplicate_routes));
137         ActionManager::session_sensitive_actions.push_back (act);
138         ActionManager::write_sensitive_actions.push_back (act);
139         ActionManager::track_selection_sensitive_actions.push_back (act);
140
141         act = ActionManager::register_action (main_actions, X_("cancel-solo"), _("Cancel Solo"), sigc::mem_fun(*this, &ARDOUR_UI::cancel_solo));
142         ActionManager::session_sensitive_actions.push_back (act);
143         ActionManager::write_sensitive_actions.push_back (act);
144
145
146         act = ActionManager::register_action (main_actions, X_("OpenVideo"), _("Open Video"),
147                                               sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::add_video), (Gtk::Window*) 0));
148         ActionManager::session_sensitive_actions.push_back (act);
149         act = ActionManager::register_action (main_actions, X_("CloseVideo"), _("Remove Video"),
150                                               sigc::mem_fun (*this, &ARDOUR_UI::remove_video));
151         act->set_sensitive (false);
152         act = ActionManager::register_action (main_actions, X_("ExportVideo"), _("Export To Video File"),
153                         hide_return (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::export_video), false)));
154         ActionManager::session_sensitive_actions.push_back (act);
155
156         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));
157         ActionManager::session_sensitive_actions.push_back (act);
158         ActionManager::write_sensitive_actions.push_back (act);
159
160         act = ActionManager::register_action (main_actions, X_("SnapshotSwitch"), _("Snapshot (& switch to new version) ..."), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::snapshot_session), true));
161         ActionManager::session_sensitive_actions.push_back (act);
162         ActionManager::write_sensitive_actions.push_back (act);
163
164         act = ActionManager::register_action (main_actions, X_("SaveAs"), _("Save As..."), sigc::mem_fun(*this, &ARDOUR_UI::save_session_as));
165         ActionManager::session_sensitive_actions.push_back (act);
166         ActionManager::write_sensitive_actions.push_back (act);
167
168         act = ActionManager::register_action (main_actions, X_("Rename"), _("Rename..."), sigc::mem_fun(*this, &ARDOUR_UI::rename_session));
169         ActionManager::session_sensitive_actions.push_back (act);
170         ActionManager::write_sensitive_actions.push_back (act);
171
172         act = ActionManager::register_action (main_actions, X_("SaveTemplate"), _("Save Template..."),  sigc::mem_fun(*this, &ARDOUR_UI::save_template));
173         ActionManager::session_sensitive_actions.push_back (act);
174
175         act = ActionManager::register_action (main_actions, X_("Metadata"), _("Metadata"));
176         ActionManager::session_sensitive_actions.push_back (act);
177
178         act = ActionManager::register_action (main_actions, X_("EditMetadata"), _("Edit Metadata..."),  sigc::mem_fun(*this, &ARDOUR_UI::edit_metadata));
179         ActionManager::session_sensitive_actions.push_back (act);
180
181         act = ActionManager::register_action (main_actions, X_("ImportMetadata"), _("Import Metadata..."),  sigc::mem_fun(*this, &ARDOUR_UI::import_metadata));
182         ActionManager::session_sensitive_actions.push_back (act);
183
184         act = ActionManager::register_action (main_actions, X_("ExportAudio"), _("Export To Audio File(s)..."),  sigc::mem_fun (*editor, &PublicEditor::export_audio));
185         ActionManager::session_sensitive_actions.push_back (act);
186
187         act = ActionManager::register_action (main_actions, X_("StemExport"), _("Stem export..."),  sigc::mem_fun (*editor, &PublicEditor::stem_export));
188         ActionManager::session_sensitive_actions.push_back (act);
189
190         act = ActionManager::register_action (main_actions, X_("Export"), _("Export"));
191         ActionManager::session_sensitive_actions.push_back (act);
192
193         act = ActionManager::register_action (main_actions, X_("CleanupUnused"), _("Clean-up Unused Sources..."),  sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::cleanup));
194         ActionManager::session_sensitive_actions.push_back (act);
195         ActionManager::write_sensitive_actions.push_back (act);
196
197         act = ActionManager::register_action (main_actions, X_("CleanupPeakFiles"), _("Reset Peak Files"),  sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::cleanup_peakfiles));
198         ActionManager::session_sensitive_actions.push_back (act);
199         ActionManager::write_sensitive_actions.push_back (act);
200
201         act = ActionManager::register_action (main_actions, X_("FlushWastebasket"), _("Flush Wastebasket"),  sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::flush_trash));
202         ActionManager::write_sensitive_actions.push_back (act);
203         ActionManager::session_sensitive_actions.push_back (act);
204
205         /* these actions are intended to be shared across all windows */
206
207         common_actions = ActionGroup::create (X_("Common"));
208         ActionManager::register_action (common_actions, X_("Quit"), _("Quit"), (hide_return (sigc::mem_fun(*this, &ARDOUR_UI::finish))));
209         ActionManager::register_action (common_actions, X_("Hide"), _("Hide"), sigc::mem_fun (*this, &ARDOUR_UI::hide_application));
210
211         /* windows visibility actions */
212
213         ActionManager::register_toggle_action (common_actions, X_("ToggleMaximalEditor"), _("Maximise Editor Space"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_editing_space));
214         ActionManager::register_toggle_action (common_actions, X_("ToggleMaximalMixer"), _("Maximise Mixer Space"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_mixer_space));
215         act = ActionManager::register_toggle_action (common_actions, X_("KeepTearoffs"), _("Show Toolbars"), mem_fun (*this, &ARDOUR_UI::toggle_keep_tearoffs));
216         ActionManager::session_sensitive_actions.push_back (act);
217
218 if (Profile->get_mixbus())
219         ActionManager::register_action (common_actions, X_("show-ui-prefs"), _("Show more UI preferences"), sigc::mem_fun (*this, &ARDOUR_UI::show_ui_prefs));
220
221         ActionManager::register_action (common_actions, X_("toggle-mixer"), S_("Window|Mixer"),  sigc::mem_fun(*this, &ARDOUR_UI::toggle_mixer_window));
222         ActionManager::register_action (common_actions, X_("toggle-editor-mixer"), _("Toggle Editor+Mixer"),  sigc::mem_fun(*this, &ARDOUR_UI::toggle_editor_mixer));
223         ActionManager::register_action (common_actions, X_("toggle-meterbridge"), S_("Window|Meterbridge"),  sigc::mem_fun(*this, &ARDOUR_UI::toggle_meterbridge));
224
225         ActionManager::register_action (common_actions, X_("reattach-all-tearoffs"), _("Reattach All Tearoffs"), sigc::mem_fun (*this, &ARDOUR_UI::reattach_all_tearoffs));
226
227         act = ActionManager::register_action (common_actions, X_("NewMIDITracer"), _("MIDI Tracer"), sigc::mem_fun(*this, &ARDOUR_UI::new_midi_tracer_window));
228         ActionManager::session_sensitive_actions.push_back (act);
229         ActionManager::register_action (common_actions, X_("Chat"), _("Chat"),  sigc::mem_fun(*this, &ARDOUR_UI::launch_chat));
230         /** TRANSLATORS: This is `Manual' in the sense of an instruction book that tells a user how to use Ardour */
231         ActionManager::register_action (common_actions, X_("Manual"), S_("Help|Manual"),  mem_fun(*this, &ARDOUR_UI::launch_manual));
232         ActionManager::register_action (common_actions, X_("Reference"), _("Reference"),  mem_fun(*this, &ARDOUR_UI::launch_reference));
233         ActionManager::register_action (common_actions, X_("Tracker"), _("Report a Bug"), mem_fun(*this, &ARDOUR_UI::launch_tracker));
234         ActionManager::register_action (common_actions, X_("Cheat_Sheet"), _("Cheat Sheet"), mem_fun(*this, &ARDOUR_UI::launch_cheat_sheet));
235         ActionManager::register_action (common_actions, X_("Website"), _("Ardour Website"), mem_fun(*this, &ARDOUR_UI::launch_website));
236         ActionManager::register_action (common_actions, X_("Website_Dev"), _("Ardour Development"), mem_fun(*this, &ARDOUR_UI::launch_website_dev));
237         ActionManager::register_action (common_actions, X_("Forums"), _("User Forums"), mem_fun(*this, &ARDOUR_UI::launch_forums));
238         ActionManager::register_action (common_actions, X_("Howto_Report"), _("How to Report a Bug"), mem_fun(*this, &ARDOUR_UI::launch_howto_report));
239
240         act = ActionManager::register_action (common_actions, X_("Save"), _("Save"),  sigc::hide_return (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::save_state), string(""), false)));
241         ActionManager::session_sensitive_actions.push_back (act);
242         ActionManager::write_sensitive_actions.push_back (act);
243
244         Glib::RefPtr<ActionGroup> transport_actions = ActionGroup::create (X_("Transport"));
245
246         /* do-nothing action for the "transport" menu bar item */
247
248         ActionManager::register_action (transport_actions, X_("Transport"), _("Transport"));
249
250         /* these two are not used by key bindings, instead use ToggleRoll for that. these two do show up in
251            menus and via button proxies.
252         */
253
254         act = ActionManager::register_action (transport_actions, X_("Stop"), _("Stop"), sigc::mem_fun(*this, &ARDOUR_UI::transport_stop));
255         ActionManager::session_sensitive_actions.push_back (act);
256         ActionManager::transport_sensitive_actions.push_back (act);
257         act = ActionManager::register_action (transport_actions, X_("Roll"), _("Roll"), sigc::mem_fun(*this, &ARDOUR_UI::transport_roll));
258         ActionManager::session_sensitive_actions.push_back (act);
259         ActionManager::transport_sensitive_actions.push_back (act);
260
261         act = ActionManager::register_action (transport_actions, X_("ToggleRoll"), _("Start/Stop"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::toggle_roll), false, false));
262         ActionManager::session_sensitive_actions.push_back (act);
263         ActionManager::transport_sensitive_actions.push_back (act);
264         act = ActionManager::register_action (transport_actions, X_("alternate-ToggleRoll"), _("Start/Stop"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::toggle_roll), false, false));
265         ActionManager::session_sensitive_actions.push_back (act);
266         ActionManager::transport_sensitive_actions.push_back (act);
267         act = ActionManager::register_action (transport_actions, X_("ToggleRollMaybe"), _("Start/Continue/Stop"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::toggle_roll), false, true));
268         ActionManager::session_sensitive_actions.push_back (act);
269         ActionManager::transport_sensitive_actions.push_back (act);
270         act = ActionManager::register_action (transport_actions, X_("ToggleRollForgetCapture"), _("Stop and Forget Capture"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::toggle_roll), true, false));
271         ActionManager::session_sensitive_actions.push_back (act);
272         ActionManager::transport_sensitive_actions.push_back (act);
273
274         /* these two behave as follows:
275
276            - if transport speed != 1.0 or != -1.0, change speed to 1.0 or -1.0 (respectively)
277            - otherwise do nothing
278         */
279
280         act = ActionManager::register_action (transport_actions, X_("TransitionToRoll"), _("Transition To Roll"), sigc::bind (sigc::mem_fun (*editor, &PublicEditor::transition_to_rolling), true));
281         ActionManager::session_sensitive_actions.push_back (act);
282         ActionManager::transport_sensitive_actions.push_back (act);
283
284         act = ActionManager::register_action (transport_actions, X_("TransitionToReverse"), _("Transition To Reverse"), sigc::bind (sigc::mem_fun (*editor, &PublicEditor::transition_to_rolling), false));
285         ActionManager::session_sensitive_actions.push_back (act);
286         ActionManager::transport_sensitive_actions.push_back (act);
287
288         act = ActionManager::register_action (transport_actions, X_("Loop"), _("Play Loop Range"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_session_auto_loop));
289         ActionManager::session_sensitive_actions.push_back (act);
290         ActionManager::transport_sensitive_actions.push_back (act);
291         act = ActionManager::register_action (transport_actions, X_("PlaySelection"), _("Play Selection"), sigc::mem_fun(*this, &ARDOUR_UI::transport_play_selection));
292         ActionManager::session_sensitive_actions.push_back (act);
293         ActionManager::transport_sensitive_actions.push_back (act);
294         act = ActionManager::register_action (transport_actions, X_("PlayPreroll"), _("Play Selection w/Preroll"), sigc::mem_fun(*this, &ARDOUR_UI::transport_play_preroll));
295         ActionManager::session_sensitive_actions.push_back (act);
296         ActionManager::transport_sensitive_actions.push_back (act);
297
298         act = ActionManager::register_action (transport_actions, X_("Record"), _("Enable Record"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_record), false));
299         ActionManager::session_sensitive_actions.push_back (act);
300         ActionManager::write_sensitive_actions.push_back (act);
301         act = ActionManager::register_action (transport_actions, X_("record-roll"), _("Start Recording"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_record), true));
302         ActionManager::session_sensitive_actions.push_back (act);
303         ActionManager::write_sensitive_actions.push_back (act);
304         ActionManager::transport_sensitive_actions.push_back (act);
305         act = ActionManager::register_action (transport_actions, X_("alternate-record-roll"), _("Start Recording"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_record), true));
306         ActionManager::session_sensitive_actions.push_back (act);
307         ActionManager::write_sensitive_actions.push_back (act);
308         ActionManager::transport_sensitive_actions.push_back (act);
309         act = ActionManager::register_action (transport_actions, X_("Rewind"), _("Rewind"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_rewind), 0));
310         ActionManager::session_sensitive_actions.push_back (act);
311         ActionManager::transport_sensitive_actions.push_back (act);
312         act = ActionManager::register_action (transport_actions, X_("RewindSlow"), _("Rewind (Slow)"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_rewind), -1));
313         ActionManager::session_sensitive_actions.push_back (act);
314         ActionManager::transport_sensitive_actions.push_back (act);
315         act = ActionManager::register_action (transport_actions, X_("RewindFast"), _("Rewind (Fast)"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_rewind), 1));
316         ActionManager::session_sensitive_actions.push_back (act);
317         ActionManager::transport_sensitive_actions.push_back (act);
318         act = ActionManager::register_action (transport_actions, X_("Forward"), _("Forward"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_forward), 0));
319         ActionManager::session_sensitive_actions.push_back (act);
320         ActionManager::transport_sensitive_actions.push_back (act);
321         act = ActionManager::register_action (transport_actions, X_("ForwardSlow"), _("Forward (Slow)"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_forward), -1));
322         ActionManager::session_sensitive_actions.push_back (act);
323         ActionManager::transport_sensitive_actions.push_back (act);
324         act = ActionManager::register_action (transport_actions, X_("ForwardFast"), _("Forward (Fast)"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_forward), 1));
325         ActionManager::session_sensitive_actions.push_back (act);
326         ActionManager::transport_sensitive_actions.push_back (act);
327         act = ActionManager::register_action (transport_actions, X_("GotoZero"), _("Go to Zero"), sigc::mem_fun(*this, &ARDOUR_UI::transport_goto_zero));
328         ActionManager::session_sensitive_actions.push_back (act);
329         ActionManager::transport_sensitive_actions.push_back (act);
330         act = ActionManager::register_action (transport_actions, X_("GotoStart"), _("Go to Start"), sigc::mem_fun(*this, &ARDOUR_UI::transport_goto_start));
331         ActionManager::session_sensitive_actions.push_back (act);
332         ActionManager::transport_sensitive_actions.push_back (act);
333         act = ActionManager::register_action (transport_actions, X_("alternate-GotoStart"), _("Go to Start"), sigc::mem_fun(*this, &ARDOUR_UI::transport_goto_start));
334         ActionManager::session_sensitive_actions.push_back (act);
335         ActionManager::transport_sensitive_actions.push_back (act);
336         act = ActionManager::register_action (transport_actions, X_("GotoEnd"), _("Go to End"), sigc::mem_fun(*this, &ARDOUR_UI::transport_goto_end));
337         ActionManager::session_sensitive_actions.push_back (act);
338         ActionManager::transport_sensitive_actions.push_back (act);
339         act = ActionManager::register_action (transport_actions, X_("GotoWallClock"), _("Go to Wall Clock"), sigc::mem_fun(*this, &ARDOUR_UI::transport_goto_wallclock));
340         ActionManager::session_sensitive_actions.push_back (act);
341         ActionManager::transport_sensitive_actions.push_back (act);
342
343         //these actions handle the numpad events, ProTools style
344         act = ActionManager::register_action (transport_actions, X_("numpad-decimal"), _("Numpad Decimal"), mem_fun(*this, &ARDOUR_UI::transport_numpad_decimal));
345         ActionManager::session_sensitive_actions.push_back (act);
346         ActionManager::transport_sensitive_actions.push_back (act);
347         act = ActionManager::register_action (transport_actions, X_("alternate-numpad-decimal"), _("Numpad Decimal"), mem_fun(*this, &ARDOUR_UI::transport_numpad_decimal));
348         ActionManager::session_sensitive_actions.push_back (act);
349         ActionManager::transport_sensitive_actions.push_back (act);
350         act = ActionManager::register_action (transport_actions, X_("numpad-0"), _("Numpad 0"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 0));
351         ActionManager::session_sensitive_actions.push_back (act);
352         ActionManager::transport_sensitive_actions.push_back (act);
353         act = ActionManager::register_action (transport_actions, X_("numpad-1"), _("Numpad 1"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 1));
354         ActionManager::session_sensitive_actions.push_back (act);
355         ActionManager::transport_sensitive_actions.push_back (act);
356         act = ActionManager::register_action (transport_actions, X_("numpad-2"), _("Numpad 2"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 2));
357         ActionManager::session_sensitive_actions.push_back (act);
358         ActionManager::transport_sensitive_actions.push_back (act);
359         act = ActionManager::register_action (transport_actions, X_("numpad-3"), _("Numpad 3"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 3));
360         ActionManager::session_sensitive_actions.push_back (act);
361         ActionManager::transport_sensitive_actions.push_back (act);
362         act = ActionManager::register_action (transport_actions, X_("numpad-4"), _("Numpad 4"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 4));
363         ActionManager::session_sensitive_actions.push_back (act);
364         ActionManager::transport_sensitive_actions.push_back (act);
365         act = ActionManager::register_action (transport_actions, X_("numpad-5"), _("Numpad 5"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 5));
366         ActionManager::session_sensitive_actions.push_back (act);
367         ActionManager::transport_sensitive_actions.push_back (act);
368         act = ActionManager::register_action (transport_actions, X_("numpad-6"), _("Numpad 6"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 6));
369         ActionManager::session_sensitive_actions.push_back (act);
370         ActionManager::transport_sensitive_actions.push_back (act);
371         act = ActionManager::register_action (transport_actions, X_("numpad-7"), _("Numpad 7"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 7));
372         ActionManager::session_sensitive_actions.push_back (act);
373         ActionManager::transport_sensitive_actions.push_back (act);
374         act = ActionManager::register_action (transport_actions, X_("numpad-8"), _("Numpad 8"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 8));
375         ActionManager::session_sensitive_actions.push_back (act);
376         ActionManager::transport_sensitive_actions.push_back (act);
377         act = ActionManager::register_action (transport_actions, X_("numpad-9"), _("Numpad 9"), bind (mem_fun(*this, &ARDOUR_UI::transport_numpad_event), 9));
378         ActionManager::session_sensitive_actions.push_back (act);
379         ActionManager::transport_sensitive_actions.push_back (act);
380
381         act = ActionManager::register_action (transport_actions, X_("focus-on-clock"), _("Focus On Clock"), sigc::mem_fun(*this, &ARDOUR_UI::focus_on_clock));
382         ActionManager::session_sensitive_actions.push_back (act);
383         ActionManager::transport_sensitive_actions.push_back (act);
384
385         act = ActionManager::register_action (transport_actions, X_("primary-clock-timecode"), _("Timecode"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::Timecode));
386         ActionManager::session_sensitive_actions.push_back (act);
387         act = ActionManager::register_action (transport_actions, X_("primary-clock-bbt"), _("Bars & Beats"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::BBT));
388         ActionManager::session_sensitive_actions.push_back (act);
389         act = ActionManager::register_action (transport_actions, X_("primary-clock-minsec"), _("Minutes & Seconds"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::MinSec));
390         ActionManager::session_sensitive_actions.push_back (act);
391         act = ActionManager::register_action (transport_actions, X_("primary-clock-samples"), _("Samples"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::Frames));
392         ActionManager::session_sensitive_actions.push_back (act);
393
394         act = ActionManager::register_action (transport_actions, X_("secondary-clock-timecode"), _("Timecode"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::Timecode));
395         ActionManager::session_sensitive_actions.push_back (act);
396         act = ActionManager::register_action (transport_actions, X_("secondary-clock-bbt"), _("Bars & Beats"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::BBT));
397         ActionManager::session_sensitive_actions.push_back (act);
398         act = ActionManager::register_action (transport_actions, X_("secondary-clock-minsec"), _("Minutes & Seconds"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::MinSec));
399         ActionManager::session_sensitive_actions.push_back (act);
400         act = ActionManager::register_action (transport_actions, X_("secondary-clock-samples"), _("Samples"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::Frames));
401         ActionManager::session_sensitive_actions.push_back (act);
402
403         act = ActionManager::register_toggle_action (transport_actions, X_("TogglePunchIn"), _("Punch In"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_punch_in));
404         act->set_short_label (_("In"));
405         ActionManager::session_sensitive_actions.push_back (act);
406         ActionManager::transport_sensitive_actions.push_back (act);
407         act = ActionManager::register_toggle_action (transport_actions, X_("TogglePunchOut"), _("Punch Out"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_punch_out));
408         act->set_short_label (_("Out"));
409         ActionManager::session_sensitive_actions.push_back (act);
410         ActionManager::transport_sensitive_actions.push_back (act);
411         act = ActionManager::register_toggle_action (transport_actions, X_("TogglePunch"), _("Punch In/Out"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_punch));
412         act->set_short_label (_("In/Out"));
413         ActionManager::session_sensitive_actions.push_back (act);
414         ActionManager::transport_sensitive_actions.push_back (act);
415         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleClick"), _("Click"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_click));
416         ActionManager::session_sensitive_actions.push_back (act);
417         ActionManager::transport_sensitive_actions.push_back (act);
418         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleAutoInput"), _("Auto Input"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_auto_input));
419         ActionManager::session_sensitive_actions.push_back (act);
420         ActionManager::transport_sensitive_actions.push_back (act);
421         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleAutoPlay"), _("Auto Play"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_auto_play));
422         ActionManager::session_sensitive_actions.push_back (act);
423         ActionManager::transport_sensitive_actions.push_back (act);
424         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleAutoReturn"), _("Auto Return"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_auto_return));
425         ActionManager::session_sensitive_actions.push_back (act);
426         ActionManager::transport_sensitive_actions.push_back (act);
427         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleFollowEdits"), _("Follow Edits"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_follow_edits));
428         ActionManager::session_sensitive_actions.push_back (act);
429         ActionManager::transport_sensitive_actions.push_back (act);
430
431
432         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleVideoSync"), _("Sync Startup to Video"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_video_sync));
433         ActionManager::session_sensitive_actions.push_back (act);
434         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleTimeMaster"), _("Time Master"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_time_master));
435         ActionManager::session_sensitive_actions.push_back (act);
436         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleExternalSync"), _("Use External Positional Sync Source"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_external_sync));
437         ActionManager::session_sensitive_actions.push_back (act);
438
439         for (int i = 1; i <= 32; ++i) {
440                 string const a = string_compose (X_("ToggleRecordEnableTrack%1"), i);
441                 string const n = string_compose (_("Toggle Record Enable Track %1"), i);
442                 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));
443                 ActionManager::session_sensitive_actions.push_back (act);
444         }
445
446         Glib::RefPtr<ActionGroup> shuttle_actions = ActionGroup::create ("ShuttleActions");
447
448         shuttle_actions->add (Action::create (X_("SetShuttleUnitsPercentage"), _("Percentage")), hide_return (sigc::bind (sigc::mem_fun (*Config, &RCConfiguration::set_shuttle_units), Percentage)));
449         shuttle_actions->add (Action::create (X_("SetShuttleUnitsSemitones"), _("Semitones")), hide_return (sigc::bind (sigc::mem_fun (*Config, &RCConfiguration::set_shuttle_units), Semitones)));
450
451         Glib::RefPtr<ActionGroup> option_actions = ActionGroup::create ("options");
452
453         act = ActionManager::register_toggle_action (option_actions, X_("SendMTC"), _("Send MTC"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_send_mtc));
454         ActionManager::session_sensitive_actions.push_back (act);
455         act = ActionManager::register_toggle_action (option_actions, X_("SendMMC"), _("Send MMC"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_send_mmc));
456         ActionManager::session_sensitive_actions.push_back (act);
457         act = ActionManager::register_toggle_action (option_actions, X_("UseMMC"), _("Use MMC"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_use_mmc));
458         ActionManager::session_sensitive_actions.push_back (act);
459         act = ActionManager::register_toggle_action (option_actions, X_("SendMidiClock"), _("Send MIDI Clock"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_send_midi_clock));
460         ActionManager::session_sensitive_actions.push_back (act);
461         act = ActionManager::register_toggle_action (option_actions, X_("SendMIDIfeedback"), _("Send MIDI Feedback"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_send_midi_feedback));
462         ActionManager::session_sensitive_actions.push_back (act);
463
464         /* MIDI */
465
466         Glib::RefPtr<ActionGroup> midi_actions = ActionGroup::create (X_("MIDI"));
467         ActionManager::register_action (midi_actions, X_("panic"), _("Panic"), sigc::mem_fun(*this, &ARDOUR_UI::midi_panic));
468
469         ActionManager::add_action_group (shuttle_actions);
470         ActionManager::add_action_group (option_actions);
471         ActionManager::add_action_group (transport_actions);
472         ActionManager::add_action_group (main_actions);
473         ActionManager::add_action_group (main_menu_actions);
474         ActionManager::add_action_group (common_actions);
475         ActionManager::add_action_group (midi_actions);
476 }
477
478 void
479 ARDOUR_UI::build_menu_bar ()
480 {
481         menu_bar = dynamic_cast<MenuBar*> (ActionManager::get_widget (X_("/Main")));
482         menu_bar->set_name ("MainMenuBar");
483
484         /*
485          * This is needed because this property does not get installed
486          * until the Menu GObject class is registered, which happens
487          * when the first menu instance is created.
488          */
489         // XXX bug in gtkmm causes this to popup an error message
490         // Gtk::Settings::get_default()->property_gtk_can_change_accels() = true;
491         // so use this instead ...
492         gtk_settings_set_long_property (gtk_settings_get_default(), "gtk-can-change-accels", 1, "Ardour:designers");
493
494         EventBox* ev = manage (new EventBox);
495         ev->show ();
496         CairoHPacker* hbox = manage (new CairoHPacker);
497         hbox->set_name (X_("StatusBarBox"));
498         hbox->show ();
499         hbox->set_border_width (3);
500
501         VBox* vbox = manage (new VBox);
502         vbox->pack_start (*hbox, true, false);
503         vbox->show();
504
505         ev->add (*vbox);
506
507         wall_clock_label.set_name ("WallClock");
508         wall_clock_label.set_use_markup ();
509         disk_space_label.set_name ("WallClock");
510         disk_space_label.set_use_markup ();
511         timecode_format_label.set_name ("WallClock");
512         timecode_format_label.set_use_markup ();
513         cpu_load_label.set_name ("CPULoad");
514         cpu_load_label.set_use_markup ();
515         xrun_label.set_name ("XrunLabel");
516         xrun_label.set_use_markup ();
517         peak_thread_work_label.set_name ("PeakThreadWork");
518         peak_thread_work_label.set_use_markup ();
519         buffer_load_label.set_name ("BufferLoad");
520         buffer_load_label.set_use_markup ();
521         sample_rate_label.set_name ("SampleRate");
522         sample_rate_label.set_use_markup ();
523         format_label.set_name ("Format");
524         format_label.set_use_markup ();
525
526 #ifndef TOP_MENUBAR
527         menu_hbox.pack_start (*menu_bar, false, false);
528 #else
529         use_menubar_as_top_menubar ();
530 #endif
531
532         bool wall_clock = false;
533         bool disk_space = false;
534
535         if (!Profile->get_small_screen()) {
536 #ifndef GTKOSX
537                 // OSX provides its own wallclock, thank you very much
538                 wall_clock = true;
539 #endif
540                 disk_space = true;
541         }
542
543         hbox->pack_end (error_alert_button, false, false, 2);
544
545         hbox->pack_end (wall_clock_label, false, false, 2);
546         hbox->pack_end (disk_space_label, false, false, 4);
547         hbox->pack_end (xrun_label, false, false, 4);
548         hbox->pack_end (peak_thread_work_label, false, false, 4);
549         hbox->pack_end (cpu_load_label, false, false, 4);
550         hbox->pack_end (buffer_load_label, false, false, 4);
551         hbox->pack_end (sample_rate_label, false, false, 4);
552         hbox->pack_end (timecode_format_label, false, false, 4);
553         hbox->pack_end (format_label, false, false, 4);
554
555         menu_hbox.pack_end (*ev, false, false, 2);
556
557         menu_bar_base.set_name ("MainMenuBar");
558         menu_bar_base.add (menu_hbox);
559
560 #ifndef GTKOSX
561         _status_bar_visibility.add (&wall_clock_label,      X_("WallClock"), _("Wall Clock"), wall_clock);
562 #endif
563         _status_bar_visibility.add (&disk_space_label,      X_("Disk"),      _("Disk Space"), disk_space);
564         _status_bar_visibility.add (&cpu_load_label,        X_("DSP"),       _("DSP"), true);
565         _status_bar_visibility.add (&xrun_label,            X_("XRun"),      _("X-run"), false);
566         _status_bar_visibility.add (&peak_thread_work_label,X_("Peakfile"),  _("Active Peak-file Work"), false);
567         _status_bar_visibility.add (&buffer_load_label,     X_("Buffers"),   _("Buffers"), true);
568         _status_bar_visibility.add (&sample_rate_label,     X_("Audio"),     _("Audio"), true);
569         _status_bar_visibility.add (&timecode_format_label, X_("TCFormat"),  _("Timecode Format"), true);
570         _status_bar_visibility.add (&format_label,          X_("Format"),    _("File Format"), true);
571
572         ev->signal_button_press_event().connect (sigc::mem_fun (_status_bar_visibility, &VisibilityGroup::button_press_event));
573         ev->signal_button_release_event().connect (sigc::mem_fun (*this, &ARDOUR_UI::xrun_button_release));
574 }
575
576 void
577 ARDOUR_UI::use_menubar_as_top_menubar ()
578 {
579         Gtk::Widget* widget;
580         Application* app = Application::instance ();
581
582         /* the addresses ("/ui/Main...") used below are based on the menu definitions in the menus file
583          */
584
585         /* Quit will be taken care of separately */
586
587         if ((widget = ActionManager::get_widget ("/ui/Main/Session/Quit"))) {
588                 widget->hide ();
589         }
590
591         /* Put items for About and Preferences into App menu (the
592          * ardour.menus.in file does not list them for OS X)
593          */
594
595         GtkApplicationMenuGroup* group = app->add_app_menu_group ();
596
597         if ((widget = ActionManager::get_widget ("/ui/Main/Session/toggle-about"))) {
598                 app->add_app_menu_item (group, dynamic_cast<MenuItem*>(widget));
599         }
600
601         if ((widget = ActionManager::get_widget ("/ui/Main/Session/toggle-rc-options-editor"))) {
602                 app->add_app_menu_item (group, dynamic_cast<MenuItem*>(widget));
603         }
604
605         app->set_menu_bar (*menu_bar);
606 }
607
608 void
609 ARDOUR_UI::save_ardour_state ()
610 {
611         if (!keyboard || !mixer || !editor || !meterbridge) {
612                 return;
613         }
614
615         /* XXX this is all a bit dubious. add_extra_xml() uses
616            a different lifetime model from add_instant_xml().
617         */
618
619         XMLNode* node = new XMLNode (keyboard->get_state());
620         Config->add_extra_xml (*node);
621         Config->add_extra_xml (get_transport_controllable_state());
622
623         XMLNode* window_node = new XMLNode (X_("UI"));
624         window_node->add_property (_status_bar_visibility.get_state_name().c_str(), _status_bar_visibility.get_state_value ());
625
626         /* Windows */
627
628         WM::Manager::instance().add_state (*window_node);
629
630         /* tearoffs */
631
632         XMLNode* tearoff_node = new XMLNode (X_("Tearoffs"));
633
634         if (transport_tearoff) {
635                 XMLNode* t = new XMLNode (X_("transport"));
636                 transport_tearoff->add_state (*t);
637                 tearoff_node->add_child_nocopy (*t);
638         }
639
640         if (mixer->monitor_section()) {
641                 XMLNode* t = new XMLNode (X_("monitor-section"));
642                 mixer->monitor_section()->tearoff().add_state (*t);
643                 tearoff_node->add_child_nocopy (*t);
644         }
645
646         if (editor->mouse_mode_tearoff()) {
647                 XMLNode* t = new XMLNode (X_("mouse-mode"));
648                 editor->mouse_mode_tearoff ()->add_state (*t);
649                 tearoff_node->add_child_nocopy (*t);
650         }
651
652         window_node->add_child_nocopy (*tearoff_node);
653
654         Config->add_extra_xml (*window_node);
655         Config->add_extra_xml (audio_midi_setup->get_state());
656
657         Config->save_state();
658
659         UIConfiguration::instance().save_state ();
660
661         XMLNode& enode (static_cast<Stateful*>(editor)->get_state());
662         XMLNode& mnode (mixer->get_state());
663         XMLNode& bnode (meterbridge->get_state());
664
665         if (_session) {
666                 _session->add_instant_xml (enode);
667                 _session->add_instant_xml (mnode);
668                 _session->add_instant_xml (bnode);
669                 if (location_ui) {
670                         _session->add_instant_xml (location_ui->ui().get_state ());
671                 }
672         } else {
673                 Config->add_instant_xml (enode);
674                 Config->add_instant_xml (mnode);
675                 if (location_ui) {
676                         Config->add_instant_xml (location_ui->ui().get_state ());
677                 }
678         }
679         delete &enode;
680
681         Keyboard::save_keybindings ();
682 }
683
684 void
685 ARDOUR_UI::resize_text_widgets ()
686 {
687         set_size_request_to_display_given_text (cpu_load_label, "DSP: 100.0%", 2, 2);
688         set_size_request_to_display_given_text (buffer_load_label, "Buffers: p:100% c:100%", 2, 2);
689         set_size_request_to_display_given_text (xrun_label, "X: 9999", 2, 2);
690 }
691
692 void
693 ARDOUR_UI::focus_on_clock ()
694 {
695         if (editor && primary_clock) {
696                 editor->present ();
697                 primary_clock->focus ();
698         }
699 }
700
701 bool
702 ARDOUR_UI::xrun_button_release (GdkEventButton* ev)
703 {
704         if (ev->button != 1 || !Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
705                 return false;
706         }
707
708         if (_session) {
709                 _session->reset_xrun_count ();
710                 update_xrun_count ();
711         }
712         return true;
713 }