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::toggle_latency_switch ()
284 Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action ("Main", "ToggleLatencyCompensation");
285 ARDOUR::Latent::force_zero_latency (tact->get_active());
289 ARDOUR_UI::setup_session_options ()
291 _session->config.ParameterChanged.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::parameter_changed, this, _1), gui_context());
292 boost::function<void (std::string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
293 _session->config.map_parameters (pc);
297 ARDOUR_UI::parameter_changed (std::string p)
299 if (p == "external-sync") {
301 /* session parameter */
303 ActionManager::map_some_state ("Transport", "ToggleExternalSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_external_sync));
305 if (!_session->config.get_external_sync()) {
306 sync_button.set_text (S_("SyncSource|Int."));
307 ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (true);
308 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (true);
309 ActionManager::get_action ("Transport", "ToggleFollowEdits")->set_sensitive (true);
311 /* XXX we need to make sure that auto-play is off as well as insensitive */
312 ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (false);
313 ActionManager::get_action ("Transport", "ToggleFollowEdits")->set_sensitive (false);
314 if (!_session->synced_to_engine()) {
315 /* JACK transport allows auto-return */
316 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (false);
320 } else if (p == "sync-source") {
322 /* app parameter (RC config) */
325 if (!_session->config.get_external_sync()) {
326 sync_button.set_text (S_("SyncSource|Int."));
328 sync_button.set_text (TransportMasterManager::instance().current()->display_name());
331 /* changing sync source without a session is unlikely/impossible , except during startup */
332 sync_button.set_text (TransportMasterManager::instance().current()->display_name());
335 } else if (p == "follow-edits") {
337 ActionManager::map_some_state ("Transport", "ToggleFollowEdits", &UIConfiguration::get_follow_edits);
339 } else if (p == "send-mtc") {
341 ActionManager::map_some_state ("Options", "SendMTC", &RCConfiguration::get_send_mtc);
343 } else if (p == "send-mmc") {
345 ActionManager::map_some_state ("Options", "SendMMC", &RCConfiguration::get_send_mmc);
347 } else if (p == "mmc-control") {
348 ActionManager::map_some_state ("Options", "UseMMC", &RCConfiguration::get_mmc_control);
349 } else if (p == "auto-play") {
350 ActionManager::map_some_state ("Transport", "ToggleAutoPlay", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_play));
351 } else if (p == "auto-return") {
352 ActionManager::map_some_state ("Transport", "ToggleAutoReturn", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_return));
353 } else if (p == "auto-input") {
354 ActionManager::map_some_state ("Transport", "ToggleAutoInput", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_input));
355 } else if (p == "session-monitoring") {
356 Glib::RefPtr<ToggleAction> tiact = ActionManager::get_toggle_action (X_("Transport"), X_("SessionMonitorIn"));
357 Glib::RefPtr<ToggleAction> tdact = ActionManager::get_toggle_action (X_("Transport"), X_("SessionMonitorDisk"));
358 switch (_session->config.get_session_monitoring ()) {
360 tdact->set_active (true);
361 tiact->set_active (false);
364 tiact->set_active (true);
365 tdact->set_active (false);
368 tdact->set_active (false);
369 tiact->set_active (false);
372 } else if (p == "punch-out") {
373 ActionManager::map_some_state ("Transport", "TogglePunchOut", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_out));
374 if (!_session->config.get_punch_out()) {
377 } else if (p == "punch-in") {
378 ActionManager::map_some_state ("Transport", "TogglePunchIn", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_in));
379 if (!_session->config.get_punch_in()) {
382 } else if (p == "clicking") {
383 ActionManager::map_some_state ("Transport", "ToggleClick", &RCConfiguration::get_clicking);
384 } else if (p == "use-video-sync") {
385 ActionManager::map_some_state ("Transport", "ToggleVideoSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_use_video_sync));
386 } else if (p == "sync-source") {
388 synchronize_sync_source_and_video_pullup ();
389 set_fps_timeout_connection ();
391 } else if (p == "show-track-meters") {
392 if (editor) editor->toggle_meter_updating();
393 } else if (p == "primary-clock-delta-mode") {
394 if (UIConfiguration::instance().get_primary_clock_delta_mode() != NoDelta) {
395 primary_clock->set_is_duration (true);
396 primary_clock->set_editable (false);
397 primary_clock->set_widget_name ("transport delta");
399 primary_clock->set_is_duration (false);
400 primary_clock->set_editable (true);
401 primary_clock->set_widget_name ("transport");
403 } else if (p == "secondary-clock-delta-mode") {
404 if (UIConfiguration::instance().get_secondary_clock_delta_mode() != NoDelta) {
405 secondary_clock->set_is_duration (true);
406 secondary_clock->set_editable (false);
407 secondary_clock->set_widget_name ("secondary delta");
409 secondary_clock->set_is_duration (false);
410 secondary_clock->set_editable (true);
411 secondary_clock->set_widget_name ("secondary");
413 } else if (p == "super-rapid-clock-update") {
418 } else if (p == "use-tooltips") {
419 /* this doesn't really belong here but it has to go somewhere */
420 if (UIConfiguration::instance().get_use_tooltips()) {
421 Gtkmm2ext::enable_tooltips ();
423 Gtkmm2ext::disable_tooltips ();
425 } else if (p == "waveform-gradient-depth") {
426 ArdourWaveView::WaveView::set_global_gradient_depth (UIConfiguration::instance().get_waveform_gradient_depth());
427 } else if (p == "show-mini-timeline") {
428 repack_transport_hbox ();
429 } else if (p == "show-dsp-load-info") {
430 repack_transport_hbox ();
431 } else if (p == "show-disk-space-info") {
432 repack_transport_hbox ();
433 } else if (p == "show-toolbar-recpunch") {
434 repack_transport_hbox ();
435 } else if (p == "show-toolbar-monitoring") {
436 repack_transport_hbox ();
437 } else if (p == "show-toolbar-selclock") {
438 repack_transport_hbox ();
439 } else if (p == "show-toolbar-latency") {
440 repack_transport_hbox ();
441 } else if (p == "show-editor-meter") {
442 repack_transport_hbox ();
443 } else if (p == "show-secondary-clock") {
444 update_clock_visibility ();
445 } else if (p == "waveform-scale") {
446 ArdourWaveView::WaveView::set_global_logscaled (UIConfiguration::instance().get_waveform_scale() == Logarithmic);
447 } else if (p == "widget-prelight") {
448 CairoWidget::set_widget_prelight (UIConfiguration::instance().get_widget_prelight());
449 } else if (p == "waveform-shape") {
450 ArdourWaveView::WaveView::set_global_shape (UIConfiguration::instance().get_waveform_shape() == Rectified
451 ? ArdourWaveView::WaveView::Rectified : ArdourWaveView::WaveView::Normal);
452 } else if (p == "show-waveform-clipping") {
453 ArdourWaveView::WaveView::set_global_show_waveform_clipping (UIConfiguration::instance().get_show_waveform_clipping());
454 } else if (p == "waveform-cache-size") {
455 /* GUI option has units of megabytes; image cache uses units of bytes */
456 ArdourWaveView::WaveView::set_image_cache_size (UIConfiguration::instance().get_waveform_cache_size() * 1048576);
457 } else if (p == "use-wm-visibility") {
458 VisibilityTracker::set_use_window_manager_visibility (UIConfiguration::instance().get_use_wm_visibility());
459 } else if (p == "action-table-columns") {
460 const uint32_t cols = UIConfiguration::instance().get_action_table_columns ();
461 for (int i = 0; i < MAX_LUA_ACTION_BUTTONS; ++i) {
462 const int col = i / 2;
463 if (cols & (1<<col)) {
464 action_script_call_btn[i].show();
466 action_script_call_btn[i].hide();
469 } else if (p == "layered-record-mode") {
470 layered_button.set_active (_session->config.get_layered_record_mode ());
471 } else if (p == "flat-buttons") {
472 bool flat = UIConfiguration::instance().get_flat_buttons();
473 if (ArdourButton::flat_buttons () != flat) {
474 ArdourButton::set_flat_buttons (flat);
476 gtk_rc_reset_styles (gtk_settings_get_default());
478 } else if (p == "boxy-buttons") {
479 bool boxy = UIConfiguration::instance().get_boxy_buttons();
480 if (ArdourButton::boxy_buttons () != boxy) {
481 ArdourButton::set_boxy_buttons (boxy);
483 gtk_rc_reset_styles (gtk_settings_get_default());
485 } else if ( (p == "snap-to-region-sync") || (p == "snap-to-region-start") || (p == "snap-to-region-end") ) {
486 if (editor) editor->mark_region_boundary_cache_dirty();
487 } else if (p == "screen-saver-mode") {
488 switch (UIConfiguration::instance().get_screen_saver_mode ()) {
489 using namespace ARDOUR_UI_UTILS;
490 case InhibitWhileRecording:
491 inhibit_screensaver (_session && _session->actively_recording ());
494 inhibit_screensaver (true);
497 inhibit_screensaver (false);
504 ARDOUR_UI::session_parameter_changed (std::string p)
506 if (p == "native-file-data-format" || p == "native-file-header-format") {
508 } else if (p == "timecode-format") {
509 set_fps_timeout_connection ();
510 } else if (p == "video-pullup" || p == "timecode-format") {
511 set_fps_timeout_connection ();
513 synchronize_sync_source_and_video_pullup ();
514 reset_main_clocks ();
515 editor->queue_visual_videotimeline_update();
516 } else if (p == "track-name-number") {
517 /* DisplaySuspender triggers _route->redisplay() when going out of scope
518 * which eventually calls reset_controls_layout_width() and re-sets the
519 * track-header width.
520 * see also RouteTimeAxisView::update_track_number_visibility()
527 ARDOUR_UI::reset_main_clocks ()
529 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::reset_main_clocks)
532 primary_clock->set (_session->audible_sample(), true);
533 secondary_clock->set (_session->audible_sample(), true);
535 primary_clock->set (0, true);
536 secondary_clock->set (0, true);
541 ARDOUR_UI::synchronize_sync_source_and_video_pullup ()
543 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("ToggleExternalSync"));
553 if (_session->config.get_video_pullup() == 0.0f) {
554 /* with no video pull up/down, any sync source is OK */
555 act->set_sensitive (true);
557 /* can't sync to JACK if video pullup != 0.0 */
558 if (TransportMasterManager::instance().current()->type() == Engine) {
559 act->set_sensitive (false);
561 act->set_sensitive (true);
565 /* XXX should really be able to set the video pull up
566 action to insensitive/sensitive, but there is no action.
571 if (act->get_sensitive ()) {
572 set_tip (sync_button, _("Enable/Disable external positional sync"));
574 set_tip (sync_button, _("Sync to JACK is not possible: video pull up/down is set"));