5a15bd7de3b9b5c8b42a580b7f5e6d97decec036
[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 <gtkmm2ext/utils.h>
22
23 #include <ardour/configuration.h>
24 #include <ardour/session.h>
25 #include <ardour/audioengine.h>
26
27 #include "ardour_ui.h"
28 #include "actions.h"
29 #include "gui_thread.h"
30
31 #include "i18n.h"
32
33 using namespace Gtk;
34 using namespace Gtkmm2ext;
35 using namespace ARDOUR;
36
37 void
38 ARDOUR_UI::toggle_time_master ()
39 {
40         toggle_config_state ("Transport", "ToggleTimeMaster", &Configuration::set_jack_time_master);
41         if (session) {
42                 session->engine().reset_timebase ();
43         }
44 }
45
46 void
47 ARDOUR_UI::toggle_config_state (const char* group, const char* action, void (Configuration::*set)(bool))
48 {
49         Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
50         if (act) {
51                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
52                 (Config->*set) (tact->get_active());
53         }
54 }
55
56 void
57 ARDOUR_UI::toggle_session_state (const char* group, const char* action, void (Session::*set)(bool), bool (Session::*get)(void) const)
58 {
59         if (session) {
60                 Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
61                 if (act) {
62                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
63                         bool x = (session->*get)();
64
65                         if (x != tact->get_active()) {
66                                 (session->*set) (!x);
67                         }
68                 }
69         }
70 }
71
72 void
73 ARDOUR_UI::toggle_session_state (const char* group, const char* action, sigc::slot<void> theSlot)
74 {
75         if (session) {
76                 Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
77                 if (act) {
78                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
79                         if (tact->get_active()) {
80                                 theSlot ();
81                         }
82                 }
83         }
84 }
85
86 void
87 ARDOUR_UI::toggle_send_mtc ()
88 {
89         toggle_session_state ("options", "SendMTC", &Session::set_send_mtc, &Session::get_send_mtc);
90 }
91
92 void
93 ARDOUR_UI::toggle_send_mmc ()
94 {
95         toggle_session_state ("options", "SendMMC", &Session::set_send_mmc, &Session::get_send_mmc);
96 }
97
98 void
99 ARDOUR_UI::toggle_use_mmc ()
100 {
101         toggle_session_state ("options", "UseMMC", &Session::set_mmc_control, &Session::get_mmc_control);
102 }
103
104 void
105 ARDOUR_UI::toggle_use_midi_control ()
106 {
107         toggle_session_state ("options", "UseMIDIcontrol", &Session::set_midi_control, &Session::get_midi_control);
108 }
109
110 void
111 ARDOUR_UI::toggle_send_midi_feedback ()
112 {
113         toggle_session_state ("options", "SendMIDIfeedback", &Session::set_midi_feedback, &Session::get_midi_feedback);
114 }
115
116 void
117 ARDOUR_UI::toggle_AutoConnectNewTrackInputsToHardware()
118 {
119         toggle_session_state ("options", "AutoConnectNewTrackInputsToHardware", &Session::set_input_auto_connect, &Session::get_input_auto_connect);
120 }
121 void
122 ARDOUR_UI::toggle_AutoConnectNewTrackOutputsToHardware()
123 {
124         toggle_session_state ("options", "AutoConnectNewTrackOutputsToHardware", bind (mem_fun (session, &Session::set_output_auto_connect), Session::AutoConnectPhysical));
125 }
126 void
127 ARDOUR_UI::toggle_AutoConnectNewTrackOutputsToMaster()
128 {
129         toggle_session_state ("options", "AutoConnectNewTrackOutputsToHardware", bind (mem_fun (session, &Session::set_output_auto_connect), Session::AutoConnectMaster));
130 }
131 void
132 ARDOUR_UI::toggle_ManuallyConnectNewTrackOutputs()
133 {
134         toggle_session_state ("options", "AutoConnectNewTrackOutputsToHardware", bind (mem_fun (session, &Session::set_output_auto_connect), Session::AutoConnectOption (0)));
135 }
136
137 void
138 ARDOUR_UI::toggle_auto_input ()
139 {
140         toggle_session_state ("Transport", "ToggleAutoInput", &Session::set_auto_input, &Session::get_auto_input);
141 }
142
143 void
144 ARDOUR_UI::toggle_auto_play ()
145 {
146         toggle_session_state ("Transport", "ToggleAutoPlay", &Session::set_auto_play, &Session::get_auto_play);
147 }
148
149 void
150 ARDOUR_UI::toggle_auto_return ()
151 {
152         toggle_session_state ("Transport", "ToggleAutoReturn", &Session::set_auto_return, &Session::get_auto_return);
153 }
154
155 void
156 ARDOUR_UI::toggle_click ()
157 {
158         toggle_session_state ("Transport", "ToggleClick", &Session::set_clicking, &Session::get_clicking);
159 }
160
161 void
162 ARDOUR_UI::toggle_session_auto_loop ()
163 {
164         if (session) {
165                 if (session->get_auto_loop()) {
166                         if (session->transport_rolling()) {
167                                 transport_roll();
168                         } else {
169                                 session->request_auto_loop (false);
170                         }
171                 } else {
172                         session->request_auto_loop (true);
173                 }
174         }
175 }
176
177 void
178 ARDOUR_UI::toggle_punch_in ()
179 {
180         toggle_session_state ("Transport", "TogglePunchIn", &Session::set_punch_in, &Session::get_punch_in);
181 }
182
183 void
184 ARDOUR_UI::toggle_punch_out ()
185 {
186         toggle_session_state ("Transport", "TogglePunchOut", &Session::set_punch_out, &Session::get_punch_out);
187 }
188
189 void
190 ARDOUR_UI::toggle_UseHardwareMonitoring()
191 {
192         Glib::RefPtr<Action> act = ActionManager::get_action ("options", "UseSoftwareMonitoring");
193         if (act) {
194                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
195                 if (tact->get_active()) {
196                         Config->set_use_hardware_monitoring (true);
197                         Config->set_use_sw_monitoring (false);
198                         if (session) {
199                                 session->reset_input_monitor_state();
200                         }
201                 }
202         }
203 }
204
205 void
206 ARDOUR_UI::toggle_UseSoftwareMonitoring()
207 {
208         Glib::RefPtr<Action> act = ActionManager::get_action ("options", "UseSoftwareMonitoring");
209         if (act) {
210                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
211                 if (tact->get_active()) {
212                         Config->set_use_hardware_monitoring (false);
213                         Config->set_use_sw_monitoring (true);
214                         if (session) {
215                                 session->reset_input_monitor_state();
216                         }
217                 }
218         }
219 }
220
221 void
222 ARDOUR_UI::toggle_UseExternalMonitoring()
223 {
224         Glib::RefPtr<Action> act = ActionManager::get_action ("options", "UseExternalMonitoring");
225         if (act) {
226                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
227                 if (tact->get_active()) {
228                         Config->set_use_hardware_monitoring (false);
229                         Config->set_use_sw_monitoring (false);
230                         if (session) {
231                                 session->reset_input_monitor_state();
232                         }
233                 }
234         }
235 }
236
237 void
238 ARDOUR_UI::toggle_StopPluginsWithTransport()
239 {
240         toggle_config_state ("options", "StopPluginsWithTransport", &Configuration::set_plugins_stop_with_transport);
241 }
242 void
243 ARDOUR_UI::toggle_DoNotRunPluginsWhileRecording()
244 {
245         toggle_session_state ("options", "DoNotRunPluginsWhileRecording", &Session::set_do_not_record_plugins, &Session::get_do_not_record_plugins);
246 }
247
248 void
249 ARDOUR_UI::toggle_VerifyRemoveLastCapture()
250 {
251         toggle_config_state ("options", "VerifyRemoveLastCapture", &Configuration::set_verify_remove_last_capture);
252 }
253
254 void
255 ARDOUR_UI::toggle_StopRecordingOnXrun()
256 {
257         toggle_config_state ("options", "StopRecordingOnXrun", &Configuration::set_stop_recording_on_xrun);
258 }
259
260 void
261 ARDOUR_UI::toggle_StopTransportAtEndOfSession()
262 {
263         toggle_config_state ("options", "StopTransportAtEndOfSession", &Configuration::set_stop_at_session_end);
264 }
265
266 void
267 ARDOUR_UI::toggle_GainReduceFastTransport()
268 {
269         Glib::RefPtr<Action> act = ActionManager::get_action ("options", "GainReduceFastTransport");
270         if (act) {
271                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
272                 if (tact->get_active()) {
273                         Config->set_quieten_at_speed (0.251189); // -12dB reduction for ffwd or rewind
274                 } else {
275                         Config->set_quieten_at_speed (1.0); /* no change */
276                 }
277         }
278 }
279
280 void
281 ARDOUR_UI::toggle_LatchedSolo()
282 {
283         toggle_session_state ("options", "LatchedSolo", &Session::set_solo_latched, &Session::solo_latched);
284 }
285
286 void
287 ARDOUR_UI::toggle_SoloViaBus()
288 {
289         if (!session) {
290                 return;
291         }
292
293         Glib::RefPtr<Action> act = ActionManager::get_action ("options", "SoloViaBus");
294         if (act) {
295                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
296
297                 if (tact->get_active()) {
298                         session->set_solo_model (Session::SoloBus);
299                 } else {
300                         session->set_solo_model (Session::InverseMute);
301                 }
302         }
303 }
304
305 void
306 ARDOUR_UI::toggle_AutomaticallyCreateCrossfades()
307 {
308 }
309 void
310 ARDOUR_UI::toggle_UnmuteNewFullCrossfades()
311 {
312 }
313
314 void
315 ARDOUR_UI::mtc_port_changed ()
316 {
317         bool have_mtc;
318
319         if (session) {
320                 if (session->mtc_port()) {
321                         have_mtc = true;
322                 } else {
323                         have_mtc = false;
324                 }
325         } else {
326                 have_mtc = false;
327         }
328
329         if (have_mtc) {
330                 const gchar *psync_strings[] = {
331                         N_("Internal"),
332                         N_("MTC"),
333                         N_("JACK"),
334                         0
335                 };
336                 
337                 positional_sync_strings = internationalize (psync_strings);
338                 
339         } else {
340                 const gchar *psync_strings[] = {
341                         N_("Internal"),
342                         N_("JACK"),
343                         0
344                 };
345                 positional_sync_strings = internationalize (psync_strings);
346         }
347         
348         set_popdown_strings (sync_option_combo, positional_sync_strings);
349 }
350
351 void
352 ARDOUR_UI::setup_options ()
353 {
354         mtc_port_changed ();
355
356         session_control_changed (Session::SlaveType);
357         session_control_changed (Session::SendMTC);
358         session_control_changed (Session::SendMMC);
359         session_control_changed (Session::MMCControl);
360         session_control_changed (Session::MidiFeedback);
361         session_control_changed (Session::MidiControl);
362         session_control_changed (Session::RecordingPlugins);
363         session_control_changed (Session::CrossFadesActive);
364         session_control_changed (Session::SoloLatch);
365         session_control_changed (Session::SoloingModel);
366         session_control_changed (Session::LayeringModel);
367         session_control_changed (Session::CrossfadingModel);
368         session_control_changed (Session::PunchOut);
369         session_control_changed (Session::PunchIn);
370         session_control_changed (Session::AutoPlay);
371         session_control_changed (Session::AutoReturn);
372         session_control_changed (Session::AutoInput);
373         session_control_changed (Session::Clicking);
374
375         session->ControlChanged.connect (mem_fun (*this, &ARDOUR_UI::queue_session_control_changed));
376 }
377
378 void
379 ARDOUR_UI::map_some_session_state (const char* group, const char* action, bool (Session::*get)() const)
380 {
381         if (!session) {
382                 return;
383         }
384
385         Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
386         if (act) {
387                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
388                 bool x = (session->*get)();
389                 if (tact->get_active() != x) {
390                         tact->set_active (x);
391                 }
392         }
393 }
394
395 void
396 ARDOUR_UI::queue_session_control_changed (Session::ControlType t)
397 {
398         ENSURE_GUI_THREAD (bind (mem_fun (*this, &ARDOUR_UI::session_control_changed), t));
399 }
400
401 void
402 ARDOUR_UI::session_control_changed (Session::ControlType t)
403 {
404         switch (t) {
405         case Session::SlaveType:
406                 switch (session->slave_source()) {
407                 case Session::None:
408                         sync_option_combo.set_active_text (_("Internal"));
409                         break;
410                 case Session::MTC:
411                         sync_option_combo.set_active_text (_("MTC"));
412                         break;
413                 case Session::JACK:
414                         sync_option_combo.set_active_text (_("JACK"));
415                         break;
416                 }
417                 
418                 break;
419
420         case Session::SendMTC:
421                 map_some_session_state ("options", "SendMTC", &Session::get_send_mtc);
422                 break;
423
424         case Session::SendMMC:
425                 map_some_session_state ("options", "SendMMC", &Session::get_send_mmc);
426                 break;
427
428         case Session::MMCControl:       
429                 map_some_session_state ("options", "UseMMC", &Session::get_mmc_control);
430                 break;
431
432         case Session::MidiFeedback:       
433                 map_some_session_state ("options", "SendMIDIfeedback", &Session::get_midi_feedback);
434                 break;
435
436         case Session::MidiControl:       
437                 map_some_session_state ("options", "UseMIDIcontrol", &Session::get_midi_control);
438                 break;
439
440         case Session::RecordingPlugins:
441                 map_some_session_state ("options", "DoNotRunPluginsWhileRecording", &Session::get_do_not_record_plugins);
442                 break;
443
444         case Session::CrossFadesActive:
445                 map_some_session_state ("options", "CrossfadesActive", &Session::get_crossfades_active);
446                 break;
447
448         case Session::SoloLatch:
449                 break;
450
451         case Session::SoloingModel:
452                 switch (session->solo_model()) {
453                 case Session::InverseMute:
454                         break;
455                 case Session::SoloBus:
456                         break;
457                 }
458                 break;
459
460         case Session::LayeringModel:
461                 break;
462
463         case Session::CrossfadingModel:
464                 break;
465
466                 
467         case Session::AutoPlay:
468                 map_some_session_state ("Transport", "ToggleAutoPlay", &Session::get_auto_play);
469                 break;
470
471         case Session::AutoLoop:
472                 break;
473
474         case Session::AutoReturn:
475                 map_some_session_state ("Transport", "ToggleAutoReturn", &Session::get_auto_return);
476                 break;
477
478         case Session::AutoInput:
479                 map_some_session_state ("Transport", "ToggleAutoInput", &Session::get_auto_input);
480                 break;
481
482         case Session::PunchOut:
483                 map_some_session_state ("Transport", "TogglePunchOut", &Session::get_punch_out);
484                 break;
485
486         case Session::PunchIn:
487                 map_some_session_state ("Transport", "TogglePunchIn", &Session::get_punch_in);
488                 break;
489
490         case Session::Clicking:
491                 map_some_session_state ("Transport", "ToggleClick", &Session::get_clicking);
492                 break;
493
494         default:
495                 // somebody else handles this 
496                 break;
497
498         }
499 }