increase threshold for drag-playhead-does-vertical-zoom
[ardour2.git] / gtk2_ardour / ardour_ui_options.cc
blobbde57f4385acf9e407344d211969f50a4875efe5
1 /*
2 Copyright (C) 2005 Paul Davis
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.
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.
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.
20 #ifdef WAF_BUILD
21 #include "gtk2ardour-config.h"
22 #endif
24 #include "pbd/convert.h"
25 #include "pbd/stacktrace.h"
27 #include <gtkmm2ext/utils.h>
29 #include "ardour/configuration.h"
30 #include "ardour/session.h"
31 #include "ardour/audioengine.h"
32 #include "ardour/rc_configuration.h"
34 #ifdef HAVE_LIBLO
35 #include "ardour/osc.h"
36 #endif
38 #include "audio_clock.h"
39 #include "ardour_ui.h"
40 #include "actions.h"
41 #include "gui_thread.h"
42 #include "public_editor.h"
44 #include "i18n.h"
46 using namespace Gtk;
47 using namespace Gtkmm2ext;
48 using namespace ARDOUR;
49 using namespace PBD;
51 void
52 ARDOUR_UI::toggle_keep_tearoffs ()
54 ActionManager::toggle_config_state ("Common", "KeepTearoffs", &RCConfiguration::set_keep_tearoffs, &RCConfiguration::get_keep_tearoffs);
56 ARDOUR_UI::toggle_editing_space ();
59 void
60 ARDOUR_UI::toggle_external_sync()
62 if (_session) {
63 if (_session->config.get_video_pullup() != 0.0f) {
64 if (_session->config.get_sync_source() == JACK) {
65 MessageDialog msg (
66 _("It is not possible to use JACK as the the sync source\n\
67 when the pull up/down setting is non-zero."));
68 msg.run ();
69 return;
73 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));
77 void
78 ARDOUR_UI::toggle_time_master ()
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));
83 void
84 ARDOUR_UI::toggle_send_mtc ()
86 ActionManager::toggle_config_state ("options", "SendMTC", &RCConfiguration::set_send_mtc, &RCConfiguration::get_send_mtc);
89 void
90 ARDOUR_UI::toggle_send_mmc ()
92 ActionManager::toggle_config_state ("options", "SendMMC", &RCConfiguration::set_send_mmc, &RCConfiguration::get_send_mmc);
95 void
96 ARDOUR_UI::toggle_send_midi_clock ()
98 ActionManager::toggle_config_state ("options", "SendMidiClock", &RCConfiguration::set_send_midi_clock, &RCConfiguration::get_send_midi_clock);
101 void
102 ARDOUR_UI::toggle_use_mmc ()
104 ActionManager::toggle_config_state ("options", "UseMMC", &RCConfiguration::set_mmc_control, &RCConfiguration::get_mmc_control);
107 void
108 ARDOUR_UI::toggle_send_midi_feedback ()
110 ActionManager::toggle_config_state ("options", "SendMIDIfeedback", &RCConfiguration::set_midi_feedback, &RCConfiguration::get_midi_feedback);
113 void
114 ARDOUR_UI::toggle_auto_input ()
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));
119 void
120 ARDOUR_UI::toggle_auto_play ()
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));
125 void
126 ARDOUR_UI::toggle_auto_return ()
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));
131 void
132 ARDOUR_UI::toggle_click ()
134 ActionManager::toggle_config_state ("Transport", "ToggleClick", &RCConfiguration::set_clicking, &RCConfiguration::get_clicking);
137 void
138 ARDOUR_UI::unset_dual_punch ()
140 Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
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;
152 void
153 ARDOUR_UI::toggle_punch ()
155 if (ignore_dual_punch) {
156 return;
159 Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
161 if (action) {
163 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
165 if (!tact) {
166 return;
169 /* drive the other two actions from this one */
171 Glib::RefPtr<Action> in_action = ActionManager::get_action ("Transport", "TogglePunchIn");
172 Glib::RefPtr<Action> out_action = ActionManager::get_action ("Transport", "TogglePunchOut");
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());
183 void
184 ARDOUR_UI::toggle_punch_in ()
186 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("TogglePunchIn"));
187 if (!act) {
188 return;
191 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
192 if (!tact) {
193 return;
196 if (tact->get_active() != _session->config.get_punch_in()) {
197 _session->config.set_punch_in (tact->get_active ());
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 ();
206 reenable_hide_loop_punch_ruler_if_appropriate ();
209 void
210 ARDOUR_UI::toggle_punch_out ()
212 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("TogglePunchOut"));
213 if (!act) {
214 return;
217 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
218 if (!tact) {
219 return;
222 if (tact->get_active() != _session->config.get_punch_out()) {
223 _session->config.set_punch_out (tact->get_active ());
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 ();
232 reenable_hide_loop_punch_ruler_if_appropriate ();
235 void
236 ARDOUR_UI::show_loop_punch_ruler_and_disallow_hide ()
238 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Rulers"), "toggle-loop-punch-ruler");
239 if (!act) {
240 return;
243 act->set_sensitive (false);
245 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
246 if (!tact) {
247 return;
250 if (!tact->get_active()) {
251 tact->set_active ();
255 /* This is a bit of a silly name for a method */
256 void
257 ARDOUR_UI::reenable_hide_loop_punch_ruler_if_appropriate ()
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);
268 void
269 ARDOUR_UI::toggle_video_sync()
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());
278 void
279 ARDOUR_UI::toggle_editing_space()
281 Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMaximalEditor");
282 if (act) {
283 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
284 if (tact->get_active()) {
285 maximise_editing_space ();
286 } else {
287 restore_editing_space ();
292 void
293 ARDOUR_UI::setup_session_options ()
295 _session->config.ParameterChanged.connect (_session_connections, MISSING_INVALIDATOR, ui_bind (&ARDOUR_UI::parameter_changed, this, _1), gui_context());
296 boost::function<void (std::string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
297 _session->config.map_parameters (pc);
300 #if 0
301 void
302 ARDOUR_UI::handle_sync_change ()
304 if (!_session) {
305 return;
307 if (!_session->config.get_external_sync()) {
308 sync_button.set_label (_("Internal"));
309 ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (true);
310 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (true);
311 } else {
312 sync_button.set_label (_("External"));
313 /* XXX need to make auto-play is off as well as insensitive */
314 ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (false);
315 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (false);
319 #endif
321 void
322 ARDOUR_UI::parameter_changed (std::string p)
324 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::parameter_changed, p)
326 if (p == "external-sync") {
328 ActionManager::map_some_state ("Transport", "ToggleExternalSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_external_sync));
330 if (!_session->config.get_external_sync()) {
331 sync_button.set_label (_("Internal"));
332 ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (true);
333 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (true);
334 } else {
335 sync_button.set_label (sync_source_to_string (_session->config.get_sync_source(), true));
336 /* XXX need to make auto-play is off as well as insensitive */
337 ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (false);
338 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (false);
341 } else if (p == "send-mtc") {
343 ActionManager::map_some_state ("options", "SendMTC", &RCConfiguration::get_send_mtc);
345 } else if (p == "send-mmc") {
347 ActionManager::map_some_state ("options", "SendMMC", &RCConfiguration::get_send_mmc);
349 } else if (p == "use-osc") {
351 #ifdef HAVE_LIBLO
352 if (Config->get_use_osc()) {
353 osc->start ();
354 } else {
355 osc->stop ();
357 #endif
359 } else if (p == "keep-tearoffs") {
360 ActionManager::map_some_state ("Common", "KeepTearoffs", &RCConfiguration::get_keep_tearoffs);
361 } else if (p == "mmc-control") {
362 ActionManager::map_some_state ("options", "UseMMC", &RCConfiguration::get_mmc_control);
363 } else if (p == "midi-feedback") {
364 ActionManager::map_some_state ("options", "SendMIDIfeedback", &RCConfiguration::get_midi_feedback);
365 } else if (p == "auto-play") {
366 ActionManager::map_some_state ("Transport", "ToggleAutoPlay", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_play));
367 } else if (p == "auto-return") {
368 ActionManager::map_some_state ("Transport", "ToggleAutoReturn", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_return));
369 } else if (p == "auto-input") {
370 ActionManager::map_some_state ("Transport", "ToggleAutoInput", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_input));
371 } else if (p == "punch-out") {
372 ActionManager::map_some_state ("Transport", "TogglePunchOut", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_out));
373 if (!_session->config.get_punch_out()) {
374 unset_dual_punch ();
376 } else if (p == "punch-in") {
377 ActionManager::map_some_state ("Transport", "TogglePunchIn", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_in));
378 if (!_session->config.get_punch_in()) {
379 unset_dual_punch ();
381 } else if (p == "clicking") {
382 ActionManager::map_some_state ("Transport", "ToggleClick", &RCConfiguration::get_clicking);
383 } else if (p == "jack-time-master") {
384 ActionManager::map_some_state ("Transport", "ToggleTimeMaster", sigc::mem_fun (_session->config, &SessionConfiguration::get_jack_time_master));
385 } else if (p == "use-video-sync") {
386 ActionManager::map_some_state ("Transport", "ToggleVideoSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_use_video_sync));
387 } else if (p == "video-pullup" || p == "timecode-format") {
389 synchronize_sync_source_and_video_pullup ();
390 reset_main_clocks ();
392 } else if (p == "sync-source") {
394 synchronize_sync_source_and_video_pullup ();
396 } else if (p == "show-track-meters") {
397 editor->toggle_meter_updating();
398 } else if (p == "primary-clock-delta-edit-cursor") {
399 primary_clock->set_is_duration (Config->get_primary_clock_delta_edit_cursor());
400 } else if (p == "secondary-clock-delta-edit-cursor") {
401 secondary_clock->set_is_duration (Config->get_secondary_clock_delta_edit_cursor());
405 void
406 ARDOUR_UI::reset_main_clocks ()
408 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::reset_main_clocks)
410 if (_session) {
411 primary_clock->set (_session->audible_frame(), true);
412 secondary_clock->set (_session->audible_frame(), true);
413 } else {
414 primary_clock->set (0, true);
415 secondary_clock->set (0, true);
419 void
420 ARDOUR_UI::synchronize_sync_source_and_video_pullup ()
422 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("ToggleExternalSync"));
424 if (!act) {
425 return;
428 if (!_session) {
429 goto just_label;
432 if (_session->config.get_video_pullup() == 0.0f) {
433 /* with no video pull up/down, any sync source is OK */
434 act->set_sensitive (true);
435 } else {
436 /* can't sync to JACK if video pullup != 0.0 */
437 if (_session->config.get_sync_source() == JACK) {
438 act->set_sensitive (false);
439 } else {
440 act->set_sensitive (true);
444 /* XXX should really be able to set the video pull up
445 action to insensitive/sensitive, but there is no action.
446 FIXME
449 just_label:
450 if (act->get_sensitive ()) {
451 set_tip (sync_button, _("Enable/Disable external positional sync"));
452 } else {
453 set_tip (sync_button, _("Sync to JACK is not possible: video pull up/down is set"));