more build script cleanups
[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 #ifdef WAF_BUILD
21 #include "gtk2ardour-config.h"
22 #endif
23
24 #include "pbd/convert.h"
25 #include "pbd/stacktrace.h"
26
27 #include <gtkmm2ext/utils.h>
28
29 #include "ardour/rc_configuration.h"
30 #include "ardour/session.h"
31
32 #ifdef HAVE_LIBLO
33 #include "ardour/osc.h"
34 #endif
35
36 #include "audio_clock.h"
37 #include "ardour_ui.h"
38 #include "actions.h"
39 #include "gui_thread.h"
40 #include "public_editor.h"
41
42 #include "i18n.h"
43
44 using namespace Gtk;
45 using namespace Gtkmm2ext;
46 using namespace ARDOUR;
47 using namespace PBD;
48
49 void
50 ARDOUR_UI::toggle_keep_tearoffs ()
51 {
52         ActionManager::toggle_config_state ("Common", "KeepTearoffs", &RCConfiguration::set_keep_tearoffs, &RCConfiguration::get_keep_tearoffs);
53
54         ARDOUR_UI::toggle_editing_space ();
55 }
56
57 void
58 ARDOUR_UI::toggle_external_sync()
59 {
60         if (_session) {
61                 if (_session->config.get_video_pullup() != 0.0f) {
62                         if (_session->config.get_sync_source() == JACK) {
63                                 MessageDialog msg (
64                                         _("It is not possible to use JACK as the the sync source\n\
65 when the pull up/down setting is non-zero."));
66                                 msg.run ();
67                                 return;
68                         }
69                 }
70
71                 ActionManager::toggle_config_state_foo ("Transport", "ToggleExternalSync", sigc::mem_fun (_session->config, &SessionConfiguration::set_external_sync), sigc::mem_fun (_session->config, &SessionConfiguration::get_external_sync));
72         }
73 }
74
75 void
76 ARDOUR_UI::toggle_time_master ()
77 {
78         ActionManager::toggle_config_state_foo ("Transport", "ToggleTimeMaster", sigc::mem_fun (_session->config, &SessionConfiguration::set_jack_time_master), sigc::mem_fun (_session->config, &SessionConfiguration::get_jack_time_master));
79 }
80
81 void
82 ARDOUR_UI::toggle_send_mtc ()
83 {
84         ActionManager::toggle_config_state ("options", "SendMTC", &RCConfiguration::set_send_mtc, &RCConfiguration::get_send_mtc);
85 }
86
87 void
88 ARDOUR_UI::toggle_send_mmc ()
89 {
90         ActionManager::toggle_config_state ("options", "SendMMC", &RCConfiguration::set_send_mmc, &RCConfiguration::get_send_mmc);
91 }
92
93 void
94 ARDOUR_UI::toggle_send_midi_clock ()
95 {
96         ActionManager::toggle_config_state ("options", "SendMidiClock", &RCConfiguration::set_send_midi_clock, &RCConfiguration::get_send_midi_clock);
97 }
98
99 void
100 ARDOUR_UI::toggle_use_mmc ()
101 {
102         ActionManager::toggle_config_state ("options", "UseMMC", &RCConfiguration::set_mmc_control, &RCConfiguration::get_mmc_control);
103 }
104
105 void
106 ARDOUR_UI::toggle_send_midi_feedback ()
107 {
108         ActionManager::toggle_config_state ("options", "SendMIDIfeedback", &RCConfiguration::set_midi_feedback, &RCConfiguration::get_midi_feedback);
109 }
110
111 void
112 ARDOUR_UI::toggle_auto_input ()
113 {
114         ActionManager::toggle_config_state_foo ("Transport", "ToggleAutoInput", sigc::mem_fun (_session->config, &SessionConfiguration::set_auto_input), sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_input));
115 }
116
117 void
118 ARDOUR_UI::toggle_auto_play ()
119 {
120         ActionManager::toggle_config_state_foo ("Transport", "ToggleAutoPlay", sigc::mem_fun (_session->config, &SessionConfiguration::set_auto_play), sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_play));
121 }
122
123 void
124 ARDOUR_UI::toggle_auto_return ()
125 {
126         ActionManager::toggle_config_state_foo ("Transport", "ToggleAutoReturn", sigc::mem_fun (_session->config, &SessionConfiguration::set_auto_return), sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_return));
127 }
128
129 void
130 ARDOUR_UI::toggle_click ()
131 {
132         ActionManager::toggle_config_state ("Transport", "ToggleClick", &RCConfiguration::set_clicking, &RCConfiguration::get_clicking);
133 }
134
135 void
136 ARDOUR_UI::unset_dual_punch ()
137 {
138         Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
139
140         if (action) {
141                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
142                 if (tact) {
143                         ignore_dual_punch = true;
144                         tact->set_active (false);
145                         ignore_dual_punch = false;
146                 }
147         }
148 }
149
150 void
151 ARDOUR_UI::toggle_punch ()
152 {
153         if (ignore_dual_punch) {
154                 return;
155         }
156
157         Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
158
159         if (action) {
160
161                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
162
163                 if (!tact) {
164                         return;
165                 }
166
167                 /* drive the other two actions from this one */
168
169                 Glib::RefPtr<Action> in_action = ActionManager::get_action ("Transport", "TogglePunchIn");
170                 Glib::RefPtr<Action> out_action = ActionManager::get_action ("Transport", "TogglePunchOut");
171
172                 if (in_action && out_action) {
173                         Glib::RefPtr<ToggleAction> tiact = Glib::RefPtr<ToggleAction>::cast_dynamic(in_action);
174                         Glib::RefPtr<ToggleAction> toact = Glib::RefPtr<ToggleAction>::cast_dynamic(out_action);
175                         tiact->set_active (tact->get_active());
176                         toact->set_active (tact->get_active());
177                 }
178         }
179 }
180
181 void
182 ARDOUR_UI::toggle_punch_in ()
183 {
184         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("TogglePunchIn"));
185         if (!act) {
186                 return;
187         }
188
189         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
190         if (!tact) {
191                 return;
192         }
193
194         if (tact->get_active() != _session->config.get_punch_in()) {
195                 _session->config.set_punch_in (tact->get_active ());
196         }
197
198         if (tact->get_active()) {
199                 /* if punch-in is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
200                    to avoid confusing the user */
201                 show_loop_punch_ruler_and_disallow_hide ();
202         }
203
204         reenable_hide_loop_punch_ruler_if_appropriate ();
205 }
206
207 void
208 ARDOUR_UI::toggle_punch_out ()
209 {
210         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("TogglePunchOut"));
211         if (!act) {
212                 return;
213         }
214
215         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
216         if (!tact) {
217                 return;
218         }
219
220         if (tact->get_active() != _session->config.get_punch_out()) {
221                 _session->config.set_punch_out (tact->get_active ());
222         }
223
224         if (tact->get_active()) {
225                 /* if punch-out is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
226                    to avoid confusing the user */
227                 show_loop_punch_ruler_and_disallow_hide ();
228         }
229
230         reenable_hide_loop_punch_ruler_if_appropriate ();
231 }
232
233 void
234 ARDOUR_UI::show_loop_punch_ruler_and_disallow_hide ()
235 {
236         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Rulers"), "toggle-loop-punch-ruler");
237         if (!act) {
238                 return;
239         }
240
241         act->set_sensitive (false);
242
243         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
244         if (!tact) {
245                 return;
246         }
247
248         if (!tact->get_active()) {
249                 tact->set_active ();
250         }
251 }
252
253 /* This is a bit of a silly name for a method */
254 void
255 ARDOUR_UI::reenable_hide_loop_punch_ruler_if_appropriate ()
256 {
257         if (!_session->config.get_punch_in() && !_session->config.get_punch_out()) {
258                 /* if punch in/out are now both off, reallow hiding of the loop/punch ruler */
259                 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Rulers"), "toggle-loop-punch-ruler");
260                 if (act) {
261                         act->set_sensitive (true);
262                 }
263         }
264 }
265
266 void
267 ARDOUR_UI::toggle_video_sync()
268 {
269         Glib::RefPtr<Action> act = ActionManager::get_action ("Transport", "ToggleVideoSync");
270         if (act) {
271                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
272                 _session->config.set_use_video_sync (tact->get_active());
273         }
274 }
275
276 void
277 ARDOUR_UI::toggle_editing_space()
278 {
279         Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMaximalEditor");
280
281         if (act) {
282                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
283                 if (tact->get_active()) {
284                         maximise_editing_space ();
285                 } else {
286                         restore_editing_space ();
287                 }
288         }
289 }
290
291 void
292 ARDOUR_UI::setup_session_options ()
293 {
294         _session->config.ParameterChanged.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::parameter_changed, this, _1), gui_context());
295         boost::function<void (std::string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
296         _session->config.map_parameters (pc);
297 }
298
299 void
300 ARDOUR_UI::parameter_changed (std::string p)
301 {
302         ENSURE_GUI_THREAD (*this, &ARDOUR_UI::parameter_changed, p)
303
304         if (p == "external-sync") {
305
306                 ActionManager::map_some_state ("Transport", "ToggleExternalSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_external_sync));
307
308                 if (!_session->config.get_external_sync()) {
309                         sync_button.set_text (_("Internal"));
310                         ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (true);
311                         ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (true);
312                 } else {
313                         sync_button.set_text (sync_source_to_string (_session->config.get_sync_source(), true));
314                         /* XXX need to make auto-play is off as well as insensitive */
315                         ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (false);
316                         ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (false);
317                 }
318
319         } else if (p == "always-play-range") {
320
321                 ActionManager::map_some_state ("Transport", "AlwaysPlayRange", &RCConfiguration::get_always_play_range);
322
323         } else if (p == "send-mtc") {
324
325                 ActionManager::map_some_state ("options", "SendMTC", &RCConfiguration::get_send_mtc);
326
327         } else if (p == "send-mmc") {
328
329                 ActionManager::map_some_state ("options", "SendMMC", &RCConfiguration::get_send_mmc);
330
331         } else if (p == "use-osc") {
332
333 #ifdef HAVE_LIBLO
334                 if (Config->get_use_osc()) {
335                         osc->start ();
336                 } else {
337                         osc->stop ();
338                 }
339 #endif
340
341         } else if (p == "keep-tearoffs") {
342                 ActionManager::map_some_state ("Common", "KeepTearoffs", &RCConfiguration::get_keep_tearoffs);
343         } else if (p == "mmc-control") {
344                 ActionManager::map_some_state ("options", "UseMMC", &RCConfiguration::get_mmc_control);
345         } else if (p == "midi-feedback") {
346                 ActionManager::map_some_state ("options", "SendMIDIfeedback", &RCConfiguration::get_midi_feedback);
347         } else if (p == "auto-play") {
348                 ActionManager::map_some_state ("Transport", "ToggleAutoPlay", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_play));
349         } else if (p == "auto-return") {
350                 ActionManager::map_some_state ("Transport", "ToggleAutoReturn", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_return));
351         } else if (p == "auto-input") {
352                 ActionManager::map_some_state ("Transport", "ToggleAutoInput", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_input));
353         } else if (p == "punch-out") {
354                 ActionManager::map_some_state ("Transport", "TogglePunchOut", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_out));
355                 if (!_session->config.get_punch_out()) {
356                         unset_dual_punch ();
357                 }
358         } else if (p == "punch-in") {
359                 ActionManager::map_some_state ("Transport", "TogglePunchIn", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_in));
360                 if (!_session->config.get_punch_in()) {
361                         unset_dual_punch ();
362                 }
363         } else if (p == "clicking") {
364                 ActionManager::map_some_state ("Transport", "ToggleClick", &RCConfiguration::get_clicking);
365         } else if (p == "use-video-sync") {
366                 ActionManager::map_some_state ("Transport",  "ToggleVideoSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_use_video_sync));
367         } else if (p == "video-pullup" || p == "timecode-format") {
368
369                 synchronize_sync_source_and_video_pullup ();
370                 reset_main_clocks ();
371
372         } else if (p == "sync-source") {
373
374                 synchronize_sync_source_and_video_pullup ();
375
376         } else if (p == "show-track-meters") {
377                 editor->toggle_meter_updating();
378         } else if (p == "primary-clock-delta-edit-cursor") {
379                 if (Config->get_primary_clock_delta_edit_cursor()) {
380                         primary_clock->set_is_duration (true);
381                         primary_clock->set_editable (false);
382                         primary_clock->set_widget_name ("transport delta");
383                 } else {
384                         primary_clock->set_is_duration (false);
385                         primary_clock->set_editable (true);
386                         primary_clock->set_widget_name ("transport");
387                 }
388         } else if (p == "secondary-clock-delta-edit-cursor") {
389                 if (Config->get_secondary_clock_delta_edit_cursor()) {
390                         secondary_clock->set_is_duration (true);
391                         secondary_clock->set_editable (false);
392                         secondary_clock->set_widget_name ("secondary delta");
393                 } else {
394                         secondary_clock->set_is_duration (false);
395                         secondary_clock->set_editable (true);
396                         secondary_clock->set_widget_name ("secondary");
397                 }
398         }
399 }
400
401 void
402 ARDOUR_UI::session_parameter_changed (std::string p)
403 {
404         if (p == "native-file-data-format" || p == "native-file-header-format") {
405                 update_format ();
406         }
407 }
408
409 void
410 ARDOUR_UI::reset_main_clocks ()
411 {
412         ENSURE_GUI_THREAD (*this, &ARDOUR_UI::reset_main_clocks)
413
414         if (_session) {
415                 primary_clock->set (_session->audible_frame(), true);
416                 secondary_clock->set (_session->audible_frame(), true);
417         } else {
418                 primary_clock->set (0, true);
419                 secondary_clock->set (0, true);
420         }
421 }
422
423 void
424 ARDOUR_UI::synchronize_sync_source_and_video_pullup ()
425 {
426         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("ToggleExternalSync"));
427
428         if (!act) {
429                 return;
430         }
431
432         if (!_session) {
433                 goto just_label;
434         }
435
436         if (_session->config.get_video_pullup() == 0.0f) {
437                 /* with no video pull up/down, any sync source is OK */
438                 act->set_sensitive (true);
439         } else {
440                 /* can't sync to JACK if video pullup != 0.0 */
441                 if (_session->config.get_sync_source() == JACK) {
442                         act->set_sensitive (false);
443                 } else {
444                         act->set_sensitive (true);
445                 }
446         }
447
448         /* XXX should really be able to set the video pull up
449            action to insensitive/sensitive, but there is no action.
450            FIXME
451         */
452
453   just_label:
454         if (act->get_sensitive ()) {
455                 set_tip (sync_button, _("Enable/Disable external positional sync"));
456         } else {
457                 set_tip (sync_button, _("Sync to JACK is not possible: video pull up/down is set"));
458         }
459
460 }
461