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