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