Move some sync-related options to being session variables.
[ardour.git] / gtk2_ardour / ardour_ui_options.cc
1 /*
2     Copyright (C) 2005 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #include "pbd/convert.h"
21 #include "pbd/stacktrace.h"
22
23 #include <gtkmm2ext/utils.h>
24
25 #include "ardour/configuration.h"
26 #include "ardour/session.h"
27 #include "ardour/audioengine.h"
28
29 #ifdef HAVE_LIBLO
30 #include "ardour/osc.h"
31 #endif
32
33 #include "ardour_ui.h"
34 #include "actions.h"
35 #include "gui_thread.h"
36 #include "public_editor.h"
37
38 #include "i18n.h"
39
40 using namespace Gtk;
41 using namespace Gtkmm2ext;
42 using namespace ARDOUR;
43 using namespace PBD;
44 using namespace sigc;
45
46 void
47 ARDOUR_UI::toggle_time_master ()
48 {
49         ActionManager::toggle_config_state_foo ("Transport", "ToggleTimeMaster", mem_fun (session->config, &SessionConfiguration::set_jack_time_master), mem_fun (session->config, &SessionConfiguration::get_jack_time_master));
50 }
51
52 void
53 ARDOUR_UI::toggle_send_mtc ()
54 {
55         ActionManager::toggle_config_state ("options", "SendMTC", &RCConfiguration::set_send_mtc, &RCConfiguration::get_send_mtc);
56 }
57
58 void
59 ARDOUR_UI::toggle_send_mmc ()
60 {
61         ActionManager::toggle_config_state ("options", "SendMMC", &RCConfiguration::set_send_mmc, &RCConfiguration::get_send_mmc);
62 }
63
64 void
65 ARDOUR_UI::toggle_send_midi_clock ()
66 {
67         ActionManager::toggle_config_state ("options", "SendMidiClock", &RCConfiguration::set_send_midi_clock, &RCConfiguration::get_send_midi_clock);
68 }
69
70 void
71 ARDOUR_UI::toggle_use_mmc ()
72 {
73         ActionManager::toggle_config_state ("options", "UseMMC", &RCConfiguration::set_mmc_control, &RCConfiguration::get_mmc_control);
74 }
75
76 void
77 ARDOUR_UI::toggle_use_osc ()
78 {
79         ActionManager::toggle_config_state ("options", "UseOSC", &RCConfiguration::set_use_osc, &RCConfiguration::get_use_osc);
80 }
81
82 void
83 ARDOUR_UI::toggle_send_midi_feedback ()
84 {
85         ActionManager::toggle_config_state ("options", "SendMIDIfeedback", &RCConfiguration::set_midi_feedback, &RCConfiguration::get_midi_feedback);
86 }
87
88 void
89 ARDOUR_UI::toggle_denormal_protection ()
90 {
91         ActionManager::toggle_config_state ("options", "DenormalProtection", &RCConfiguration::set_denormal_protection, &RCConfiguration::get_denormal_protection);
92 }
93
94 void
95 ARDOUR_UI::toggle_only_copy_imported_files ()
96 {
97         ActionManager::toggle_config_state ("options", "OnlyCopyImportedFiles", &RCConfiguration::set_only_copy_imported_files, &RCConfiguration::get_only_copy_imported_files);
98 }
99
100
101 void
102 ARDOUR_UI::set_native_file_header_format (HeaderFormat hf)
103 {
104         const char *action = 0;
105
106         switch (hf) {
107         case BWF:
108                 action = X_("FileHeaderFormatBWF");
109                 break;
110         case WAVE:
111                 action = X_("FileHeaderFormatWAVE");
112                 break;
113         case WAVE64:
114                 action = X_("FileHeaderFormatWAVE64");
115                 break;
116         case iXML:
117                 action = X_("FileHeaderFormatiXML");
118                 break;
119         case RF64:
120                 action = X_("FileHeaderFormatRF64");
121                 break;
122         case CAF:
123                 action = X_("FileHeaderFormatCAF");
124                 break;
125         case AIFF:
126                 action = X_("FileHeaderFormatAIFF");
127                 break;
128         default:
129                 fatal << string_compose (_("programming error: %1"), "illegal file header format in ::set_native_file_header_format") << endmsg;
130                 /*NOTREACHED*/
131         }
132
133         Glib::RefPtr<Action> act = ActionManager::get_action ("options", action);
134
135         if (act) {
136                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic(act);
137                 if (ract && ract->get_active() && session->config.get_native_file_header_format() != hf) {
138                         session->config.set_native_file_header_format (hf);
139                 }
140         }
141 }
142
143 void
144 ARDOUR_UI::set_native_file_data_format (SampleFormat sf)
145 {
146         const char* action = 0;
147
148         switch (sf) {
149         case FormatFloat:
150                 action = X_("FileDataFormatFloat");
151                 break;
152         case FormatInt24:
153                 action = X_("FileDataFormat24bit");
154                 break;
155         case FormatInt16:
156                 action = X_("FileDataFormat16bit");
157                 break;
158         default:
159                 fatal << string_compose (_("programming error: %1"), "illegal file data format in ::set_native_file_data_format") << endmsg;
160                 /*NOTREACHED*/
161         }
162
163         Glib::RefPtr<Action> act = ActionManager::get_action ("options", action);
164
165         if (act) {
166                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic(act);
167                 if (ract && ract->get_active() && session->config.get_native_file_data_format() != sf) {
168                         session->config.set_native_file_data_format (sf);
169                 }
170         }
171 }
172
173 void
174 ARDOUR_UI::set_input_auto_connect (AutoConnectOption option)
175 {
176         const char* action;
177
178         switch (option) {
179         case AutoConnectPhysical:
180                 action = X_("InputAutoConnectPhysical");
181                 break;
182         default:
183                 action = X_("InputAutoConnectManual");
184         }
185
186         Glib::RefPtr<Action> act = ActionManager::get_action ("options", action);
187
188         if (act) {
189                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic(act);
190
191                 if (ract && ract->get_active() && Config->get_input_auto_connect() != option) {
192                         Config->set_input_auto_connect (option);
193                 }
194         }
195 }
196
197 void
198 ARDOUR_UI::set_output_auto_connect (AutoConnectOption option)
199 {
200         const char* action;
201
202         switch (option) {
203         case AutoConnectPhysical:
204                 action = X_("OutputAutoConnectPhysical");
205                 break;
206         case AutoConnectMaster:
207                 action = X_("OutputAutoConnectMaster");
208                 break;
209         default:
210                 action = X_("OutputAutoConnectManual");
211         }
212
213         Glib::RefPtr<Action> act = ActionManager::get_action ("options", action);
214
215         if (act) {
216                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic(act);
217
218                 if (ract && ract->get_active() && Config->get_output_auto_connect() != option) {
219                         Config->set_output_auto_connect (option);
220                 }
221         }
222 }
223
224 void
225 ARDOUR_UI::set_solo_model (SoloModel model)
226 {
227         const char* action = 0;
228
229         switch (model) {
230         case SoloBus:
231                 action = X_("SoloViaBus");
232                 break;
233
234         case InverseMute:
235                 action = X_("SoloInPlace");
236                 break;
237         default:
238                 fatal << string_compose (_("programming error: unknown solo model in ARDOUR_UI::set_solo_model: %1"), model) << endmsg;
239                 /*NOTREACHED*/
240         }
241
242         Glib::RefPtr<Action> act = ActionManager::get_action ("options", action);
243
244         if (act) {
245                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic(act);
246
247                 if (ract && ract->get_active() && Config->get_solo_model() != model) {
248                         Config->set_solo_model (model);
249                 }
250         }
251
252 }
253
254 void
255 ARDOUR_UI::set_remote_model (RemoteModel model)
256 {
257         const char* action = 0;
258
259         switch (model) {
260         case UserOrdered:
261                 action = X_("RemoteUserDefined");
262                 break;
263         case MixerOrdered:
264                 action = X_("RemoteMixerDefined");
265                 break;
266         case EditorOrdered:
267                 action = X_("RemoteEditorDefined");
268                 break;
269
270         default:
271                 fatal << string_compose (_("programming error: unknown remote model in ARDOUR_UI::set_remote_model: %1"), model) << endmsg;
272                 /*NOTREACHED*/
273         }
274
275         Glib::RefPtr<Action> act = ActionManager::get_action ("options", action);
276
277         if (act) {
278                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic(act);
279
280                 if (ract && ract->get_active() && Config->get_remote_model() != model) {
281                         Config->set_remote_model (model);
282                 }
283         }
284
285 }
286
287 void
288 ARDOUR_UI::set_monitor_model (MonitorModel model)
289 {
290         const char* action = 0;
291
292         switch (model) {
293         case HardwareMonitoring:
294                 action = X_("UseHardwareMonitoring");
295                 break;
296
297         case SoftwareMonitoring:
298                 action = X_("UseSoftwareMonitoring");
299                 break;
300         case ExternalMonitoring:
301                 action = X_("UseExternalMonitoring");
302                 break;
303
304         default:
305                 fatal << string_compose (_("programming error: unknown monitor model in ARDOUR_UI::set_monitor_model: %1"), model) << endmsg;
306                 /*NOTREACHED*/
307         }
308
309         Glib::RefPtr<Action> act = ActionManager::get_action ("options", action);
310
311         if (act) {
312                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic(act);
313
314                 if (ract && ract->get_active() && Config->get_monitoring_model() != model) {
315                         Config->set_monitoring_model (model);
316                 }
317         }
318
319 }
320
321 void
322 ARDOUR_UI::set_denormal_model (DenormalModel model)
323 {
324         const char* action = 0;
325
326         switch (model) {
327         case DenormalNone:
328                 action = X_("DenormalNone");
329                 break;
330
331         case DenormalFTZ:
332                 action = X_("DenormalFTZ");
333                 break;
334
335         case DenormalDAZ:
336                 action = X_("DenormalDAZ");
337                 break;
338
339         case DenormalFTZDAZ:
340                 action = X_("DenormalFTZDAZ");
341                 break;
342
343         default:
344                 fatal << string_compose (_("programming error: unknown denormal model in ARDOUR_UI::set_denormal_model: %1"), model) << endmsg;
345                 /*NOTREACHED*/
346         }
347
348         Glib::RefPtr<Action> act = ActionManager::get_action ("options", action);
349
350         if (act) {
351                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic(act);
352
353                 if (ract && ract->get_active() && Config->get_denormal_model() != model) {
354                         Config->set_denormal_model (model);
355                 }
356         }
357
358 }
359
360 void
361 ARDOUR_UI::toggle_auto_input ()
362 {
363         ActionManager::toggle_config_state_foo ("Transport", "ToggleAutoInput", mem_fun (session->config, &SessionConfiguration::set_auto_input), mem_fun (session->config, &SessionConfiguration::get_auto_input));
364 }
365
366 void
367 ARDOUR_UI::toggle_auto_play ()
368 {
369         ActionManager::toggle_config_state_foo ("Transport", "ToggleAutoPlay", mem_fun (session->config, &SessionConfiguration::set_auto_play), mem_fun (session->config, &SessionConfiguration::get_auto_play));
370 }
371
372 void
373 ARDOUR_UI::toggle_auto_return ()
374 {
375         ActionManager::toggle_config_state_foo ("Transport", "ToggleAutoReturn", mem_fun (session->config, &SessionConfiguration::set_auto_return), mem_fun (session->config, &SessionConfiguration::get_auto_return));
376 }
377
378 void
379 ARDOUR_UI::toggle_click ()
380 {
381         ActionManager::toggle_config_state ("Transport", "ToggleClick", &RCConfiguration::set_clicking, &RCConfiguration::get_clicking);
382 }
383
384 void
385 ARDOUR_UI::toggle_session_auto_loop ()
386 {
387         if (session) {
388                 if (session->get_play_loop()) {
389                         if (session->transport_rolling()) {
390                                 transport_roll();
391                         } else {
392                                 session->request_play_loop (false);
393                         }
394                 } else {
395                         session->request_play_loop (true);
396                 }
397         }
398 }
399
400 void
401 ARDOUR_UI::unset_dual_punch ()
402 {
403         Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
404
405         if (action) {
406                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
407                 if (tact) {
408                         ignore_dual_punch = true;
409                         tact->set_active (false);
410                         ignore_dual_punch = false;
411                 }
412         }
413 }
414
415 void
416 ARDOUR_UI::toggle_punch ()
417 {
418         if (ignore_dual_punch) {
419                 return;
420         }
421
422         Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
423
424         if (action) {
425
426                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
427
428                 if (!tact) {
429                         return;
430                 }
431
432                 /* drive the other two actions from this one */
433
434                 Glib::RefPtr<Action> in_action = ActionManager::get_action ("Transport", "TogglePunchIn");
435                 Glib::RefPtr<Action> out_action = ActionManager::get_action ("Transport", "TogglePunchOut");
436
437                 if (in_action && out_action) {
438                         Glib::RefPtr<ToggleAction> tiact = Glib::RefPtr<ToggleAction>::cast_dynamic(in_action);
439                         Glib::RefPtr<ToggleAction> toact = Glib::RefPtr<ToggleAction>::cast_dynamic(out_action);
440                         tiact->set_active (tact->get_active());
441                         toact->set_active (tact->get_active());
442                 }
443         }
444 }
445
446 void
447 ARDOUR_UI::toggle_punch_in ()
448 {
449         ActionManager::toggle_config_state_foo ("Transport", "TogglePunchIn", mem_fun (session->config, &SessionConfiguration::set_punch_in), mem_fun (session->config, &SessionConfiguration::get_punch_in));
450 }
451
452 void
453 ARDOUR_UI::toggle_punch_out ()
454 {
455         ActionManager::toggle_config_state_foo ("Transport", "TogglePunchOut", mem_fun (session->config, &SessionConfiguration::set_punch_out), mem_fun (session->config, &SessionConfiguration::get_punch_out));
456 }
457
458 void
459 ARDOUR_UI::toggle_video_sync()
460 {
461         Glib::RefPtr<Action> act = ActionManager::get_action ("Transport", "ToggleVideoSync");
462         if (act) {
463                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
464                 session->config.set_use_video_sync (tact->get_active());
465         }
466 }
467
468 void
469 ARDOUR_UI::toggle_editing_space()
470 {
471         Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMaximalEditor");
472         if (act) {
473                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
474                 if (tact->get_active()) {
475                         maximise_editing_space ();
476                 } else {
477                         restore_editing_space ();
478                 }
479         }
480 }
481
482 void
483 ARDOUR_UI::toggle_new_plugins_active ()
484 {
485         ActionManager::toggle_config_state ("options", "NewPluginsActive", &RCConfiguration::set_new_plugins_active, &RCConfiguration::get_new_plugins_active);
486 }
487
488 void
489 ARDOUR_UI::toggle_StopPluginsWithTransport()
490 {
491         ActionManager::toggle_config_state ("options", "StopPluginsWithTransport", &RCConfiguration::set_plugins_stop_with_transport, &RCConfiguration::get_plugins_stop_with_transport);
492 }
493
494 void
495 ARDOUR_UI::toggle_LatchedRecordEnable()
496 {
497         ActionManager::toggle_config_state ("options", "LatchedRecordEnable", &RCConfiguration::set_latched_record_enable, &RCConfiguration::get_latched_record_enable);
498 }
499
500 void
501 ARDOUR_UI::toggle_RegionEquivalentsOverlap()
502 {
503         ActionManager::toggle_config_state ("options", "RegionEquivalentsOverlap", &RCConfiguration::set_use_overlap_equivalency, &RCConfiguration::get_use_overlap_equivalency);
504 }
505
506 void
507 ARDOUR_UI::toggle_DoNotRunPluginsWhileRecording()
508 {
509         ActionManager::toggle_config_state ("options", "DoNotRunPluginsWhileRecording", &RCConfiguration::set_do_not_record_plugins, &RCConfiguration::get_do_not_record_plugins);
510 }
511
512 void
513 ARDOUR_UI::toggle_VerifyRemoveLastCapture()
514 {
515         ActionManager::toggle_config_state ("options", "VerifyRemoveLastCapture", &RCConfiguration::set_verify_remove_last_capture, &RCConfiguration::get_verify_remove_last_capture);
516 }
517
518 void
519 ARDOUR_UI::toggle_PeriodicSafetyBackups()
520 {
521         ActionManager::toggle_config_state ("options", "PeriodicSafetyBackups", &RCConfiguration::set_periodic_safety_backups, &RCConfiguration::get_periodic_safety_backups);
522 }
523
524 void
525 ARDOUR_UI::toggle_StopRecordingOnXrun()
526 {
527         ActionManager::toggle_config_state ("options", "StopRecordingOnXrun", &RCConfiguration::set_stop_recording_on_xrun, &RCConfiguration::get_stop_recording_on_xrun);
528 }
529
530 void
531 ARDOUR_UI::toggle_CreateXrunMarker()
532 {
533         ActionManager::toggle_config_state ("options", "CreateXrunMarker", &RCConfiguration::set_create_xrun_marker, &RCConfiguration::get_create_xrun_marker);
534 }
535
536 void
537 ARDOUR_UI::toggle_sync_order_keys ()
538 {
539         ActionManager::toggle_config_state ("options", "SyncEditorAndMixerTrackOrder", &RCConfiguration::set_sync_all_route_ordering, &RCConfiguration::get_sync_all_route_ordering);
540 }
541
542 void
543 ARDOUR_UI::toggle_StopTransportAtEndOfSession()
544 {
545         ActionManager::toggle_config_state ("options", "StopTransportAtEndOfSession", &RCConfiguration::set_stop_at_session_end, &RCConfiguration::get_stop_at_session_end);
546 }
547
548 void
549 ARDOUR_UI::toggle_GainReduceFastTransport()
550 {
551         ActionManager::toggle_config_state ("options", "GainReduceFastTransport", &RCConfiguration::set_quieten_at_speed, &RCConfiguration::get_quieten_at_speed);
552 }
553
554 void
555 ARDOUR_UI::toggle_LatchedSolo()
556 {
557         ActionManager::toggle_config_state ("options", "LatchedSolo", &RCConfiguration::set_solo_latched, &RCConfiguration::get_solo_latched);
558 }
559
560 void
561 ARDOUR_UI::toggle_ShowSoloMutes()
562 {
563         ActionManager::toggle_config_state ("options", "ShowSoloMutes", &RCConfiguration::set_show_solo_mutes, &RCConfiguration::get_show_solo_mutes);
564 }
565
566 void
567 ARDOUR_UI::toggle_SoloMuteOverride()
568 {
569         ActionManager::toggle_config_state ("options", "SoloMuteOverride", &RCConfiguration::set_solo_mute_override, &RCConfiguration::get_solo_mute_override);
570 }
571
572 void
573 ARDOUR_UI::toggle_PrimaryClockDeltaEditCursor()
574 {
575         ActionManager::toggle_config_state ("options", "PrimaryClockDeltaEditCursor", &RCConfiguration::set_primary_clock_delta_edit_cursor, &RCConfiguration::get_primary_clock_delta_edit_cursor);
576 }
577
578 void
579 ARDOUR_UI::toggle_SecondaryClockDeltaEditCursor()
580 {
581         ActionManager::toggle_config_state ("options", "SecondaryClockDeltaEditCursor", &RCConfiguration::set_secondary_clock_delta_edit_cursor, &RCConfiguration::get_secondary_clock_delta_edit_cursor);
582 }
583
584 void
585 ARDOUR_UI::toggle_ShowTrackMeters()
586 {
587         ActionManager::toggle_config_state ("options", "ShowTrackMeters", &RCConfiguration::set_show_track_meters, &RCConfiguration::get_show_track_meters);
588 }
589
590 void
591 ARDOUR_UI::toggle_TapeMachineMode ()
592 {
593         ActionManager::toggle_config_state ("options", "ToggleTapeMachineMode", &RCConfiguration::set_tape_machine_mode, &RCConfiguration::get_tape_machine_mode);
594 }
595
596 void
597 ARDOUR_UI::toggle_use_narrow_ms()
598 {
599         ActionManager::toggle_config_state ("options", "DefaultNarrowMS", &RCConfiguration::set_default_narrow_ms, &RCConfiguration::get_default_narrow_ms);
600 }
601
602 void
603 ARDOUR_UI::toggle_NameNewMarkers()
604 {
605         ActionManager::toggle_config_state ("options", "NameNewMarkers", &RCConfiguration::set_name_new_markers, &RCConfiguration::get_name_new_markers);
606 }
607
608 void
609 ARDOUR_UI::toggle_rubberbanding_snaps_to_grid ()
610 {
611         ActionManager::toggle_config_state ("options", "RubberbandingSnapsToGrid", &RCConfiguration::set_rubberbanding_snaps_to_grid, &RCConfiguration::get_rubberbanding_snaps_to_grid);
612 }
613
614 void
615 ARDOUR_UI::toggle_auto_analyse_audio ()
616 {
617         ActionManager::toggle_config_state ("options", "AutoAnalyseAudio", &RCConfiguration::set_auto_analyse_audio, &RCConfiguration::get_auto_analyse_audio);
618 }
619
620 void
621 ARDOUR_UI::mtc_port_changed ()
622 {
623         bool have_mtc;
624         bool have_midi_clock;
625
626         if (session) {
627                 if (session->mtc_port()) {
628                         have_mtc = true;
629                 } else {
630                         have_mtc = false;
631                 }
632                 if (session->midi_clock_port()) {
633                         have_midi_clock = true;
634                 } else {
635                         have_midi_clock = false;
636                 }
637         } else {
638                 have_mtc = false;
639                 have_midi_clock = false;
640         }
641
642         positional_sync_strings.clear ();
643         positional_sync_strings.push_back (slave_source_to_string (None));
644         if (have_mtc) {
645                 positional_sync_strings.push_back (slave_source_to_string (MTC));
646         }
647         if (have_midi_clock) {
648                 positional_sync_strings.push_back (slave_source_to_string (MIDIClock));
649         }
650         positional_sync_strings.push_back (slave_source_to_string (JACK));
651
652         set_popdown_strings (sync_option_combo, positional_sync_strings);
653 }
654
655 void
656 ARDOUR_UI::setup_session_options ()
657 {
658         mtc_port_changed ();
659
660         Config->ParameterChanged.connect (mem_fun (*this, &ARDOUR_UI::parameter_changed));
661 }
662
663
664 void
665 ARDOUR_UI::map_solo_model ()
666 {
667         const char* on;
668
669         if (Config->get_solo_model() == InverseMute) {
670                 on = X_("SoloInPlace");
671         } else {
672                 on = X_("SoloViaBus");
673         }
674
675         Glib::RefPtr<Action> act = ActionManager::get_action ("options", on);
676         if (act) {
677                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
678
679                 if (tact && !tact->get_active()) {
680                         tact->set_active (true);
681                 }
682         }
683 }
684
685 void
686 ARDOUR_UI::map_monitor_model ()
687 {
688         const char* on = 0;
689
690         switch (Config->get_monitoring_model()) {
691         case HardwareMonitoring:
692                 on = X_("UseHardwareMonitoring");
693                 break;
694         case SoftwareMonitoring:
695                 on = X_("UseSoftwareMonitoring");
696                 break;
697         case ExternalMonitoring:
698                 on = X_("UseExternalMonitoring");
699                 break;
700         }
701
702         Glib::RefPtr<Action> act = ActionManager::get_action ("options", on);
703         if (act) {
704                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
705
706                 if (tact && !tact->get_active()) {
707                         tact->set_active (true);
708                 }
709         }
710 }
711
712 void
713 ARDOUR_UI::map_denormal_protection ()
714 {
715         Glib::RefPtr<Action> act = ActionManager::get_action ("options", X_("DenormalProtection"));
716         if (act) {
717                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
718
719                 if (tact && !tact->get_active()) {
720                         tact->set_active (Config->get_denormal_protection());
721                 }
722         }
723 }
724
725 void
726 ARDOUR_UI::map_denormal_model ()
727 {
728         const char* on = 0;
729
730         switch (Config->get_denormal_model()) {
731         case DenormalNone:
732                 on = X_("DenormalNone");
733                 break;
734         case DenormalFTZ:
735                 on = X_("DenormalFTZ");
736                 break;
737         case DenormalDAZ:
738                 on = X_("DenormalDAZ");
739                 break;
740         case DenormalFTZDAZ:
741                 on = X_("DenormalFTZDAZ");
742                 break;
743         }
744
745         Glib::RefPtr<Action> act = ActionManager::get_action ("options", on);
746         if (act) {
747                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
748
749                 if (tact && !tact->get_active()) {
750                         tact->set_active (true);
751                 }
752         }
753 }
754
755 void
756 ARDOUR_UI::map_remote_model ()
757 {
758         const char* on = 0;
759
760         switch (Config->get_remote_model()) {
761         case UserOrdered:
762                 on = X_("RemoteUserDefined");
763                 break;
764         case MixerOrdered:
765                 on = X_("RemoteMixerDefined");
766                 break;
767         case EditorOrdered:
768                 on = X_("RemoteEditorDefined");
769                 break;
770         }
771
772         Glib::RefPtr<Action> act = ActionManager::get_action ("options", on);
773         if (act) {
774                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
775
776                 if (tact && !tact->get_active()) {
777                         tact->set_active (true);
778                 }
779         }
780 }
781
782 void
783 ARDOUR_UI::map_file_header_format ()
784 {
785         const char* action = 0;
786
787         switch (session->config.get_native_file_header_format()) {
788         case BWF:
789                 action = X_("FileHeaderFormatBWF");
790                 break;
791
792         case WAVE:
793                 action = X_("FileHeaderFormatWAVE");
794                 break;
795
796         case WAVE64:
797                 action = X_("FileHeaderFormatWAVE64");
798                 break;
799
800         case iXML:
801                 action = X_("FileHeaderFormatiXML");
802                 break;
803
804         case RF64:
805                 action = X_("FileHeaderFormatRF64");
806                 break;
807
808         case CAF:
809                 action = X_("FileHeaderFormatCAF");
810                 break;
811
812         default:
813                 fatal << string_compose (_("programming error: unknown file header format passed to ARDOUR_UI::map_file_data_format: %1"),
814                                          session->config.get_native_file_header_format()) << endmsg;
815                 /*NOTREACHED*/
816         }
817
818
819         Glib::RefPtr<Action> act = ActionManager::get_action ("options", action);
820
821         if (act) {
822                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
823
824                 if (tact && !tact->get_active()) {
825                         tact->set_active (true);
826                 }
827         }
828 }
829
830 void
831 ARDOUR_UI::map_file_data_format ()
832 {
833         const char* action = 0;
834
835         switch (session->config.get_native_file_data_format()) {
836         case FormatFloat:
837                 action = X_("FileDataFormatFloat");
838                 break;
839
840         case FormatInt24:
841                 action = X_("FileDataFormat24bit");
842                 break;
843
844         case FormatInt16:
845                 action = X_("FileDataFormat16bit");
846                 break;
847
848         default:
849                 fatal << string_compose (_("programming error: unknown file data format passed to ARDOUR_UI::map_file_data_format: %1"),
850                                          session->config.get_native_file_data_format()) << endmsg;
851                 /*NOTREACHED*/
852         }
853
854
855         Glib::RefPtr<Action> act = ActionManager::get_action ("options", action);
856
857         if (act) {
858                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
859
860                 if (tact && !tact->get_active()) {
861                         tact->set_active (true);
862                 }
863         }
864 }
865
866 void
867 ARDOUR_UI::map_input_auto_connect ()
868 {
869         const char* on;
870
871         if (Config->get_input_auto_connect() == (AutoConnectOption) 0) {
872                 on = "InputAutoConnectManual";
873         } else {
874                 on = "InputAutoConnectPhysical";
875         }
876
877         Glib::RefPtr<Action> act = ActionManager::get_action ("options", on);
878         if (act) {
879                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
880
881                 if (tact && !tact->get_active()) {
882                         tact->set_active (true);
883                 }
884         }
885 }
886
887 void
888 ARDOUR_UI::map_output_auto_connect ()
889 {
890         const char* on;
891
892         if (Config->get_output_auto_connect() == (AutoConnectOption) 0) {
893                 on = "OutputAutoConnectManual";
894         } else if (Config->get_output_auto_connect() == AutoConnectPhysical) {
895                 on = "OutputAutoConnectPhysical";
896         } else {
897                 on = "OutputAutoConnectMaster";
898         }
899
900         Glib::RefPtr<Action> act = ActionManager::get_action ("options", on);
901         if (act) {
902                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
903
904                 if (tact && !tact->get_active()) {
905                         tact->set_active (true);
906                 }
907         }
908 }
909
910 void
911 ARDOUR_UI::map_only_copy_imported_files ()
912 {
913         Glib::RefPtr<Action> act = ActionManager::get_action ("options", X_("OnlyCopyImportedFiles"));
914         if (act) {
915                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
916
917                 if (tact && !tact->get_active()) {
918                         tact->set_active (Config->get_only_copy_imported_files());
919                 }
920         }
921
922 }
923
924
925 void
926 ARDOUR_UI::map_meter_falloff ()
927 {
928         const char* action = X_("MeterFalloffMedium");
929
930         float val = Config->get_meter_falloff ();
931         MeterFalloff code = meter_falloff_from_float(val);
932
933         switch (code) {
934         case MeterFalloffOff:
935                 action = X_("MeterFalloffOff");
936                 break;
937         case MeterFalloffSlowest:
938                 action = X_("MeterFalloffSlowest");
939                 break;
940         case MeterFalloffSlow:
941                 action = X_("MeterFalloffSlow");
942                 break;
943         case MeterFalloffMedium:
944                 action = X_("MeterFalloffMedium");
945                 break;
946         case MeterFalloffFast:
947                 action = X_("MeterFalloffFast");
948                 break;
949         case MeterFalloffFaster:
950                 action = X_("MeterFalloffFaster");
951                 break;
952         case MeterFalloffFastest:
953                 action = X_("MeterFalloffFastest");
954                 break;
955         }
956
957         Glib::RefPtr<Action> act = ActionManager::get_action (X_("options"), action);
958
959         if (act) {
960                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic(act);
961                 if (ract && !ract->get_active()) {
962                         ract->set_active (true);
963                 }
964         }
965 }
966
967 void
968 ARDOUR_UI::map_meter_hold ()
969 {
970         const char* action = X_("MeterHoldMedium");
971
972         /* XXX hack alert. Fix this. Please */
973
974         float val = Config->get_meter_hold ();
975         MeterHold code = (MeterHold) (int) (floor (val));
976
977         switch (code) {
978         case MeterHoldOff:
979                 action = X_("MeterHoldOff");
980                 break;
981         case MeterHoldShort:
982                 action = X_("MeterHoldShort");
983                 break;
984         case MeterHoldMedium:
985                 action = X_("MeterHoldMedium");
986                 break;
987         case MeterHoldLong:
988                 action = X_("MeterHoldLong");
989                 break;
990         }
991
992         Glib::RefPtr<Action> act = ActionManager::get_action (X_("options"), action);
993
994         if (act) {
995                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic(act);
996                 if (ract && !ract->get_active()) {
997                         ract->set_active (true);
998                 }
999         }
1000 }
1001
1002 void
1003 ARDOUR_UI::set_meter_hold (MeterHold val)
1004 {
1005         const char* action = 0;
1006         float fval;
1007
1008         fval = meter_hold_to_float (val);
1009
1010         switch (val) {
1011         case MeterHoldOff:
1012                 action = X_("MeterHoldOff");
1013                 break;
1014         case MeterHoldShort:
1015                 action = X_("MeterHoldShort");
1016                 break;
1017         case MeterHoldMedium:
1018                 action = X_("MeterHoldMedium");
1019                 break;
1020         case MeterHoldLong:
1021                 action = X_("MeterHoldLong");
1022                 break;
1023         }
1024
1025         Glib::RefPtr<Action> act = ActionManager::get_action (X_("options"), action);
1026
1027         if (act) {
1028                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic(act);
1029                 if (ract && ract->get_active() && Config->get_meter_hold() != fval) {
1030                         Config->set_meter_hold (fval);
1031                 }
1032         }
1033 }
1034
1035 void
1036 ARDOUR_UI::set_meter_falloff (MeterFalloff val)
1037 {
1038         const char* action = 0;
1039         float fval;
1040
1041         fval = meter_falloff_to_float (val);
1042
1043         switch (val) {
1044         case MeterFalloffOff:
1045                 action = X_("MeterFalloffOff");
1046                 break;
1047         case MeterFalloffSlowest:
1048                 action = X_("MeterFalloffSlowest");
1049                 break;
1050         case MeterFalloffSlow:
1051                 action = X_("MeterFalloffSlow");
1052                 break;
1053         case MeterFalloffMedium:
1054                 action = X_("MeterFalloffMedium");
1055                 break;
1056         case MeterFalloffFast:
1057                 action = X_("MeterFalloffFast");
1058                 break;
1059         case MeterFalloffFaster:
1060                 action = X_("MeterFalloffFaster");
1061                 break;
1062         case MeterFalloffFastest:
1063                 action = X_("MeterFalloffFastest");
1064                 break;
1065         }
1066
1067         Glib::RefPtr<Action> act = ActionManager::get_action (X_("options"), action);
1068
1069         if (act) {
1070                 Glib::RefPtr<RadioAction> ract = Glib::RefPtr<RadioAction>::cast_dynamic(act);
1071                 if (ract && ract->get_active() && Config->get_meter_falloff () != fval) {
1072                         Config->set_meter_falloff (fval);
1073                 }
1074         }
1075 }
1076
1077 void
1078 ARDOUR_UI::parameter_changed (std::string p)
1079 {
1080         ENSURE_GUI_THREAD (bind (mem_fun (*this, &ARDOUR_UI::parameter_changed), p));
1081
1082         if (p == "slave-source") {
1083
1084                 sync_option_combo.set_active_text (slave_source_to_string (Config->get_slave_source()));
1085
1086                 switch (Config->get_slave_source()) {
1087                 case None:
1088                         ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (true);
1089                         ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (true);
1090                         break;
1091
1092                 default:
1093                         /* XXX need to make auto-play is off as well as insensitive */
1094                         ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (false);
1095                         ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (false);
1096                         break;
1097                 }
1098
1099         } else if (p == "send-mtc") {
1100
1101                 ActionManager::map_some_state ("options", "SendMTC", &RCConfiguration::get_send_mtc);
1102
1103         } else if (p == "send-mmc") {
1104
1105                 ActionManager::map_some_state ("options", "SendMMC", &RCConfiguration::get_send_mmc);
1106
1107         } else if (p == "use-osc") {
1108
1109 #ifdef HAVE_LIBLO
1110                 if (Config->get_use_osc()) {
1111                         osc->start ();
1112                 } else {
1113                         osc->stop ();
1114                 }
1115 #endif
1116
1117                 ActionManager::map_some_state ("options", "UseOSC", &RCConfiguration::get_use_osc);
1118
1119         } else if (p == "mmc-control") {
1120                 ActionManager::map_some_state ("options", "UseMMC", &RCConfiguration::get_mmc_control);
1121         } else if (p == "midi-feedback") {
1122                 ActionManager::map_some_state ("options", "SendMIDIfeedback", &RCConfiguration::get_midi_feedback);
1123         } else if (p == "do-not-record-plugins") {
1124                 ActionManager::map_some_state ("options", "DoNotRunPluginsWhileRecording", &RCConfiguration::get_do_not_record_plugins);
1125         } else if (p == "latched-record-enable") {
1126                 ActionManager::map_some_state ("options", "LatchedRecordEnable", &RCConfiguration::get_latched_record_enable);
1127         } else if (p == "solo-latched") {
1128                 ActionManager::map_some_state ("options", "LatchedSolo", &RCConfiguration::get_solo_latched);
1129         } else if (p == "show-solo-mutes") {
1130                 ActionManager::map_some_state ("options", "ShowSoloMutes", &RCConfiguration::get_show_solo_mutes);
1131         } else if (p == "solo-mute-override") {
1132                 ActionManager::map_some_state ("options", "SoloMuteOverride", &RCConfiguration::get_solo_mute_override);
1133         } else if (p == "solo-model") {
1134                 map_solo_model ();
1135         } else if (p == "auto-play") {
1136                 ActionManager::map_some_state ("Transport", "ToggleAutoPlay", mem_fun (session->config, &SessionConfiguration::get_auto_play));
1137         } else if (p == "auto-return") {
1138                 ActionManager::map_some_state ("Transport", "ToggleAutoReturn", mem_fun (session->config, &SessionConfiguration::get_auto_return));
1139         } else if (p == "auto-input") {
1140                 ActionManager::map_some_state ("Transport", "ToggleAutoInput", mem_fun (session->config, &SessionConfiguration::get_auto_input));
1141         } else if (p == "tape-machine-mode") {
1142                 ActionManager::map_some_state ("options", "ToggleTapeMachineMode", &RCConfiguration::get_tape_machine_mode);
1143         } else if (p == "punch-out") {
1144                 ActionManager::map_some_state ("Transport", "TogglePunchOut", mem_fun (session->config, &SessionConfiguration::get_punch_out));
1145                 if (!session->config.get_punch_out()) {
1146                         unset_dual_punch ();
1147                 }
1148         } else if (p == "punch-in") {
1149                 ActionManager::map_some_state ("Transport", "TogglePunchIn", mem_fun (session->config, &SessionConfiguration::get_punch_in));
1150                 if (!session->config.get_punch_in()) {
1151                         unset_dual_punch ();
1152                 }
1153         } else if (p == "clicking") {
1154                 ActionManager::map_some_state ("Transport", "ToggleClick", &RCConfiguration::get_clicking);
1155         } else if (p == "jack-time-master") {
1156                 ActionManager::map_some_state ("Transport",  "ToggleTimeMaster", mem_fun (session->config, &SessionConfiguration::get_jack_time_master));
1157         } else if (p == "plugins-stop-with-transport") {
1158                 ActionManager::map_some_state ("options",  "StopPluginsWithTransport", &RCConfiguration::get_plugins_stop_with_transport);
1159         } else if (p == "new-plugins-active") {
1160                 ActionManager::map_some_state ("options",  "NewPluginsActive", &RCConfiguration::get_new_plugins_active);
1161         } else if (p == "latched-record-enable") {
1162                 ActionManager::map_some_state ("options", "LatchedRecordEnable", &RCConfiguration::get_latched_record_enable);
1163         } else if (p == "verify-remove-last-capture") {
1164                 ActionManager::map_some_state ("options",  "VerifyRemoveLastCapture", &RCConfiguration::get_verify_remove_last_capture);
1165         } else if (p == "periodic-safety-backups") {
1166                 ActionManager::map_some_state ("options",  "PeriodicSafetyBackups", &RCConfiguration::get_periodic_safety_backups);
1167         } else if (p == "stop-recording-on-xrun") {
1168                 ActionManager::map_some_state ("options",  "StopRecordingOnXrun", &RCConfiguration::get_stop_recording_on_xrun);
1169         } else if (p == "create-xrun-marker") {
1170                 ActionManager::map_some_state ("options",  "CreateXrunMarker", &RCConfiguration::get_create_xrun_marker);
1171         } else if (p == "sync-all-route-ordering") {
1172                 ActionManager::map_some_state ("options",  "SyncEditorAndMixerTrackOrder", &RCConfiguration::get_sync_all_route_ordering);
1173         } else if (p == "stop-at-session-end") {
1174                 ActionManager::map_some_state ("options",  "StopTransportAtEndOfSession", &RCConfiguration::get_stop_at_session_end);
1175         } else if (p == "monitoring-model") {
1176                 map_monitor_model ();
1177         } else if (p == "denormal-model") {
1178                 map_denormal_model ();
1179         } else if (p == "denormal-protection") {
1180                 map_denormal_protection ();
1181         } else if (p == "remote-model") {
1182                 map_remote_model ();
1183         } else if (p == "use-video-sync") {
1184                 ActionManager::map_some_state ("Transport",  "ToggleVideoSync", mem_fun (session->config, &SessionConfiguration::get_use_video_sync));
1185         } else if (p == "quieten-at-speed") {
1186                 ActionManager::map_some_state ("options",  "GainReduceFastTransport", &RCConfiguration::get_quieten_at_speed);
1187         } else if (p == "shuttle-behaviour") {
1188
1189                 switch (Config->get_shuttle_behaviour ()) {
1190                 case Sprung:
1191                         shuttle_style_button.set_active_text (_("sprung"));
1192                         shuttle_fract = 0.0;
1193                         shuttle_box.queue_draw ();
1194                         if (session) {
1195                                 if (session->transport_rolling()) {
1196                                         shuttle_fract = SHUTTLE_FRACT_SPEED1;
1197                                         session->request_transport_speed (1.0);
1198                                 }
1199                         }
1200                         break;
1201                 case Wheel:
1202                         shuttle_style_button.set_active_text (_("wheel"));
1203                         break;
1204                 }
1205
1206         } else if (p == "shuttle-units") {
1207
1208                 switch (Config->get_shuttle_units()) {
1209                 case Percentage:
1210                         shuttle_units_button.set_label("% ");
1211                         break;
1212                 case Semitones:
1213                         shuttle_units_button.set_label(_("ST"));
1214                         break;
1215                 }
1216         } else if (p == "input-auto-connect") {
1217                 map_input_auto_connect ();
1218         } else if (p == "output-auto-connect") {
1219                 map_output_auto_connect ();
1220         } else if (p == "native-file-header-format") {
1221                 map_file_header_format ();
1222         } else if (p == "native-file-data-format") {
1223                 map_file_data_format ();
1224         } else if (p == "meter-hold") {
1225                 map_meter_hold ();
1226         } else if (p == "meter-falloff") {
1227                 map_meter_falloff ();
1228         } else if (p == "video-pullup" || p == "smpte-format") {
1229                 if (session) {
1230                         primary_clock.set (session->audible_frame(), true);
1231                         secondary_clock.set (session->audible_frame(), true);
1232                 } else {
1233                         primary_clock.set (0, true);
1234                         secondary_clock.set (0, true);
1235                 }
1236         } else if (p == "use-overlap-equivalency") {
1237                 ActionManager::map_some_state ("options", "RegionEquivalentsOverlap", &RCConfiguration::get_use_overlap_equivalency);
1238         } else if (p == "primary-clock-delta-edit-cursor") {
1239                 ActionManager::map_some_state ("options",  "PrimaryClockDeltaEditCursor", &RCConfiguration::get_primary_clock_delta_edit_cursor);
1240         } else if (p == "secondary-clock-delta-edit-cursor") {
1241                 ActionManager::map_some_state ("options",  "SecondaryClockDeltaEditCursor", &RCConfiguration::get_secondary_clock_delta_edit_cursor);
1242         } else if (p == "only-copy-imported-files") {
1243                 map_only_copy_imported_files ();
1244         } else if (p == "show-track-meters") {
1245                 ActionManager::map_some_state ("options",  "ShowTrackMeters", &RCConfiguration::get_show_track_meters);
1246                 editor->toggle_meter_updating();
1247         } else if (p == "default-narrow_ms") {
1248                 ActionManager::map_some_state ("options",  "DefaultNarrowMS", &RCConfiguration::get_default_narrow_ms);
1249         } else if (p =="rubberbanding-snaps-to-grid") {
1250                 ActionManager::map_some_state ("options", "RubberbandingSnapsToGrid", &RCConfiguration::get_rubberbanding_snaps_to_grid);
1251         }
1252 }