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