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 <gtkmm2ext/utils.h>
30 #include "ardour/rc_configuration.h"
31 #include "ardour/session.h"
33 #include "canvas/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) {
55 if (Config->get_sync_source() == Engine) {
57 _("It is not possible to use JACK as the the sync source\n\
58 when the pull up/down setting is non-zero."));
64 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));
66 /* activating a slave is a session-property.
67 * The slave type is a RC property.
68 * When the slave is active is must not be reconfigured.
69 * This is a UI limitation, imposed by audio-clock and
70 * status displays which combine RC-config & session-properties.
72 * Notficy RCOptionEditor by emitting a signal if the active
75 Config->ParameterChanged("sync-source");
80 ARDOUR_UI::toggle_time_master ()
82 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));
86 ARDOUR_UI::toggle_send_mtc ()
88 ActionManager::toggle_config_state ("Options", "SendMTC", &RCConfiguration::set_send_mtc, &RCConfiguration::get_send_mtc);
92 ARDOUR_UI::toggle_send_mmc ()
94 ActionManager::toggle_config_state ("Options", "SendMMC", &RCConfiguration::set_send_mmc, &RCConfiguration::get_send_mmc);
98 ARDOUR_UI::toggle_send_midi_clock ()
100 ActionManager::toggle_config_state ("Options", "SendMidiClock", &RCConfiguration::set_send_midi_clock, &RCConfiguration::get_send_midi_clock);
104 ARDOUR_UI::toggle_use_mmc ()
106 ActionManager::toggle_config_state ("Options", "UseMMC", &RCConfiguration::set_mmc_control, &RCConfiguration::get_mmc_control);
110 ARDOUR_UI::toggle_auto_input ()
112 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));
116 ARDOUR_UI::toggle_auto_play ()
118 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));
122 ARDOUR_UI::toggle_auto_return ()
124 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));
128 ARDOUR_UI::toggle_click ()
130 ActionManager::toggle_config_state ("Transport", "ToggleClick", &RCConfiguration::set_clicking, &RCConfiguration::get_clicking);
134 ARDOUR_UI::toggle_session_monitoring_in ()
136 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("SessionMonitorIn"));
140 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
145 if (tact->get_active() && _session->config.get_session_monitoring () == MonitorInput) {
148 if (!tact->get_active() && _session->config.get_session_monitoring () != MonitorInput) {
152 if (tact->get_active()) {
153 _session->config.set_session_monitoring (MonitorInput);
155 _session->config.set_session_monitoring (MonitorAuto);
160 ARDOUR_UI::toggle_session_monitoring_disk ()
162 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("SessionMonitorDisk"));
166 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
170 if (tact->get_active() && _session->config.get_session_monitoring () == MonitorDisk) {
173 if (!tact->get_active() && _session->config.get_session_monitoring () != MonitorDisk) {
177 if (tact->get_active()) {
178 _session->config.set_session_monitoring (MonitorDisk);
180 _session->config.set_session_monitoring (MonitorAuto);
185 ARDOUR_UI::unset_dual_punch ()
187 Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
190 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
192 ignore_dual_punch = true;
193 tact->set_active (false);
194 ignore_dual_punch = false;
200 ARDOUR_UI::toggle_punch ()
202 if (ignore_dual_punch) {
206 Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
210 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
216 /* drive the other two actions from this one */
218 Glib::RefPtr<Action> in_action = ActionManager::get_action ("Transport", "TogglePunchIn");
219 Glib::RefPtr<Action> out_action = ActionManager::get_action ("Transport", "TogglePunchOut");
221 if (in_action && out_action) {
222 Glib::RefPtr<ToggleAction> tiact = Glib::RefPtr<ToggleAction>::cast_dynamic(in_action);
223 Glib::RefPtr<ToggleAction> toact = Glib::RefPtr<ToggleAction>::cast_dynamic(out_action);
224 tiact->set_active (tact->get_active());
225 toact->set_active (tact->get_active());
231 ARDOUR_UI::toggle_punch_in ()
233 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("TogglePunchIn"));
238 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
243 if (tact->get_active() != _session->config.get_punch_in()) {
244 _session->config.set_punch_in (tact->get_active ());
247 if (tact->get_active()) {
248 /* if punch-in is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
249 to avoid confusing the user */
250 show_loop_punch_ruler_and_disallow_hide ();
253 reenable_hide_loop_punch_ruler_if_appropriate ();
257 ARDOUR_UI::toggle_punch_out ()
259 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("TogglePunchOut"));
264 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
269 if (tact->get_active() != _session->config.get_punch_out()) {
270 _session->config.set_punch_out (tact->get_active ());
273 if (tact->get_active()) {
274 /* if punch-out is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
275 to avoid confusing the user */
276 show_loop_punch_ruler_and_disallow_hide ();
279 reenable_hide_loop_punch_ruler_if_appropriate ();
283 ARDOUR_UI::show_loop_punch_ruler_and_disallow_hide ()
285 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Rulers"), "toggle-loop-punch-ruler");
290 act->set_sensitive (false);
292 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
297 if (!tact->get_active()) {
302 /* This is a bit of a silly name for a method */
304 ARDOUR_UI::reenable_hide_loop_punch_ruler_if_appropriate ()
306 if (!_session->config.get_punch_in() && !_session->config.get_punch_out()) {
307 /* if punch in/out are now both off, reallow hiding of the loop/punch ruler */
308 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Rulers"), "toggle-loop-punch-ruler");
310 act->set_sensitive (true);
316 ARDOUR_UI::toggle_video_sync()
318 Glib::RefPtr<Action> act = ActionManager::get_action ("Transport", "ToggleVideoSync");
320 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
321 _session->config.set_use_video_sync (tact->get_active());
326 ARDOUR_UI::toggle_editing_space()
328 Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMaximalEditor");
331 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
332 if (tact->get_active()) {
333 maximise_editing_space ();
335 restore_editing_space ();
341 ARDOUR_UI::setup_session_options ()
343 _session->config.ParameterChanged.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::parameter_changed, this, _1), gui_context());
344 boost::function<void (std::string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
345 _session->config.map_parameters (pc);
349 ARDOUR_UI::parameter_changed (std::string p)
351 if (p == "external-sync") {
353 ActionManager::map_some_state ("Transport", "ToggleExternalSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_external_sync));
355 if (!_session->config.get_external_sync()) {
356 sync_button.set_text (S_("SyncSource|Int."));
357 ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (true);
358 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (true);
359 ActionManager::get_action ("Transport", "ToggleFollowEdits")->set_sensitive (true);
361 sync_button.set_text (sync_source_to_string (Config->get_sync_source(), true));
362 if (_session && _session->locations()->auto_loop_location()) {
363 // disable looping with external sync.
364 // This is not necessary because session-transport ignores the loop-state,
365 // but makes it clear to the user that it's disabled.
366 _session->request_play_loop (false, false);
368 /* XXX we need to make sure that auto-play is off as well as insensitive */
369 ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (false);
370 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (false);
371 ActionManager::get_action ("Transport", "ToggleFollowEdits")->set_sensitive (false);
373 set_loop_sensitivity ();
375 } else if (p == "follow-edits") {
377 ActionManager::map_some_state ("Transport", "ToggleFollowEdits", &UIConfiguration::get_follow_edits);
379 } else if (p == "send-mtc") {
381 ActionManager::map_some_state ("Options", "SendMTC", &RCConfiguration::get_send_mtc);
383 } else if (p == "send-mmc") {
385 ActionManager::map_some_state ("Options", "SendMMC", &RCConfiguration::get_send_mmc);
387 } else if (p == "mmc-control") {
388 ActionManager::map_some_state ("Options", "UseMMC", &RCConfiguration::get_mmc_control);
389 } else if (p == "auto-play") {
390 ActionManager::map_some_state ("Transport", "ToggleAutoPlay", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_play));
391 } else if (p == "auto-return") {
392 ActionManager::map_some_state ("Transport", "ToggleAutoReturn", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_return));
393 } else if (p == "auto-input") {
394 ActionManager::map_some_state ("Transport", "ToggleAutoInput", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_input));
395 } else if (p == "session-monitoring") {
396 Glib::RefPtr<Action> iact = ActionManager::get_action (X_("Transport"), X_("SessionMonitorIn"));
397 Glib::RefPtr<Action> dact = ActionManager::get_action (X_("Transport"), X_("SessionMonitorDisk"));
399 Glib::RefPtr<ToggleAction> tdact = Glib::RefPtr<ToggleAction>::cast_dynamic(dact);
400 Glib::RefPtr<ToggleAction> tiact = Glib::RefPtr<ToggleAction>::cast_dynamic(iact);
401 if (tdact && tiact) {
402 switch (_session->config.get_session_monitoring ()) {
404 tdact->set_active (true);
405 tiact->set_active (false);
408 tiact->set_active (true);
409 tdact->set_active (false);
412 tdact->set_active (false);
413 tiact->set_active (false);
418 } else if (p == "punch-out") {
419 ActionManager::map_some_state ("Transport", "TogglePunchOut", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_out));
420 if (!_session->config.get_punch_out()) {
423 } else if (p == "punch-in") {
424 ActionManager::map_some_state ("Transport", "TogglePunchIn", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_in));
425 if (!_session->config.get_punch_in()) {
428 } else if (p == "clicking") {
429 ActionManager::map_some_state ("Transport", "ToggleClick", &RCConfiguration::get_clicking);
430 } else if (p == "click-record-only") {
431 // TODO set a flag, blink or gray-out metronome button while rolling, only
432 if (Config->get_click_record_only()) {
433 click_button.set_name ("generic button"); // XXX
435 click_button.set_name ("transport button");
437 } else if (p == "use-video-sync") {
438 ActionManager::map_some_state ("Transport", "ToggleVideoSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_use_video_sync));
439 } else if (p == "sync-source") {
441 synchronize_sync_source_and_video_pullup ();
442 set_fps_timeout_connection ();
444 } else if (p == "show-track-meters") {
445 if (editor) editor->toggle_meter_updating();
446 } else if (p == "primary-clock-delta-edit-cursor") {
447 if (UIConfiguration::instance().get_primary_clock_delta_edit_cursor()) {
448 primary_clock->set_is_duration (true);
449 primary_clock->set_editable (false);
450 primary_clock->set_widget_name ("transport delta");
452 primary_clock->set_is_duration (false);
453 primary_clock->set_editable (true);
454 primary_clock->set_widget_name ("transport");
456 } else if (p == "secondary-clock-delta-edit-cursor") {
457 if (UIConfiguration::instance().get_secondary_clock_delta_edit_cursor()) {
458 secondary_clock->set_is_duration (true);
459 secondary_clock->set_editable (false);
460 secondary_clock->set_widget_name ("secondary delta");
462 secondary_clock->set_is_duration (false);
463 secondary_clock->set_editable (true);
464 secondary_clock->set_widget_name ("secondary");
466 } else if (p == "super-rapid-clock-update") {
471 } else if (p == "use-tooltips") {
472 /* this doesn't really belong here but it has to go somewhere */
473 if (UIConfiguration::instance().get_use_tooltips()) {
474 Gtkmm2ext::enable_tooltips ();
476 Gtkmm2ext::disable_tooltips ();
478 } else if (p == "waveform-gradient-depth") {
479 ArdourCanvas::WaveView::set_global_gradient_depth (UIConfiguration::instance().get_waveform_gradient_depth());
480 } else if (p == "show-mini-timeline") {
481 repack_transport_hbox ();
482 } else if (p == "show-toolbar-recpunch") {
483 repack_transport_hbox ();
484 } else if (p == "show-toolbar-monitoring") {
485 repack_transport_hbox ();
486 } else if (p == "show-toolbar-selclock") {
487 repack_transport_hbox ();
488 } else if (p == "show-editor-meter") {
489 repack_transport_hbox ();
490 } else if (p == "show-secondary-clock") {
491 update_clock_visibility ();
492 } else if (p == "waveform-scale") {
493 ArdourCanvas::WaveView::set_global_logscaled (UIConfiguration::instance().get_waveform_scale() == Logarithmic);
494 } else if (p == "widget-prelight") {
495 CairoWidget::set_widget_prelight (UIConfiguration::instance().get_widget_prelight());
496 } else if (p == "waveform-shape") {
497 ArdourCanvas::WaveView::set_global_shape (UIConfiguration::instance().get_waveform_shape() == Rectified
498 ? ArdourCanvas::WaveView::Rectified : ArdourCanvas::WaveView::Normal);
499 } else if (p == "show-waveform-clipping") {
500 ArdourCanvas::WaveView::set_global_show_waveform_clipping (UIConfiguration::instance().get_show_waveform_clipping());
501 } else if (p == "waveform-cache-size") {
502 /* GUI option has units of megabytes; image cache uses units of bytes */
503 ArdourCanvas::WaveView::set_image_cache_size (UIConfiguration::instance().get_waveform_cache_size() * 1048576);
504 } else if (p == "use-wm-visibility") {
505 VisibilityTracker::set_use_window_manager_visibility (UIConfiguration::instance().get_use_wm_visibility());
506 } else if (p == "action-table-columns") {
507 const uint32_t cols = UIConfiguration::instance().get_action_table_columns ();
508 for (int i = 0; i < 9; ++i) {
509 const int col = i / 2;
510 if (cols & (1<<col)) {
511 action_script_call_btn[i].show();
513 action_script_call_btn[i].hide();
516 } else if (p == "layered-record-mode") {
517 layered_button.set_active (_session->config.get_layered_record_mode ());
518 } else if (p == "show-waveform-clipping") {
519 ArdourCanvas::WaveView::set_global_show_waveform_clipping (UIConfiguration::instance().get_show_waveform_clipping());
520 } else if (p == "waveform-gradient-depth") {
521 ArdourCanvas::WaveView::set_global_gradient_depth (UIConfiguration::instance().get_waveform_gradient_depth());
522 } else if (p == "flat-buttons") {
523 bool flat = UIConfiguration::instance().get_flat_buttons();
524 if (ArdourButton::flat_buttons () != flat) {
525 ArdourButton::set_flat_buttons (flat);
527 gtk_rc_reset_styles (gtk_settings_get_default());
529 } else if (p == "click-gain") {
530 float gain_db = accurate_coefficient_to_dB (Config->get_click_gain());
532 snprintf(tmp, 31, "%+.1f", gain_db);
533 set_tip (click_button, string_compose (_("Enable/Disable metronome\n\nRight-click to access preferences\nMouse-wheel to modify level\nSignal Level: %1 dBFS"), tmp));
538 ARDOUR_UI::session_parameter_changed (std::string p)
540 if (p == "native-file-data-format" || p == "native-file-header-format") {
542 } else if (p == "timecode-format") {
543 set_fps_timeout_connection ();
544 } else if (p == "video-pullup" || p == "timecode-format") {
545 set_fps_timeout_connection ();
547 synchronize_sync_source_and_video_pullup ();
548 reset_main_clocks ();
549 editor->queue_visual_videotimeline_update();
550 } else if (p == "track-name-number") {
551 /* DisplaySuspender triggers _route->redisplay() when going out of scope
552 * which eventually calls reset_controls_layout_width() and re-sets the
553 * track-header width.
554 * see also RouteTimeAxisView::update_track_number_visibility()
561 ARDOUR_UI::reset_main_clocks ()
563 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::reset_main_clocks)
566 primary_clock->set (_session->audible_frame(), true);
567 secondary_clock->set (_session->audible_frame(), true);
569 primary_clock->set (0, true);
570 secondary_clock->set (0, true);
575 ARDOUR_UI::synchronize_sync_source_and_video_pullup ()
577 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("ToggleExternalSync"));
587 if (_session->config.get_video_pullup() == 0.0f) {
588 /* with no video pull up/down, any sync source is OK */
589 act->set_sensitive (true);
591 /* can't sync to JACK if video pullup != 0.0 */
592 if (Config->get_sync_source() == Engine) {
593 act->set_sensitive (false);
595 act->set_sensitive (true);
599 /* XXX should really be able to set the video pull up
600 action to insensitive/sensitive, but there is no action.
605 if (act->get_sensitive ()) {
606 set_tip (sync_button, _("Enable/Disable external positional sync"));
608 set_tip (sync_button, _("Sync to JACK is not possible: video pull up/down is set"));