changes to help strp silence
[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/configuration.h"
30 #include "ardour/session.h"
31 #include "ardour/audioengine.h"
32
33 #ifdef HAVE_LIBLO
34 #include "ardour/osc.h"
35 #endif
36
37 #include "ardour_ui.h"
38 #include "actions.h"
39 #include "gui_thread.h"
40 #include "public_editor.h"
41
42 #include "i18n.h"
43
44 using namespace Gtk;
45 using namespace Gtkmm2ext;
46 using namespace ARDOUR;
47 using namespace PBD;
48
49 void
50 ARDOUR_UI::toggle_external_sync()
51 {
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));
53 }
54
55 void
56 ARDOUR_UI::toggle_time_master ()
57 {
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));
59 }
60
61 void
62 ARDOUR_UI::toggle_send_mtc ()
63 {
64         ActionManager::toggle_config_state ("options", "SendMTC", &RCConfiguration::set_send_mtc, &RCConfiguration::get_send_mtc);
65 }
66
67 void
68 ARDOUR_UI::toggle_send_mmc ()
69 {
70         ActionManager::toggle_config_state ("options", "SendMMC", &RCConfiguration::set_send_mmc, &RCConfiguration::get_send_mmc);
71 }
72
73 void
74 ARDOUR_UI::toggle_send_midi_clock ()
75 {
76         ActionManager::toggle_config_state ("options", "SendMidiClock", &RCConfiguration::set_send_midi_clock, &RCConfiguration::get_send_midi_clock);
77 }
78
79 void
80 ARDOUR_UI::toggle_use_mmc ()
81 {
82         ActionManager::toggle_config_state ("options", "UseMMC", &RCConfiguration::set_mmc_control, &RCConfiguration::get_mmc_control);
83 }
84
85 void
86 ARDOUR_UI::toggle_send_midi_feedback ()
87 {
88         ActionManager::toggle_config_state ("options", "SendMIDIfeedback", &RCConfiguration::set_midi_feedback, &RCConfiguration::get_midi_feedback);
89 }
90
91 void
92 ARDOUR_UI::toggle_auto_input ()
93 {
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));
95 }
96
97 void
98 ARDOUR_UI::toggle_auto_play ()
99 {
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));
101 }
102
103 void
104 ARDOUR_UI::toggle_auto_return ()
105 {
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));
107 }
108
109 void
110 ARDOUR_UI::toggle_click ()
111 {
112         ActionManager::toggle_config_state ("Transport", "ToggleClick", &RCConfiguration::set_clicking, &RCConfiguration::get_clicking);
113 }
114
115 void
116 ARDOUR_UI::unset_dual_punch ()
117 {
118         Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
119
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;
126                 }
127         }
128 }
129
130 void
131 ARDOUR_UI::toggle_punch ()
132 {
133         if (ignore_dual_punch) {
134                 return;
135         }
136
137         Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
138
139         if (action) {
140
141                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
142
143                 if (!tact) {
144                         return;
145                 }
146
147                 /* drive the other two actions from this one */
148
149                 Glib::RefPtr<Action> in_action = ActionManager::get_action ("Transport", "TogglePunchIn");
150                 Glib::RefPtr<Action> out_action = ActionManager::get_action ("Transport", "TogglePunchOut");
151
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());
157                 }
158         }
159 }
160
161 void
162 ARDOUR_UI::toggle_punch_in ()
163 {
164         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("TogglePunchIn"));
165         if (!act) {
166                 return;
167         }
168
169         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
170         if (!tact) {
171                 return;
172         }
173
174         if (tact->get_active() != _session->config.get_punch_in()) {
175                 _session->config.set_punch_in (tact->get_active ());
176         }
177
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 ();
182         }
183
184         reenable_hide_loop_punch_ruler_if_appropriate ();
185 }
186
187 void
188 ARDOUR_UI::toggle_punch_out ()
189 {
190         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("TogglePunchOut"));
191         if (!act) {
192                 return;
193         }
194
195         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
196         if (!tact) {
197                 return;
198         }
199
200         if (tact->get_active() != _session->config.get_punch_out()) {
201                 _session->config.set_punch_out (tact->get_active ());
202         }
203
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 ();
208         }
209
210         reenable_hide_loop_punch_ruler_if_appropriate ();
211 }
212
213 void
214 ARDOUR_UI::show_loop_punch_ruler_and_disallow_hide ()
215 {
216         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Rulers"), "toggle-loop-punch-ruler");
217         if (!act) {
218                 return;
219         }
220
221         act->set_sensitive (false);
222         
223         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
224         if (!tact) {
225                 return;
226         }
227         
228         if (!tact->get_active()) {
229                 tact->set_active ();
230         }
231 }
232
233 /* This is a bit of a silly name for a method */
234 void
235 ARDOUR_UI::reenable_hide_loop_punch_ruler_if_appropriate ()
236 {
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);
242                 }
243         }
244 }
245
246 void
247 ARDOUR_UI::toggle_video_sync()
248 {
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());
253         }
254 }
255
256 void
257 ARDOUR_UI::toggle_editing_space()
258 {
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 ();
266                 }
267         }
268 }
269
270 void
271 ARDOUR_UI::setup_session_options ()
272 {
273         _session->config.ParameterChanged.connect (_session_connections, 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);
276 }
277
278 #if 0
279 void
280 ARDOUR_UI::handle_sync_change ()
281 {
282         if (!_session) {
283                 return;
284         }
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);
294         }
295
296 }
297 #endif
298
299 void
300 ARDOUR_UI::parameter_changed (std::string p)
301 {
302         ENSURE_GUI_THREAD (*this, &ARDOUR_UI::parameter_changed, 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_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);
317                 }
318         
319         } else if (p == "send-mtc") {
320
321                 ActionManager::map_some_state ("options", "SendMTC", &RCConfiguration::get_send_mtc);
322
323         } else if (p == "send-mmc") {
324
325                 ActionManager::map_some_state ("options", "SendMMC", &RCConfiguration::get_send_mmc);
326
327         } else if (p == "use-osc") {
328
329 #ifdef HAVE_LIBLO
330                 if (Config->get_use_osc()) {
331                         osc->start ();
332                 } else {
333                         osc->stop ();
334                 }
335 #endif
336
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 ();
351                 }
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 ();
356                 }
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") {
364
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);
374                                 }
375                         }
376                         break;
377                 case Wheel:
378                         shuttle_style_button.set_active_text (_("wheel"));
379                         break;
380                 }
381
382         } else if (p == "shuttle-units") {
383
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;
391                 }
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();
396         }
397 }
398
399 void
400 ARDOUR_UI::reset_main_clocks ()
401 {
402         ENSURE_GUI_THREAD (*this, &ARDOUR_UI::reset_main_clocks)
403
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);
410         }
411 }