2 * Copyright (C) 2005-2019 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2006-2007 Doug McLain <doug@nostar.net>
4 * Copyright (C) 2006-2007 Nick Mainsbridge <mainsbridge@gmail.com>
5 * Copyright (C) 2006 Sampo Savolainen <v2@iki.fi>
6 * Copyright (C) 2007-2015 Tim Mayberry <mojofunk@gmail.com>
7 * Copyright (C) 2008-2012 David Robillard <d@drobilla.net>
8 * Copyright (C) 2008 Hans Baier <hansfbaier@googlemail.com>
9 * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
10 * Copyright (C) 2012-2019 Robin Gareus <robin@gareus.org>
11 * Copyright (C) 2014-2018 Ben Loftis <ben@harrisonconsoles.com>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "gtk2ardour-config.h"
32 #include "pbd/convert.h"
33 #include "pbd/stacktrace.h"
34 #include "pbd/unwind.h"
36 #include "ardour/rc_configuration.h"
37 #include "ardour/session.h"
38 #include "ardour/transport_master_manager.h"
40 #include "gtkmm2ext/utils.h"
41 #include "waveview/wave_view.h"
43 #include "audio_clock.h"
44 #include "ardour_ui.h"
46 #include "gui_thread.h"
47 #include "public_editor.h"
48 #include "main_clock.h"
53 using namespace Gtkmm2ext;
54 using namespace ARDOUR;
56 using namespace ArdourWidgets;
59 ARDOUR_UI::toggle_external_sync()
62 if (_session->config.get_video_pullup() != 0.0f && (TransportMasterManager::instance().current()->type() == Engine)) {
63 MessageDialog msg (_("It is not possible to use JACK as the the sync source\n when the pull up/down setting is non-zero."));
68 ActionManager::toggle_config_state_foo ("Transport", "ToggleExternalSync", sigc::mem_fun (_session->config, &SessionConfiguration::set_external_sync), sigc::mem_fun (_session->config, &SessionConfiguration::get_external_sync));
70 /* activating a slave is a session-property.
71 * The slave type is a RC property.
72 * When the slave is active is must not be reconfigured.
73 * This is a UI limitation, imposed by audio-clock and
74 * status displays which combine RC-config & session-properties.
76 * Notify RCOptionEditor by emitting a signal if the active
79 Config->ParameterChanged("sync-source");
84 ARDOUR_UI::toggle_time_master ()
86 ActionManager::toggle_config_state_foo ("Transport", "ToggleTimeMaster", sigc::mem_fun (_session->config, &SessionConfiguration::set_jack_time_master), sigc::mem_fun (_session->config, &SessionConfiguration::get_jack_time_master));
90 ARDOUR_UI::toggle_send_mtc ()
92 ActionManager::toggle_config_state ("Options", "SendMTC", &RCConfiguration::set_send_mtc, &RCConfiguration::get_send_mtc);
96 ARDOUR_UI::toggle_send_mmc ()
98 ActionManager::toggle_config_state ("Options", "SendMMC", &RCConfiguration::set_send_mmc, &RCConfiguration::get_send_mmc);
102 ARDOUR_UI::toggle_send_midi_clock ()
104 ActionManager::toggle_config_state ("Options", "SendMidiClock", &RCConfiguration::set_send_midi_clock, &RCConfiguration::get_send_midi_clock);
108 ARDOUR_UI::toggle_use_mmc ()
110 ActionManager::toggle_config_state ("Options", "UseMMC", &RCConfiguration::set_mmc_control, &RCConfiguration::get_mmc_control);
114 ARDOUR_UI::toggle_auto_input ()
116 ActionManager::toggle_config_state_foo ("Transport", "ToggleAutoInput", sigc::mem_fun (_session->config, &SessionConfiguration::set_auto_input), sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_input));
120 ARDOUR_UI::toggle_auto_play ()
122 ActionManager::toggle_config_state_foo ("Transport", "ToggleAutoPlay", sigc::mem_fun (_session->config, &SessionConfiguration::set_auto_play), sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_play));
126 ARDOUR_UI::toggle_auto_return ()
128 ActionManager::toggle_config_state_foo ("Transport", "ToggleAutoReturn", sigc::mem_fun (_session->config, &SessionConfiguration::set_auto_return), sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_return));
132 ARDOUR_UI::toggle_click ()
134 ActionManager::toggle_config_state ("Transport", "ToggleClick", &RCConfiguration::set_clicking, &RCConfiguration::get_clicking);
138 ARDOUR_UI::toggle_session_monitoring_in ()
140 Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Transport"), X_("SessionMonitorIn"));
142 if (tact->get_active() && _session->config.get_session_monitoring () == MonitorInput) {
145 if (!tact->get_active() && _session->config.get_session_monitoring () != MonitorInput) {
149 if (tact->get_active()) {
150 _session->config.set_session_monitoring (MonitorInput);
152 _session->config.set_session_monitoring (MonitorAuto);
157 ARDOUR_UI::toggle_session_monitoring_disk ()
159 Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Transport"), X_("SessionMonitorDisk"));
160 if (tact->get_active() && _session->config.get_session_monitoring () == MonitorDisk) {
163 if (!tact->get_active() && _session->config.get_session_monitoring () != MonitorDisk) {
167 if (tact->get_active()) {
168 _session->config.set_session_monitoring (MonitorDisk);
170 _session->config.set_session_monitoring (MonitorAuto);
175 ARDOUR_UI::unset_dual_punch ()
177 Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action ("Transport", "TogglePunch");
179 ignore_dual_punch = true;
180 tact->set_active (false);
181 ignore_dual_punch = false;
186 ARDOUR_UI::toggle_punch ()
188 if (ignore_dual_punch) {
192 Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action ("Transport", "TogglePunch");
194 /* drive the other two actions from this one */
195 Glib::RefPtr<ToggleAction> in_action = ActionManager::get_toggle_action ("Transport", "TogglePunchIn");
196 Glib::RefPtr<ToggleAction> out_action = ActionManager::get_toggle_action ("Transport", "TogglePunchOut");
198 in_action->set_active (tact->get_active());
199 out_action->set_active (tact->get_active());
203 ARDOUR_UI::toggle_punch_in ()
205 Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Transport"), X_("TogglePunchIn"));
207 if (tact->get_active() != _session->config.get_punch_in()) {
208 _session->config.set_punch_in (tact->get_active ());
211 if (tact->get_active()) {
212 /* if punch-in is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
213 to avoid confusing the user */
214 show_loop_punch_ruler_and_disallow_hide ();
217 reenable_hide_loop_punch_ruler_if_appropriate ();
221 ARDOUR_UI::toggle_punch_out ()
223 Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Transport"), X_("TogglePunchOut"));
225 if (tact->get_active() != _session->config.get_punch_out()) {
226 _session->config.set_punch_out (tact->get_active ());
229 if (tact->get_active()) {
230 /* if punch-out is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
231 to avoid confusing the user */
232 show_loop_punch_ruler_and_disallow_hide ();
235 reenable_hide_loop_punch_ruler_if_appropriate ();
239 ARDOUR_UI::show_loop_punch_ruler_and_disallow_hide ()
241 Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Rulers"), "toggle-loop-punch-ruler");
243 tact->set_sensitive (false);
245 if (!tact->get_active()) {
250 /* This is a bit of a silly name for a method */
252 ARDOUR_UI::reenable_hide_loop_punch_ruler_if_appropriate ()
254 if (!_session->config.get_punch_in() && !_session->config.get_punch_out()) {
255 /* if punch in/out are now both off, reallow hiding of the loop/punch ruler */
256 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Rulers"), "toggle-loop-punch-ruler");
258 act->set_sensitive (true);
264 ARDOUR_UI::toggle_video_sync()
266 Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action ("Transport", "ToggleVideoSync");
267 _session->config.set_use_video_sync (tact->get_active());
271 ARDOUR_UI::toggle_editing_space()
273 Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action ("Common", "ToggleMaximalEditor");
274 if (tact->get_active()) {
275 maximise_editing_space ();
277 restore_editing_space ();
282 ARDOUR_UI::setup_session_options ()
284 _session->config.ParameterChanged.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::parameter_changed, this, _1), gui_context());
285 boost::function<void (std::string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
286 _session->config.map_parameters (pc);
290 ARDOUR_UI::parameter_changed (std::string p)
292 if (p == "external-sync") {
294 /* session parameter */
296 ActionManager::map_some_state ("Transport", "ToggleExternalSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_external_sync));
298 if (!_session->config.get_external_sync()) {
299 sync_button.set_text (S_("SyncSource|Int."));
300 ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (true);
301 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (true);
302 ActionManager::get_action ("Transport", "ToggleFollowEdits")->set_sensitive (true);
304 /* XXX we need to make sure that auto-play is off as well as insensitive */
305 ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (false);
306 ActionManager::get_action ("Transport", "ToggleFollowEdits")->set_sensitive (false);
307 if (!_session->synced_to_engine()) {
308 /* JACK transport allows auto-return */
309 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (false);
313 } else if (p == "sync-source") {
315 /* app parameter (RC config) */
318 if (!_session->config.get_external_sync()) {
319 sync_button.set_text (S_("SyncSource|Int."));
321 sync_button.set_text (TransportMasterManager::instance().current()->display_name());
324 /* changing sync source without a session is unlikely/impossible , except during startup */
325 sync_button.set_text (TransportMasterManager::instance().current()->display_name());
328 } else if (p == "follow-edits") {
330 ActionManager::map_some_state ("Transport", "ToggleFollowEdits", &UIConfiguration::get_follow_edits);
332 } else if (p == "send-mtc") {
334 ActionManager::map_some_state ("Options", "SendMTC", &RCConfiguration::get_send_mtc);
336 } else if (p == "send-mmc") {
338 ActionManager::map_some_state ("Options", "SendMMC", &RCConfiguration::get_send_mmc);
340 } else if (p == "mmc-control") {
341 ActionManager::map_some_state ("Options", "UseMMC", &RCConfiguration::get_mmc_control);
342 } else if (p == "auto-play") {
343 ActionManager::map_some_state ("Transport", "ToggleAutoPlay", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_play));
344 } else if (p == "auto-return") {
345 ActionManager::map_some_state ("Transport", "ToggleAutoReturn", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_return));
346 } else if (p == "auto-input") {
347 ActionManager::map_some_state ("Transport", "ToggleAutoInput", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_input));
348 } else if (p == "session-monitoring") {
349 Glib::RefPtr<ToggleAction> tiact = ActionManager::get_toggle_action (X_("Transport"), X_("SessionMonitorIn"));
350 Glib::RefPtr<ToggleAction> tdact = ActionManager::get_toggle_action (X_("Transport"), X_("SessionMonitorDisk"));
351 switch (_session->config.get_session_monitoring ()) {
353 tdact->set_active (true);
354 tiact->set_active (false);
357 tiact->set_active (true);
358 tdact->set_active (false);
361 tdact->set_active (false);
362 tiact->set_active (false);
365 } else if (p == "punch-out") {
366 ActionManager::map_some_state ("Transport", "TogglePunchOut", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_out));
367 if (!_session->config.get_punch_out()) {
370 } else if (p == "punch-in") {
371 ActionManager::map_some_state ("Transport", "TogglePunchIn", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_in));
372 if (!_session->config.get_punch_in()) {
375 } else if (p == "clicking") {
376 ActionManager::map_some_state ("Transport", "ToggleClick", &RCConfiguration::get_clicking);
377 } else if (p == "use-video-sync") {
378 ActionManager::map_some_state ("Transport", "ToggleVideoSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_use_video_sync));
379 } else if (p == "sync-source") {
381 synchronize_sync_source_and_video_pullup ();
382 set_fps_timeout_connection ();
384 } else if (p == "show-track-meters") {
385 if (editor) editor->toggle_meter_updating();
386 } else if (p == "primary-clock-delta-mode") {
387 if (UIConfiguration::instance().get_primary_clock_delta_mode() != NoDelta) {
388 primary_clock->set_is_duration (true);
389 primary_clock->set_editable (false);
390 primary_clock->set_widget_name ("transport delta");
392 primary_clock->set_is_duration (false);
393 primary_clock->set_editable (true);
394 primary_clock->set_widget_name ("transport");
396 } else if (p == "secondary-clock-delta-mode") {
397 if (UIConfiguration::instance().get_secondary_clock_delta_mode() != NoDelta) {
398 secondary_clock->set_is_duration (true);
399 secondary_clock->set_editable (false);
400 secondary_clock->set_widget_name ("secondary delta");
402 secondary_clock->set_is_duration (false);
403 secondary_clock->set_editable (true);
404 secondary_clock->set_widget_name ("secondary");
406 } else if (p == "super-rapid-clock-update") {
411 } else if (p == "use-tooltips") {
412 /* this doesn't really belong here but it has to go somewhere */
413 if (UIConfiguration::instance().get_use_tooltips()) {
414 Gtkmm2ext::enable_tooltips ();
416 Gtkmm2ext::disable_tooltips ();
418 } else if (p == "waveform-gradient-depth") {
419 ArdourWaveView::WaveView::set_global_gradient_depth (UIConfiguration::instance().get_waveform_gradient_depth());
420 } else if (p == "show-mini-timeline") {
421 repack_transport_hbox ();
422 } else if (p == "show-dsp-load-info") {
423 repack_transport_hbox ();
424 } else if (p == "show-disk-space-info") {
425 repack_transport_hbox ();
426 } else if (p == "show-toolbar-recpunch") {
427 repack_transport_hbox ();
428 } else if (p == "show-toolbar-monitoring") {
429 repack_transport_hbox ();
430 } else if (p == "show-toolbar-selclock") {
431 repack_transport_hbox ();
432 } else if (p == "show-editor-meter") {
433 repack_transport_hbox ();
434 } else if (p == "show-secondary-clock") {
435 update_clock_visibility ();
436 } else if (p == "waveform-scale") {
437 ArdourWaveView::WaveView::set_global_logscaled (UIConfiguration::instance().get_waveform_scale() == Logarithmic);
438 } else if (p == "widget-prelight") {
439 CairoWidget::set_widget_prelight (UIConfiguration::instance().get_widget_prelight());
440 } else if (p == "waveform-shape") {
441 ArdourWaveView::WaveView::set_global_shape (UIConfiguration::instance().get_waveform_shape() == Rectified
442 ? ArdourWaveView::WaveView::Rectified : ArdourWaveView::WaveView::Normal);
443 } else if (p == "show-waveform-clipping") {
444 ArdourWaveView::WaveView::set_global_show_waveform_clipping (UIConfiguration::instance().get_show_waveform_clipping());
445 } else if (p == "waveform-cache-size") {
446 /* GUI option has units of megabytes; image cache uses units of bytes */
447 ArdourWaveView::WaveView::set_image_cache_size (UIConfiguration::instance().get_waveform_cache_size() * 1048576);
448 } else if (p == "use-wm-visibility") {
449 VisibilityTracker::set_use_window_manager_visibility (UIConfiguration::instance().get_use_wm_visibility());
450 } else if (p == "action-table-columns") {
451 const uint32_t cols = UIConfiguration::instance().get_action_table_columns ();
452 for (int i = 0; i < MAX_LUA_ACTION_BUTTONS; ++i) {
453 const int col = i / 2;
454 if (cols & (1<<col)) {
455 action_script_call_btn[i].show();
457 action_script_call_btn[i].hide();
460 } else if (p == "layered-record-mode") {
461 layered_button.set_active (_session->config.get_layered_record_mode ());
462 } else if (p == "flat-buttons") {
463 bool flat = UIConfiguration::instance().get_flat_buttons();
464 if (ArdourButton::flat_buttons () != flat) {
465 ArdourButton::set_flat_buttons (flat);
467 gtk_rc_reset_styles (gtk_settings_get_default());
469 } else if (p == "boxy-buttons") {
470 bool boxy = UIConfiguration::instance().get_boxy_buttons();
471 if (ArdourButton::boxy_buttons () != boxy) {
472 ArdourButton::set_boxy_buttons (boxy);
474 gtk_rc_reset_styles (gtk_settings_get_default());
476 } else if ( (p == "snap-to-region-sync") || (p == "snap-to-region-start") || (p == "snap-to-region-end") ) {
477 if (editor) editor->mark_region_boundary_cache_dirty();
478 } else if (p == "screen-saver-mode") {
479 switch (UIConfiguration::instance().get_screen_saver_mode ()) {
480 using namespace ARDOUR_UI_UTILS;
481 case InhibitWhileRecording:
482 inhibit_screensaver (_session && _session->actively_recording ());
485 inhibit_screensaver (true);
488 inhibit_screensaver (false);
495 ARDOUR_UI::session_parameter_changed (std::string p)
497 if (p == "native-file-data-format" || p == "native-file-header-format") {
499 } else if (p == "timecode-format") {
500 set_fps_timeout_connection ();
501 } else if (p == "video-pullup" || p == "timecode-format") {
502 set_fps_timeout_connection ();
504 synchronize_sync_source_and_video_pullup ();
505 reset_main_clocks ();
506 editor->queue_visual_videotimeline_update();
507 } else if (p == "track-name-number") {
508 /* DisplaySuspender triggers _route->redisplay() when going out of scope
509 * which eventually calls reset_controls_layout_width() and re-sets the
510 * track-header width.
511 * see also RouteTimeAxisView::update_track_number_visibility()
518 ARDOUR_UI::reset_main_clocks ()
520 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::reset_main_clocks)
523 primary_clock->set (_session->audible_sample(), true);
524 secondary_clock->set (_session->audible_sample(), true);
526 primary_clock->set (0, true);
527 secondary_clock->set (0, true);
532 ARDOUR_UI::synchronize_sync_source_and_video_pullup ()
534 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("ToggleExternalSync"));
544 if (_session->config.get_video_pullup() == 0.0f) {
545 /* with no video pull up/down, any sync source is OK */
546 act->set_sensitive (true);
548 /* can't sync to JACK if video pullup != 0.0 */
549 if (TransportMasterManager::instance().current()->type() == Engine) {
550 act->set_sensitive (false);
552 act->set_sensitive (true);
556 /* XXX should really be able to set the video pull up
557 action to insensitive/sensitive, but there is no action.
562 if (act->get_sensitive ()) {
563 set_tip (sync_button, _("Enable/Disable external positional sync"));
565 set_tip (sync_button, _("Sync to JACK is not possible: video pull up/down is set"));