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