Make menu option for speaker config the same as the window title.
[ardour2.git] / gtk2_ardour / ardour_ui_ed.cc
blobb90e67bc195b4b195ec9451a7f7bb0cfdaea730c
1 /*
2 Copyright (C) 20002-2004 Paul Davis
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.
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.
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.
20 #ifdef WAF_BUILD
21 #include "gtk2ardour-config.h"
22 #endif
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.
30 #include <cmath>
32 #include <glibmm/miscutils.h>
33 #include <gtk/gtk.h>
35 #include "gtkmm2ext/utils.h"
36 #include "gtkmm2ext/window_title.h"
37 #include "gtkmm2ext/tearoff.h"
39 #include "pbd/file_utils.h"
40 #include "pbd/fpu.h"
41 #include "pbd/convert.h"
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"
57 #include <gtkmm2ext/application.h>
59 #include "ardour/session.h"
60 #include "ardour/profile.h"
61 #include "ardour/audioengine.h"
62 #include "ardour/control_protocol_manager.h"
64 #include "control_protocol/control_protocol.h"
66 #include "i18n.h"
68 using namespace std;
69 using namespace ARDOUR;
70 using namespace PBD;
71 using namespace Gtkmm2ext;
72 using namespace Gtk;
73 using namespace Glib;
75 int
76 ARDOUR_UI::create_editor ()
78 try {
79 editor = new Editor ();
82 catch (failed_constructor& err) {
83 return -1;
86 editor->Realized.connect (sigc::mem_fun (*this, &ARDOUR_UI::editor_realized));
87 editor->signal_window_state_event().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::main_window_state_event_handler), true));
89 return 0;
92 void
93 ARDOUR_UI::install_actions ()
95 Glib::RefPtr<ActionGroup> main_actions = ActionGroup::create (X_("Main"));
96 Glib::RefPtr<Action> act;
98 /* menus + submenus that need action items */
100 ActionManager::register_action (main_actions, X_("Session"), _("Session"));
101 act = ActionManager::register_action (main_actions, X_("Cleanup"), _("Cleanup"));
102 ActionManager::write_sensitive_actions.push_back (act);
103 ActionManager::register_action (main_actions, X_("Sync"), _("Sync"));
104 ActionManager::register_action (main_actions, X_("TransportOptions"), _("Options"));
105 ActionManager::register_action (main_actions, X_("Help"), _("Help"));
106 ActionManager::register_action (main_actions, X_("KeyMouseActions"), _("Misc. Shortcuts"));
107 ActionManager::register_action (main_actions, X_("AudioFileFormat"), _("Audio File Format"));
108 ActionManager::register_action (main_actions, X_("AudioFileFormatHeader"), _("File Type"));
109 ActionManager::register_action (main_actions, X_("AudioFileFormatData"), _("Sample Format"));
110 ActionManager::register_action (main_actions, X_("ControlSurfaces"), _("Control Surfaces"));
111 ActionManager::register_action (main_actions, X_("Plugins"), _("Plugins"));
112 ActionManager::register_action (main_actions, X_("Metering"), _("Metering"));
113 ActionManager::register_action (main_actions, X_("MeteringFallOffRate"), _("Fall Off Rate"));
114 ActionManager::register_action (main_actions, X_("MeteringHoldTime"), _("Hold Time"));
115 ActionManager::register_action (main_actions, X_("Denormals"), _("Denormal Handling"));
117 /* the real actions */
119 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 ActionManager::register_action (main_actions, X_("Open"), _("Open..."), sigc::mem_fun(*this, &ARDOUR_UI::open_session));
122 ActionManager::register_action (main_actions, X_("Recent"), _("Recent..."), sigc::mem_fun(*this, &ARDOUR_UI::open_recent_session));
123 act = ActionManager::register_action (main_actions, X_("Close"), _("Close"), sigc::mem_fun(*this, &ARDOUR_UI::close_session));
124 ActionManager::session_sensitive_actions.push_back (act);
126 act = ActionManager::register_action (main_actions, X_("AddTrackBus"), _("Add Track or Bus..."),
127 sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::add_route), (Gtk::Window*) 0));
128 ActionManager::session_sensitive_actions.push_back (act);
129 ActionManager::write_sensitive_actions.push_back (act);
131 #ifdef WITH_CMT
133 sys::path anicomp_file_path;
135 if (PBD::find_file_in_search_path (Glib::getenv("PATH"), "AniComp", anicomp_file_path)) {
136 act = ActionManager::register_action (main_actions, X_("aniConnect"), _("Connect"), (sigc::mem_fun (*editor, &PublicEditor::connect_to_image_compositor)));
137 ActionManager::session_sensitive_actions.push_back (act);
140 #endif
142 act = ActionManager::register_action (main_actions, X_("Snapshot"), _("Snapshot..."), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::snapshot_session), false));
143 ActionManager::session_sensitive_actions.push_back (act);
144 ActionManager::write_sensitive_actions.push_back (act);
146 act = ActionManager::register_action (main_actions, X_("SaveAs"), _("Save As..."), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::snapshot_session), true));
147 ActionManager::session_sensitive_actions.push_back (act);
148 ActionManager::write_sensitive_actions.push_back (act);
150 act = ActionManager::register_action (main_actions, X_("SaveTemplate"), _("Save Template..."), sigc::mem_fun(*this, &ARDOUR_UI::save_template));
151 ActionManager::session_sensitive_actions.push_back (act);
153 act = ActionManager::register_action (main_actions, X_("Metadata"), _("Metadata"));
154 ActionManager::session_sensitive_actions.push_back (act);
156 act = ActionManager::register_action (main_actions, X_("EditMetadata"), _("Edit Metadata..."), sigc::mem_fun(*this, &ARDOUR_UI::edit_metadata));
157 ActionManager::session_sensitive_actions.push_back (act);
159 act = ActionManager::register_action (main_actions, X_("ImportMetadata"), _("Import Metadata..."), sigc::mem_fun(*this, &ARDOUR_UI::import_metadata));
160 ActionManager::session_sensitive_actions.push_back (act);
162 act = ActionManager::register_action (main_actions, X_("ExportAudio"), _("Export To Audio File(s)..."), sigc::mem_fun (*editor, &PublicEditor::export_audio));
163 ActionManager::session_sensitive_actions.push_back (act);
165 act = ActionManager::register_action (main_actions, X_("StemExport"), _("Stem export..."), sigc::mem_fun (*editor, &PublicEditor::stem_export));
166 ActionManager::session_sensitive_actions.push_back (act);
168 act = ActionManager::register_action (main_actions, X_("Export"), _("Export"));
169 ActionManager::session_sensitive_actions.push_back (act);
171 act = ActionManager::register_action (main_actions, X_("CleanupUnused"), _("Cleanup Unused Sources..."), sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::cleanup));
172 ActionManager::session_sensitive_actions.push_back (act);
173 ActionManager::write_sensitive_actions.push_back (act);
175 act = ActionManager::register_action (main_actions, X_("FlushWastebasket"), _("Flush Wastebasket"), sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::flush_trash));
176 ActionManager::write_sensitive_actions.push_back (act);
177 ActionManager::session_sensitive_actions.push_back (act);
179 /* JACK actions for controlling ... JACK */
181 Glib::RefPtr<ActionGroup> jack_actions = ActionGroup::create (X_("JACK"));
182 ActionManager::register_action (jack_actions, X_("JACK"), _("JACK"));
183 ActionManager::register_action (jack_actions, X_("Latency"), _("Latency"));
185 act = ActionManager::register_action (jack_actions, X_("JACKReconnect"), _("Reconnect"), sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::reconnect_to_jack));
186 ActionManager::jack_opposite_sensitive_actions.push_back (act);
188 act = ActionManager::register_action (jack_actions, X_("JACKDisconnect"), _("Disconnect"), sigc::mem_fun (*(ARDOUR_UI::instance()), &ARDOUR_UI::disconnect_from_jack));
189 ActionManager::jack_sensitive_actions.push_back (act);
191 RadioAction::Group jack_latency_group;
193 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));
194 ActionManager::jack_sensitive_actions.push_back (act);
195 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));
196 ActionManager::jack_sensitive_actions.push_back (act);
197 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));
198 ActionManager::jack_sensitive_actions.push_back (act);
199 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));
200 ActionManager::jack_sensitive_actions.push_back (act);
201 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));
202 ActionManager::jack_sensitive_actions.push_back (act);
203 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));
204 ActionManager::jack_sensitive_actions.push_back (act);
205 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));
206 ActionManager::jack_sensitive_actions.push_back (act);
207 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));
208 ActionManager::jack_sensitive_actions.push_back (act);
209 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));
210 ActionManager::jack_sensitive_actions.push_back (act);
212 /* these actions are intended to be shared across all windows */
214 common_actions = ActionGroup::create (X_("Common"));
215 ActionManager::register_action (main_actions, X_("WindowMenu"), _("Window"));
216 ActionManager::register_action (common_actions, X_("Quit"), _("Quit"), (hide_return (sigc::mem_fun(*this, &ARDOUR_UI::finish))));
218 /* windows visibility actions */
220 ActionManager::register_toggle_action (common_actions, X_("ToggleMaximalEditor"), _("Maximise Editor Space"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_editing_space));
221 act = ActionManager::register_toggle_action (common_actions, X_("KeepTearoffs"), _("Toolbars when Maximised"), mem_fun (*this, &ARDOUR_UI::toggle_keep_tearoffs));
222 ActionManager::session_sensitive_actions.push_back (act);
224 ActionManager::register_toggle_action (common_actions, X_("toggle-mixer"), _("Mixer"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_mixer_window));
225 ActionManager::register_toggle_action (common_actions, X_("toggle-mixer-on-top"), _("Mixer on Top"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_mixer_on_top));
226 ActionManager::register_toggle_action (common_actions, X_("ToggleRCOptionsEditor"), _("Preferences"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_rc_options_window));
227 ActionManager::register_toggle_action (common_actions, X_("ToggleSessionOptionsEditor"), _("Properties"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_session_options_window));
228 act = ActionManager::register_toggle_action (common_actions, X_("ToggleInspector"), _("Tracks and Busses"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_route_params_window));
229 ActionManager::session_sensitive_actions.push_back (act);
230 ActionManager::session_sensitive_actions.push_back (act);
231 act = ActionManager::register_toggle_action (common_actions, X_("ToggleLocations"), _("Locations"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_location_window));
232 ActionManager::session_sensitive_actions.push_back (act);
233 act = ActionManager::register_toggle_action (common_actions, X_("ToggleBigClock"), _("Big Clock"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_big_clock_window));
234 ActionManager::session_sensitive_actions.push_back (act);
235 act = ActionManager::register_toggle_action (common_actions, X_("toggle-speaker-config"), _("Speaker Configuration"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_speaker_config_window));
236 ActionManager::session_sensitive_actions.push_back (act);
237 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));
238 ActionManager::session_sensitive_actions.push_back (act);
239 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));
240 ActionManager::session_sensitive_actions.push_back (act);
241 act = ActionManager::register_action (common_actions, X_("NewMIDITracer"), _("MIDI Tracer"), sigc::mem_fun(*this, &ARDOUR_UI::new_midi_tracer_window));
242 ActionManager::session_sensitive_actions.push_back (act);
243 ActionManager::register_action (common_actions, X_("About"), _("About"), sigc::mem_fun(*this, &ARDOUR_UI::show_about));
244 ActionManager::register_action (common_actions, X_("Chat"), _("Chat"), sigc::mem_fun(*this, &ARDOUR_UI::launch_chat));
245 ActionManager::register_action (common_actions, X_("Manual"), _("Manual"), mem_fun(*this, &ARDOUR_UI::launch_manual));
246 ActionManager::register_action (common_actions, X_("Reference"), _("Reference"), mem_fun(*this, &ARDOUR_UI::launch_reference));
247 ActionManager::register_toggle_action (common_actions, X_("ToggleThemeManager"), _("Theme Manager"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_theme_manager));
248 ActionManager::register_toggle_action (common_actions, X_("ToggleKeyEditor"), _("Key Bindings"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_key_editor));
249 ActionManager::register_toggle_action (common_actions, X_("ToggleBundleManager"), _("Bundle Manager"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_bundle_manager));
251 #if 0
252 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));
253 ActionManager::session_sensitive_actions.push_back (act);
254 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));
255 ActionManager::session_sensitive_actions.push_back (act);
256 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));
257 ActionManager::session_sensitive_actions.push_back (act);
258 //act = ActionManager::register_action (common_actions, X_("AddMidiBus"), _("Add Midi Bus"), sigc::mem_fun(*this, &ARDOUR_UI::session_add_midi_bus));
259 //ActionManager::session_sensitive_actions.push_back (act);
260 #endif
261 act = ActionManager::register_action (common_actions, X_("Save"), _("Save"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::save_state), string(""), false));
262 ActionManager::session_sensitive_actions.push_back (act);
263 ActionManager::write_sensitive_actions.push_back (act);
264 act = ActionManager::register_action (common_actions, X_("RemoveLastCapture"), _("Remove Last Capture"), sigc::mem_fun(*this, &ARDOUR_UI::remove_last_capture));
265 ActionManager::session_sensitive_actions.push_back (act);
267 Glib::RefPtr<ActionGroup> transport_actions = ActionGroup::create (X_("Transport"));
269 /* do-nothing action for the "transport" menu bar item */
271 ActionManager::register_action (transport_actions, X_("Transport"), _("Transport"));
273 /* these two are not used by key bindings, instead use ToggleRoll for that. these two do show up in
274 menus and via button proxies.
277 act = ActionManager::register_action (transport_actions, X_("Stop"), _("Stop"), sigc::mem_fun(*this, &ARDOUR_UI::transport_stop));
278 ActionManager::session_sensitive_actions.push_back (act);
279 ActionManager::transport_sensitive_actions.push_back (act);
280 act = ActionManager::register_action (transport_actions, X_("Roll"), _("Roll"), sigc::mem_fun(*this, &ARDOUR_UI::transport_roll));
281 ActionManager::session_sensitive_actions.push_back (act);
282 ActionManager::transport_sensitive_actions.push_back (act);
284 act = ActionManager::register_action (transport_actions, X_("ToggleRoll"), _("Start/Stop"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::toggle_roll), false, false));
285 ActionManager::session_sensitive_actions.push_back (act);
286 ActionManager::transport_sensitive_actions.push_back (act);
287 act = ActionManager::register_action (transport_actions, X_("ToggleRollMaybe"), _("Start/Continue/Stop"), sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::toggle_roll), false, true));
288 ActionManager::session_sensitive_actions.push_back (act);
289 ActionManager::transport_sensitive_actions.push_back (act);
290 act = ActionManager::register_action (transport_actions, X_("ToggleRollForgetCapture"), _("Stop and Forget Capture"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::toggle_roll), true, false));
291 ActionManager::session_sensitive_actions.push_back (act);
292 ActionManager::transport_sensitive_actions.push_back (act);
294 /* these two behave as follows:
296 - if transport speed != 1.0 or != -1.0, change speed to 1.0 or -1.0 (respectively)
297 - otherwise do nothing
300 act = ActionManager::register_action (transport_actions, X_("TransitionToRoll"), _("Transition To Roll"), sigc::bind (sigc::mem_fun (*editor, &PublicEditor::transition_to_rolling), true));
301 ActionManager::session_sensitive_actions.push_back (act);
302 ActionManager::transport_sensitive_actions.push_back (act);
304 act = ActionManager::register_action (transport_actions, X_("TransitionToReverse"), _("Transition To Reverse"), sigc::bind (sigc::mem_fun (*editor, &PublicEditor::transition_to_rolling), false));
305 ActionManager::session_sensitive_actions.push_back (act);
306 ActionManager::transport_sensitive_actions.push_back (act);
308 act = ActionManager::register_action (transport_actions, X_("Loop"), _("Play Loop Range"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_session_auto_loop));
309 ActionManager::session_sensitive_actions.push_back (act);
310 ActionManager::transport_sensitive_actions.push_back (act);
311 act = ActionManager::register_action (transport_actions, X_("PlaySelection"), _("Play Selection"), sigc::mem_fun(*this, &ARDOUR_UI::transport_play_selection));
312 ActionManager::session_sensitive_actions.push_back (act);
313 ActionManager::transport_sensitive_actions.push_back (act);
315 act = ActionManager::register_action (transport_actions, X_("Record"), _("Enable Record"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_record), false));
316 ActionManager::session_sensitive_actions.push_back (act);
317 ActionManager::write_sensitive_actions.push_back (act);
318 act = ActionManager::register_action (transport_actions, X_("record-roll"), _("Start Recording"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_record), true));
319 ActionManager::session_sensitive_actions.push_back (act);
320 ActionManager::write_sensitive_actions.push_back (act);
321 ActionManager::transport_sensitive_actions.push_back (act);
322 act = ActionManager::register_action (transport_actions, X_("Rewind"), _("Rewind"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_rewind), 0));
323 ActionManager::session_sensitive_actions.push_back (act);
324 ActionManager::transport_sensitive_actions.push_back (act);
325 act = ActionManager::register_action (transport_actions, X_("RewindSlow"), _("Rewind (Slow)"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_rewind), -1));
326 ActionManager::session_sensitive_actions.push_back (act);
327 ActionManager::transport_sensitive_actions.push_back (act);
328 act = ActionManager::register_action (transport_actions, X_("RewindFast"), _("Rewind (Fast)"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_rewind), 1));
329 ActionManager::session_sensitive_actions.push_back (act);
330 ActionManager::transport_sensitive_actions.push_back (act);
331 act = ActionManager::register_action (transport_actions, X_("Forward"), _("Forward"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_forward), 0));
332 ActionManager::session_sensitive_actions.push_back (act);
333 ActionManager::transport_sensitive_actions.push_back (act);
334 act = ActionManager::register_action (transport_actions, X_("ForwardSlow"), _("Forward (Slow)"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_forward), -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_("ForwardFast"), _("Forward (Fast)"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::transport_forward), 1));
338 ActionManager::session_sensitive_actions.push_back (act);
339 ActionManager::transport_sensitive_actions.push_back (act);
340 act = ActionManager::register_action (transport_actions, X_("GotoZero"), _("Goto Zero"), sigc::mem_fun(*this, &ARDOUR_UI::transport_goto_zero));
341 ActionManager::session_sensitive_actions.push_back (act);
342 ActionManager::transport_sensitive_actions.push_back (act);
343 act = ActionManager::register_action (transport_actions, X_("GotoStart"), _("Goto Start"), sigc::mem_fun(*this, &ARDOUR_UI::transport_goto_start));
344 ActionManager::session_sensitive_actions.push_back (act);
345 ActionManager::transport_sensitive_actions.push_back (act);
346 act = ActionManager::register_action (transport_actions, X_("GotoEnd"), _("Goto End"), sigc::mem_fun(*this, &ARDOUR_UI::transport_goto_end));
347 ActionManager::session_sensitive_actions.push_back (act);
348 ActionManager::transport_sensitive_actions.push_back (act);
349 act = ActionManager::register_action (transport_actions, X_("GotoWallClock"), _("Goto Wall Clock"), sigc::mem_fun(*this, &ARDOUR_UI::transport_goto_wallclock));
350 ActionManager::session_sensitive_actions.push_back (act);
351 ActionManager::transport_sensitive_actions.push_back (act);
353 act = ActionManager::register_action (transport_actions, X_("focus-on-clock"), _("Focus On Clock"), sigc::mem_fun(primary_clock, &AudioClock::focus));
354 ActionManager::session_sensitive_actions.push_back (act);
355 ActionManager::transport_sensitive_actions.push_back (act);
357 act = ActionManager::register_action (transport_actions, X_("primary-clock-bbt"), _("Bars & Beats"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::BBT));
358 ActionManager::session_sensitive_actions.push_back (act);
359 act = ActionManager::register_action (transport_actions, X_("primary-clock-minsec"), _("Minutes & Seconds"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::MinSec));
360 ActionManager::session_sensitive_actions.push_back (act);
361 act = ActionManager::register_action (transport_actions, X_("primary-clock-samples"), _("Samples"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::Frames));
362 ActionManager::session_sensitive_actions.push_back (act);
363 act = ActionManager::register_action (transport_actions, X_("primary-clock-off"), _("Off"), sigc::bind (sigc::mem_fun(primary_clock, &AudioClock::set_mode), AudioClock::Off));
364 ActionManager::session_sensitive_actions.push_back (act);
366 act = ActionManager::register_action (transport_actions, X_("secondary-clock-bbt"), _("Bars & Beats"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::BBT));
367 ActionManager::session_sensitive_actions.push_back (act);
368 act = ActionManager::register_action (transport_actions, X_("secondary-clock-minsec"), _("Minutes & Seconds"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::MinSec));
369 ActionManager::session_sensitive_actions.push_back (act);
370 act = ActionManager::register_action (transport_actions, X_("secondary-clock-samples"), _("Samples"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::Frames));
371 ActionManager::session_sensitive_actions.push_back (act);
372 act = ActionManager::register_action (transport_actions, X_("secondary-clock-off"), _("Off"), sigc::bind (sigc::mem_fun(secondary_clock, &AudioClock::set_mode), AudioClock::Off));
373 ActionManager::session_sensitive_actions.push_back (act);
375 act = ActionManager::register_toggle_action (transport_actions, X_("TogglePunchIn"), _("Punch In"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_punch_in));
376 ActionManager::session_sensitive_actions.push_back (act);
377 ActionManager::transport_sensitive_actions.push_back (act);
378 act = ActionManager::register_toggle_action (transport_actions, X_("TogglePunchOut"), _("Punch Out"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_punch_out));
379 ActionManager::session_sensitive_actions.push_back (act);
380 ActionManager::transport_sensitive_actions.push_back (act);
381 act = ActionManager::register_toggle_action (transport_actions, X_("TogglePunch"), _("Punch In/Out"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_punch));
382 ActionManager::session_sensitive_actions.push_back (act);
383 ActionManager::transport_sensitive_actions.push_back (act);
384 act = ActionManager::register_toggle_action (transport_actions, X_("ToggleClick"), _("Click"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_click));
385 ActionManager::session_sensitive_actions.push_back (act);
386 ActionManager::transport_sensitive_actions.push_back (act);
387 act = ActionManager::register_toggle_action (transport_actions, X_("ToggleAutoInput"), _("Auto Input"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_auto_input));
388 ActionManager::session_sensitive_actions.push_back (act);
389 ActionManager::transport_sensitive_actions.push_back (act);
390 act = ActionManager::register_toggle_action (transport_actions, X_("ToggleAutoPlay"), _("Auto Play"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_auto_play));
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_("ToggleAutoReturn"), _("Auto Return"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_auto_return));
394 ActionManager::session_sensitive_actions.push_back (act);
395 ActionManager::transport_sensitive_actions.push_back (act);
397 act = ActionManager::register_toggle_action (transport_actions, X_("ToggleVideoSync"), _("Sync Startup to Video"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_video_sync));
398 ActionManager::session_sensitive_actions.push_back (act);
399 act = ActionManager::register_toggle_action (transport_actions, X_("ToggleTimeMaster"), _("Time Master"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_time_master));
400 ActionManager::session_sensitive_actions.push_back (act);
401 act = ActionManager::register_toggle_action (transport_actions, X_("ToggleExternalSync"), "", sigc::mem_fun(*this, &ARDOUR_UI::toggle_external_sync));
402 ActionManager::session_sensitive_actions.push_back (act);
404 for (int i = 1; i <= 32; ++i) {
405 string const a = string_compose (X_("ToggleRecordEnableTrack%1"), i);
406 string const n = string_compose (_("Toggle Record Enable Track %1"), i);
407 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));
408 ActionManager::session_sensitive_actions.push_back (act);
411 Glib::RefPtr<ActionGroup> shuttle_actions = ActionGroup::create ("ShuttleActions");
413 shuttle_actions->add (Action::create (X_("SetShuttleUnitsPercentage"), _("Percentage")), hide_return (sigc::bind (sigc::mem_fun (*Config, &RCConfiguration::set_shuttle_units), Percentage)));
414 shuttle_actions->add (Action::create (X_("SetShuttleUnitsSemitones"), _("Semitones")), hide_return (sigc::bind (sigc::mem_fun (*Config, &RCConfiguration::set_shuttle_units), Semitones)));
416 Glib::RefPtr<ActionGroup> option_actions = ActionGroup::create ("options");
418 act = ActionManager::register_toggle_action (option_actions, X_("SendMTC"), _("Send MTC"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_send_mtc));
419 ActionManager::session_sensitive_actions.push_back (act);
420 act = ActionManager::register_toggle_action (option_actions, X_("SendMMC"), _("Send MMC"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_send_mmc));
421 ActionManager::session_sensitive_actions.push_back (act);
422 act = ActionManager::register_toggle_action (option_actions, X_("UseMMC"), _("Use MMC"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_use_mmc));
423 ActionManager::session_sensitive_actions.push_back (act);
424 act = ActionManager::register_toggle_action (option_actions, X_("SendMidiClock"), _("Send MIDI Clock"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_send_midi_clock));
425 ActionManager::session_sensitive_actions.push_back (act);
426 act = ActionManager::register_toggle_action (option_actions, X_("SendMIDIfeedback"), _("Send MIDI Feedback"), sigc::mem_fun (*this, &ARDOUR_UI::toggle_send_midi_feedback));
427 ActionManager::session_sensitive_actions.push_back (act);
430 if (getenv ("ARDOUR_BUNDLED")) {
431 act = ActionManager::register_toggle_action (main_actions, X_("EnableTranslation"), _("Enable Translations"), mem_fun (*this, &ARDOUR_UI::toggle_translations));
432 if (act) {
433 RefPtr<ToggleAction> ract = RefPtr<ToggleAction>::cast_dynamic (act);
434 if (ract) {
435 ract->set_active (!ARDOUR::translations_are_disabled());
440 ActionManager::add_action_group (shuttle_actions);
441 ActionManager::add_action_group (option_actions);
442 ActionManager::add_action_group (jack_actions);
443 ActionManager::add_action_group (transport_actions);
444 ActionManager::add_action_group (main_actions);
445 ActionManager::add_action_group (common_actions);
448 void
449 ARDOUR_UI::set_jack_buffer_size (pframes_t nframes)
451 Glib::RefPtr<Action> action;
452 const char* action_name = 0;
454 switch (nframes) {
455 case 32:
456 action_name = X_("JACKLatency32");
457 break;
458 case 64:
459 action_name = X_("JACKLatency64");
460 break;
461 case 128:
462 action_name = X_("JACKLatency128");
463 break;
464 case 256:
465 action_name = X_("JACKLatency256");
466 break;
467 case 512:
468 action_name = X_("JACKLatency512");
469 break;
470 case 1024:
471 action_name = X_("JACKLatency1024");
472 break;
473 case 2048:
474 action_name = X_("JACKLatency2048");
475 break;
476 case 4096:
477 action_name = X_("JACKLatency4096");
478 break;
479 case 8192:
480 action_name = X_("JACKLatency8192");
481 break;
482 default:
483 /* XXX can we do anything useful ? */
484 break;
487 if (action_name) {
489 action = ActionManager::get_action (X_("JACK"), action_name);
491 if (action) {
492 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic (action);
494 if (ract && ract->get_active()) {
495 engine->request_buffer_size (nframes);
496 update_sample_rate (0);
502 void
503 ARDOUR_UI::build_menu_bar ()
505 menu_bar = dynamic_cast<MenuBar*> (ActionManager::get_widget (X_("/Main")));
506 menu_bar->set_name ("MainMenuBar");
509 * This is needed because this property does not get installed
510 * until the Menu GObject class is registered, which happens
511 * when the first menu instance is created.
513 // XXX bug in gtkmm causes this to popup an error message
514 // Gtk::Settings::get_default()->property_gtk_can_change_accels() = true;
515 // so use this instead ...
516 gtk_settings_set_long_property (gtk_settings_get_default(), "gtk-can-change-accels", 1, "Ardour:designers");
518 wall_clock_box.add (wall_clock_label);
519 wall_clock_box.set_name ("WallClock");
520 wall_clock_label.set_name ("WallClock");
522 disk_space_box.add (disk_space_label);
523 disk_space_box.set_name ("WallClock");
524 disk_space_label.set_name ("WallClock");
526 cpu_load_box.add (cpu_load_label);
527 cpu_load_box.set_name ("CPULoad");
528 cpu_load_label.set_name ("CPULoad");
530 buffer_load_box.add (buffer_load_label);
531 buffer_load_box.set_name ("BufferLoad");
532 buffer_load_label.set_name ("BufferLoad");
534 sample_rate_box.add (sample_rate_label);
535 sample_rate_box.set_name ("SampleRate");
536 sample_rate_label.set_name ("SampleRate");
538 #ifndef TOP_MENUBAR
539 menu_hbox.pack_start (*menu_bar, false, false);
540 #else
541 use_menubar_as_top_menubar ();
542 #endif
544 if (!Profile->get_small_screen()) {
545 #ifndef GTKOSX
546 // OSX provides its own wallclock, thank you very much
547 menu_hbox.pack_end (wall_clock_box, false, false, 2);
548 #endif
549 menu_hbox.pack_end (disk_space_box, false, false, 4);
552 menu_hbox.pack_end (cpu_load_box, false, false, 4);
553 menu_hbox.pack_end (buffer_load_box, false, false, 4);
554 menu_hbox.pack_end (sample_rate_box, false, false, 4);
556 menu_bar_base.set_name ("MainMenuBar");
557 menu_bar_base.add (menu_hbox);
560 void
561 ARDOUR_UI::use_menubar_as_top_menubar ()
563 Gtk::Widget* widget;
564 Application* app = Application::instance ();
566 /* Quit will be taken of separately */
568 if ((widget = ActionManager::get_widget ("/ui/Main/Session/Quit"))) {
569 widget->hide ();
572 GtkApplicationMenuGroup* group = app->add_app_menu_group ();
574 if ((widget = ActionManager::get_widget ("/ui/Main/Help/About"))) {
575 app->add_app_menu_item (group, dynamic_cast<MenuItem*>(widget));
578 if ((widget = ActionManager::get_widget ("/ui/Main/WindowMenu/ToggleOptionsEditor"))) {
579 app->add_app_menu_item (group, dynamic_cast<MenuItem*>(widget));
582 app->set_menu_bar (*menu_bar);
585 void
586 ARDOUR_UI::setup_clock ()
588 ARDOUR_UI::Clock.connect (sigc::bind (sigc::mem_fun (big_clock, &AudioClock::set), false));
590 big_clock_window->set (new Window (WINDOW_TOPLEVEL), false);
592 big_clock_window->get()->set_keep_above (true);
593 big_clock_window->get()->set_border_width (0);
594 big_clock_window->get()->add (big_clock);
596 big_clock_window->get()->set_title (_("Big Clock"));
597 big_clock_window->get()->set_type_hint (Gdk::WINDOW_TYPE_HINT_UTILITY);
598 big_clock_window->get()->signal_realize().connect (sigc::mem_fun (*this, &ARDOUR_UI::big_clock_realized));
599 big_clock_window->get()->signal_unmap().connect (sigc::bind (sigc::ptr_fun(&ActionManager::uncheck_toggleaction), X_("<Actions>/Common/ToggleBigClock")));
600 big_clock_window->get()->signal_key_press_event().connect (sigc::bind (sigc::ptr_fun (relay_key_press), big_clock_window->get()), false);
601 big_clock_window->get()->signal_size_allocate().connect (sigc::mem_fun (*this, &ARDOUR_UI::big_clock_size_allocate));
603 manage_window (*big_clock_window->get());
606 void
607 ARDOUR_UI::big_clock_realized ()
609 int x, y, w, d;
611 set_decoration (big_clock_window->get(), (Gdk::DECOR_BORDER|Gdk::DECOR_RESIZEH));
612 big_clock_window->get()->get_window()->get_geometry (x, y, w, big_clock_height, d);
614 original_big_clock_height = big_clock_height;
615 original_big_clock_width = w;
617 Pango::FontDescription fd (big_clock.get_style()->get_font());
618 original_big_clock_font_size = fd.get_size ();
620 if (!fd.get_size_is_absolute ()) {
621 original_big_clock_font_size /= PANGO_SCALE;
624 big_clock_window->setup ();
627 void
628 ARDOUR_UI::float_big_clock (Gtk::Window* parent)
630 if (big_clock_window->get()) {
631 if (parent) {
632 big_clock_window->get()->set_transient_for (*parent);
633 } else {
634 gtk_window_set_transient_for (big_clock_window->get()->gobj(), (GtkWindow*) 0);
639 void
640 ARDOUR_UI::big_clock_size_allocate (Gtk::Allocation&)
642 if (!big_clock_resize_in_progress) {
643 Glib::signal_idle().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::idle_big_clock_text_resizer), 0, 0));
644 big_clock_resize_in_progress = true;
648 bool
649 ARDOUR_UI::idle_big_clock_text_resizer (int, int)
651 big_clock_resize_in_progress = false;
653 Glib::RefPtr<Gdk::Window> win = big_clock_window->get()->get_window();
654 Pango::FontDescription fd (big_clock.get_style()->get_font());
655 int current_size = fd.get_size ();
656 int x, y, w, h, d;
658 if (!fd.get_size_is_absolute ()) {
659 current_size /= PANGO_SCALE;
662 win->get_geometry (x, y, w, h, d);
664 double scale = min (((double) w / (double) original_big_clock_width),
665 ((double) h / (double) original_big_clock_height));
667 int size = (int) lrintf (original_big_clock_font_size * scale);
669 if (size != current_size) {
671 string family = fd.get_family();
672 char buf[family.length()+16];
673 snprintf (buf, family.length()+16, "%s %d", family.c_str(), size);
675 try {
676 Pango::FontDescription fd (buf);
677 Glib::RefPtr<Gtk::RcStyle> rcstyle = big_clock.get_modifier_style ();
678 rcstyle->set_font (fd);
679 big_clock.modify_style (rcstyle);
682 catch (...) {
683 /* oh well, do nothing */
687 return false;
690 void
691 ARDOUR_UI::save_ardour_state ()
693 if (!keyboard || !mixer || !editor) {
694 return;
697 /* XXX this is all a bit dubious. add_extra_xml() uses
698 a different lifetime model from add_instant_xml().
701 XMLNode* node = new XMLNode (keyboard->get_state());
702 Config->add_extra_xml (*node);
703 Config->add_extra_xml (get_transport_controllable_state());
705 XMLNode* window_node = new XMLNode (X_("UI"));
707 for (list<WindowProxyBase*>::iterator i = _window_proxies.begin(); i != _window_proxies.end(); ++i) {
708 if ((*i)->rc_configured()) {
709 window_node->add_child_nocopy (*((*i)->get_state ()));
713 /* tearoffs */
715 XMLNode* tearoff_node = new XMLNode (X_("Tearoffs"));
717 if (transport_tearoff) {
718 XMLNode* t = new XMLNode (X_("transport"));
719 transport_tearoff->add_state (*t);
720 tearoff_node->add_child_nocopy (*t);
723 if (mixer && mixer->monitor_section()) {
724 XMLNode* t = new XMLNode (X_("monitor-section"));
725 mixer->monitor_section()->tearoff().add_state (*t);
726 tearoff_node->add_child_nocopy (*t);
729 if (editor && editor->mouse_mode_tearoff()) {
730 XMLNode* t = new XMLNode (X_("mouse-mode"));
731 editor->mouse_mode_tearoff ()->add_state (*t);
732 tearoff_node->add_child_nocopy (*t);
735 window_node->add_child_nocopy (*tearoff_node);
737 Config->add_extra_xml (*window_node);
739 if (_startup && _startup->engine_control() && _startup->engine_control()->was_used()) {
740 Config->add_extra_xml (_startup->engine_control()->get_state());
742 Config->save_state();
743 ui_config->save_state ();
745 XMLNode enode(static_cast<Stateful*>(editor)->get_state());
746 XMLNode mnode(mixer->get_state());
748 if (_session) {
749 _session->add_instant_xml (enode);
750 _session->add_instant_xml (mnode);
751 } else {
752 Config->add_instant_xml (enode);
753 Config->add_instant_xml (mnode);
756 Keyboard::save_keybindings ();
759 void
760 ARDOUR_UI::toggle_global_port_matrix (ARDOUR::DataType t)
762 std::string const action = string_compose ("toggle-%1-connection-manager", t.to_string ());
764 if (_global_port_matrix[t]->get() == 0) {
765 _global_port_matrix[t]->set (new GlobalPortMatrixWindow (_session, t));
766 _global_port_matrix[t]->get()->signal_unmap().connect(sigc::bind (sigc::ptr_fun (&ActionManager::uncheck_toggleaction), string_compose (X_("<Actions>/Common/%1"), action)));
769 RefPtr<Action> act = ActionManager::get_action (X_("Common"), action.c_str());
770 if (act) {
771 RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic (act);
773 if (tact->get_active()) {
774 _global_port_matrix[t]->get()->present ();
775 } else {
776 _global_port_matrix[t]->get()->hide ();