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