2 Copyright (C) 2005 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.
21 #include "gtk2ardour-config.h"
24 #include "pbd/convert.h"
25 #include "pbd/stacktrace.h"
26 #include "pbd/unwind.h"
28 #include "ardour/rc_configuration.h"
29 #include "ardour/session.h"
30 #include "ardour/transport_master_manager.h"
32 #include "gtkmm2ext/utils.h"
33 #include "waveview/wave_view.h"
35 #include "audio_clock.h"
36 #include "ardour_ui.h"
38 #include "gui_thread.h"
39 #include "public_editor.h"
40 #include "main_clock.h"
45 using namespace Gtkmm2ext;
46 using namespace ARDOUR;
48 using namespace ArdourWidgets;
51 ARDOUR_UI::toggle_external_sync()
54 if (_session->config.get_video_pullup() != 0.0f && (TransportMasterManager::instance().current()->type() == Engine)) {
55 MessageDialog msg (_("It is not possible to use JACK as the the sync source\n when the pull up/down setting is non-zero."));
60 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));
62 /* activating a slave is a session-property.
63 * The slave type is a RC property.
64 * When the slave is active is must not be reconfigured.
65 * This is a UI limitation, imposed by audio-clock and
66 * status displays which combine RC-config & session-properties.
68 * Notify RCOptionEditor by emitting a signal if the active
71 Config->ParameterChanged("sync-source");
76 ARDOUR_UI::toggle_time_master ()
78 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));
82 ARDOUR_UI::toggle_send_mtc ()
84 ActionManager::toggle_config_state ("Options", "SendMTC", &RCConfiguration::set_send_mtc, &RCConfiguration::get_send_mtc);
88 ARDOUR_UI::toggle_send_mmc ()
90 ActionManager::toggle_config_state ("Options", "SendMMC", &RCConfiguration::set_send_mmc, &RCConfiguration::get_send_mmc);
94 ARDOUR_UI::toggle_send_midi_clock ()
96 ActionManager::toggle_config_state ("Options", "SendMidiClock", &RCConfiguration::set_send_midi_clock, &RCConfiguration::get_send_midi_clock);
100 ARDOUR_UI::toggle_use_mmc ()
102 ActionManager::toggle_config_state ("Options", "UseMMC", &RCConfiguration::set_mmc_control, &RCConfiguration::get_mmc_control);
106 ARDOUR_UI::toggle_auto_input ()
108 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));
112 ARDOUR_UI::toggle_auto_play ()
114 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));
118 ARDOUR_UI::toggle_auto_return ()
120 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));
124 ARDOUR_UI::toggle_click ()
126 ActionManager::toggle_config_state ("Transport", "ToggleClick", &RCConfiguration::set_clicking, &RCConfiguration::get_clicking);
130 ARDOUR_UI::toggle_session_monitoring_in ()
132 Glib::RefPtr<Action> act = global_actions.find_action (X_("Transport"), X_("SessionMonitorIn"));
136 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
141 if (tact->get_active() && _session->config.get_session_monitoring () == MonitorInput) {
144 if (!tact->get_active() && _session->config.get_session_monitoring () != MonitorInput) {
148 if (tact->get_active()) {
149 _session->config.set_session_monitoring (MonitorInput);
151 _session->config.set_session_monitoring (MonitorAuto);
156 ARDOUR_UI::toggle_session_monitoring_disk ()
158 Glib::RefPtr<Action> act = global_actions.find_action (X_("Transport"), X_("SessionMonitorDisk"));
162 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
166 if (tact->get_active() && _session->config.get_session_monitoring () == MonitorDisk) {
169 if (!tact->get_active() && _session->config.get_session_monitoring () != MonitorDisk) {
173 if (tact->get_active()) {
174 _session->config.set_session_monitoring (MonitorDisk);
176 _session->config.set_session_monitoring (MonitorAuto);
181 ARDOUR_UI::unset_dual_punch ()
183 Glib::RefPtr<Action> action = global_actions.find_action ("Transport", "TogglePunch");
186 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
188 ignore_dual_punch = true;
189 tact->set_active (false);
190 ignore_dual_punch = false;
196 ARDOUR_UI::toggle_punch ()
198 if (ignore_dual_punch) {
202 Glib::RefPtr<Action> action = global_actions.find_action ("Transport", "TogglePunch");
206 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
212 /* drive the other two actions from this one */
214 Glib::RefPtr<Action> in_action = global_actions.find_action ("Transport", "TogglePunchIn");
215 Glib::RefPtr<Action> out_action = global_actions.find_action ("Transport", "TogglePunchOut");
217 if (in_action && out_action) {
218 Glib::RefPtr<ToggleAction> tiact = Glib::RefPtr<ToggleAction>::cast_dynamic(in_action);
219 Glib::RefPtr<ToggleAction> toact = Glib::RefPtr<ToggleAction>::cast_dynamic(out_action);
220 tiact->set_active (tact->get_active());
221 toact->set_active (tact->get_active());
227 ARDOUR_UI::toggle_punch_in ()
229 Glib::RefPtr<Action> act = global_actions.find_action (X_("Transport"), X_("TogglePunchIn"));
234 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
239 if (tact->get_active() != _session->config.get_punch_in()) {
240 _session->config.set_punch_in (tact->get_active ());
243 if (tact->get_active()) {
244 /* if punch-in is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
245 to avoid confusing the user */
246 show_loop_punch_ruler_and_disallow_hide ();
249 reenable_hide_loop_punch_ruler_if_appropriate ();
253 ARDOUR_UI::toggle_punch_out ()
255 Glib::RefPtr<Action> act = global_actions.find_action (X_("Transport"), X_("TogglePunchOut"));
260 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
265 if (tact->get_active() != _session->config.get_punch_out()) {
266 _session->config.set_punch_out (tact->get_active ());
269 if (tact->get_active()) {
270 /* if punch-out is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
271 to avoid confusing the user */
272 show_loop_punch_ruler_and_disallow_hide ();
275 reenable_hide_loop_punch_ruler_if_appropriate ();
279 ARDOUR_UI::show_loop_punch_ruler_and_disallow_hide ()
281 Glib::RefPtr<Action> act = editor->find_action (X_("Rulers"), "toggle-loop-punch-ruler");
286 act->set_sensitive (false);
288 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
293 if (!tact->get_active()) {
298 /* This is a bit of a silly name for a method */
300 ARDOUR_UI::reenable_hide_loop_punch_ruler_if_appropriate ()
302 if (!_session->config.get_punch_in() && !_session->config.get_punch_out()) {
303 /* if punch in/out are now both off, reallow hiding of the loop/punch ruler */
304 Glib::RefPtr<Action> act = editor->find_action (X_("Rulers"), "toggle-loop-punch-ruler");
306 act->set_sensitive (true);
312 ARDOUR_UI::toggle_video_sync()
314 Glib::RefPtr<Action> act = global_actions.find_action ("Transport", "ToggleVideoSync");
316 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
317 _session->config.set_use_video_sync (tact->get_active());
322 ARDOUR_UI::toggle_editing_space()
324 Glib::RefPtr<Action> act = global_actions.find_action ("Common", "ToggleMaximalEditor");
327 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
328 if (tact->get_active()) {
329 maximise_editing_space ();
331 restore_editing_space ();
337 ARDOUR_UI::setup_session_options ()
339 _session->config.ParameterChanged.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::parameter_changed, this, _1), gui_context());
340 boost::function<void (std::string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
341 _session->config.map_parameters (pc);
345 ARDOUR_UI::parameter_changed (std::string p)
347 if (p == "external-sync") {
349 /* session parameter */
351 ActionManager::map_some_state ("Transport", "ToggleExternalSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_external_sync));
353 if (!_session->config.get_external_sync()) {
354 sync_button.set_text (S_("SyncSource|Int."));
355 global_actions.find_action ("Transport", "ToggleAutoPlay")->set_sensitive (true);
356 global_actions.find_action ("Transport", "ToggleAutoReturn")->set_sensitive (true);
357 global_actions.find_action ("Transport", "ToggleFollowEdits")->set_sensitive (true);
359 /* XXX we need to make sure that auto-play is off as well as insensitive */
360 global_actions.find_action ("Transport", "ToggleAutoPlay")->set_sensitive (false);
361 global_actions.find_action ("Transport", "ToggleAutoReturn")->set_sensitive (false);
362 global_actions.find_action ("Transport", "ToggleFollowEdits")->set_sensitive (false);
365 } else if (p == "sync-source") {
367 /* app parameter (RC config) */
370 if (!_session->config.get_external_sync()) {
371 sync_button.set_text (S_("SyncSource|Int."));
373 sync_button.set_text (TransportMasterManager::instance().current()->display_name());
376 /* changing sync source without a session is unlikely/impossible , except during startup */
377 sync_button.set_text (TransportMasterManager::instance().current()->display_name());
380 } else if (p == "follow-edits") {
382 ActionManager::map_some_state ("Transport", "ToggleFollowEdits", &UIConfiguration::get_follow_edits);
384 } else if (p == "send-mtc") {
386 ActionManager::map_some_state ("Options", "SendMTC", &RCConfiguration::get_send_mtc);
388 } else if (p == "send-mmc") {
390 ActionManager::map_some_state ("Options", "SendMMC", &RCConfiguration::get_send_mmc);
392 } else if (p == "mmc-control") {
393 ActionManager::map_some_state ("Options", "UseMMC", &RCConfiguration::get_mmc_control);
394 } else if (p == "auto-play") {
395 ActionManager::map_some_state ("Transport", "ToggleAutoPlay", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_play));
396 } else if (p == "auto-return") {
397 ActionManager::map_some_state ("Transport", "ToggleAutoReturn", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_return));
398 } else if (p == "auto-input") {
399 ActionManager::map_some_state ("Transport", "ToggleAutoInput", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_input));
400 } else if (p == "session-monitoring") {
401 Glib::RefPtr<Action> iact = global_actions.find_action (X_("Transport"), X_("SessionMonitorIn"));
402 Glib::RefPtr<Action> dact = global_actions.find_action (X_("Transport"), X_("SessionMonitorDisk"));
404 Glib::RefPtr<ToggleAction> tdact = Glib::RefPtr<ToggleAction>::cast_dynamic(dact);
405 Glib::RefPtr<ToggleAction> tiact = Glib::RefPtr<ToggleAction>::cast_dynamic(iact);
406 if (tdact && tiact) {
407 switch (_session->config.get_session_monitoring ()) {
409 tdact->set_active (true);
410 tiact->set_active (false);
413 tiact->set_active (true);
414 tdact->set_active (false);
417 tdact->set_active (false);
418 tiact->set_active (false);
423 } else if (p == "punch-out") {
424 ActionManager::map_some_state ("Transport", "TogglePunchOut", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_out));
425 if (!_session->config.get_punch_out()) {
428 } else if (p == "punch-in") {
429 ActionManager::map_some_state ("Transport", "TogglePunchIn", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_in));
430 if (!_session->config.get_punch_in()) {
433 } else if (p == "clicking") {
434 ActionManager::map_some_state ("Transport", "ToggleClick", &RCConfiguration::get_clicking);
435 } else if (p == "use-video-sync") {
436 ActionManager::map_some_state ("Transport", "ToggleVideoSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_use_video_sync));
437 } else if (p == "sync-source") {
439 synchronize_sync_source_and_video_pullup ();
440 set_fps_timeout_connection ();
442 } else if (p == "show-track-meters") {
443 if (editor) editor->toggle_meter_updating();
444 } else if (p == "primary-clock-delta-mode") {
445 if (UIConfiguration::instance().get_primary_clock_delta_mode() != NoDelta) {
446 primary_clock->set_is_duration (true);
447 primary_clock->set_editable (false);
448 primary_clock->set_widget_name ("transport delta");
450 primary_clock->set_is_duration (false);
451 primary_clock->set_editable (true);
452 primary_clock->set_widget_name ("transport");
454 } else if (p == "secondary-clock-delta-mode") {
455 if (UIConfiguration::instance().get_secondary_clock_delta_mode() != NoDelta) {
456 secondary_clock->set_is_duration (true);
457 secondary_clock->set_editable (false);
458 secondary_clock->set_widget_name ("secondary delta");
460 secondary_clock->set_is_duration (false);
461 secondary_clock->set_editable (true);
462 secondary_clock->set_widget_name ("secondary");
464 } else if (p == "super-rapid-clock-update") {
469 } else if (p == "use-tooltips") {
470 /* this doesn't really belong here but it has to go somewhere */
471 if (UIConfiguration::instance().get_use_tooltips()) {
472 Gtkmm2ext::enable_tooltips ();
474 Gtkmm2ext::disable_tooltips ();
476 } else if (p == "waveform-gradient-depth") {
477 ArdourWaveView::WaveView::set_global_gradient_depth (UIConfiguration::instance().get_waveform_gradient_depth());
478 } else if (p == "show-mini-timeline") {
479 repack_transport_hbox ();
480 } else if (p == "show-dsp-load-info") {
481 repack_transport_hbox ();
482 } else if (p == "show-disk-space-info") {
483 repack_transport_hbox ();
484 } else if (p == "show-toolbar-recpunch") {
485 repack_transport_hbox ();
486 } else if (p == "show-toolbar-monitoring") {
487 repack_transport_hbox ();
488 } else if (p == "show-toolbar-selclock") {
489 repack_transport_hbox ();
490 } else if (p == "show-editor-meter") {
491 repack_transport_hbox ();
492 } else if (p == "show-secondary-clock") {
493 update_clock_visibility ();
494 } else if (p == "waveform-scale") {
495 ArdourWaveView::WaveView::set_global_logscaled (UIConfiguration::instance().get_waveform_scale() == Logarithmic);
496 } else if (p == "widget-prelight") {
497 CairoWidget::set_widget_prelight (UIConfiguration::instance().get_widget_prelight());
498 } else if (p == "waveform-shape") {
499 ArdourWaveView::WaveView::set_global_shape (UIConfiguration::instance().get_waveform_shape() == Rectified
500 ? ArdourWaveView::WaveView::Rectified : ArdourWaveView::WaveView::Normal);
501 } else if (p == "show-waveform-clipping") {
502 ArdourWaveView::WaveView::set_global_show_waveform_clipping (UIConfiguration::instance().get_show_waveform_clipping());
503 } else if (p == "waveform-cache-size") {
504 /* GUI option has units of megabytes; image cache uses units of bytes */
505 ArdourWaveView::WaveView::set_image_cache_size (UIConfiguration::instance().get_waveform_cache_size() * 1048576);
506 } else if (p == "use-wm-visibility") {
507 VisibilityTracker::set_use_window_manager_visibility (UIConfiguration::instance().get_use_wm_visibility());
508 } else if (p == "action-table-columns") {
509 const uint32_t cols = UIConfiguration::instance().get_action_table_columns ();
510 for (int i = 0; i < MAX_LUA_ACTION_SCRIPTS; ++i) {
511 const int col = i / 2;
512 if (cols & (1<<col)) {
513 action_script_call_btn[i].show();
515 action_script_call_btn[i].hide();
518 } else if (p == "layered-record-mode") {
519 layered_button.set_active (_session->config.get_layered_record_mode ());
520 } else if (p == "flat-buttons") {
521 bool flat = UIConfiguration::instance().get_flat_buttons();
522 if (ArdourButton::flat_buttons () != flat) {
523 ArdourButton::set_flat_buttons (flat);
525 gtk_rc_reset_styles (gtk_settings_get_default());
527 } else if (p == "boxy-buttons") {
528 bool boxy = UIConfiguration::instance().get_boxy_buttons();
529 if (ArdourButton::boxy_buttons () != boxy) {
530 ArdourButton::set_boxy_buttons (boxy);
532 gtk_rc_reset_styles (gtk_settings_get_default());
534 } else if ( (p == "snap-to-region-sync") || (p == "snap-to-region-start") || (p == "snap-to-region-end") ) {
535 if (editor) editor->mark_region_boundary_cache_dirty();
541 ARDOUR_UI::session_parameter_changed (std::string p)
543 if (p == "native-file-data-format" || p == "native-file-header-format") {
545 } else if (p == "timecode-format") {
546 set_fps_timeout_connection ();
547 } else if (p == "video-pullup" || p == "timecode-format") {
548 set_fps_timeout_connection ();
550 synchronize_sync_source_and_video_pullup ();
551 reset_main_clocks ();
552 editor->queue_visual_videotimeline_update();
553 } else if (p == "track-name-number") {
554 /* DisplaySuspender triggers _route->redisplay() when going out of scope
555 * which eventually calls reset_controls_layout_width() and re-sets the
556 * track-header width.
557 * see also RouteTimeAxisView::update_track_number_visibility()
564 ARDOUR_UI::reset_main_clocks ()
566 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::reset_main_clocks)
569 primary_clock->set (_session->audible_sample(), true);
570 secondary_clock->set (_session->audible_sample(), true);
572 primary_clock->set (0, true);
573 secondary_clock->set (0, true);
578 ARDOUR_UI::synchronize_sync_source_and_video_pullup ()
580 Glib::RefPtr<Action> act = global_actions.find_action (X_("Transport"), X_("ToggleExternalSync"));
590 if (_session->config.get_video_pullup() == 0.0f) {
591 /* with no video pull up/down, any sync source is OK */
592 act->set_sensitive (true);
594 /* can't sync to JACK if video pullup != 0.0 */
595 if (TransportMasterManager::instance().current()->type() == Engine) {
596 act->set_sensitive (false);
598 act->set_sensitive (true);
602 /* XXX should really be able to set the video pull up
603 action to insensitive/sensitive, but there is no action.
608 if (act->get_sensitive ()) {
609 set_tip (sync_button, _("Enable/Disable external positional sync"));
611 set_tip (sync_button, _("Sync to JACK is not possible: video pull up/down is set"));