Hopefully fix some i18n bugs (#3565).
[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
39 #include "pbd/file_utils.h"
40 #include "pbd/fpu.h"
41 #include "pbd/convert.h"
42
43 #include "ardour_ui.h"
44 #include "public_editor.h"
45 #include "audio_clock.h"
46 #include "keyboard.h"
47 #include "monitor_section.h"
48 #include "engine_dialog.h"
49 #include "editor.h"
50 #include "actions.h"
51 #include "mixer_ui.h"
52 #include "startup.h"
53 #include "utils.h"
54 #include "window_proxy.h"
55 #include "global_port_matrix.h"
56 #include "location_ui.h"
57
58 #include <gtkmm2ext/application.h>
59
60 #include "ardour/session.h"
61 #include "ardour/profile.h"
62 #include "ardour/audioengine.h"
63 #include "ardour/control_protocol_manager.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<Action> act;
98
99         /* menus + submenus that need action items */
100
101         ActionManager::register_action (main_actions, X_("Session"), _("Session"));
102         act = ActionManager::register_action (main_actions, X_("Cleanup"), _("Clean-up"));
103         ActionManager::write_sensitive_actions.push_back (act);
104         ActionManager::register_action (main_actions, X_("Sync"), _("Sync"));
105         ActionManager::register_action (main_actions, X_("TransportOptions"), _("Options"));
106         ActionManager::register_action (main_actions, X_("Help"), _("Help"));
107         ActionManager::register_action (main_actions, X_("KeyMouseActions"), _("Misc. Shortcuts"));
108         ActionManager::register_action (main_actions, X_("AudioFileFormat"), _("Audio File Format"));
109         ActionManager::register_action (main_actions, X_("AudioFileFormatHeader"), _("File Type"));
110         ActionManager::register_action (main_actions, X_("AudioFileFormatData"), _("Sample Format"));
111         ActionManager::register_action (main_actions, X_("ControlSurfaces"), _("Control Surfaces"));
112         ActionManager::register_action (main_actions, X_("Plugins"), _("Plugins"));
113         ActionManager::register_action (main_actions, X_("Metering"), _("Metering"));
114         ActionManager::register_action (main_actions, X_("MeteringFallOffRate"), _("Fall Off Rate"));
115         ActionManager::register_action (main_actions, X_("MeteringHoldTime"), _("Hold Time"));
116         ActionManager::register_action (main_actions, X_("Denormals"), _("Denormal Handling"));
117
118         /* the real actions */
119
120         act = ActionManager::register_action (main_actions, X_("New"), _("New..."),  hide_return (sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::get_session_parameters), false, true, "")));
121
122         ActionManager::register_action (main_actions, X_("Open"), _("Open..."),  sigc::mem_fun(*this, &ARDOUR_UI::open_session));
123         ActionManager::register_action (main_actions, X_("Recent"), _("Recent..."),  sigc::mem_fun(*this, &ARDOUR_UI::open_recent_session));
124         act = ActionManager::register_action (main_actions, X_("Close"), _("Close"),  sigc::mem_fun(*this, &ARDOUR_UI::close_session));
125         ActionManager::session_sensitive_actions.push_back (act);
126
127         act = ActionManager::register_action (main_actions, X_("AddTrackBus"), _("Add Track or Bus..."),
128                                               sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::add_route), (Gtk::Window*) 0));
129         ActionManager::session_sensitive_actions.push_back (act);
130         ActionManager::write_sensitive_actions.push_back (act);
131
132 #ifdef WITH_CMT
133
134         sys::path anicomp_file_path;
135
136         if (PBD::find_file_in_search_path (Glib::getenv("PATH"), "AniComp", anicomp_file_path)) {
137                 act = ActionManager::register_action (main_actions, X_("aniConnect"), _("Connect"),  (sigc::mem_fun (*editor, &PublicEditor::connect_to_image_compositor)));
138                 ActionManager::session_sensitive_actions.push_back (act);
139         }
140
141 #endif
142
143         act = ActionManager::register_action (main_actions, X_("Snapshot"), _("Snapshot..."), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::snapshot_session), false));
144         ActionManager::session_sensitive_actions.push_back (act);
145         ActionManager::write_sensitive_actions.push_back (act);
146
147         act = ActionManager::register_action (main_actions, X_("SaveAs"), _("Save As..."), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::snapshot_session), true));
148         ActionManager::session_sensitive_actions.push_back (act);
149         ActionManager::write_sensitive_actions.push_back (act);
150
151         act = ActionManager::register_action (main_actions, X_("Rename"), _("Rename..."), sigc::mem_fun(*this, &ARDOUR_UI::rename_session));
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_("SaveTemplate"), _("Save Template..."),  sigc::mem_fun(*this, &ARDOUR_UI::save_template));
156         ActionManager::session_sensitive_actions.push_back (act);
157
158         act = ActionManager::register_action (main_actions, X_("Metadata"), _("Metadata"));
159         ActionManager::session_sensitive_actions.push_back (act);
160
161         act = ActionManager::register_action (main_actions, X_("EditMetadata"), _("Edit Metadata..."),  sigc::mem_fun(*this, &ARDOUR_UI::edit_metadata));
162         ActionManager::session_sensitive_actions.push_back (act);
163
164         act = ActionManager::register_action (main_actions, X_("ImportMetadata"), _("Import Metadata..."),  sigc::mem_fun(*this, &ARDOUR_UI::import_metadata));
165         ActionManager::session_sensitive_actions.push_back (act);
166
167         act = ActionManager::register_action (main_actions, X_("ExportAudio"), _("Export To Audio File(s)..."),  sigc::mem_fun (*editor, &PublicEditor::export_audio));
168         ActionManager::session_sensitive_actions.push_back (act);
169
170         act = ActionManager::register_action (main_actions, X_("StemExport"), _("Stem export..."),  sigc::mem_fun (*editor, &PublicEditor::stem_export));
171         ActionManager::session_sensitive_actions.push_back (act);
172
173         act = ActionManager::register_action (main_actions, X_("Export"), _("Export"));
174         ActionManager::session_sensitive_actions.push_back (act);
175
176         act = ActionManager::register_action (main_actions, X_("CleanupUnused"), _("Clean-up Unused Sources..."),  sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::cleanup));
177         ActionManager::session_sensitive_actions.push_back (act);
178         ActionManager::write_sensitive_actions.push_back (act);
179
180         act = ActionManager::register_action (main_actions, X_("FlushWastebasket"), _("Flush Wastebasket"),  sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::flush_trash));
181         ActionManager::write_sensitive_actions.push_back (act);
182         ActionManager::session_sensitive_actions.push_back (act);
183
184         /* JACK actions for controlling ... JACK */
185
186         Glib::RefPtr<ActionGroup> jack_actions = ActionGroup::create (X_("JACK"));
187         ActionManager::register_action (jack_actions, X_("JACK"), _("JACK"));
188         ActionManager::register_action (jack_actions, X_("Latency"), _("Latency"));
189
190         act = ActionManager::register_action (jack_actions, X_("JACKReconnect"), _("Reconnect"), sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::reconnect_to_jack));
191         ActionManager::jack_opposite_sensitive_actions.push_back (act);
192
193         act = ActionManager::register_action (jack_actions, X_("JACKDisconnect"), _("Disconnect"), sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::disconnect_from_jack));
194         ActionManager::jack_sensitive_actions.push_back (act);
195
196         RadioAction::Group jack_latency_group;
197
198         act = ActionManager::register_radio_action (jack_actions, jack_latency_group, X_("JACKLatency32"), X_("32"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::set_jack_buffer_size), (pframes_t) 32));
199         ActionManager::jack_sensitive_actions.push_back (act);
200         act = ActionManager::register_radio_action (jack_actions, jack_latency_group, X_("JACKLatency64"), X_("64"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::set_jack_buffer_size), (pframes_t) 64));
201         ActionManager::jack_sensitive_actions.push_back (act);
202         act = ActionManager::register_radio_action (jack_actions, jack_latency_group, X_("JACKLatency128"), X_("128"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::set_jack_buffer_size), (pframes_t) 128));
203         ActionManager::jack_sensitive_actions.push_back (act);
204         act = ActionManager::register_radio_action (jack_actions, jack_latency_group, X_("JACKLatency256"), X_("256"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::set_jack_buffer_size), (pframes_t) 256));
205         ActionManager::jack_sensitive_actions.push_back (act);
206         act = ActionManager::register_radio_action (jack_actions, jack_latency_group, X_("JACKLatency512"), X_("512"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::set_jack_buffer_size), (pframes_t) 512));
207         ActionManager::jack_sensitive_actions.push_back (act);
208         act = ActionManager::register_radio_action (jack_actions, jack_latency_group, X_("JACKLatency1024"), X_("1024"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::set_jack_buffer_size), (pframes_t) 1024));
209         ActionManager::jack_sensitive_actions.push_back (act);
210         act = ActionManager::register_radio_action (jack_actions, jack_latency_group, X_("JACKLatency2048"), X_("2048"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::set_jack_buffer_size), (pframes_t) 2048));
211         ActionManager::jack_sensitive_actions.push_back (act);
212         act = ActionManager::register_radio_action (jack_actions, jack_latency_group, X_("JACKLatency4096"), X_("4096"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::set_jack_buffer_size), (pframes_t) 4096));
213         ActionManager::jack_sensitive_actions.push_back (act);
214         act = ActionManager::register_radio_action (jack_actions, jack_latency_group, X_("JACKLatency8192"), X_("8192"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::set_jack_buffer_size), (pframes_t) 8192));
215         ActionManager::jack_sensitive_actions.push_back (act);
216
217         /* these actions are intended to be shared across all windows */
218
219         common_actions = ActionGroup::create (X_("Common"));
220         ActionManager::register_action (main_actions, X_("WindowMenu"), _("Window"));
221         ActionManager::register_action (common_actions, X_("Quit"), _("Quit"), (hide_return (sigc::mem_fun(*this, &ARDOUR_UI::finish))));
222
223         /* windows visibility actions */
224
225         ActionManager::register_toggle_action (common_actions, X_("ToggleMaximalEditor"), _("Maximise Editor Space"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_editing_space));
226         act = ActionManager::register_toggle_action (common_actions, X_("KeepTearoffs"), _("Toolbars when Maximised"), mem_fun (*this, &ARDOUR_UI::toggle_keep_tearoffs));
227         ActionManager::session_sensitive_actions.push_back (act);
228
229         ActionManager::register_toggle_action (common_actions, X_("toggle-mixer"), S_("Window|Mixer"),  sigc::mem_fun(*this, &ARDOUR_UI::toggle_mixer_window));
230         ActionManager::register_toggle_action (common_actions, X_("toggle-mixer-on-top"), _("Mixer on Top"),  sigc::mem_fun(*this, &ARDOUR_UI::toggle_mixer_on_top));
231         ActionManager::register_toggle_action (common_actions, X_("ToggleRCOptionsEditor"), _("Preferences"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_rc_options_window));
232         ActionManager::register_toggle_action (common_actions, X_("ToggleSessionOptionsEditor"), _("Properties"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_session_options_window));
233         act = ActionManager::register_toggle_action (common_actions, X_("ToggleInspector"), _("Tracks and Busses"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_route_params_window));
234         ActionManager::session_sensitive_actions.push_back (act);
235         ActionManager::session_sensitive_actions.push_back (act);
236         act = ActionManager::register_toggle_action (common_actions, X_("ToggleLocations"), _("Locations"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_location_window));
237         ActionManager::session_sensitive_actions.push_back (act);
238         act = ActionManager::register_toggle_action (common_actions, X_("ToggleBigClock"), _("Big Clock"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_big_clock_window));
239         ActionManager::session_sensitive_actions.push_back (act);
240         act = ActionManager::register_toggle_action (common_actions, X_("toggle-speaker-config"), _("Speaker Configuration"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_speaker_config_window));
241         ActionManager::session_sensitive_actions.push_back (act);
242         act = ActionManager::register_toggle_action (common_actions, X_("toggle-audio-connection-manager"), _("Audio Connection Manager"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::toggle_global_port_matrix), ARDOUR::DataType::AUDIO));
243         ActionManager::session_sensitive_actions.push_back (act);
244         act = ActionManager::register_toggle_action (common_actions, X_("toggle-midi-connection-manager"), _("MIDI Connection Manager"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::toggle_global_port_matrix), ARDOUR::DataType::MIDI));
245         ActionManager::session_sensitive_actions.push_back (act);
246         act = ActionManager::register_action (common_actions, X_("NewMIDITracer"), _("MIDI Tracer"), sigc::mem_fun(*this, &ARDOUR_UI::new_midi_tracer_window));
247         ActionManager::session_sensitive_actions.push_back (act);
248         ActionManager::register_action (common_actions, X_("About"), _("About"),  sigc::mem_fun(*this, &ARDOUR_UI::show_about));
249         ActionManager::register_action (common_actions, X_("Chat"), _("Chat"),  sigc::mem_fun(*this, &ARDOUR_UI::launch_chat));
250         /** TRANSLATORS: This is `Manual' in the sense of an instruction book that tells a user how to use Ardour */
251         ActionManager::register_action (common_actions, X_("Manual"), S_("Help|Manual"),  mem_fun(*this, &ARDOUR_UI::launch_manual));
252         ActionManager::register_action (common_actions, X_("Reference"), _("Reference"),  mem_fun(*this, &ARDOUR_UI::launch_reference));
253         ActionManager::register_toggle_action (common_actions, X_("ToggleThemeManager"), _("Theme Manager"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_theme_manager));
254         ActionManager::register_toggle_action (common_actions, X_("ToggleKeyEditor"), _("Key Bindings"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_key_editor));
255         ActionManager::register_toggle_action (common_actions, X_("ToggleBundleManager"), _("Bundle Manager"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_bundle_manager));
256
257 #if 0
258         act = ActionManager::register_action (common_actions, X_("AddAudioTrack"), _("Add Audio Track"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::session_add_audio_track), 1, 1, ARDOUR::Normal, (ARDOUR::RouteGroup *) 0, 1));
259         ActionManager::session_sensitive_actions.push_back (act);
260         act = ActionManager::register_action (common_actions, X_("AddAudioBus"), _("Add Audio Bus"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::session_add_audio_bus), 1, 1, (ARDOUR::RouteGroup *) 0, 1));
261         ActionManager::session_sensitive_actions.push_back (act);
262         act = ActionManager::register_action (common_actions, X_("AddMIDITrack"), _("Add MIDI Track"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::session_add_midi_track), (ARDOUR::RouteGroup *) 0, 1));
263         ActionManager::session_sensitive_actions.push_back (act);
264         //act = ActionManager::register_action (common_actions, X_("AddMidiBus"), _("Add Midi Bus"), sigc::mem_fun(*this, &ARDOUR_UI::session_add_midi_bus));
265         //ActionManager::session_sensitive_actions.push_back (act);
266 #endif
267         act = ActionManager::register_action (common_actions, X_("Save"), _("Save"),  sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::save_state), string(""), false));
268         ActionManager::session_sensitive_actions.push_back (act);
269         ActionManager::write_sensitive_actions.push_back (act);
270         act = ActionManager::register_action (common_actions, X_("RemoveLastCapture"), _("Remove Last Capture"), sigc::mem_fun(*this, &ARDOUR_UI::remove_last_capture));
271         ActionManager::session_sensitive_actions.push_back (act);
272
273         Glib::RefPtr<ActionGroup> transport_actions = ActionGroup::create (X_("Transport"));
274
275         /* do-nothing action for the "transport" menu bar item */
276
277         ActionManager::register_action (transport_actions, X_("Transport"), _("Transport"));
278
279         /* these two are not used by key bindings, instead use ToggleRoll for that. these two do show up in
280            menus and via button proxies.
281         */
282
283         act = ActionManager::register_action (transport_actions, X_("Stop"), _("Stop"), sigc::mem_fun(*this, &ARDOUR_UI::transport_stop));
284         ActionManager::session_sensitive_actions.push_back (act);
285         ActionManager::transport_sensitive_actions.push_back (act);
286         act = ActionManager::register_action (transport_actions, X_("Roll"), _("Roll"), sigc::mem_fun(*this, &ARDOUR_UI::transport_roll));
287         ActionManager::session_sensitive_actions.push_back (act);
288         ActionManager::transport_sensitive_actions.push_back (act);
289
290         act = ActionManager::register_action (transport_actions, X_("ToggleRoll"), _("Start/Stop"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::toggle_roll), false, false));
291         ActionManager::session_sensitive_actions.push_back (act);
292         ActionManager::transport_sensitive_actions.push_back (act);
293         act = ActionManager::register_action (transport_actions, X_("ToggleRollMaybe"), _("Start/Continue/Stop"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::toggle_roll), false, true));
294         ActionManager::session_sensitive_actions.push_back (act);
295         ActionManager::transport_sensitive_actions.push_back (act);
296         act = ActionManager::register_action (transport_actions, X_("ToggleRollForgetCapture"), _("Stop and Forget Capture"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::toggle_roll), true, false));
297         ActionManager::session_sensitive_actions.push_back (act);
298         ActionManager::transport_sensitive_actions.push_back (act);
299
300         /* these two behave as follows:
301
302            - if transport speed != 1.0 or != -1.0, change speed to 1.0 or -1.0 (respectively)
303            - otherwise do nothing
304         */
305
306         act = ActionManager::register_action (transport_actions, X_("TransitionToRoll"), _("Transition To Roll"), sigc::bind (sigc::mem_fun (*editor, &PublicEditor::transition_to_rolling), true));
307         ActionManager::session_sensitive_actions.push_back (act);
308         ActionManager::transport_sensitive_actions.push_back (act);
309
310         act = ActionManager::register_action (transport_actions, X_("TransitionToReverse"), _("Transition To Reverse"), sigc::bind (sigc::mem_fun (*editor, &PublicEditor::transition_to_rolling), false));
311         ActionManager::session_sensitive_actions.push_back (act);
312         ActionManager::transport_sensitive_actions.push_back (act);
313
314         act = ActionManager::register_action (transport_actions, X_("Loop"), _("Play Loop Range"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_session_auto_loop));
315         ActionManager::session_sensitive_actions.push_back (act);
316         ActionManager::transport_sensitive_actions.push_back (act);
317         act = ActionManager::register_action (transport_actions, X_("PlaySelection"), _("Play Selected Range"), sigc::mem_fun(*this, &ARDOUR_UI::transport_play_selection));
318         ActionManager::session_sensitive_actions.push_back (act);
319         ActionManager::transport_sensitive_actions.push_back (act);
320
321         act = ActionManager::register_action (transport_actions, X_("Record"), _("Enable Record"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_record), false));
322         ActionManager::session_sensitive_actions.push_back (act);
323         ActionManager::write_sensitive_actions.push_back (act);
324         act = ActionManager::register_action (transport_actions, X_("record-roll"), _("Start Recording"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_record), true));
325         ActionManager::session_sensitive_actions.push_back (act);
326         ActionManager::write_sensitive_actions.push_back (act);
327         ActionManager::transport_sensitive_actions.push_back (act);
328         act = ActionManager::register_action (transport_actions, X_("Rewind"), _("Rewind"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_rewind), 0));
329         ActionManager::session_sensitive_actions.push_back (act);
330         ActionManager::transport_sensitive_actions.push_back (act);
331         act = ActionManager::register_action (transport_actions, X_("RewindSlow"), _("Rewind (Slow)"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_rewind), -1));
332         ActionManager::session_sensitive_actions.push_back (act);
333         ActionManager::transport_sensitive_actions.push_back (act);
334         act = ActionManager::register_action (transport_actions, X_("RewindFast"), _("Rewind (Fast)"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_rewind), 1));
335         ActionManager::session_sensitive_actions.push_back (act);
336         ActionManager::transport_sensitive_actions.push_back (act);
337         act = ActionManager::register_action (transport_actions, X_("Forward"), _("Forward"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_forward), 0));
338         ActionManager::session_sensitive_actions.push_back (act);
339         ActionManager::transport_sensitive_actions.push_back (act);
340         act = ActionManager::register_action (transport_actions, X_("ForwardSlow"), _("Forward (Slow)"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_forward), -1));
341         ActionManager::session_sensitive_actions.push_back (act);
342         ActionManager::transport_sensitive_actions.push_back (act);
343         act = ActionManager::register_action (transport_actions, X_("ForwardFast"), _("Forward (Fast)"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_forward), 1));
344         ActionManager::session_sensitive_actions.push_back (act);
345         ActionManager::transport_sensitive_actions.push_back (act);
346         act = ActionManager::register_action (transport_actions, X_("GotoZero"), _("Goto Zero"), sigc::mem_fun(*this, &ARDOUR_UI::transport_goto_zero));
347         ActionManager::session_sensitive_actions.push_back (act);
348         ActionManager::transport_sensitive_actions.push_back (act);
349         act = ActionManager::register_action (transport_actions, X_("GotoStart"), _("Goto Start"), sigc::mem_fun(*this, &ARDOUR_UI::transport_goto_start));
350         ActionManager::session_sensitive_actions.push_back (act);
351         ActionManager::transport_sensitive_actions.push_back (act);
352         act = ActionManager::register_action (transport_actions, X_("GotoEnd"), _("Goto End"), sigc::mem_fun(*this, &ARDOUR_UI::transport_goto_end));
353         ActionManager::session_sensitive_actions.push_back (act);
354         ActionManager::transport_sensitive_actions.push_back (act);
355         act = ActionManager::register_action (transport_actions, X_("GotoWallClock"), _("Goto Wall Clock"), sigc::mem_fun(*this, &ARDOUR_UI::transport_goto_wallclock));
356         ActionManager::session_sensitive_actions.push_back (act);
357         ActionManager::transport_sensitive_actions.push_back (act);
358
359         act = ActionManager::register_action (transport_actions, X_("focus-on-clock"), _("Focus On Clock"), sigc::mem_fun(*this, &ARDOUR_UI::focus_on_clock));
360         ActionManager::session_sensitive_actions.push_back (act);
361         ActionManager::transport_sensitive_actions.push_back (act);
362
363         act = ActionManager::register_action (transport_actions, X_("primary-clock-timecode"), _("Timecode"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::Timecode));
364         ActionManager::session_sensitive_actions.push_back (act);
365         act = ActionManager::register_action (transport_actions, X_("primary-clock-bbt"), _("Bars & Beats"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::BBT));
366         ActionManager::session_sensitive_actions.push_back (act);
367         act = ActionManager::register_action (transport_actions, X_("primary-clock-minsec"), _("Minutes & Seconds"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::MinSec));
368         ActionManager::session_sensitive_actions.push_back (act);
369         act = ActionManager::register_action (transport_actions, X_("primary-clock-samples"), _("Samples"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::Frames));
370         ActionManager::session_sensitive_actions.push_back (act);
371
372         act = ActionManager::register_action (transport_actions, X_("secondary-clock-timecode"), _("Timecode"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::Timecode));
373         ActionManager::session_sensitive_actions.push_back (act);
374         act = ActionManager::register_action (transport_actions, X_("secondary-clock-bbt"), _("Bars & Beats"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::BBT));
375         ActionManager::session_sensitive_actions.push_back (act);
376         act = ActionManager::register_action (transport_actions, X_("secondary-clock-minsec"), _("Minutes & Seconds"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::MinSec));
377         ActionManager::session_sensitive_actions.push_back (act);
378         act = ActionManager::register_action (transport_actions, X_("secondary-clock-samples"), _("Samples"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::Frames));
379         ActionManager::session_sensitive_actions.push_back (act);
380
381         act = ActionManager::register_toggle_action (transport_actions, X_("TogglePunchIn"), _("Punch In"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_punch_in));
382         act->set_short_label (_("In"));
383         ActionManager::session_sensitive_actions.push_back (act);
384         ActionManager::transport_sensitive_actions.push_back (act);
385         act = ActionManager::register_toggle_action (transport_actions, X_("TogglePunchOut"), _("Punch Out"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_punch_out));
386         act->set_short_label (_("Out"));
387         ActionManager::session_sensitive_actions.push_back (act);
388         ActionManager::transport_sensitive_actions.push_back (act);
389         act = ActionManager::register_toggle_action (transport_actions, X_("TogglePunch"), _("Punch In/Out"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_punch));
390         act->set_short_label (_("In/Out"));
391         ActionManager::session_sensitive_actions.push_back (act);
392         ActionManager::transport_sensitive_actions.push_back (act);
393         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleClick"), _("Click"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_click));
394         ActionManager::session_sensitive_actions.push_back (act);
395         ActionManager::transport_sensitive_actions.push_back (act);
396         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleAutoInput"), _("Auto Input"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_auto_input));
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_("ToggleAutoPlay"), _("Auto Play"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_auto_play));
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_("ToggleAutoReturn"), _("Auto Return"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_auto_return));
403         ActionManager::session_sensitive_actions.push_back (act);
404         ActionManager::transport_sensitive_actions.push_back (act);
405
406         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleVideoSync"), _("Sync Startup to Video"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_video_sync));
407         ActionManager::session_sensitive_actions.push_back (act);
408         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleTimeMaster"), _("Time Master"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_time_master));
409         ActionManager::session_sensitive_actions.push_back (act);
410         act = ActionManager::register_toggle_action (transport_actions, X_("ToggleExternalSync"), "", sigc::mem_fun(*this, &ARDOUR_UI::toggle_external_sync));
411         ActionManager::session_sensitive_actions.push_back (act);
412
413         for (int i = 1; i <= 32; ++i) {
414                 string const a = string_compose (X_("ToggleRecordEnableTrack%1"), i);
415                 string const n = string_compose (_("Toggle Record Enable Track %1"), i);
416                 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));
417                 ActionManager::session_sensitive_actions.push_back (act);
418         }
419
420         Glib::RefPtr<ActionGroup> shuttle_actions = ActionGroup::create ("ShuttleActions");
421
422         shuttle_actions->add (Action::create (X_("SetShuttleUnitsPercentage"), _("Percentage")), hide_return (sigc::bind (sigc::mem_fun (*Config, &RCConfiguration::set_shuttle_units), Percentage)));
423         shuttle_actions->add (Action::create (X_("SetShuttleUnitsSemitones"), _("Semitones")), hide_return (sigc::bind (sigc::mem_fun (*Config, &RCConfiguration::set_shuttle_units), Semitones)));
424
425         Glib::RefPtr<ActionGroup> option_actions = ActionGroup::create ("options");
426
427         act = ActionManager::register_toggle_action (option_actions, X_("SendMTC"), _("Send MTC"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_send_mtc));
428         ActionManager::session_sensitive_actions.push_back (act);
429         act = ActionManager::register_toggle_action (option_actions, X_("SendMMC"), _("Send MMC"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_send_mmc));
430         ActionManager::session_sensitive_actions.push_back (act);
431         act = ActionManager::register_toggle_action (option_actions, X_("UseMMC"), _("Use MMC"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_use_mmc));
432         ActionManager::session_sensitive_actions.push_back (act);
433         act = ActionManager::register_toggle_action (option_actions, X_("SendMidiClock"), _("Send MIDI Clock"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_send_midi_clock));
434         ActionManager::session_sensitive_actions.push_back (act);
435         act = ActionManager::register_toggle_action (option_actions, X_("SendMIDIfeedback"), _("Send MIDI Feedback"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_send_midi_feedback));
436         ActionManager::session_sensitive_actions.push_back (act);
437
438
439         if (getenv ("ARDOUR_BUNDLED")) {
440                 act = ActionManager::register_toggle_action (main_actions, X_("EnableTranslation"), _("Enable Translations"), mem_fun (*this, &ARDOUR_UI::toggle_translations));
441                 if (act) {
442                         RefPtr<ToggleAction> ract = RefPtr<ToggleAction>::cast_dynamic (act);
443                         if (ract) {
444                                 ract->set_active (!ARDOUR::translations_are_disabled());
445                         }
446                 }
447         }
448
449         /* MIDI */
450
451         Glib::RefPtr<ActionGroup> midi_actions = ActionGroup::create (X_("MIDI"));
452         ActionManager::register_action (midi_actions, X_("panic"), _("Panic"), sigc::mem_fun(*this, &ARDOUR_UI::midi_panic));
453
454         ActionManager::add_action_group (shuttle_actions);
455         ActionManager::add_action_group (option_actions);
456         ActionManager::add_action_group (jack_actions);
457         ActionManager::add_action_group (transport_actions);
458         ActionManager::add_action_group (main_actions);
459         ActionManager::add_action_group (common_actions);
460         ActionManager::add_action_group (midi_actions);
461 }
462
463 void
464 ARDOUR_UI::set_jack_buffer_size (pframes_t nframes)
465 {
466         Glib::RefPtr<Action> action;
467         const char* action_name = 0;
468
469         switch (nframes) {
470         case 32:
471                 action_name = X_("JACKLatency32");
472                 break;
473         case 64:
474                 action_name = X_("JACKLatency64");
475                 break;
476         case 128:
477                 action_name = X_("JACKLatency128");
478                 break;
479         case 256:
480                 action_name = X_("JACKLatency256");
481                 break;
482         case 512:
483                 action_name = X_("JACKLatency512");
484                 break;
485         case 1024:
486                 action_name = X_("JACKLatency1024");
487                 break;
488         case 2048:
489                 action_name = X_("JACKLatency2048");
490                 break;
491         case 4096:
492                 action_name = X_("JACKLatency4096");
493                 break;
494         case 8192:
495                 action_name = X_("JACKLatency8192");
496                 break;
497         default:
498                 /* XXX can we do anything useful ? */
499                 break;
500         }
501
502         if (action_name) {
503
504                 action = ActionManager::get_action (X_("JACK"), action_name);
505
506                 if (action) {
507                         Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (action);
508
509                         if (ract && ract->get_active()) {
510                                 engine->request_buffer_size (nframes);
511                                 update_sample_rate (0);
512                         }
513                 }
514         }
515 }
516
517 void
518 ARDOUR_UI::build_menu_bar ()
519 {
520         menu_bar = dynamic_cast<MenuBar*> (ActionManager::get_widget (X_("/Main")));
521         menu_bar->set_name ("MainMenuBar");
522
523         /*
524          * This is needed because this property does not get installed
525          * until the Menu GObject class is registered, which happens
526          * when the first menu instance is created.
527          */
528         // XXX bug in gtkmm causes this to popup an error message
529         // Gtk::Settings::get_default()->property_gtk_can_change_accels() = true;
530         // so use this instead ...
531         gtk_settings_set_long_property (gtk_settings_get_default(), "gtk-can-change-accels", 1, "Ardour:designers");
532
533         EventBox* ev = manage (new EventBox);
534         ev->show ();
535         HBox* hbox = manage (new HBox);
536         hbox->show ();
537         
538         ev->add (*hbox);
539
540         wall_clock_box.add (wall_clock_label);
541         wall_clock_box.set_name ("WallClock");
542         wall_clock_label.set_name ("WallClock");
543
544         disk_space_box.add (disk_space_label);
545         disk_space_box.set_name ("WallClock");
546         disk_space_label.set_name ("WallClock");
547         disk_space_label.set_use_markup ();
548
549         cpu_load_box.add (cpu_load_label);
550         cpu_load_box.set_name ("CPULoad");
551         cpu_load_label.set_name ("CPULoad");
552         cpu_load_label.set_use_markup ();
553
554         buffer_load_box.add (buffer_load_label);
555         buffer_load_box.set_name ("BufferLoad");
556         buffer_load_label.set_name ("BufferLoad");
557         buffer_load_label.set_use_markup ();
558
559         sample_rate_box.add (sample_rate_label);
560         sample_rate_box.set_name ("SampleRate");
561         sample_rate_label.set_name ("SampleRate");
562         sample_rate_label.set_use_markup ();
563
564         format_box.add (format_label);
565         format_box.set_name ("Format");
566         format_label.set_name ("Format");
567         format_label.set_use_markup ();
568
569 #ifndef TOP_MENUBAR
570         menu_hbox.pack_start (*menu_bar, false, false);
571 #else
572         use_menubar_as_top_menubar ();
573 #endif
574
575         bool wall_clock = false;
576         bool disk_space = false;
577
578         if (!Profile->get_small_screen()) {
579 #ifndef GTKOSX
580                 // OSX provides its own wallclock, thank you very much
581                 wall_clock = true;
582 #endif
583                 disk_space = true;
584         }
585         
586         hbox->pack_end (wall_clock_box, false, false, 2);
587         hbox->pack_end (disk_space_box, false, false, 4);
588         hbox->pack_end (cpu_load_box, false, false, 4);
589         hbox->pack_end (buffer_load_box, false, false, 4);
590         hbox->pack_end (sample_rate_box, false, false, 4);
591         hbox->pack_end (format_box, false, false, 4);
592
593         menu_hbox.pack_end (*ev, false, false);
594
595         menu_bar_base.set_name ("MainMenuBar");
596         menu_bar_base.add (menu_hbox);
597
598         _status_bar_visibility.add (&wall_clock_box,  X_("WallClock"), _("Wall Clock"), wall_clock);
599         _status_bar_visibility.add (&disk_space_box,  X_("Disk"),      _("Disk Space"), disk_space);
600         _status_bar_visibility.add (&cpu_load_box,    X_("DSP"),       _("DSP"), true);
601         _status_bar_visibility.add (&buffer_load_box, X_("Buffers"),   _("Buffers"), true);
602         _status_bar_visibility.add (&sample_rate_box, X_("JACK"),      _("JACK Sampling Rate and Latency"), true);
603         _status_bar_visibility.add (&format_box,      X_("Format"),    _("File Format"), true);
604
605         ev->signal_button_press_event().connect (sigc::mem_fun (_status_bar_visibility, &VisibilityGroup::button_press_event));
606 }
607
608 void
609 ARDOUR_UI::use_menubar_as_top_menubar ()
610 {
611         Gtk::Widget* widget;
612         Application* app = Application::instance ();
613
614         /* Quit will be taken of separately */
615
616         if ((widget = ActionManager::get_widget ("/ui/Main/Session/Quit"))) {
617                 widget->hide ();
618         }
619
620         GtkApplicationMenuGroup* group = app->add_app_menu_group ();
621
622         if ((widget = ActionManager::get_widget ("/ui/Main/Session/About"))) {
623                 app->add_app_menu_item (group, dynamic_cast<MenuItem*>(widget));
624         }
625
626         if ((widget = ActionManager::get_widget ("/ui/Main/Session/ToggleRCOptionsEditor"))) {
627                 app->add_app_menu_item (group, dynamic_cast<MenuItem*>(widget));
628         }
629
630         app->set_menu_bar (*menu_bar);
631 }
632
633 void
634 ARDOUR_UI::big_clock_catch_focus ()
635 {
636         PublicEditor::instance().reset_focus ();
637 }
638
639 void
640 ARDOUR_UI::setup_clock ()
641 {
642         ARDOUR_UI::Clock.connect (sigc::mem_fun (big_clock, &AudioClock::set));
643
644         big_clock->set_corner_radius (0.0);
645         big_clock->set_fixed_width (false);
646         big_clock->mode_changed.connect (sigc::mem_fun (*this, &ARDOUR_UI::big_clock_reset_aspect_ratio));
647
648         big_clock_window->set (new Window (WINDOW_TOPLEVEL), false);
649
650         big_clock_window->get()->set_keep_above (true);
651         big_clock_window->get()->set_border_width (0);
652         big_clock_window->get()->add (*big_clock);
653
654         big_clock_window->get()->set_title (_("Big Clock"));
655         big_clock_window->get()->signal_realize().connect (sigc::mem_fun (*this, &ARDOUR_UI::big_clock_realized));
656         big_clock_window->get()->signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), big_clock_window->get()), false);
657         big_clock_window->get()->signal_size_allocate().connect (sigc::mem_fun (*this, &ARDOUR_UI::big_clock_size_allocate));
658
659         big_clock_window->get()->signal_unmap().connect (sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleBigClock")));
660         big_clock_window->get()->signal_unmap().connect (sigc::mem_fun (*this, &ARDOUR_UI::big_clock_catch_focus));
661
662         manage_window (*big_clock_window->get());
663 }
664
665 void
666 ARDOUR_UI::big_clock_reset_aspect_ratio ()
667 {
668         Gtk::Requisition req;
669         big_clock->size_request (req);
670         float aspect = req.width/(float)req.height;
671         Gdk::Geometry geom;
672
673         geom.min_aspect = aspect;
674         geom.max_aspect = aspect;
675
676         big_clock_window->get()->set_geometry_hints (*big_clock, geom, Gdk::HINT_ASPECT);
677 }
678
679 void
680 ARDOUR_UI::big_clock_realized ()
681 {
682         int x, y, w, d;
683
684         set_decoration (big_clock_window->get(), (Gdk::DECOR_BORDER|Gdk::DECOR_RESIZEH));
685         big_clock_window->get()->get_window()->get_geometry (x, y, w, big_clock_height, d);
686
687         big_clock_reset_aspect_ratio ();
688
689         original_big_clock_height = big_clock_height;
690         original_big_clock_width = w;
691
692         Pango::FontDescription fd (big_clock->get_style()->get_font());
693         original_big_clock_font_size = fd.get_size ();
694
695         if (!fd.get_size_is_absolute ()) {
696                 original_big_clock_font_size /= PANGO_SCALE;
697         }
698
699         big_clock_window->setup ();
700 }
701
702 void
703 ARDOUR_UI::float_big_clock (Gtk::Window* parent)
704 {
705         if (big_clock_window->get()) {
706                 if (parent) {
707                         big_clock_window->get()->set_transient_for (*parent);
708                 } else {
709                         gtk_window_set_transient_for (big_clock_window->get()->gobj(), (GtkWindow*) 0);
710                 }
711         }
712 }
713
714 void
715 ARDOUR_UI::big_clock_size_allocate (Gtk::Allocation& alloc)
716 {
717         if (!big_clock_resize_in_progress) {
718                 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::idle_big_clock_text_resizer), 0, 0));
719                 big_clock_resize_in_progress = true;
720         }
721 }
722
723 bool
724 ARDOUR_UI::idle_big_clock_text_resizer (int, int)
725 {
726         big_clock_resize_in_progress = false;
727
728         Glib::RefPtr<Gdk::Window> win = big_clock_window->get()->get_window();
729         Pango::FontDescription fd (big_clock->get_style()->get_font());
730         int current_size = fd.get_size ();
731         int x, y, w, h, d;
732
733         if (!fd.get_size_is_absolute ()) {
734                 current_size /= PANGO_SCALE;
735         }
736
737         win->get_geometry (x, y, w, h, d);
738
739         double scale  = min (((double) w / (double) original_big_clock_width),
740                              ((double) h / (double) original_big_clock_height));
741
742         int size = (int) lrintf (original_big_clock_font_size * scale);
743
744         if (size != current_size) {
745
746                 string family = fd.get_family();
747                 char buf[family.length()+16];
748                 snprintf (buf, family.length()+16, "%s %d", family.c_str(), size);
749
750                 try {
751                         Pango::FontDescription fd (buf);
752                         Glib::RefPtr<Gtk::RcStyle> rcstyle = big_clock->get_modifier_style ();
753                         rcstyle->set_font (fd);
754                         big_clock->modify_style (rcstyle);
755                 }
756
757                 catch (...) {
758                         /* oh well, do nothing */
759                 }
760         }
761
762         return false;
763 }
764
765 void
766 ARDOUR_UI::save_ardour_state ()
767 {
768         if (!keyboard || !mixer || !editor) {
769                 return;
770         }
771
772         /* XXX this is all a bit dubious. add_extra_xml() uses
773            a different lifetime model from add_instant_xml().
774         */
775
776         XMLNode* node = new XMLNode (keyboard->get_state());
777         Config->add_extra_xml (*node);
778         Config->add_extra_xml (get_transport_controllable_state());
779
780         XMLNode* window_node = new XMLNode (X_("UI"));
781         window_node->add_property (_status_bar_visibility.get_state_name().c_str(), _status_bar_visibility.get_state_value ());
782
783         for (list<WindowProxyBase*>::iterator i = _window_proxies.begin(); i != _window_proxies.end(); ++i) {
784                 if ((*i)->rc_configured()) {
785                         window_node->add_child_nocopy (*((*i)->get_state ()));
786                 }
787         }
788
789         /* tearoffs */
790
791         XMLNode* tearoff_node = new XMLNode (X_("Tearoffs"));
792
793         if (transport_tearoff) {
794                 XMLNode* t = new XMLNode (X_("transport"));
795                 transport_tearoff->add_state (*t);
796                 tearoff_node->add_child_nocopy (*t);
797         }
798
799         if (mixer && mixer->monitor_section()) {
800                 XMLNode* t = new XMLNode (X_("monitor-section"));
801                 mixer->monitor_section()->tearoff().add_state (*t);
802                 tearoff_node->add_child_nocopy (*t);
803         }
804
805         if (editor && editor->mouse_mode_tearoff()) {
806                 XMLNode* t = new XMLNode (X_("mouse-mode"));
807                 editor->mouse_mode_tearoff ()->add_state (*t);
808                 tearoff_node->add_child_nocopy (*t);
809         }
810
811         window_node->add_child_nocopy (*tearoff_node);
812
813         Config->add_extra_xml (*window_node);
814
815         if (_startup && _startup->engine_control() && _startup->engine_control()->was_used()) {
816                 Config->add_extra_xml (_startup->engine_control()->get_state());
817         }
818         Config->save_state();
819         if (ui_config->dirty()) {
820                 ui_config->save_state ();
821         }
822
823         XMLNode& enode (static_cast<Stateful*>(editor)->get_state());
824         XMLNode& mnode (mixer->get_state());
825
826         if (_session) {
827                 _session->add_instant_xml (enode);
828                 _session->add_instant_xml (mnode);
829                 if (location_ui->get ()) {
830                         _session->add_instant_xml (location_ui->get()->ui().get_state ());
831                 }
832         } else {
833                 Config->add_instant_xml (enode);
834                 Config->add_instant_xml (mnode);
835                 if (location_ui->get ()) {
836                         Config->add_instant_xml (location_ui->get()->ui().get_state ());
837                 }
838         }
839
840         Keyboard::save_keybindings ();
841 }
842
843 void
844 ARDOUR_UI::toggle_global_port_matrix (ARDOUR::DataType t)
845 {
846         std::string const action = string_compose ("toggle-%1-connection-manager", t.to_string ());
847
848         if (_global_port_matrix[t]->get() == 0) {
849                 _global_port_matrix[t]->set (new GlobalPortMatrixWindow (_session, t));
850                 _global_port_matrix[t]->get()->signal_unmap().connect(sigc::bind (sigc::ptr_fun (&ActionManager::uncheck_toggleaction), string_compose (X_("<Actions>/Common/%1"), action)));
851         }
852
853         RefPtr<Action> act = ActionManager::get_action (X_("Common"), action.c_str());
854         if (act) {
855                 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic (act);
856
857                 if (tact->get_active()) {
858                         _global_port_matrix[t]->get()->present ();
859                 } else {
860                         _global_port_matrix[t]->get()->hide ();
861                 }
862         }
863 }
864
865 void
866 ARDOUR_UI::resize_text_widgets ()
867 {
868         set_size_request_to_display_given_text (cpu_load_label, "DSP: 100.0%", 2, 2);
869         set_size_request_to_display_given_text (buffer_load_label, "Buffers: p:100% c:100%", 2, 2);
870 }
871
872 void
873 ARDOUR_UI::focus_on_clock ()
874 {
875         if (editor && primary_clock) {
876                 editor->present ();
877                 primary_clock->focus ();
878         }
879 }