Bodge around visual glitch where the ranges & markers list would overlap the editor...
[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 using namespace sigc;
49
50 void
51 ARDOUR_UI::toggle_external_sync()
52 {
53         ActionManager::toggle_config_state_foo ("Transport", "ToggleExternalSync", mem_fun (session->config, &SessionConfiguration::set_external_sync), mem_fun (session->config, &SessionConfiguration::get_external_sync));
54 }
55
56 void
57 ARDOUR_UI::toggle_time_master ()
58 {
59         ActionManager::toggle_config_state_foo ("Transport", "ToggleTimeMaster", mem_fun (session->config, &SessionConfiguration::set_jack_time_master), mem_fun (session->config, &SessionConfiguration::get_jack_time_master));
60 }
61
62 void
63 ARDOUR_UI::toggle_send_mtc ()
64 {
65         ActionManager::toggle_config_state ("options", "SendMTC", &RCConfiguration::set_send_mtc, &RCConfiguration::get_send_mtc);
66 }
67
68 void
69 ARDOUR_UI::toggle_send_mmc ()
70 {
71         ActionManager::toggle_config_state ("options", "SendMMC", &RCConfiguration::set_send_mmc, &RCConfiguration::get_send_mmc);
72 }
73
74 void
75 ARDOUR_UI::toggle_send_midi_clock ()
76 {
77         ActionManager::toggle_config_state ("options", "SendMidiClock", &RCConfiguration::set_send_midi_clock, &RCConfiguration::get_send_midi_clock);
78 }
79
80 void
81 ARDOUR_UI::toggle_use_mmc ()
82 {
83         ActionManager::toggle_config_state ("options", "UseMMC", &RCConfiguration::set_mmc_control, &RCConfiguration::get_mmc_control);
84 }
85
86 void
87 ARDOUR_UI::toggle_send_midi_feedback ()
88 {
89         ActionManager::toggle_config_state ("options", "SendMIDIfeedback", &RCConfiguration::set_midi_feedback, &RCConfiguration::get_midi_feedback);
90 }
91
92 void
93 ARDOUR_UI::toggle_auto_input ()
94 {
95         ActionManager::toggle_config_state_foo ("Transport", "ToggleAutoInput", mem_fun (session->config, &SessionConfiguration::set_auto_input), mem_fun (session->config, &SessionConfiguration::get_auto_input));
96 }
97
98 void
99 ARDOUR_UI::toggle_auto_play ()
100 {
101         ActionManager::toggle_config_state_foo ("Transport", "ToggleAutoPlay", mem_fun (session->config, &SessionConfiguration::set_auto_play), mem_fun (session->config, &SessionConfiguration::get_auto_play));
102 }
103
104 void
105 ARDOUR_UI::toggle_auto_return ()
106 {
107         ActionManager::toggle_config_state_foo ("Transport", "ToggleAutoReturn", mem_fun (session->config, &SessionConfiguration::set_auto_return), mem_fun (session->config, &SessionConfiguration::get_auto_return));
108 }
109
110 void
111 ARDOUR_UI::toggle_click ()
112 {
113         ActionManager::toggle_config_state ("Transport", "ToggleClick", &RCConfiguration::set_clicking, &RCConfiguration::get_clicking);
114 }
115
116 void
117 ARDOUR_UI::unset_dual_punch ()
118 {
119         Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
120
121         if (action) {
122                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
123                 if (tact) {
124                         ignore_dual_punch = true;
125                         tact->set_active (false);
126                         ignore_dual_punch = false;
127                 }
128         }
129 }
130
131 void
132 ARDOUR_UI::toggle_punch ()
133 {
134         if (ignore_dual_punch) {
135                 return;
136         }
137
138         Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
139
140         if (action) {
141
142                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
143
144                 if (!tact) {
145                         return;
146                 }
147
148                 /* drive the other two actions from this one */
149
150                 Glib::RefPtr<Action> in_action = ActionManager::get_action ("Transport", "TogglePunchIn");
151                 Glib::RefPtr<Action> out_action = ActionManager::get_action ("Transport", "TogglePunchOut");
152
153                 if (in_action && out_action) {
154                         Glib::RefPtr<ToggleAction> tiact = Glib::RefPtr<ToggleAction>::cast_dynamic(in_action);
155                         Glib::RefPtr<ToggleAction> toact = Glib::RefPtr<ToggleAction>::cast_dynamic(out_action);
156                         tiact->set_active (tact->get_active());
157                         toact->set_active (tact->get_active());
158                 }
159         }
160 }
161
162 void
163 ARDOUR_UI::toggle_punch_in ()
164 {
165         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("TogglePunchIn"));
166         if (!act) {
167                 return;
168         }
169
170         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
171         if (!tact) {
172                 return;
173         }
174
175         if (tact->get_active() != session->config.get_punch_in()) {
176                 session->config.set_punch_in (tact->get_active ());
177         }
178
179         if (tact->get_active()) {
180                 /* if punch-in is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
181                    to avoid confusing the user */
182                 show_loop_punch_ruler_and_disallow_hide ();
183         }
184
185         reenable_hide_loop_punch_ruler_if_appropriate ();
186 }
187
188 void
189 ARDOUR_UI::toggle_punch_out ()
190 {
191         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("TogglePunchOut"));
192         if (!act) {
193                 return;
194         }
195
196         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
197         if (!tact) {
198                 return;
199         }
200
201         if (tact->get_active() != session->config.get_punch_out()) {
202                 session->config.set_punch_out (tact->get_active ());
203         }
204
205         if (tact->get_active()) {
206                 /* if punch-out is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
207                    to avoid confusing the user */
208                 show_loop_punch_ruler_and_disallow_hide ();
209         }
210
211         reenable_hide_loop_punch_ruler_if_appropriate ();
212 }
213
214 void
215 ARDOUR_UI::show_loop_punch_ruler_and_disallow_hide ()
216 {
217         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Rulers"), "toggle-loop-punch-ruler");
218         if (!act) {
219                 return;
220         }
221
222         act->set_sensitive (false);
223         
224         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
225         if (!tact) {
226                 return;
227         }
228         
229         if (!tact->get_active()) {
230                 tact->set_active ();
231         }
232 }
233
234 /* This is a bit of a silly name for a method */
235 void
236 ARDOUR_UI::reenable_hide_loop_punch_ruler_if_appropriate ()
237 {
238         if (!session->config.get_punch_in() && !session->config.get_punch_out()) {
239                 /* if punch in/out are now both off, reallow hiding of the loop/punch ruler */
240                 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Rulers"), "toggle-loop-punch-ruler");
241                 if (act) {
242                         act->set_sensitive (true);
243                 }
244         }
245 }
246
247 void
248 ARDOUR_UI::toggle_video_sync()
249 {
250         Glib::RefPtr<Action> act = ActionManager::get_action ("Transport", "ToggleVideoSync");
251         if (act) {
252                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
253                 session->config.set_use_video_sync (tact->get_active());
254         }
255 }
256
257 void
258 ARDOUR_UI::toggle_editing_space()
259 {
260         Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMaximalEditor");
261         if (act) {
262                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
263                 if (tact->get_active()) {
264                         maximise_editing_space ();
265                 } else {
266                         restore_editing_space ();
267                 }
268         }
269 }
270
271 void
272 ARDOUR_UI::setup_session_options ()
273 {
274         session->config.ParameterChanged.connect (mem_fun (*this, &ARDOUR_UI::parameter_changed));
275         session->config.map_parameters (mem_fun (*this, &ARDOUR_UI::parameter_changed));
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 (bind (mem_fun (*this, &ARDOUR_UI::parameter_changed), p));
303
304         if (p == "external-sync") {
305
306                 ActionManager::map_some_state ("Transport", "ToggleExternalSync", 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", mem_fun (session->config, &SessionConfiguration::get_auto_play));
343         } else if (p == "auto-return") {
344                 ActionManager::map_some_state ("Transport", "ToggleAutoReturn", mem_fun (session->config, &SessionConfiguration::get_auto_return));
345         } else if (p == "auto-input") {
346                 ActionManager::map_some_state ("Transport", "ToggleAutoInput", mem_fun (session->config, &SessionConfiguration::get_auto_input));
347         } else if (p == "punch-out") {
348                 ActionManager::map_some_state ("Transport", "TogglePunchOut", 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", 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", mem_fun (session->config, &SessionConfiguration::get_jack_time_master));
361         } else if (p == "use-video-sync") {
362                 ActionManager::map_some_state ("Transport",  "ToggleVideoSync", 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                 if (session) {
394                         primary_clock.set (session->audible_frame(), true);
395                         secondary_clock.set (session->audible_frame(), true);
396                 } else {
397                         primary_clock.set (0, true);
398                         secondary_clock.set (0, true);
399                 }
400         } else if (p == "show-track-meters") {
401                 editor->toggle_meter_updating();
402         }
403 }