the BIG CONFIG patch
[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     $Id$
19 */
20
21 #include <pbd/convert.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 #include "ardour_ui.h"
30 #include "actions.h"
31 #include "gui_thread.h"
32
33 #include "i18n.h"
34
35 using namespace Gtk;
36 using namespace Gtkmm2ext;
37 using namespace ARDOUR;
38 using namespace PBD;
39 using namespace sigc;
40
41 void
42 ARDOUR_UI::toggle_config_state (const char* group, const char* action, bool (Configuration::*set)(bool), bool (Configuration::*get)(void) const)
43 {
44         Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
45         if (act) {
46                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
47
48                 if (tact) {
49                         bool x = (Config->*get)();
50                         
51                         if (x != tact->get_active()) {
52                                 (Config->*set) (!x);
53                         }
54                 }
55         }
56 }
57
58 void
59 ARDOUR_UI::toggle_config_state (const char* group, const char* action, sigc::slot<void> theSlot)
60 {
61         if (session) {
62                 Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
63                 if (act) {
64                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
65                         if (tact->get_active()) {
66                                 theSlot ();
67                         }
68                 }
69         }
70 }
71
72 void
73 ARDOUR_UI::toggle_time_master ()
74 {
75         toggle_config_state ("Transport", "ToggleTimeMaster", &Configuration::set_jack_time_master, &Configuration::get_jack_time_master);
76         if (session) {
77                 session->engine().reset_timebase ();
78         }
79 }
80
81 void
82 ARDOUR_UI::toggle_send_mtc ()
83 {
84         toggle_config_state ("options", "SendMTC", &Configuration::set_send_mtc, &Configuration::get_send_mtc);
85 }
86
87 void
88 ARDOUR_UI::toggle_send_mmc ()
89 {
90         toggle_config_state ("options", "SendMMC", &Configuration::set_send_mmc, &Configuration::get_send_mmc);
91 }
92
93 void
94 ARDOUR_UI::toggle_use_mmc ()
95 {
96         toggle_config_state ("options", "UseMMC", &Configuration::set_mmc_control, &Configuration::get_mmc_control);
97 }
98
99 void
100 ARDOUR_UI::toggle_use_midi_control ()
101 {
102         toggle_config_state ("options", "UseMIDIcontrol", &Configuration::set_midi_control, &Configuration::get_midi_control);
103 }
104
105 void
106 ARDOUR_UI::toggle_send_midi_feedback ()
107 {
108         toggle_config_state ("options", "SendMIDIfeedback", &Configuration::set_midi_feedback, &Configuration::get_midi_feedback);
109 }
110
111 void
112 ARDOUR_UI::toggle_AutoConnectNewTrackInputsToHardware()
113 {
114         toggle_config_state ("options", "AutoConnectNewTrackInputsToHardware", hide_return (bind (mem_fun (*Config, &Configuration::set_input_auto_connect), AutoConnectPhysical)));
115 }
116 void
117 ARDOUR_UI::toggle_AutoConnectNewTrackOutputsToHardware()
118 {
119         toggle_config_state ("options", "AutoConnectNewTrackOutputsToHardware", hide_return (bind (mem_fun (*Config, &Configuration::set_output_auto_connect), AutoConnectPhysical)));
120 }
121 void
122 ARDOUR_UI::toggle_AutoConnectNewTrackOutputsToMaster()
123 {
124         toggle_config_state ("options", "AutoConnectNewTrackOutputsToHardware", hide_return (bind (mem_fun (*Config, &Configuration::set_output_auto_connect), AutoConnectMaster)));
125 }
126 void
127 ARDOUR_UI::toggle_ManuallyConnectNewTrackOutputs()
128 {
129         toggle_config_state ("options", "AutoConnectNewTrackOutputsToHardware", hide_return (bind (mem_fun (*Config, &Configuration::set_output_auto_connect), AutoConnectOption (0))));
130 }
131
132 void
133 ARDOUR_UI::toggle_auto_input ()
134 {
135         toggle_config_state ("Transport", "ToggleAutoInput", &Configuration::set_auto_input, &Configuration::get_auto_input);
136 }
137
138 void
139 ARDOUR_UI::toggle_auto_play ()
140 {
141         toggle_config_state ("Transport", "ToggleAutoPlay", &Configuration::set_auto_play, &Configuration::get_auto_play);
142 }
143
144 void
145 ARDOUR_UI::toggle_auto_return ()
146 {
147         toggle_config_state ("Transport", "ToggleAutoReturn", &Configuration::set_auto_return, &Configuration::get_auto_return);
148 }
149
150 void
151 ARDOUR_UI::toggle_click ()
152 {
153         toggle_config_state ("Transport", "ToggleClick", &Configuration::set_clicking, &Configuration::get_clicking);
154 }
155
156 void
157 ARDOUR_UI::toggle_session_auto_loop ()
158 {
159         if (session) {
160                 if (Config->get_auto_loop()) {
161                         if (session->transport_rolling()) {
162                                 transport_roll();
163                         } else {
164                                 session->request_play_loop (false);
165                         }
166                 } else {
167                         session->request_play_loop (true);
168                 }
169         }
170 }
171
172 void
173 ARDOUR_UI::toggle_punch_in ()
174 {
175         toggle_config_state ("Transport", "TogglePunchIn", &Configuration::set_punch_in, &Configuration::get_punch_in);
176 }
177
178 void
179 ARDOUR_UI::toggle_punch_out ()
180 {
181         toggle_config_state ("Transport", "TogglePunchOut", &Configuration::set_punch_out, &Configuration::get_punch_out);
182 }
183
184 void
185 ARDOUR_UI::toggle_video_sync()
186 {
187         Glib::RefPtr<Action> act = ActionManager::get_action ("Transport", "ToggleVideoSync");
188         if (act) {
189                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
190                 Config->set_use_video_sync (tact->get_active());
191         }
192 }
193
194 void
195 ARDOUR_UI::toggle_editing_space()
196 {
197         Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMaximalEditor");
198         if (act) {
199                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
200                 if (tact->get_active()) {
201                         maximise_editing_space ();
202                 } else {
203                         restore_editing_space ();
204                 }
205         }
206 }
207
208 void
209 ARDOUR_UI::toggle_UseHardwareMonitoring()
210 {
211         Glib::RefPtr<Action> act = ActionManager::get_action ("options", "UseHardwareMonitoring");
212         if (act) {
213                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
214                 if (tact->get_active()) {
215                         Config->set_use_hardware_monitoring (true);
216                         Config->set_use_sw_monitoring (false);
217                         Config->set_use_external_monitoring (false);
218                         if (session) {
219                                 session->reset_input_monitor_state();
220                         }
221                 }
222         }
223 }
224
225 void
226 ARDOUR_UI::toggle_UseSoftwareMonitoring()
227 {
228         Glib::RefPtr<Action> act = ActionManager::get_action ("options", "UseSoftwareMonitoring");
229         if (act) {
230                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
231                 if (tact->get_active()) {
232                         Config->set_use_hardware_monitoring (false);
233                         Config->set_use_sw_monitoring (true);
234                         Config->set_use_external_monitoring (false);
235                         if (session) {
236                                 session->reset_input_monitor_state();
237                         }
238                 }
239         }
240 }
241
242 void
243 ARDOUR_UI::toggle_UseExternalMonitoring()
244 {
245         Glib::RefPtr<Action> act = ActionManager::get_action ("options", "UseExternalMonitoring");
246         if (act) {
247                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
248                 if (tact->get_active()) {
249                         Config->set_use_hardware_monitoring (false);
250                         Config->set_use_sw_monitoring (false);
251                         Config->set_use_external_monitoring (true);
252                         if (session) {
253                                 session->reset_input_monitor_state();
254                         }
255                 }
256         }
257 }
258
259 void
260 ARDOUR_UI::toggle_StopPluginsWithTransport()
261 {
262         toggle_config_state ("options", "StopPluginsWithTransport", &Configuration::set_plugins_stop_with_transport, &Configuration::get_plugins_stop_with_transport);
263 }
264
265 void
266 ARDOUR_UI::toggle_LatchedRecordEnable()
267 {
268         toggle_config_state ("options", "LatchedRecordEnable", &Configuration::set_latched_record_enable, &Configuration::get_latched_record_enable);
269 }
270
271 void
272 ARDOUR_UI::toggle_DoNotRunPluginsWhileRecording()
273 {
274         toggle_config_state ("options", "DoNotRunPluginsWhileRecording", &Configuration::set_do_not_record_plugins, &Configuration::get_do_not_record_plugins);
275 }
276
277 void
278 ARDOUR_UI::toggle_VerifyRemoveLastCapture()
279 {
280         toggle_config_state ("options", "VerifyRemoveLastCapture", &Configuration::set_verify_remove_last_capture, &Configuration::get_verify_remove_last_capture);
281 }
282
283 void
284 ARDOUR_UI::toggle_StopRecordingOnXrun()
285 {
286         toggle_config_state ("options", "StopRecordingOnXrun", &Configuration::set_stop_recording_on_xrun, &Configuration::get_stop_recording_on_xrun);
287 }
288
289 void
290 ARDOUR_UI::toggle_StopTransportAtEndOfSession()
291 {
292         toggle_config_state ("options", "StopTransportAtEndOfSession", &Configuration::set_stop_at_session_end, &Configuration::get_stop_at_session_end);
293 }
294
295 void
296 ARDOUR_UI::toggle_GainReduceFastTransport()
297 {
298         Glib::RefPtr<Action> act = ActionManager::get_action ("options", "GainReduceFastTransport");
299         if (act) {
300                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
301                 if (tact->get_active()) {
302                         Config->set_quieten_at_speed (0.251189); // -12dB reduction for ffwd or rewind
303                 } else {
304                         Config->set_quieten_at_speed (1.0); /* no change */
305                 }
306         }
307 }
308
309 void
310 ARDOUR_UI::toggle_LatchedSolo()
311 {
312         toggle_config_state ("options", "LatchedSolo", &Configuration::set_solo_latched, &Configuration::get_solo_latched);
313 }
314
315 void
316 ARDOUR_UI::toggle_SoloViaBus()
317 {
318         if (!session) {
319                 return;
320         }
321
322         Glib::RefPtr<Action> act = ActionManager::get_action ("options", "SoloViaBus");
323         if (act) {
324                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
325
326                 if (tact->get_active()) {
327                         Config->set_solo_model (SoloBus);
328                 } else {
329                         Config->set_solo_model (InverseMute);
330                 }
331         }
332 }
333
334 void
335 ARDOUR_UI::toggle_AutomaticallyCreateCrossfades()
336 {
337 }
338
339 void
340 ARDOUR_UI::toggle_UnmuteNewFullCrossfades()
341 {
342 }
343
344 void
345 ARDOUR_UI::mtc_port_changed ()
346 {
347         bool have_mtc;
348
349         if (session) {
350                 if (session->mtc_port()) {
351                         have_mtc = true;
352                 } else {
353                         have_mtc = false;
354                 }
355         } else {
356                 have_mtc = false;
357         }
358
359         positional_sync_strings.clear ();
360         positional_sync_strings.push_back (slave_source_to_string (None));
361         if (have_mtc) {
362                 positional_sync_strings.push_back (slave_source_to_string (MTC));
363         }
364         positional_sync_strings.push_back (slave_source_to_string (JACK));
365         
366         set_popdown_strings (sync_option_combo, positional_sync_strings);
367 }
368
369 void
370 ARDOUR_UI::setup_session_options ()
371 {
372         mtc_port_changed ();
373
374         Config->ParameterChanged.connect (mem_fun (*this, &ARDOUR_UI::parameter_changed));
375 }
376
377 void
378 ARDOUR_UI::map_some_state (const char* group, const char* action, bool (Configuration::*get)() const)
379 {
380         Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
381         if (act) {
382                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
383
384                 if (tact) {
385                         bool x = (Config->*get)();
386                         
387                         if (tact->get_active() != x) {
388                                 tact->set_active (x);
389                         }
390                 }
391         }
392 }
393
394 void
395 ARDOUR_UI::parameter_changed (const char* parameter_name)
396 {
397 #define PARAM_IS(x) (!strcmp (parameter_name, (x)))
398
399         if (PARAM_IS ("slave-source")) {
400
401                 sync_option_combo.set_active_text (slave_source_to_string (Config->get_slave_source()));
402
403         } else if (PARAM_IS ("send-mtc")) {
404
405                 map_some_state ("options", "SendMTC", &Configuration::get_send_mtc);
406
407         } else if (PARAM_IS ("send-mmc")) {
408
409                 map_some_state ("options", "SendMMC", &Configuration::get_send_mmc);
410
411         } else if (PARAM_IS ("mmc-control")) {
412                 map_some_state ("options", "UseMMC", &Configuration::get_mmc_control);
413         } else if (PARAM_IS ("midi-feedback")) {
414                 map_some_state ("options", "SendMIDIfeedback", &Configuration::get_midi_feedback);
415         } else if (PARAM_IS ("midi-control")) {
416                 map_some_state ("options", "UseMIDIcontrol", &Configuration::get_midi_control);
417         } else if (PARAM_IS ("do-not-record-plugins")) {
418                 map_some_state ("options", "DoNotRunPluginsWhileRecording", &Configuration::get_do_not_record_plugins);
419         } else if (PARAM_IS ("crossfades-active")) {
420                 map_some_state ("options", "CrossfadesActive", &Configuration::get_crossfades_active);
421         } else if (PARAM_IS ("latched-record-enable")) {
422                 map_some_state ("options", "LatchedRecordEnable", &Configuration::get_latched_record_enable);
423         } else if (PARAM_IS ("solo-latch")) {
424                 map_some_state ("options", "LatchedSolo", &Configuration::get_solo_latched);
425         } else if (PARAM_IS ("solo-model")) {
426         } else if (PARAM_IS ("layer-model")) {
427         } else if (PARAM_IS ("crossfade-model")) {
428         } else if (PARAM_IS ("auto-play")) {
429                 map_some_state ("Transport", "ToggleAutoPlay", &Configuration::get_auto_play);
430         } else if (PARAM_IS ("auto-loop")) {
431                 map_some_state ("Transport", "Loop", &Configuration::get_auto_loop);
432         } else if (PARAM_IS ("auto-return")) {
433                 map_some_state ("Transport", "ToggleAutoReturn", &Configuration::get_auto_return);
434         } else if (PARAM_IS ("auto-input")) {
435                 map_some_state ("Transport", "ToggleAutoInput", &Configuration::get_auto_input);
436         } else if (PARAM_IS ("punch-out")) {
437                 map_some_state ("Transport", "TogglePunchOut", &Configuration::get_punch_out);
438         } else if (PARAM_IS ("punch-in")) {
439                 map_some_state ("Transport", "TogglePunchIn", &Configuration::get_punch_in);
440         } else if (PARAM_IS ("clicking")) {
441                 map_some_state ("Transport", "ToggleClick", &Configuration::get_clicking);
442         } else if (PARAM_IS ("jack-time-master")) {
443                 map_some_state ("Transport",  "ToggleTimeMaster", &Configuration::get_jack_time_master);
444         } else if (PARAM_IS ("plugins-stop-with-transport")) {
445                 map_some_state ("options",  "StopPluginsWithTransport", &Configuration::get_plugins_stop_with_transport);
446         } else if (PARAM_IS ("latched-record-enable")) {
447                 map_some_state ("options", "LatchedRecordEnable", &Configuration::get_latched_record_enable);
448         } else if (PARAM_IS ("verify-remove-last-capture")) {
449                 map_some_state ("options",  "VerifyRemoveLastCapture", &Configuration::get_verify_remove_last_capture);
450         } else if (PARAM_IS ("stop-recording-on-xrun")) {
451                 map_some_state ("options",  "StopRecordingOnXrun", &Configuration::get_stop_recording_on_xrun);
452         } else if (PARAM_IS ("stop-at-session-end")) {
453                 map_some_state ("options",  "StopTransportAtEndOfSession", &Configuration::get_stop_at_session_end);
454         } else if (PARAM_IS ("use-hardware-monitoring")) {
455                 map_some_state ("options",  "UseHardwareMonitoring", &Configuration::get_use_hardware_monitoring);
456         } else if (PARAM_IS ("use-sw-monitoring")) {
457                 map_some_state ("options",  "UseSoftwareMonitoring", &Configuration::get_use_sw_monitoring);
458         } else if (PARAM_IS ("use-external-monitoring")) {
459                 map_some_state ("options",  "UseExternalMonitoring", &Configuration::get_use_external_monitoring);
460         } else if (PARAM_IS ("use-video-sync")) {
461                 map_some_state ("Transport",  "ToggleVideoSync", &Configuration::get_use_video_sync);
462         } else if (PARAM_IS ("quieten-at-speed")) {
463                 map_some_state ("options",  "GainReduceFastTransport", &Configuration::get_quieten_at_speed);
464         } else if (PARAM_IS ("shuttle-behaviour")) {
465
466                 switch (Config->get_shuttle_behaviour ()) {
467                 case Sprung:
468                         shuttle_style_button.set_active_text (_("sprung"));
469                         shuttle_fract = 0.0;
470                         shuttle_box.queue_draw ();
471                         if (session) {
472                                 if (session->transport_rolling()) {
473                                         shuttle_fract = SHUTTLE_FRACT_SPEED1;
474                                         session->request_transport_speed (1.0);
475                                 }
476                         }
477                         break;
478                 case Wheel:
479                         shuttle_style_button.set_active_text (_("wheel"));
480                         break;
481                 }
482
483         } else if (PARAM_IS ("shuttle-units")) {
484                 
485                 switch (Config->get_shuttle_units()) {
486                 case Percentage:
487                         shuttle_units_button.set_label("% ");
488                         break;
489                 case Semitones:
490                         shuttle_units_button.set_label(_("ST"));
491                         break;
492                 }
493         }
494         
495 #undef PARAM_IS
496 }