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