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"
31 #include "gtkmm2ext/utils.h"
32 #include "waveview/wave_view.h"
34 #include "audio_clock.h"
35 #include "ardour_ui.h"
37 #include "gui_thread.h"
38 #include "public_editor.h"
39 #include "main_clock.h"
44 using namespace Gtkmm2ext;
45 using namespace ARDOUR;
47 using namespace ArdourWidgets;
50 ARDOUR_UI::toggle_external_sync()
53 if (_session->config.get_video_pullup() != 0.0f) {
54 if (Config->get_sync_source() == Engine) {
56 _("It is not possible to use JACK as the the sync source\n\
57 when the pull up/down setting is non-zero."));
63 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));
65 /* activating a slave is a session-property.
66 * The slave type is a RC property.
67 * When the slave is active is must not be reconfigured.
68 * This is a UI limitation, imposed by audio-clock and
69 * status displays which combine RC-config & session-properties.
71 * Notficy RCOptionEditor by emitting a signal if the active
74 Config->ParameterChanged("sync-source");
79 ARDOUR_UI::toggle_time_master ()
81 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));
85 ARDOUR_UI::toggle_send_mtc ()
87 ActionManager::toggle_config_state ("Options", "SendMTC", &RCConfiguration::set_send_mtc, &RCConfiguration::get_send_mtc);
91 ARDOUR_UI::toggle_send_mmc ()
93 ActionManager::toggle_config_state ("Options", "SendMMC", &RCConfiguration::set_send_mmc, &RCConfiguration::get_send_mmc);
97 ARDOUR_UI::toggle_send_midi_clock ()
99 ActionManager::toggle_config_state ("Options", "SendMidiClock", &RCConfiguration::set_send_midi_clock, &RCConfiguration::get_send_midi_clock);
103 ARDOUR_UI::toggle_use_mmc ()
105 ActionManager::toggle_config_state ("Options", "UseMMC", &RCConfiguration::set_mmc_control, &RCConfiguration::get_mmc_control);
109 ARDOUR_UI::toggle_auto_input ()
111 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));
115 ARDOUR_UI::toggle_auto_play ()
117 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));
121 ARDOUR_UI::toggle_auto_return ()
123 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));
127 ARDOUR_UI::toggle_click ()
129 ActionManager::toggle_config_state ("Transport", "ToggleClick", &RCConfiguration::set_clicking, &RCConfiguration::get_clicking);
133 ARDOUR_UI::toggle_session_monitoring_in ()
135 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("SessionMonitorIn"));
139 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
144 if (tact->get_active() && _session->config.get_session_monitoring () == MonitorInput) {
147 if (!tact->get_active() && _session->config.get_session_monitoring () != MonitorInput) {
151 if (tact->get_active()) {
152 _session->config.set_session_monitoring (MonitorInput);
154 _session->config.set_session_monitoring (MonitorAuto);
159 ARDOUR_UI::toggle_session_monitoring_disk ()
161 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("SessionMonitorDisk"));
165 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
169 if (tact->get_active() && _session->config.get_session_monitoring () == MonitorDisk) {
172 if (!tact->get_active() && _session->config.get_session_monitoring () != MonitorDisk) {
176 if (tact->get_active()) {
177 _session->config.set_session_monitoring (MonitorDisk);
179 _session->config.set_session_monitoring (MonitorAuto);
184 ARDOUR_UI::unset_dual_punch ()
186 Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
189 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
191 ignore_dual_punch = true;
192 tact->set_active (false);
193 ignore_dual_punch = false;
199 ARDOUR_UI::toggle_punch ()
201 if (ignore_dual_punch) {
205 Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
209 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
215 /* drive the other two actions from this one */
217 Glib::RefPtr<Action> in_action = ActionManager::get_action ("Transport", "TogglePunchIn");
218 Glib::RefPtr<Action> out_action = ActionManager::get_action ("Transport", "TogglePunchOut");
220 if (in_action && out_action) {
221 Glib::RefPtr<ToggleAction> tiact = Glib::RefPtr<ToggleAction>::cast_dynamic(in_action);
222 Glib::RefPtr<ToggleAction> toact = Glib::RefPtr<ToggleAction>::cast_dynamic(out_action);
223 tiact->set_active (tact->get_active());
224 toact->set_active (tact->get_active());
230 ARDOUR_UI::toggle_punch_in ()
232 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("TogglePunchIn"));
237 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
242 if (tact->get_active() != _session->config.get_punch_in()) {
243 _session->config.set_punch_in (tact->get_active ());
246 if (tact->get_active()) {
247 /* if punch-in is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
248 to avoid confusing the user */
249 show_loop_punch_ruler_and_disallow_hide ();
252 reenable_hide_loop_punch_ruler_if_appropriate ();
256 ARDOUR_UI::toggle_punch_out ()
258 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("TogglePunchOut"));
263 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
268 if (tact->get_active() != _session->config.get_punch_out()) {
269 _session->config.set_punch_out (tact->get_active ());
272 if (tact->get_active()) {
273 /* if punch-out is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
274 to avoid confusing the user */
275 show_loop_punch_ruler_and_disallow_hide ();
278 reenable_hide_loop_punch_ruler_if_appropriate ();
282 ARDOUR_UI::show_loop_punch_ruler_and_disallow_hide ()
284 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Rulers"), "toggle-loop-punch-ruler");
289 act->set_sensitive (false);
291 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
296 if (!tact->get_active()) {
301 /* This is a bit of a silly name for a method */
303 ARDOUR_UI::reenable_hide_loop_punch_ruler_if_appropriate ()
305 if (!_session->config.get_punch_in() && !_session->config.get_punch_out()) {
306 /* if punch in/out are now both off, reallow hiding of the loop/punch ruler */
307 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Rulers"), "toggle-loop-punch-ruler");
309 act->set_sensitive (true);
315 ARDOUR_UI::toggle_video_sync()
317 Glib::RefPtr<Action> act = ActionManager::get_action ("Transport", "ToggleVideoSync");
319 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
320 _session->config.set_use_video_sync (tact->get_active());
325 ARDOUR_UI::toggle_editing_space()
327 Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMaximalEditor");
330 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
331 if (tact->get_active()) {
332 maximise_editing_space ();
334 restore_editing_space ();
340 ARDOUR_UI::setup_session_options ()
342 _session->config.ParameterChanged.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::parameter_changed, this, _1), gui_context());
343 boost::function<void (std::string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
344 _session->config.map_parameters (pc);
348 ARDOUR_UI::parameter_changed (std::string p)
350 if (p == "external-sync") {
352 ActionManager::map_some_state ("Transport", "ToggleExternalSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_external_sync));
354 if (!_session->config.get_external_sync()) {
355 sync_button.set_text (S_("SyncSource|Int."));
356 ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (true);
357 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (true);
358 ActionManager::get_action ("Transport", "ToggleFollowEdits")->set_sensitive (true);
360 sync_button.set_text (sync_source_to_string (Config->get_sync_source(), true));
361 if (_session && _session->locations()->auto_loop_location()) {
362 // disable looping with external sync.
363 // This is not necessary because session-transport ignores the loop-state,
364 // but makes it clear to the user that it's disabled.
365 _session->request_play_loop (false, false);
367 /* XXX we need to make sure that auto-play is off as well as insensitive */
368 ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (false);
369 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (false);
370 ActionManager::get_action ("Transport", "ToggleFollowEdits")->set_sensitive (false);
373 } else if (p == "follow-edits") {
375 ActionManager::map_some_state ("Transport", "ToggleFollowEdits", &UIConfiguration::get_follow_edits);
377 } else if (p == "send-mtc") {
379 ActionManager::map_some_state ("Options", "SendMTC", &RCConfiguration::get_send_mtc);
381 } else if (p == "send-mmc") {
383 ActionManager::map_some_state ("Options", "SendMMC", &RCConfiguration::get_send_mmc);
385 } else if (p == "mmc-control") {
386 ActionManager::map_some_state ("Options", "UseMMC", &RCConfiguration::get_mmc_control);
387 } else if (p == "auto-play") {
388 ActionManager::map_some_state ("Transport", "ToggleAutoPlay", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_play));
389 } else if (p == "auto-return") {
390 ActionManager::map_some_state ("Transport", "ToggleAutoReturn", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_return));
391 } else if (p == "auto-input") {
392 ActionManager::map_some_state ("Transport", "ToggleAutoInput", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_input));
393 } else if (p == "session-monitoring") {
394 Glib::RefPtr<Action> iact = ActionManager::get_action (X_("Transport"), X_("SessionMonitorIn"));
395 Glib::RefPtr<Action> dact = ActionManager::get_action (X_("Transport"), X_("SessionMonitorDisk"));
397 Glib::RefPtr<ToggleAction> tdact = Glib::RefPtr<ToggleAction>::cast_dynamic(dact);
398 Glib::RefPtr<ToggleAction> tiact = Glib::RefPtr<ToggleAction>::cast_dynamic(iact);
399 if (tdact && tiact) {
400 switch (_session->config.get_session_monitoring ()) {
402 tdact->set_active (true);
403 tiact->set_active (false);
406 tiact->set_active (true);
407 tdact->set_active (false);
410 tdact->set_active (false);
411 tiact->set_active (false);
416 } else if (p == "punch-out") {
417 ActionManager::map_some_state ("Transport", "TogglePunchOut", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_out));
418 if (!_session->config.get_punch_out()) {
421 } else if (p == "punch-in") {
422 ActionManager::map_some_state ("Transport", "TogglePunchIn", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_in));
423 if (!_session->config.get_punch_in()) {
426 } else if (p == "clicking") {
427 ActionManager::map_some_state ("Transport", "ToggleClick", &RCConfiguration::get_clicking);
428 } else if (p == "use-video-sync") {
429 ActionManager::map_some_state ("Transport", "ToggleVideoSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_use_video_sync));
430 } else if (p == "sync-source") {
432 synchronize_sync_source_and_video_pullup ();
433 set_fps_timeout_connection ();
435 } else if (p == "show-track-meters") {
436 if (editor) editor->toggle_meter_updating();
437 } else if (p == "primary-clock-delta-mode") {
438 if (UIConfiguration::instance().get_primary_clock_delta_mode() != NoDelta) {
439 primary_clock->set_is_duration (true);
440 primary_clock->set_editable (false);
441 primary_clock->set_widget_name ("transport delta");
443 primary_clock->set_is_duration (false);
444 primary_clock->set_editable (true);
445 primary_clock->set_widget_name ("transport");
447 } else if (p == "secondary-clock-delta-mode") {
448 if (UIConfiguration::instance().get_secondary_clock_delta_mode() != NoDelta) {
449 secondary_clock->set_is_duration (true);
450 secondary_clock->set_editable (false);
451 secondary_clock->set_widget_name ("secondary delta");
453 secondary_clock->set_is_duration (false);
454 secondary_clock->set_editable (true);
455 secondary_clock->set_widget_name ("secondary");
457 } else if (p == "super-rapid-clock-update") {
462 } else if (p == "use-tooltips") {
463 /* this doesn't really belong here but it has to go somewhere */
464 if (UIConfiguration::instance().get_use_tooltips()) {
465 Gtkmm2ext::enable_tooltips ();
467 Gtkmm2ext::disable_tooltips ();
469 } else if (p == "waveform-gradient-depth") {
470 ArdourWaveView::WaveView::set_global_gradient_depth (UIConfiguration::instance().get_waveform_gradient_depth());
471 } else if (p == "show-mini-timeline") {
472 repack_transport_hbox ();
473 } else if (p == "show-dsp-load-info") {
474 repack_transport_hbox ();
475 } else if (p == "show-disk-space-info") {
476 repack_transport_hbox ();
477 } else if (p == "show-toolbar-recpunch") {
478 repack_transport_hbox ();
479 } else if (p == "show-toolbar-monitoring") {
480 repack_transport_hbox ();
481 } else if (p == "show-toolbar-selclock") {
482 repack_transport_hbox ();
483 } else if (p == "show-editor-meter") {
484 repack_transport_hbox ();
485 } else if (p == "show-secondary-clock") {
486 update_clock_visibility ();
487 } else if (p == "waveform-scale") {
488 ArdourWaveView::WaveView::set_global_logscaled (UIConfiguration::instance().get_waveform_scale() == Logarithmic);
489 } else if (p == "widget-prelight") {
490 CairoWidget::set_widget_prelight (UIConfiguration::instance().get_widget_prelight());
491 } else if (p == "waveform-shape") {
492 ArdourWaveView::WaveView::set_global_shape (UIConfiguration::instance().get_waveform_shape() == Rectified
493 ? ArdourWaveView::WaveView::Rectified : ArdourWaveView::WaveView::Normal);
494 } else if (p == "show-waveform-clipping") {
495 ArdourWaveView::WaveView::set_global_show_waveform_clipping (UIConfiguration::instance().get_show_waveform_clipping());
496 } else if (p == "waveform-cache-size") {
497 /* GUI option has units of megabytes; image cache uses units of bytes */
498 ArdourWaveView::WaveView::set_image_cache_size (UIConfiguration::instance().get_waveform_cache_size() * 1048576);
499 } else if (p == "use-wm-visibility") {
500 VisibilityTracker::set_use_window_manager_visibility (UIConfiguration::instance().get_use_wm_visibility());
501 } else if (p == "action-table-columns") {
502 const uint32_t cols = UIConfiguration::instance().get_action_table_columns ();
503 for (int i = 0; i < 9; ++i) {
504 const int col = i / 2;
505 if (cols & (1<<col)) {
506 action_script_call_btn[i].show();
508 action_script_call_btn[i].hide();
511 } else if (p == "layered-record-mode") {
512 layered_button.set_active (_session->config.get_layered_record_mode ());
513 } else if (p == "flat-buttons") {
514 bool flat = UIConfiguration::instance().get_flat_buttons();
515 if (ArdourButton::flat_buttons () != flat) {
516 ArdourButton::set_flat_buttons (flat);
518 gtk_rc_reset_styles (gtk_settings_get_default());
520 } else if ( (p == "snap-to-region-sync") || (p == "snap-to-region-start") || (p == "snap-to-region-end") ) {
521 if (editor) editor->mark_region_boundary_cache_dirty();
527 ARDOUR_UI::session_parameter_changed (std::string p)
529 if (p == "native-file-data-format" || p == "native-file-header-format") {
531 } else if (p == "timecode-format") {
532 set_fps_timeout_connection ();
533 } else if (p == "video-pullup" || p == "timecode-format") {
534 set_fps_timeout_connection ();
536 synchronize_sync_source_and_video_pullup ();
537 reset_main_clocks ();
538 editor->queue_visual_videotimeline_update();
539 } else if (p == "track-name-number") {
540 /* DisplaySuspender triggers _route->redisplay() when going out of scope
541 * which eventually calls reset_controls_layout_width() and re-sets the
542 * track-header width.
543 * see also RouteTimeAxisView::update_track_number_visibility()
550 ARDOUR_UI::reset_main_clocks ()
552 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::reset_main_clocks)
555 primary_clock->set (_session->audible_sample(), true);
556 secondary_clock->set (_session->audible_sample(), true);
558 primary_clock->set (0, true);
559 secondary_clock->set (0, true);
564 ARDOUR_UI::synchronize_sync_source_and_video_pullup ()
566 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("ToggleExternalSync"));
576 if (_session->config.get_video_pullup() == 0.0f) {
577 /* with no video pull up/down, any sync source is OK */
578 act->set_sensitive (true);
580 /* can't sync to JACK if video pullup != 0.0 */
581 if (Config->get_sync_source() == Engine) {
582 act->set_sensitive (false);
584 act->set_sensitive (true);
588 /* XXX should really be able to set the video pull up
589 action to insensitive/sensitive, but there is no action.
594 if (act->get_sensitive ()) {
595 set_tip (sync_button, _("Enable/Disable external positional sync"));
597 set_tip (sync_button, _("Sync to JACK is not possible: video pull up/down is set"));