AudioUnit work.
[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
40 void
41 ARDOUR_UI::setup_config_options ()
42 {
43         std::vector<Glib::ustring> groups;
44         groups.push_back("options");
45         groups.push_back("Editor");
46         
47         struct { 
48             char* name;
49             bool (Configuration::*method)(void) const;
50             char act_type;  //(t)oggle or (r)adio
51         } options[] = {
52                 { "ToggleTimeMaster", &Configuration::get_jack_time_master, 't' },
53                 { "StopPluginsWithTransport", &Configuration::get_plugins_stop_with_transport, 't' },
54                 { "LatchedRecordEnable", &Configuration::get_latched_record_enable, 't' },
55                 { "VerifyRemoveLastCapture", &Configuration::get_verify_remove_last_capture, 't' },
56                 { "StopRecordingOnXrun", &Configuration::get_stop_recording_on_xrun, 't' },
57                 { "StopTransportAtEndOfSession", &Configuration::get_stop_at_session_end, 't' },
58                 { "UseHardwareMonitoring", &Configuration::get_use_hardware_monitoring, 'r' },
59                 { "UseSoftwareMonitoring", &Configuration::get_use_sw_monitoring, 'r' },
60                 { "UseExternalMonitoring", &Configuration::get_use_external_monitoring, 'r' },
61                 { "MeterFalloffOff", &Configuration::get_meter_falloff_off, 'r' },
62                 { "MeterFalloffSlowest", &Configuration::get_meter_falloff_slowest, 'r' },
63                 { "MeterFalloffSlow", &Configuration::get_meter_falloff_slow, 'r' },
64                 { "MeterFalloffMedium", &Configuration::get_meter_falloff_medium, 'r' },
65                 { "MeterFalloffFast", &Configuration::get_meter_falloff_fast, 'r' },
66                 { "MeterFalloffFaster", &Configuration::get_meter_falloff_faster, 'r' },
67                 { "MeterFalloffFastest", &Configuration::get_meter_falloff_fastest, 'r' },
68                 { "MeterHoldOff", &Configuration::get_meter_hold_off, 'r' },
69                 { "MeterHoldShort", &Configuration::get_meter_hold_short, 'r' },
70                 { "MeterHoldMedium", &Configuration::get_meter_hold_medium, 'r' },
71                 { "MeterHoldLong", &Configuration::get_meter_hold_long, 'r' },
72                 { 0, 0, 0 }
73         };
74         
75         for (uint32_t n = 0; options[n].name; ++n) {
76                 for (std::vector<Glib::ustring>::iterator i = groups.begin(); i != groups.end(); i++) {
77                         Glib::RefPtr<Action> act = ActionManager::get_action (i->c_str(), options[n].name);
78                         if (act) {
79                                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
80                                 if (options[n].act_type == 't' || (options[n].act_type == 'r' && (Config->*(options[n].method))()))
81                                         tact->set_active ((Config->*(options[n].method))());
82                                 continue;
83                         }
84                 }
85         }
86 }
87
88 void
89 ARDOUR_UI::toggle_time_master ()
90 {
91         toggle_config_state ("Transport", "ToggleTimeMaster", &Configuration::set_jack_time_master);
92         if (session) {
93                 session->engine().reset_timebase ();
94         }
95 }
96
97 void
98 ARDOUR_UI::toggle_config_state (const char* group, const char* action, void (Configuration::*set)(bool))
99 {
100         Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
101         if (act) {
102                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
103                 (Config->*set) (tact->get_active());
104         }
105 }
106
107 void
108 ARDOUR_UI::toggle_session_state (const char* group, const char* action, void (Session::*set)(bool), bool (Session::*get)(void) const)
109 {
110         if (session) {
111                 Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
112                 if (act) {
113                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
114                         bool x = (session->*get)();
115
116                         if (x != tact->get_active()) {
117                                 (session->*set) (!x);
118                         }
119                 }
120         }
121 }
122
123 void
124 ARDOUR_UI::toggle_session_state (const char* group, const char* action, sigc::slot<void> theSlot)
125 {
126         if (session) {
127                 Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
128                 if (act) {
129                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
130                         if (tact->get_active()) {
131                                 theSlot ();
132                         }
133                 }
134         }
135 }
136
137 void
138 ARDOUR_UI::toggle_send_mtc ()
139 {
140         toggle_session_state ("options", "SendMTC", &Session::set_send_mtc, &Session::get_send_mtc);
141 }
142
143 void
144 ARDOUR_UI::toggle_send_mmc ()
145 {
146         toggle_session_state ("options", "SendMMC", &Session::set_send_mmc, &Session::get_send_mmc);
147 }
148
149 void
150 ARDOUR_UI::toggle_use_mmc ()
151 {
152         toggle_session_state ("options", "UseMMC", &Session::set_mmc_control, &Session::get_mmc_control);
153 }
154
155 void
156 ARDOUR_UI::toggle_use_midi_control ()
157 {
158         toggle_session_state ("options", "UseMIDIcontrol", &Session::set_midi_control, &Session::get_midi_control);
159 }
160
161 void
162 ARDOUR_UI::toggle_send_midi_feedback ()
163 {
164         toggle_session_state ("options", "SendMIDIfeedback", &Session::set_midi_feedback, &Session::get_midi_feedback);
165 }
166
167 void
168 ARDOUR_UI::toggle_AutoConnectNewTrackInputsToHardware()
169 {
170         toggle_session_state ("options", "AutoConnectNewTrackInputsToHardware", &Session::set_input_auto_connect, &Session::get_input_auto_connect);
171 }
172 void
173 ARDOUR_UI::toggle_AutoConnectNewTrackOutputsToHardware()
174 {
175         toggle_session_state ("options", "AutoConnectNewTrackOutputsToHardware", bind (mem_fun (session, &Session::set_output_auto_connect), Session::AutoConnectPhysical));
176 }
177 void
178 ARDOUR_UI::toggle_AutoConnectNewTrackOutputsToMaster()
179 {
180         toggle_session_state ("options", "AutoConnectNewTrackOutputsToHardware", bind (mem_fun (session, &Session::set_output_auto_connect), Session::AutoConnectMaster));
181 }
182 void
183 ARDOUR_UI::toggle_ManuallyConnectNewTrackOutputs()
184 {
185         toggle_session_state ("options", "AutoConnectNewTrackOutputsToHardware", bind (mem_fun (session, &Session::set_output_auto_connect), Session::AutoConnectOption (0)));
186 }
187
188 void
189 ARDOUR_UI::toggle_auto_input ()
190 {
191         toggle_session_state ("Transport", "ToggleAutoInput", &Session::set_auto_input, &Session::get_auto_input);
192 }
193
194 void
195 ARDOUR_UI::toggle_auto_play ()
196 {
197         toggle_session_state ("Transport", "ToggleAutoPlay", &Session::set_auto_play, &Session::get_auto_play);
198 }
199
200 void
201 ARDOUR_UI::toggle_auto_return ()
202 {
203         toggle_session_state ("Transport", "ToggleAutoReturn", &Session::set_auto_return, &Session::get_auto_return);
204 }
205
206 void
207 ARDOUR_UI::toggle_click ()
208 {
209         toggle_session_state ("Transport", "ToggleClick", &Session::set_clicking, &Session::get_clicking);
210 }
211
212 void
213 ARDOUR_UI::toggle_session_auto_loop ()
214 {
215         if (session) {
216                 if (session->get_auto_loop()) {
217                         if (session->transport_rolling()) {
218                                 transport_roll();
219                         } else {
220                                 session->request_auto_loop (false);
221                         }
222                 } else {
223                         session->request_auto_loop (true);
224                 }
225         }
226 }
227
228 void
229 ARDOUR_UI::toggle_punch_in ()
230 {
231         toggle_session_state ("Transport", "TogglePunchIn", &Session::set_punch_in, &Session::get_punch_in);
232 }
233
234 void
235 ARDOUR_UI::toggle_punch_out ()
236 {
237         toggle_session_state ("Transport", "TogglePunchOut", &Session::set_punch_out, &Session::get_punch_out);
238 }
239
240 void
241 ARDOUR_UI::toggle_editing_space()
242 {
243         Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMaximalEditor");
244         if (act) {
245                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
246                 if (tact->get_active()) {
247                         maximise_editing_space ();
248                 } else {
249                         restore_editing_space ();
250                 }
251         }
252 }
253
254 void
255 ARDOUR_UI::toggle_UseHardwareMonitoring()
256 {
257         Glib::RefPtr<Action> act = ActionManager::get_action ("options", "UseHardwareMonitoring");
258         if (act) {
259                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
260                 if (tact->get_active()) {
261                         Config->set_use_hardware_monitoring (true);
262                         Config->set_use_sw_monitoring (false);
263                         Config->set_use_external_monitoring (false);
264                         if (session) {
265                                 session->reset_input_monitor_state();
266                         }
267                 }
268         }
269 }
270
271 void
272 ARDOUR_UI::toggle_UseSoftwareMonitoring()
273 {
274         Glib::RefPtr<Action> act = ActionManager::get_action ("options", "UseSoftwareMonitoring");
275         if (act) {
276                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
277                 if (tact->get_active()) {
278                         Config->set_use_hardware_monitoring (false);
279                         Config->set_use_sw_monitoring (true);
280                         Config->set_use_external_monitoring (false);
281                         if (session) {
282                                 session->reset_input_monitor_state();
283                         }
284                 }
285         }
286 }
287
288 void
289 ARDOUR_UI::toggle_UseExternalMonitoring()
290 {
291         Glib::RefPtr<Action> act = ActionManager::get_action ("options", "UseExternalMonitoring");
292         if (act) {
293                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
294                 if (tact->get_active()) {
295                         Config->set_use_hardware_monitoring (false);
296                         Config->set_use_sw_monitoring (false);
297                         Config->set_use_external_monitoring (true);
298                         if (session) {
299                                 session->reset_input_monitor_state();
300                         }
301                 }
302         }
303 }
304
305 void
306 ARDOUR_UI::toggle_StopPluginsWithTransport()
307 {
308         toggle_config_state ("options", "StopPluginsWithTransport", &Configuration::set_plugins_stop_with_transport);
309 }
310
311 void
312 ARDOUR_UI::toggle_LatchedRecordEnable()
313 {
314         toggle_config_state ("options", "LatchedRecordEnable", &Configuration::set_latched_record_enable);
315 }
316
317 void
318 ARDOUR_UI::toggle_DoNotRunPluginsWhileRecording()
319 {
320         toggle_session_state ("options", "DoNotRunPluginsWhileRecording", &Session::set_do_not_record_plugins, &Session::get_do_not_record_plugins);
321 }
322
323 void
324 ARDOUR_UI::toggle_VerifyRemoveLastCapture()
325 {
326         toggle_config_state ("options", "VerifyRemoveLastCapture", &Configuration::set_verify_remove_last_capture);
327 }
328
329 void
330 ARDOUR_UI::toggle_StopRecordingOnXrun()
331 {
332         toggle_config_state ("options", "StopRecordingOnXrun", &Configuration::set_stop_recording_on_xrun);
333 }
334
335 void
336 ARDOUR_UI::toggle_StopTransportAtEndOfSession()
337 {
338         toggle_config_state ("options", "StopTransportAtEndOfSession", &Configuration::set_stop_at_session_end);
339 }
340
341 void
342 ARDOUR_UI::toggle_GainReduceFastTransport()
343 {
344         Glib::RefPtr<Action> act = ActionManager::get_action ("options", "GainReduceFastTransport");
345         if (act) {
346                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
347                 if (tact->get_active()) {
348                         Config->set_quieten_at_speed (0.251189); // -12dB reduction for ffwd or rewind
349                 } else {
350                         Config->set_quieten_at_speed (1.0); /* no change */
351                 }
352         }
353 }
354
355 void
356 ARDOUR_UI::toggle_LatchedSolo()
357 {
358         toggle_session_state ("options", "LatchedSolo", &Session::set_solo_latched, &Session::solo_latched);
359 }
360
361 void
362 ARDOUR_UI::toggle_SoloViaBus()
363 {
364         if (!session) {
365                 return;
366         }
367
368         Glib::RefPtr<Action> act = ActionManager::get_action ("options", "SoloViaBus");
369         if (act) {
370                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
371
372                 if (tact->get_active()) {
373                         session->set_solo_model (Session::SoloBus);
374                 } else {
375                         session->set_solo_model (Session::InverseMute);
376                 }
377         }
378 }
379
380 void
381 ARDOUR_UI::toggle_AutomaticallyCreateCrossfades()
382 {
383 }
384 void
385 ARDOUR_UI::toggle_UnmuteNewFullCrossfades()
386 {
387 }
388
389 void
390 ARDOUR_UI::mtc_port_changed ()
391 {
392         bool have_mtc;
393
394         if (session) {
395                 if (session->mtc_port()) {
396                         have_mtc = true;
397                 } else {
398                         have_mtc = false;
399                 }
400         } else {
401                 have_mtc = false;
402         }
403
404         if (have_mtc) {
405                 const gchar *psync_strings[] = {
406                         N_("Internal"),
407                         N_("MTC"),
408                         N_("JACK"),
409                         0
410                 };
411                 
412                 positional_sync_strings = PBD::internationalize (psync_strings);
413                 
414         } else {
415                 const gchar *psync_strings[] = {
416                         N_("Internal"),
417                         N_("JACK"),
418                         0
419                 };
420                 positional_sync_strings = PBD::internationalize (psync_strings);
421         }
422         
423         set_popdown_strings (sync_option_combo, positional_sync_strings);
424 }
425
426 void
427 ARDOUR_UI::setup_session_options ()
428 {
429         mtc_port_changed ();
430
431         session_control_changed (Session::SlaveType);
432         session_control_changed (Session::SendMTC);
433         session_control_changed (Session::SendMMC);
434         session_control_changed (Session::MMCControl);
435         session_control_changed (Session::MidiFeedback);
436         session_control_changed (Session::MidiControl);
437         session_control_changed (Session::RecordingPlugins);
438         session_control_changed (Session::CrossFadesActive);
439         session_control_changed (Session::SoloLatch);
440         session_control_changed (Session::SoloingModel);
441         session_control_changed (Session::LayeringModel);
442         session_control_changed (Session::CrossfadingModel);
443         session_control_changed (Session::PunchOut);
444         session_control_changed (Session::PunchIn);
445         session_control_changed (Session::AutoPlay);
446         session_control_changed (Session::AutoReturn);
447         session_control_changed (Session::AutoInput);
448         session_control_changed (Session::Clicking);
449         
450         session->ControlChanged.connect (mem_fun (*this, &ARDOUR_UI::queue_session_control_changed));
451 }
452
453 void
454 ARDOUR_UI::map_some_session_state (const char* group, const char* action, bool (Session::*get)() const)
455 {
456         if (!session) {
457                 return;
458         }
459
460         Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
461         if (act) {
462                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
463                 bool x = (session->*get)();
464                 if (tact->get_active() != x) {
465                         tact->set_active (x);
466                 }
467         }
468 }
469
470 void
471 ARDOUR_UI::queue_session_control_changed (Session::ControlType t)
472 {
473         ENSURE_GUI_THREAD (bind (mem_fun (*this, &ARDOUR_UI::session_control_changed), t));
474 }
475
476 void
477 ARDOUR_UI::session_control_changed (Session::ControlType t)
478 {
479         switch (t) {
480         case Session::SlaveType:
481                 switch (session->slave_source()) {
482                 case Session::None:
483                         sync_option_combo.set_active_text (_("Internal"));
484                         break;
485                 case Session::MTC:
486                         sync_option_combo.set_active_text (_("MTC"));
487                         break;
488                 case Session::JACK:
489                         sync_option_combo.set_active_text (_("JACK"));
490                         break;
491                 }
492                 
493                 break;
494
495         case Session::SendMTC:
496                 map_some_session_state ("options", "SendMTC", &Session::get_send_mtc);
497                 break;
498
499         case Session::SendMMC:
500                 map_some_session_state ("options", "SendMMC", &Session::get_send_mmc);
501                 break;
502
503         case Session::MMCControl:       
504                 map_some_session_state ("options", "UseMMC", &Session::get_mmc_control);
505                 break;
506
507         case Session::MidiFeedback:       
508                 map_some_session_state ("options", "SendMIDIfeedback", &Session::get_midi_feedback);
509                 break;
510
511         case Session::MidiControl:       
512                 map_some_session_state ("options", "UseMIDIcontrol", &Session::get_midi_control);
513                 break;
514
515         case Session::RecordingPlugins:
516                 map_some_session_state ("options", "DoNotRunPluginsWhileRecording", &Session::get_do_not_record_plugins);
517                 break;
518
519         case Session::CrossFadesActive:
520                 map_some_session_state ("options", "CrossfadesActive", &Session::get_crossfades_active);
521                 break;
522
523         case Session::SoloLatch:
524                 break;
525
526         case Session::SoloingModel:
527                 switch (session->solo_model()) {
528                 case Session::InverseMute:
529                         break;
530                 case Session::SoloBus:
531                         break;
532                 }
533                 break;
534
535         case Session::LayeringModel:
536                 break;
537
538         case Session::CrossfadingModel:
539                 break;
540
541                 
542         case Session::AutoPlay:
543                 map_some_session_state ("Transport", "ToggleAutoPlay", &Session::get_auto_play);
544                 break;
545
546         case Session::AutoLoop:
547                 break;
548
549         case Session::AutoReturn:
550                 map_some_session_state ("Transport", "ToggleAutoReturn", &Session::get_auto_return);
551                 break;
552
553         case Session::AutoInput:
554                 map_some_session_state ("Transport", "ToggleAutoInput", &Session::get_auto_input);
555                 break;
556
557         case Session::PunchOut:
558                 map_some_session_state ("Transport", "TogglePunchOut", &Session::get_punch_out);
559                 break;
560
561         case Session::PunchIn:
562                 map_some_session_state ("Transport", "TogglePunchIn", &Session::get_punch_in);
563                 break;
564
565         case Session::Clicking:
566                 map_some_session_state ("Transport", "ToggleClick", &Session::get_clicking);
567                 break;
568
569         default:
570                 // somebody else handles this 
571                 break;
572
573         }
574 }