Remove cruft (old MIDI feedback API)
[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_auto_input ()
109 {
110         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));
111 }
112
113 void
114 ARDOUR_UI::toggle_auto_play ()
115 {
116         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));
117 }
118
119 void
120 ARDOUR_UI::toggle_auto_return ()
121 {
122         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));
123 }
124
125 void
126 ARDOUR_UI::toggle_click ()
127 {
128         ActionManager::toggle_config_state ("Transport", "ToggleClick", &RCConfiguration::set_clicking, &RCConfiguration::get_clicking);
129 }
130
131 void
132 ARDOUR_UI::unset_dual_punch ()
133 {
134         Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
135
136         if (action) {
137                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
138                 if (tact) {
139                         ignore_dual_punch = true;
140                         tact->set_active (false);
141                         ignore_dual_punch = false;
142                 }
143         }
144 }
145
146 void
147 ARDOUR_UI::toggle_punch ()
148 {
149         if (ignore_dual_punch) {
150                 return;
151         }
152
153         Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
154
155         if (action) {
156
157                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
158
159                 if (!tact) {
160                         return;
161                 }
162
163                 /* drive the other two actions from this one */
164
165                 Glib::RefPtr<Action> in_action = ActionManager::get_action ("Transport", "TogglePunchIn");
166                 Glib::RefPtr<Action> out_action = ActionManager::get_action ("Transport", "TogglePunchOut");
167
168                 if (in_action && out_action) {
169                         Glib::RefPtr<ToggleAction> tiact = Glib::RefPtr<ToggleAction>::cast_dynamic(in_action);
170                         Glib::RefPtr<ToggleAction> toact = Glib::RefPtr<ToggleAction>::cast_dynamic(out_action);
171                         tiact->set_active (tact->get_active());
172                         toact->set_active (tact->get_active());
173                 }
174         }
175 }
176
177 void
178 ARDOUR_UI::toggle_punch_in ()
179 {
180         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("TogglePunchIn"));
181         if (!act) {
182                 return;
183         }
184
185         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
186         if (!tact) {
187                 return;
188         }
189
190         if (tact->get_active() != _session->config.get_punch_in()) {
191                 _session->config.set_punch_in (tact->get_active ());
192         }
193
194         if (tact->get_active()) {
195                 /* if punch-in is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
196                    to avoid confusing the user */
197                 show_loop_punch_ruler_and_disallow_hide ();
198         }
199
200         reenable_hide_loop_punch_ruler_if_appropriate ();
201 }
202
203 void
204 ARDOUR_UI::toggle_punch_out ()
205 {
206         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("TogglePunchOut"));
207         if (!act) {
208                 return;
209         }
210
211         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
212         if (!tact) {
213                 return;
214         }
215
216         if (tact->get_active() != _session->config.get_punch_out()) {
217                 _session->config.set_punch_out (tact->get_active ());
218         }
219
220         if (tact->get_active()) {
221                 /* if punch-out is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
222                    to avoid confusing the user */
223                 show_loop_punch_ruler_and_disallow_hide ();
224         }
225
226         reenable_hide_loop_punch_ruler_if_appropriate ();
227 }
228
229 void
230 ARDOUR_UI::show_loop_punch_ruler_and_disallow_hide ()
231 {
232         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Rulers"), "toggle-loop-punch-ruler");
233         if (!act) {
234                 return;
235         }
236
237         act->set_sensitive (false);
238
239         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
240         if (!tact) {
241                 return;
242         }
243
244         if (!tact->get_active()) {
245                 tact->set_active ();
246         }
247 }
248
249 /* This is a bit of a silly name for a method */
250 void
251 ARDOUR_UI::reenable_hide_loop_punch_ruler_if_appropriate ()
252 {
253         if (!_session->config.get_punch_in() && !_session->config.get_punch_out()) {
254                 /* if punch in/out are now both off, reallow hiding of the loop/punch ruler */
255                 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Rulers"), "toggle-loop-punch-ruler");
256                 if (act) {
257                         act->set_sensitive (true);
258                 }
259         }
260 }
261
262 void
263 ARDOUR_UI::toggle_video_sync()
264 {
265         Glib::RefPtr<Action> act = ActionManager::get_action ("Transport", "ToggleVideoSync");
266         if (act) {
267                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
268                 _session->config.set_use_video_sync (tact->get_active());
269         }
270 }
271
272 void
273 ARDOUR_UI::toggle_editing_space()
274 {
275         Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMaximalEditor");
276
277         if (act) {
278                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
279                 if (tact->get_active()) {
280                         maximise_editing_space ();
281                 } else {
282                         restore_editing_space ();
283                 }
284         }
285 }
286
287 void
288 ARDOUR_UI::setup_session_options ()
289 {
290         _session->config.ParameterChanged.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::parameter_changed, this, _1), gui_context());
291         boost::function<void (std::string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
292         _session->config.map_parameters (pc);
293 }
294
295 void
296 ARDOUR_UI::parameter_changed (std::string p)
297 {
298         if (p == "external-sync") {
299
300                 ActionManager::map_some_state ("Transport", "ToggleExternalSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_external_sync));
301
302                 if (!_session->config.get_external_sync()) {
303                         sync_button.set_text (S_("SyncSource|Int."));
304                         auto_loop_button.set_sensitive (true);
305                         ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (true);
306                         ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (true);
307                         ActionManager::get_action ("Transport", "ToggleFollowEdits")->set_sensitive (true);
308                 } else {
309                         sync_button.set_text (sync_source_to_string (Config->get_sync_source(), true));
310                         if (_session && _session->locations()->auto_loop_location()) {
311                                 // disable looping with external sync.
312                                 // This is not necessary because session-transport ignores the loop-state,
313                                 // but makes it clear to the user that it's disabled.
314                                 _session->request_play_loop (false, false);
315                         }
316                         auto_loop_button.set_sensitive (false);
317                         /* XXX we need to make sure that 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 == "mmc-control") {
336                 ActionManager::map_some_state ("Options", "UseMMC", &RCConfiguration::get_mmc_control);
337         } else if (p == "auto-play") {
338                 ActionManager::map_some_state ("Transport", "ToggleAutoPlay", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_play));
339         } else if (p == "auto-return") {
340                 ActionManager::map_some_state ("Transport", "ToggleAutoReturn", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_return));
341         } else if (p == "auto-input") {
342                 ActionManager::map_some_state ("Transport", "ToggleAutoInput", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_input));
343         } else if (p == "punch-out") {
344                 ActionManager::map_some_state ("Transport", "TogglePunchOut", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_out));
345                 if (!_session->config.get_punch_out()) {
346                         unset_dual_punch ();
347                 }
348         } else if (p == "punch-in") {
349                 ActionManager::map_some_state ("Transport", "TogglePunchIn", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_in));
350                 if (!_session->config.get_punch_in()) {
351                         unset_dual_punch ();
352                 }
353         } else if (p == "clicking") {
354                 ActionManager::map_some_state ("Transport", "ToggleClick", &RCConfiguration::get_clicking);
355         } else if (p == "use-video-sync") {
356                 ActionManager::map_some_state ("Transport",  "ToggleVideoSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_use_video_sync));
357         } else if (p == "sync-source") {
358
359                 synchronize_sync_source_and_video_pullup ();
360                 set_fps_timeout_connection ();
361
362         } else if (p == "show-track-meters") {
363                 if (editor) editor->toggle_meter_updating();
364         } else if (p == "primary-clock-delta-edit-cursor") {
365                 if (UIConfiguration::instance().get_primary_clock_delta_edit_cursor()) {
366                         primary_clock->set_is_duration (true);
367                         primary_clock->set_editable (false);
368                         primary_clock->set_widget_name ("transport delta");
369                 } else {
370                         primary_clock->set_is_duration (false);
371                         primary_clock->set_editable (true);
372                         primary_clock->set_widget_name ("transport");
373                 }
374         } else if (p == "secondary-clock-delta-edit-cursor") {
375                 if (UIConfiguration::instance().get_secondary_clock_delta_edit_cursor()) {
376                         secondary_clock->set_is_duration (true);
377                         secondary_clock->set_editable (false);
378                         secondary_clock->set_widget_name ("secondary delta");
379                 } else {
380                         secondary_clock->set_is_duration (false);
381                         secondary_clock->set_editable (true);
382                         secondary_clock->set_widget_name ("secondary");
383                 }
384         } else if (p == "super-rapid-clock-update") {
385                 if (_session) {
386                         stop_clocking ();
387                         start_clocking ();
388                 }
389         } else if (p == "use-tooltips") {
390                 /* this doesn't really belong here but it has to go somewhere */
391                 if (UIConfiguration::instance().get_use_tooltips()) {
392                         Gtkmm2ext::enable_tooltips ();
393                 } else {
394                         Gtkmm2ext::disable_tooltips ();
395                 }
396         } else if (p == "waveform-gradient-depth") {
397                 ArdourCanvas::WaveView::set_global_gradient_depth (UIConfiguration::instance().get_waveform_gradient_depth());
398         } else if (p == "show-mini-timeline") {
399                 repack_transport_hbox ();
400         } else if (p == "show-toolbar-selclock") {
401                 repack_transport_hbox ();
402         } else if (p == "show-editor-meter") {
403                 repack_transport_hbox ();
404         } else if (p == "show-secondary-clock") {
405                 update_clock_visibility ();
406         } else if (p == "waveform-scale") {
407                 ArdourCanvas::WaveView::set_global_logscaled (UIConfiguration::instance().get_waveform_scale() == Logarithmic);
408         } else if (p == "widget-prelight") {
409                 CairoWidget::set_widget_prelight (UIConfiguration::instance().get_widget_prelight());
410         } else if (p == "waveform-shape") {
411                 ArdourCanvas::WaveView::set_global_shape (UIConfiguration::instance().get_waveform_shape() == Rectified
412                                 ? ArdourCanvas::WaveView::Rectified : ArdourCanvas::WaveView::Normal);
413         } else if (p == "show-waveform-clipping") {
414                 ArdourCanvas::WaveView::set_global_show_waveform_clipping (UIConfiguration::instance().get_show_waveform_clipping());
415         } else if (p == "waveform-cache-size") {
416                 /* GUI option has units of megabytes; image cache uses units of bytes */
417                 ArdourCanvas::WaveView::set_image_cache_size (UIConfiguration::instance().get_waveform_cache_size() * 1048576);
418         } else if (p == "use-wm-visibility") {
419                 VisibilityTracker::set_use_window_manager_visibility (UIConfiguration::instance().get_use_wm_visibility());
420         } else if (p == "action-table-columns") {
421                 const uint32_t cols = UIConfiguration::instance().get_action_table_columns ();
422                 for (int i = 0; i < 9; ++i) {
423                         const int col = i / 2;
424                         if (cols & (1<<col)) {
425                                 action_script_call_btn[i].show();
426                         } else {
427                                 action_script_call_btn[i].hide();
428                         }
429                 }
430         } else if (p == "layered-record-mode") {
431                 layered_button.set_active (_session->config.get_layered_record_mode ());
432         } else if (p == "show-waveform-clipping") {
433                 ArdourCanvas::WaveView::set_global_show_waveform_clipping (UIConfiguration::instance().get_show_waveform_clipping());
434         } else if (p == "waveform-gradient-depth") {
435                 ArdourCanvas::WaveView::set_global_gradient_depth (UIConfiguration::instance().get_waveform_gradient_depth());
436         } else if (p == "flat-buttons") {
437                 bool flat = UIConfiguration::instance().get_flat_buttons();
438                 if (ArdourButton::flat_buttons () != flat) {
439                         ArdourButton::set_flat_buttons (flat);
440                         /* force a redraw */
441                         gtk_rc_reset_styles (gtk_settings_get_default());
442                 }
443         }
444 }
445
446 void
447 ARDOUR_UI::session_parameter_changed (std::string p)
448 {
449         if (p == "native-file-data-format" || p == "native-file-header-format") {
450                 update_format ();
451         } else if (p == "timecode-format") {
452                 set_fps_timeout_connection ();
453         } else if (p == "video-pullup" || p == "timecode-format") {
454                 set_fps_timeout_connection ();
455
456                 synchronize_sync_source_and_video_pullup ();
457                 reset_main_clocks ();
458                 editor->queue_visual_videotimeline_update();
459         } else if (p == "track-name-number") {
460                 /* DisplaySuspender triggers _route->redisplay() when going out of scope
461                  * which eventually calls reset_controls_layout_width() and re-sets the
462                  * track-header width.
463                  * see also RouteTimeAxisView::update_track_number_visibility()
464                  */
465                 DisplaySuspender ds;
466         }
467 }
468
469 void
470 ARDOUR_UI::reset_main_clocks ()
471 {
472         ENSURE_GUI_THREAD (*this, &ARDOUR_UI::reset_main_clocks)
473
474         if (_session) {
475                 primary_clock->set (_session->audible_frame(), true);
476                 secondary_clock->set (_session->audible_frame(), true);
477         } else {
478                 primary_clock->set (0, true);
479                 secondary_clock->set (0, true);
480         }
481 }
482
483 void
484 ARDOUR_UI::synchronize_sync_source_and_video_pullup ()
485 {
486         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("ToggleExternalSync"));
487
488         if (!act) {
489                 return;
490         }
491
492         if (!_session) {
493                 goto just_label;
494         }
495
496         if (_session->config.get_video_pullup() == 0.0f) {
497                 /* with no video pull up/down, any sync source is OK */
498                 act->set_sensitive (true);
499         } else {
500                 /* can't sync to JACK if video pullup != 0.0 */
501                 if (Config->get_sync_source() == Engine) {
502                         act->set_sensitive (false);
503                 } else {
504                         act->set_sensitive (true);
505                 }
506         }
507
508         /* XXX should really be able to set the video pull up
509            action to insensitive/sensitive, but there is no action.
510            FIXME
511         */
512
513   just_label:
514         if (act->get_sensitive ()) {
515                 set_tip (sync_button, _("Enable/Disable external positional sync"));
516         } else {
517                 set_tip (sync_button, _("Sync to JACK is not possible: video pull up/down is set"));
518         }
519
520 }
521