Increase available Lua action script slots
[ardour.git] / gtk2_ardour / ardour_ui_options.cc
1 /*
2  * Copyright (C) 2005-2019 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2006-2007 Doug McLain <doug@nostar.net>
4  * Copyright (C) 2006-2007 Nick Mainsbridge <mainsbridge@gmail.com>
5  * Copyright (C) 2006 Sampo Savolainen <v2@iki.fi>
6  * Copyright (C) 2007-2015 Tim Mayberry <mojofunk@gmail.com>
7  * Copyright (C) 2008-2012 David Robillard <d@drobilla.net>
8  * Copyright (C) 2008 Hans Baier <hansfbaier@googlemail.com>
9  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
10  * Copyright (C) 2012-2019 Robin Gareus <robin@gareus.org>
11  * Copyright (C) 2014-2018 Ben Loftis <ben@harrisonconsoles.com>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with this program; if not, write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26  */
27
28 #ifdef WAF_BUILD
29 #include "gtk2ardour-config.h"
30 #endif
31
32 #include "pbd/convert.h"
33 #include "pbd/stacktrace.h"
34 #include "pbd/unwind.h"
35
36 #include "ardour/rc_configuration.h"
37 #include "ardour/session.h"
38 #include "ardour/transport_master_manager.h"
39
40 #include "gtkmm2ext/utils.h"
41 #include "waveview/wave_view.h"
42
43 #include "audio_clock.h"
44 #include "ardour_ui.h"
45 #include "actions.h"
46 #include "gui_thread.h"
47 #include "public_editor.h"
48 #include "main_clock.h"
49
50 #include "pbd/i18n.h"
51
52 using namespace Gtk;
53 using namespace Gtkmm2ext;
54 using namespace ARDOUR;
55 using namespace PBD;
56 using namespace ArdourWidgets;
57
58 void
59 ARDOUR_UI::toggle_external_sync()
60 {
61         if (_session) {
62                 if (_session->config.get_video_pullup() != 0.0f && (TransportMasterManager::instance().current()->type() == Engine)) {
63                         MessageDialog msg (_("It is not possible to use JACK as the the sync source\n when the pull up/down setting is non-zero."));
64                         msg.run ();
65                         return;
66                 }
67
68                 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));
69
70                 /* activating a slave is a session-property.
71                  * The slave type is a RC property.
72                  * When the slave is active is must not be reconfigured.
73                  * This is a UI limitation, imposed by audio-clock and
74                  * status displays which combine RC-config & session-properties.
75                  *
76                  * Notify RCOptionEditor by emitting a signal if the active
77                  * status changed:
78                  */
79                 Config->ParameterChanged("sync-source");
80         }
81 }
82
83 void
84 ARDOUR_UI::toggle_time_master ()
85 {
86         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));
87 }
88
89 void
90 ARDOUR_UI::toggle_send_mtc ()
91 {
92         ActionManager::toggle_config_state ("Options", "SendMTC", &RCConfiguration::set_send_mtc, &RCConfiguration::get_send_mtc);
93 }
94
95 void
96 ARDOUR_UI::toggle_send_mmc ()
97 {
98         ActionManager::toggle_config_state ("Options", "SendMMC", &RCConfiguration::set_send_mmc, &RCConfiguration::get_send_mmc);
99 }
100
101 void
102 ARDOUR_UI::toggle_send_midi_clock ()
103 {
104         ActionManager::toggle_config_state ("Options", "SendMidiClock", &RCConfiguration::set_send_midi_clock, &RCConfiguration::get_send_midi_clock);
105 }
106
107 void
108 ARDOUR_UI::toggle_use_mmc ()
109 {
110         ActionManager::toggle_config_state ("Options", "UseMMC", &RCConfiguration::set_mmc_control, &RCConfiguration::get_mmc_control);
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::toggle_session_monitoring_in ()
139 {
140         Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Transport"), X_("SessionMonitorIn"));
141
142         if (tact->get_active() && _session->config.get_session_monitoring () == MonitorInput) {
143                 return;
144         }
145         if (!tact->get_active() && _session->config.get_session_monitoring () != MonitorInput) {
146                 return;
147         }
148
149         if (tact->get_active()) {
150                 _session->config.set_session_monitoring (MonitorInput);
151         } else {
152                 _session->config.set_session_monitoring (MonitorAuto);
153         }
154 }
155
156 void
157 ARDOUR_UI::toggle_session_monitoring_disk ()
158 {
159         Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Transport"), X_("SessionMonitorDisk"));
160         if (tact->get_active() && _session->config.get_session_monitoring () == MonitorDisk) {
161                 return;
162         }
163         if (!tact->get_active() && _session->config.get_session_monitoring () != MonitorDisk) {
164                 return;
165         }
166
167         if (tact->get_active()) {
168                 _session->config.set_session_monitoring (MonitorDisk);
169         } else {
170                 _session->config.set_session_monitoring (MonitorAuto);
171         }
172 }
173
174 void
175 ARDOUR_UI::unset_dual_punch ()
176 {
177         Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action ("Transport", "TogglePunch");
178         if (tact) {
179                 ignore_dual_punch = true;
180                 tact->set_active (false);
181                 ignore_dual_punch = false;
182         }
183 }
184
185 void
186 ARDOUR_UI::toggle_punch ()
187 {
188         if (ignore_dual_punch) {
189                 return;
190         }
191
192         Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action ("Transport", "TogglePunch");
193
194         /* drive the other two actions from this one */
195         Glib::RefPtr<ToggleAction> in_action = ActionManager::get_toggle_action ("Transport", "TogglePunchIn");
196         Glib::RefPtr<ToggleAction> out_action = ActionManager::get_toggle_action ("Transport", "TogglePunchOut");
197
198         in_action->set_active (tact->get_active());
199         out_action->set_active (tact->get_active());
200 }
201
202 void
203 ARDOUR_UI::toggle_punch_in ()
204 {
205         Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Transport"), X_("TogglePunchIn"));
206
207         if (tact->get_active() != _session->config.get_punch_in()) {
208                 _session->config.set_punch_in (tact->get_active ());
209         }
210
211         if (tact->get_active()) {
212                 /* if punch-in is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
213                    to avoid confusing the user */
214                 show_loop_punch_ruler_and_disallow_hide ();
215         }
216
217         reenable_hide_loop_punch_ruler_if_appropriate ();
218 }
219
220 void
221 ARDOUR_UI::toggle_punch_out ()
222 {
223         Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Transport"), X_("TogglePunchOut"));
224
225         if (tact->get_active() != _session->config.get_punch_out()) {
226                 _session->config.set_punch_out (tact->get_active ());
227         }
228
229         if (tact->get_active()) {
230                 /* if punch-out is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
231                    to avoid confusing the user */
232                 show_loop_punch_ruler_and_disallow_hide ();
233         }
234
235         reenable_hide_loop_punch_ruler_if_appropriate ();
236 }
237
238 void
239 ARDOUR_UI::show_loop_punch_ruler_and_disallow_hide ()
240 {
241         Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Rulers"), "toggle-loop-punch-ruler");
242
243         tact->set_sensitive (false);
244
245         if (!tact->get_active()) {
246                 tact->set_active ();
247         }
248 }
249
250 /* This is a bit of a silly name for a method */
251 void
252 ARDOUR_UI::reenable_hide_loop_punch_ruler_if_appropriate ()
253 {
254         if (!_session->config.get_punch_in() && !_session->config.get_punch_out()) {
255                 /* if punch in/out are now both off, reallow hiding of the loop/punch ruler */
256                 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Rulers"), "toggle-loop-punch-ruler");
257                 if (act) {
258                         act->set_sensitive (true);
259                 }
260         }
261 }
262
263 void
264 ARDOUR_UI::toggle_video_sync()
265 {
266         Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action ("Transport", "ToggleVideoSync");
267         _session->config.set_use_video_sync (tact->get_active());
268 }
269
270 void
271 ARDOUR_UI::toggle_editing_space()
272 {
273         Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action ("Common", "ToggleMaximalEditor");
274         if (tact->get_active()) {
275                 maximise_editing_space ();
276         } else {
277                 restore_editing_space ();
278         }
279 }
280
281 void
282 ARDOUR_UI::setup_session_options ()
283 {
284         _session->config.ParameterChanged.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::parameter_changed, this, _1), gui_context());
285         boost::function<void (std::string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
286         _session->config.map_parameters (pc);
287 }
288
289 void
290 ARDOUR_UI::parameter_changed (std::string p)
291 {
292         if (p == "external-sync") {
293
294                 /* session parameter */
295
296                 ActionManager::map_some_state ("Transport", "ToggleExternalSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_external_sync));
297
298                 if (!_session->config.get_external_sync()) {
299                         sync_button.set_text (S_("SyncSource|Int."));
300                         ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (true);
301                         ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (true);
302                         ActionManager::get_action ("Transport", "ToggleFollowEdits")->set_sensitive (true);
303                 } else {
304                         /* XXX we need to make sure that auto-play is off as well as insensitive */
305                         ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (false);
306                         ActionManager::get_action ("Transport", "ToggleFollowEdits")->set_sensitive (false);
307                         if (!_session->synced_to_engine()) {
308                                 /* JACK transport allows auto-return */
309                                 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (false);
310                         }
311                 }
312
313         } else if (p == "sync-source") {
314
315                 /* app parameter (RC config) */
316
317                 if (_session) {
318                         if (!_session->config.get_external_sync()) {
319                                 sync_button.set_text (S_("SyncSource|Int."));
320                         } else {
321                                 sync_button.set_text (TransportMasterManager::instance().current()->display_name());
322                         }
323                 } else {
324                         /* changing sync source without a session is unlikely/impossible , except during startup */
325                         sync_button.set_text (TransportMasterManager::instance().current()->display_name());
326                 }
327
328         } else if (p == "follow-edits") {
329
330                 ActionManager::map_some_state ("Transport", "ToggleFollowEdits", &UIConfiguration::get_follow_edits);
331
332         } else if (p == "send-mtc") {
333
334                 ActionManager::map_some_state ("Options", "SendMTC", &RCConfiguration::get_send_mtc);
335
336         } else if (p == "send-mmc") {
337
338                 ActionManager::map_some_state ("Options", "SendMMC", &RCConfiguration::get_send_mmc);
339
340         } else if (p == "mmc-control") {
341                 ActionManager::map_some_state ("Options", "UseMMC", &RCConfiguration::get_mmc_control);
342         } else if (p == "auto-play") {
343                 ActionManager::map_some_state ("Transport", "ToggleAutoPlay", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_play));
344         } else if (p == "auto-return") {
345                 ActionManager::map_some_state ("Transport", "ToggleAutoReturn", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_return));
346         } else if (p == "auto-input") {
347                 ActionManager::map_some_state ("Transport", "ToggleAutoInput", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_input));
348         } else if (p == "session-monitoring") {
349                 Glib::RefPtr<ToggleAction> tiact = ActionManager::get_toggle_action (X_("Transport"), X_("SessionMonitorIn"));
350                 Glib::RefPtr<ToggleAction> tdact = ActionManager::get_toggle_action (X_("Transport"), X_("SessionMonitorDisk"));
351                 switch (_session->config.get_session_monitoring ()) {
352                         case MonitorDisk:
353                                 tdact->set_active (true);
354                                 tiact->set_active (false);
355                                 break;
356                         case MonitorInput:
357                                 tiact->set_active (true);
358                                 tdact->set_active (false);
359                                 break;
360                         default:
361                                 tdact->set_active (false);
362                                 tiact->set_active (false);
363                                 break;
364                 }
365         } else if (p == "punch-out") {
366                 ActionManager::map_some_state ("Transport", "TogglePunchOut", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_out));
367                 if (!_session->config.get_punch_out()) {
368                         unset_dual_punch ();
369                 }
370         } else if (p == "punch-in") {
371                 ActionManager::map_some_state ("Transport", "TogglePunchIn", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_in));
372                 if (!_session->config.get_punch_in()) {
373                         unset_dual_punch ();
374                 }
375         } else if (p == "clicking") {
376                 ActionManager::map_some_state ("Transport", "ToggleClick", &RCConfiguration::get_clicking);
377         } else if (p == "use-video-sync") {
378                 ActionManager::map_some_state ("Transport",  "ToggleVideoSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_use_video_sync));
379         } else if (p == "sync-source") {
380
381                 synchronize_sync_source_and_video_pullup ();
382                 set_fps_timeout_connection ();
383
384         } else if (p == "show-track-meters") {
385                 if (editor) editor->toggle_meter_updating();
386         } else if (p == "primary-clock-delta-mode") {
387                 if (UIConfiguration::instance().get_primary_clock_delta_mode() != NoDelta) {
388                         primary_clock->set_is_duration (true);
389                         primary_clock->set_editable (false);
390                         primary_clock->set_widget_name ("transport delta");
391                 } else {
392                         primary_clock->set_is_duration (false);
393                         primary_clock->set_editable (true);
394                         primary_clock->set_widget_name ("transport");
395                 }
396         } else if (p == "secondary-clock-delta-mode") {
397                 if (UIConfiguration::instance().get_secondary_clock_delta_mode() != NoDelta) {
398                         secondary_clock->set_is_duration (true);
399                         secondary_clock->set_editable (false);
400                         secondary_clock->set_widget_name ("secondary delta");
401                 } else {
402                         secondary_clock->set_is_duration (false);
403                         secondary_clock->set_editable (true);
404                         secondary_clock->set_widget_name ("secondary");
405                 }
406         } else if (p == "super-rapid-clock-update") {
407                 if (_session) {
408                         stop_clocking ();
409                         start_clocking ();
410                 }
411         } else if (p == "use-tooltips") {
412                 /* this doesn't really belong here but it has to go somewhere */
413                 if (UIConfiguration::instance().get_use_tooltips()) {
414                         Gtkmm2ext::enable_tooltips ();
415                 } else {
416                         Gtkmm2ext::disable_tooltips ();
417                 }
418         } else if (p == "waveform-gradient-depth") {
419                 ArdourWaveView::WaveView::set_global_gradient_depth (UIConfiguration::instance().get_waveform_gradient_depth());
420         } else if (p == "show-mini-timeline") {
421                 repack_transport_hbox ();
422         } else if (p == "show-dsp-load-info") {
423                 repack_transport_hbox ();
424         } else if (p == "show-disk-space-info") {
425                 repack_transport_hbox ();
426         } else if (p == "show-toolbar-recpunch") {
427                 repack_transport_hbox ();
428         } else if (p == "show-toolbar-monitoring") {
429                 repack_transport_hbox ();
430         } else if (p == "show-toolbar-selclock") {
431                 repack_transport_hbox ();
432         } else if (p == "show-editor-meter") {
433                 repack_transport_hbox ();
434         } else if (p == "show-secondary-clock") {
435                 update_clock_visibility ();
436         } else if (p == "waveform-scale") {
437                 ArdourWaveView::WaveView::set_global_logscaled (UIConfiguration::instance().get_waveform_scale() == Logarithmic);
438         } else if (p == "widget-prelight") {
439                 CairoWidget::set_widget_prelight (UIConfiguration::instance().get_widget_prelight());
440         } else if (p == "waveform-shape") {
441                 ArdourWaveView::WaveView::set_global_shape (UIConfiguration::instance().get_waveform_shape() == Rectified
442                                 ? ArdourWaveView::WaveView::Rectified : ArdourWaveView::WaveView::Normal);
443         } else if (p == "show-waveform-clipping") {
444                 ArdourWaveView::WaveView::set_global_show_waveform_clipping (UIConfiguration::instance().get_show_waveform_clipping());
445         } else if (p == "waveform-cache-size") {
446                 /* GUI option has units of megabytes; image cache uses units of bytes */
447                 ArdourWaveView::WaveView::set_image_cache_size (UIConfiguration::instance().get_waveform_cache_size() * 1048576);
448         } else if (p == "use-wm-visibility") {
449                 VisibilityTracker::set_use_window_manager_visibility (UIConfiguration::instance().get_use_wm_visibility());
450         } else if (p == "action-table-columns") {
451                 const uint32_t cols = UIConfiguration::instance().get_action_table_columns ();
452                 for (int i = 0; i < MAX_LUA_ACTION_BUTTONS; ++i) {
453                         const int col = i / 2;
454                         if (cols & (1<<col)) {
455                                 action_script_call_btn[i].show();
456                         } else {
457                                 action_script_call_btn[i].hide();
458                         }
459                 }
460         } else if (p == "layered-record-mode") {
461                 layered_button.set_active (_session->config.get_layered_record_mode ());
462         } else if (p == "flat-buttons") {
463                 bool flat = UIConfiguration::instance().get_flat_buttons();
464                 if (ArdourButton::flat_buttons () != flat) {
465                         ArdourButton::set_flat_buttons (flat);
466                         /* force a redraw */
467                         gtk_rc_reset_styles (gtk_settings_get_default());
468                 }
469         } else if (p == "boxy-buttons") {
470                 bool boxy = UIConfiguration::instance().get_boxy_buttons();
471                 if (ArdourButton::boxy_buttons () != boxy) {
472                         ArdourButton::set_boxy_buttons (boxy);
473                         /* force a redraw */
474                         gtk_rc_reset_styles (gtk_settings_get_default());
475                 }
476         } else if ( (p == "snap-to-region-sync") || (p == "snap-to-region-start") || (p == "snap-to-region-end") ) {
477                 if (editor) editor->mark_region_boundary_cache_dirty();
478         } else if (p == "screen-saver-mode") {
479                 switch (UIConfiguration::instance().get_screen_saver_mode ()) {
480                         using namespace ARDOUR_UI_UTILS;
481                         case InhibitWhileRecording:
482                                 inhibit_screensaver (_session && _session->actively_recording ());
483                                 break;
484                         case InhibitAlways:
485                                 inhibit_screensaver (true);
486                                 break;
487                         case InhibitNever:
488                                 inhibit_screensaver (false);
489                                 break;
490                 }
491         }
492 }
493
494 void
495 ARDOUR_UI::session_parameter_changed (std::string p)
496 {
497         if (p == "native-file-data-format" || p == "native-file-header-format") {
498                 update_format ();
499         } else if (p == "timecode-format") {
500                 set_fps_timeout_connection ();
501         } else if (p == "video-pullup" || p == "timecode-format") {
502                 set_fps_timeout_connection ();
503
504                 synchronize_sync_source_and_video_pullup ();
505                 reset_main_clocks ();
506                 editor->queue_visual_videotimeline_update();
507         } else if (p == "track-name-number") {
508                 /* DisplaySuspender triggers _route->redisplay() when going out of scope
509                  * which eventually calls reset_controls_layout_width() and re-sets the
510                  * track-header width.
511                  * see also RouteTimeAxisView::update_track_number_visibility()
512                  */
513                 DisplaySuspender ds;
514         }
515 }
516
517 void
518 ARDOUR_UI::reset_main_clocks ()
519 {
520         ENSURE_GUI_THREAD (*this, &ARDOUR_UI::reset_main_clocks)
521
522         if (_session) {
523                 primary_clock->set (_session->audible_sample(), true);
524                 secondary_clock->set (_session->audible_sample(), true);
525         } else {
526                 primary_clock->set (0, true);
527                 secondary_clock->set (0, true);
528         }
529 }
530
531 void
532 ARDOUR_UI::synchronize_sync_source_and_video_pullup ()
533 {
534         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("ToggleExternalSync"));
535
536         if (!act) {
537                 return;
538         }
539
540         if (!_session) {
541                 goto just_label;
542         }
543
544         if (_session->config.get_video_pullup() == 0.0f) {
545                 /* with no video pull up/down, any sync source is OK */
546                 act->set_sensitive (true);
547         } else {
548                 /* can't sync to JACK if video pullup != 0.0 */
549                 if (TransportMasterManager::instance().current()->type() == Engine) {
550                         act->set_sensitive (false);
551                 } else {
552                         act->set_sensitive (true);
553                 }
554         }
555
556         /* XXX should really be able to set the video pull up
557            action to insensitive/sensitive, but there is no action.
558            FIXME
559         */
560
561   just_label:
562         if (act->get_sensitive ()) {
563                 set_tip (sync_button, _("Enable/Disable external positional sync"));
564         } else {
565                 set_tip (sync_button, _("Sync to JACK is not possible: video pull up/down is set"));
566         }
567
568 }