Add browse button to recent session dialogue. Fixes #3357.
[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_keep_tearoffs ()
51 {
52         ActionManager::toggle_config_state ("Common", "KeepTearoffs", &RCConfiguration::set_keep_tearoffs, &RCConfiguration::get_keep_tearoffs);
53  
54         ARDOUR_UI::toggle_editing_space ();
55 }
56
57 void
58 ARDOUR_UI::toggle_external_sync()
59 {
60         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));
61 }
62
63 void
64 ARDOUR_UI::toggle_time_master ()
65 {
66         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));
67 }
68
69 void
70 ARDOUR_UI::toggle_send_mtc ()
71 {
72         ActionManager::toggle_config_state ("options", "SendMTC", &RCConfiguration::set_send_mtc, &RCConfiguration::get_send_mtc);
73 }
74
75 void
76 ARDOUR_UI::toggle_send_mmc ()
77 {
78         ActionManager::toggle_config_state ("options", "SendMMC", &RCConfiguration::set_send_mmc, &RCConfiguration::get_send_mmc);
79 }
80
81 void
82 ARDOUR_UI::toggle_send_midi_clock ()
83 {
84         ActionManager::toggle_config_state ("options", "SendMidiClock", &RCConfiguration::set_send_midi_clock, &RCConfiguration::get_send_midi_clock);
85 }
86
87 void
88 ARDOUR_UI::toggle_use_mmc ()
89 {
90         ActionManager::toggle_config_state ("options", "UseMMC", &RCConfiguration::set_mmc_control, &RCConfiguration::get_mmc_control);
91 }
92
93 void
94 ARDOUR_UI::toggle_send_midi_feedback ()
95 {
96         ActionManager::toggle_config_state ("options", "SendMIDIfeedback", &RCConfiguration::set_midi_feedback, &RCConfiguration::get_midi_feedback);
97 }
98
99 void
100 ARDOUR_UI::toggle_auto_input ()
101 {
102         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));
103 }
104
105 void
106 ARDOUR_UI::toggle_auto_play ()
107 {
108         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));
109 }
110
111 void
112 ARDOUR_UI::toggle_auto_return ()
113 {
114         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));
115 }
116
117 void
118 ARDOUR_UI::toggle_click ()
119 {
120         ActionManager::toggle_config_state ("Transport", "ToggleClick", &RCConfiguration::set_clicking, &RCConfiguration::get_clicking);
121 }
122
123 void
124 ARDOUR_UI::unset_dual_punch ()
125 {
126         Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
127
128         if (action) {
129                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
130                 if (tact) {
131                         ignore_dual_punch = true;
132                         tact->set_active (false);
133                         ignore_dual_punch = false;
134                 }
135         }
136 }
137
138 void
139 ARDOUR_UI::toggle_punch ()
140 {
141         if (ignore_dual_punch) {
142                 return;
143         }
144
145         Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
146
147         if (action) {
148
149                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
150
151                 if (!tact) {
152                         return;
153                 }
154
155                 /* drive the other two actions from this one */
156
157                 Glib::RefPtr<Action> in_action = ActionManager::get_action ("Transport", "TogglePunchIn");
158                 Glib::RefPtr<Action> out_action = ActionManager::get_action ("Transport", "TogglePunchOut");
159
160                 if (in_action && out_action) {
161                         Glib::RefPtr<ToggleAction> tiact = Glib::RefPtr<ToggleAction>::cast_dynamic(in_action);
162                         Glib::RefPtr<ToggleAction> toact = Glib::RefPtr<ToggleAction>::cast_dynamic(out_action);
163                         tiact->set_active (tact->get_active());
164                         toact->set_active (tact->get_active());
165                 }
166         }
167 }
168
169 void
170 ARDOUR_UI::toggle_punch_in ()
171 {
172         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("TogglePunchIn"));
173         if (!act) {
174                 return;
175         }
176
177         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
178         if (!tact) {
179                 return;
180         }
181
182         if (tact->get_active() != _session->config.get_punch_in()) {
183                 _session->config.set_punch_in (tact->get_active ());
184         }
185
186         if (tact->get_active()) {
187                 /* if punch-in is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
188                    to avoid confusing the user */
189                 show_loop_punch_ruler_and_disallow_hide ();
190         }
191
192         reenable_hide_loop_punch_ruler_if_appropriate ();
193 }
194
195 void
196 ARDOUR_UI::toggle_punch_out ()
197 {
198         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Transport"), X_("TogglePunchOut"));
199         if (!act) {
200                 return;
201         }
202
203         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
204         if (!tact) {
205                 return;
206         }
207
208         if (tact->get_active() != _session->config.get_punch_out()) {
209                 _session->config.set_punch_out (tact->get_active ());
210         }
211
212         if (tact->get_active()) {
213                 /* if punch-out is turned on, make sure the loop/punch ruler is visible, and stop it being hidden,
214                    to avoid confusing the user */
215                 show_loop_punch_ruler_and_disallow_hide ();
216         }
217
218         reenable_hide_loop_punch_ruler_if_appropriate ();
219 }
220
221 void
222 ARDOUR_UI::show_loop_punch_ruler_and_disallow_hide ()
223 {
224         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Rulers"), "toggle-loop-punch-ruler");
225         if (!act) {
226                 return;
227         }
228
229         act->set_sensitive (false);
230         
231         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
232         if (!tact) {
233                 return;
234         }
235         
236         if (!tact->get_active()) {
237                 tact->set_active ();
238         }
239 }
240
241 /* This is a bit of a silly name for a method */
242 void
243 ARDOUR_UI::reenable_hide_loop_punch_ruler_if_appropriate ()
244 {
245         if (!_session->config.get_punch_in() && !_session->config.get_punch_out()) {
246                 /* if punch in/out are now both off, reallow hiding of the loop/punch ruler */
247                 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Rulers"), "toggle-loop-punch-ruler");
248                 if (act) {
249                         act->set_sensitive (true);
250                 }
251         }
252 }
253
254 void
255 ARDOUR_UI::toggle_video_sync()
256 {
257         Glib::RefPtr<Action> act = ActionManager::get_action ("Transport", "ToggleVideoSync");
258         if (act) {
259                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
260                 _session->config.set_use_video_sync (tact->get_active());
261         }
262 }
263
264 void
265 ARDOUR_UI::toggle_editing_space()
266 {
267         Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMaximalEditor");
268         if (act) {
269                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
270                 if (tact->get_active()) {
271                         maximise_editing_space ();
272                 } else {
273                         restore_editing_space ();
274                 }
275         }
276 }
277
278 void
279 ARDOUR_UI::setup_session_options ()
280 {
281         _session->config.ParameterChanged.connect (_session_connections, MISSING_INVALIDATOR, ui_bind (&ARDOUR_UI::parameter_changed, this, _1), gui_context());
282         boost::function<void (std::string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
283         _session->config.map_parameters (pc);
284 }
285
286 #if 0
287 void
288 ARDOUR_UI::handle_sync_change ()
289 {
290         if (!_session) {
291                 return;
292         }
293         if (!_session->config.get_external_sync()) {
294                 sync_button.set_label (_("Internal"));
295                 ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (true);
296                 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (true);
297         } else {
298                 sync_button.set_label (_("External"));
299                 /* XXX need to make auto-play is off as well as insensitive */
300                 ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (false);
301                 ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (false);
302         }
303
304 }
305 #endif
306
307 void
308 ARDOUR_UI::parameter_changed (std::string p)
309 {
310         ENSURE_GUI_THREAD (*this, &ARDOUR_UI::parameter_changed, p)
311
312         if (p == "external-sync") {
313
314                 ActionManager::map_some_state ("Transport", "ToggleExternalSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_external_sync));
315
316                 if (!_session->config.get_external_sync()) {
317                         sync_button.set_label (_("Internal"));
318                         ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (true);
319                         ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (true);
320                 } else {
321                         sync_button.set_label (sync_source_to_string (_session->config.get_sync_source()));
322                         /* XXX need to make auto-play is off as well as insensitive */
323                         ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (false);
324                         ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (false);
325                 }
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 == "use-osc") {
336
337 #ifdef HAVE_LIBLO
338                 if (Config->get_use_osc()) {
339                         osc->start ();
340                 } else {
341                         osc->stop ();
342                 }
343 #endif
344
345         } else if (p == "keep-tearoffs") {
346                 ActionManager::map_some_state ("Common", "KeepTearoffs", &RCConfiguration::get_keep_tearoffs);
347         } else if (p == "mmc-control") {
348                 ActionManager::map_some_state ("options", "UseMMC", &RCConfiguration::get_mmc_control);
349         } else if (p == "midi-feedback") {
350                 ActionManager::map_some_state ("options", "SendMIDIfeedback", &RCConfiguration::get_midi_feedback);
351         } else if (p == "auto-play") {
352                 ActionManager::map_some_state ("Transport", "ToggleAutoPlay", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_play));
353         } else if (p == "auto-return") {
354                 ActionManager::map_some_state ("Transport", "ToggleAutoReturn", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_return));
355         } else if (p == "auto-input") {
356                 ActionManager::map_some_state ("Transport", "ToggleAutoInput", sigc::mem_fun (_session->config, &SessionConfiguration::get_auto_input));
357         } else if (p == "punch-out") {
358                 ActionManager::map_some_state ("Transport", "TogglePunchOut", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_out));
359                 if (!_session->config.get_punch_out()) {
360                         unset_dual_punch ();
361                 }
362         } else if (p == "punch-in") {
363                 ActionManager::map_some_state ("Transport", "TogglePunchIn", sigc::mem_fun (_session->config, &SessionConfiguration::get_punch_in));
364                 if (!_session->config.get_punch_in()) {
365                         unset_dual_punch ();
366                 }
367         } else if (p == "clicking") {
368                 ActionManager::map_some_state ("Transport", "ToggleClick", &RCConfiguration::get_clicking);
369         } else if (p == "jack-time-master") {
370                 ActionManager::map_some_state ("Transport",  "ToggleTimeMaster", sigc::mem_fun (_session->config, &SessionConfiguration::get_jack_time_master));
371         } else if (p == "use-video-sync") {
372                 ActionManager::map_some_state ("Transport",  "ToggleVideoSync", sigc::mem_fun (_session->config, &SessionConfiguration::get_use_video_sync));
373         } else if (p == "shuttle-behaviour") {
374
375                 switch (Config->get_shuttle_behaviour ()) {
376                 case Sprung:
377                         shuttle_style_button.set_active_text (_("sprung"));
378                         shuttle_fract = 0.0;
379                         shuttle_box.queue_draw ();
380                         if (_session) {
381                                 if (_session->transport_rolling()) {
382                                         shuttle_fract = SHUTTLE_FRACT_SPEED1;
383                                         _session->request_transport_speed (1.0);
384                                 }
385                         }
386                         break;
387                 case Wheel:
388                         shuttle_style_button.set_active_text (_("wheel"));
389                         break;
390                 }
391
392         } else if (p == "shuttle-units") {
393
394                 switch (Config->get_shuttle_units()) {
395                 case Percentage:
396                         shuttle_units_button.set_label("% ");
397                         break;
398                 case Semitones:
399                         shuttle_units_button.set_label(_("ST"));
400                         break;
401                 }
402         } else if (p == "video-pullup" || p == "timecode-format") {
403                 reset_main_clocks ();
404         } else if (p == "show-track-meters") {
405                 editor->toggle_meter_updating();
406         }
407 }
408
409 void
410 ARDOUR_UI::reset_main_clocks ()
411 {
412         ENSURE_GUI_THREAD (*this, &ARDOUR_UI::reset_main_clocks)
413
414         if (_session) {
415                 primary_clock.set (_session->audible_frame(), true);
416                 secondary_clock.set (_session->audible_frame(), true);
417         } else {
418                 primary_clock.set (0, true);
419                 secondary_clock.set (0, true);
420         }
421 }