fix up file renaming code a little bit
[ArdourMidi.git] / gtk2_ardour / ardour_ui_options.cc
blob72404798bcba3ed0e90c45cf9f1424b00d7d20ae
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"
33 #ifdef HAVE_LIBLO
34 #include "ardour/osc.h"
35 #endif
37 #include "ardour_ui.h"
38 #include "actions.h"
39 #include "gui_thread.h"
40 #include "public_editor.h"
42 #include "i18n.h"
44 using namespace Gtk;
45 using namespace Gtkmm2ext;
46 using namespace ARDOUR;
47 using namespace PBD;
49 void
50 ARDOUR_UI::toggle_external_sync()
52 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));
55 void
56 ARDOUR_UI::toggle_time_master ()
58 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));
61 void
62 ARDOUR_UI::toggle_send_mtc ()
64 ActionManager::toggle_config_state ("options", "SendMTC", &RCConfiguration::set_send_mtc, &RCConfiguration::get_send_mtc);
67 void
68 ARDOUR_UI::toggle_send_mmc ()
70 ActionManager::toggle_config_state ("options", "SendMMC", &RCConfiguration::set_send_mmc, &RCConfiguration::get_send_mmc);
73 void
74 ARDOUR_UI::toggle_send_midi_clock ()
76 ActionManager::toggle_config_state ("options", "SendMidiClock", &RCConfiguration::set_send_midi_clock, &RCConfiguration::get_send_midi_clock);
79 void
80 ARDOUR_UI::toggle_use_mmc ()
82 ActionManager::toggle_config_state ("options", "UseMMC", &RCConfiguration::set_mmc_control, &RCConfiguration::get_mmc_control);
85 void
86 ARDOUR_UI::toggle_send_midi_feedback ()
88 ActionManager::toggle_config_state ("options", "SendMIDIfeedback", &RCConfiguration::set_midi_feedback, &RCConfiguration::get_midi_feedback);
91 void
92 ARDOUR_UI::toggle_auto_input ()
94 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));
97 void
98 ARDOUR_UI::toggle_auto_play ()
100 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));
103 void
104 ARDOUR_UI::toggle_auto_return ()
106 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));
109 void
110 ARDOUR_UI::toggle_click ()
112 ActionManager::toggle_config_state ("Transport", "ToggleClick", &RCConfiguration::set_clicking, &RCConfiguration::get_clicking);
115 void
116 ARDOUR_UI::unset_dual_punch ()
118 Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
120 if (action) {
121 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
122 if (tact) {
123 ignore_dual_punch = true;
124 tact->set_active (false);
125 ignore_dual_punch = false;
130 void
131 ARDOUR_UI::toggle_punch ()
133 if (ignore_dual_punch) {
134 return;
137 Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
139 if (action) {
141 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
143 if (!tact) {
144 return;
147 /* drive the other two actions from this one */
149 Glib::RefPtr<Action> in_action = ActionManager::get_action ("Transport", "TogglePunchIn");
150 Glib::RefPtr<Action> out_action = ActionManager::get_action ("Transport", "TogglePunchOut");
152 if (in_action && out_action) {
153 Glib::RefPtr<ToggleAction> tiact = Glib::RefPtr<ToggleAction>::cast_dynamic(in_action);
154 Glib::RefPtr<ToggleAction> toact = Glib::RefPtr<ToggleAction>::cast_dynamic(out_action);
155 tiact->set_active (tact->get_active());
156 toact->set_active (tact->get_active());
161 void
162 ARDOUR_UI::toggle_punch_in ()
164 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("TogglePunchIn"));
165 if (!act) {
166 return;
169 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
170 if (!tact) {
171 return;
174 if (tact->get_active() != _session->config.get_punch_in()) {
175 _session->config.set_punch_in (tact->get_active ());
178 if (tact->get_active()) {
179 /* if punch-in is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
180 to avoid confusing the user */
181 show_loop_punch_ruler_and_disallow_hide ();
184 reenable_hide_loop_punch_ruler_if_appropriate ();
187 void
188 ARDOUR_UI::toggle_punch_out ()
190 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("TogglePunchOut"));
191 if (!act) {
192 return;
195 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
196 if (!tact) {
197 return;
200 if (tact->get_active() != _session->config.get_punch_out()) {
201 _session->config.set_punch_out (tact->get_active ());
204 if (tact->get_active()) {
205 /* if punch-out is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
206 to avoid confusing the user */
207 show_loop_punch_ruler_and_disallow_hide ();
210 reenable_hide_loop_punch_ruler_if_appropriate ();
213 void
214 ARDOUR_UI::show_loop_punch_ruler_and_disallow_hide ()
216 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Rulers"), "toggle-loop-punch-ruler");
217 if (!act) {
218 return;
221 act->set_sensitive (false);
223 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
224 if (!tact) {
225 return;
228 if (!tact->get_active()) {
229 tact->set_active ();
233 /* This is a bit of a silly name for a method */
234 void
235 ARDOUR_UI::reenable_hide_loop_punch_ruler_if_appropriate ()
237 if (!_session->config.get_punch_in() && !_session->config.get_punch_out()) {
238 /* if punch in/out are now both off, reallow hiding of the loop/punch ruler */
239 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Rulers"), "toggle-loop-punch-ruler");
240 if (act) {
241 act->set_sensitive (true);
246 void
247 ARDOUR_UI::toggle_video_sync()
249 Glib::RefPtr<Action> act = ActionManager::get_action ("Transport", "ToggleVideoSync");
250 if (act) {
251 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
252 _session->config.set_use_video_sync (tact->get_active());
256 void
257 ARDOUR_UI::toggle_editing_space()
259 Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMaximalEditor");
260 if (act) {
261 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
262 if (tact->get_active()) {
263 maximise_editing_space ();
264 } else {
265 restore_editing_space ();
270 void
271 ARDOUR_UI::setup_session_options ()
273 _session->config.ParameterChanged.connect (_session_connections, MISSING_INVALIDATOR, ui_bind (&ARDOUR_UI::parameter_changed, this, _1), gui_context());
274 boost::function<void (std::string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
275 _session->config.map_parameters (pc);
278 #if 0
279 void
280 ARDOUR_UI::handle_sync_change ()
282 if (!_session) {
283 return;
285 if (!_session->config.get_external_sync()) {
286 sync_button.set_label (_("Internal"));
287 ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (true);
288 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (true);
289 } else {
290 sync_button.set_label (_("External"));
291 /* XXX need to make auto-play is off as well as insensitive */
292 ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (false);
293 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (false);
297 #endif
299 void
300 ARDOUR_UI::parameter_changed (std::string p)
302 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::parameter_changed, p)
304 if (p == "external-sync") {
306 ActionManager::map_some_state ("Transport", "ToggleExternalSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_external_sync));
308 if (!_session->config.get_external_sync()) {
309 sync_button.set_label (_("Internal"));
310 ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (true);
311 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (true);
312 } else {
313 sync_button.set_label (sync_source_to_string (_session->config.get_sync_source()));
314 /* XXX need to make auto-play is off as well as insensitive */
315 ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (false);
316 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (false);
319 } else if (p == "send-mtc") {
321 ActionManager::map_some_state ("options", "SendMTC", &RCConfiguration::get_send_mtc);
323 } else if (p == "send-mmc") {
325 ActionManager::map_some_state ("options", "SendMMC", &RCConfiguration::get_send_mmc);
327 } else if (p == "use-osc") {
329 #ifdef HAVE_LIBLO
330 if (Config->get_use_osc()) {
331 osc->start ();
332 } else {
333 osc->stop ();
335 #endif
337 } else if (p == "mmc-control") {
338 ActionManager::map_some_state ("options", "UseMMC", &RCConfiguration::get_mmc_control);
339 } else if (p == "midi-feedback") {
340 ActionManager::map_some_state ("options", "SendMIDIfeedback", &RCConfiguration::get_midi_feedback);
341 } else if (p == "auto-play") {
342 ActionManager::map_some_state ("Transport", "ToggleAutoPlay", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_play));
343 } else if (p == "auto-return") {
344 ActionManager::map_some_state ("Transport", "ToggleAutoReturn", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_return));
345 } else if (p == "auto-input") {
346 ActionManager::map_some_state ("Transport", "ToggleAutoInput", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_input));
347 } else if (p == "punch-out") {
348 ActionManager::map_some_state ("Transport", "TogglePunchOut", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_out));
349 if (!_session->config.get_punch_out()) {
350 unset_dual_punch ();
352 } else if (p == "punch-in") {
353 ActionManager::map_some_state ("Transport", "TogglePunchIn", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_in));
354 if (!_session->config.get_punch_in()) {
355 unset_dual_punch ();
357 } else if (p == "clicking") {
358 ActionManager::map_some_state ("Transport", "ToggleClick", &RCConfiguration::get_clicking);
359 } else if (p == "jack-time-master") {
360 ActionManager::map_some_state ("Transport", "ToggleTimeMaster", sigc::mem_fun (_session->config, &SessionConfiguration::get_jack_time_master));
361 } else if (p == "use-video-sync") {
362 ActionManager::map_some_state ("Transport", "ToggleVideoSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_use_video_sync));
363 } else if (p == "shuttle-behaviour") {
365 switch (Config->get_shuttle_behaviour ()) {
366 case Sprung:
367 shuttle_style_button.set_active_text (_("sprung"));
368 shuttle_fract = 0.0;
369 shuttle_box.queue_draw ();
370 if (_session) {
371 if (_session->transport_rolling()) {
372 shuttle_fract = SHUTTLE_FRACT_SPEED1;
373 _session->request_transport_speed (1.0);
376 break;
377 case Wheel:
378 shuttle_style_button.set_active_text (_("wheel"));
379 break;
382 } else if (p == "shuttle-units") {
384 switch (Config->get_shuttle_units()) {
385 case Percentage:
386 shuttle_units_button.set_label("% ");
387 break;
388 case Semitones:
389 shuttle_units_button.set_label(_("ST"));
390 break;
392 } else if (p == "video-pullup" || p == "timecode-format") {
393 reset_main_clocks ();
394 } else if (p == "show-track-meters") {
395 editor->toggle_meter_updating();
399 void
400 ARDOUR_UI::reset_main_clocks ()
402 ENSURE_GUI_THREAD (*this, &ARDOUR_UI::reset_main_clocks)
404 if (_session) {
405 primary_clock.set (_session->audible_frame(), true);
406 secondary_clock.set (_session->audible_frame(), true);
407 } else {
408 primary_clock.set (0, true);
409 secondary_clock.set (0, true);