Remove excess menu separator.
[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_time_master ()
52 {
53         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));
54 }
55
56 void
57 ARDOUR_UI::toggle_send_mtc ()
58 {
59         ActionManager::toggle_config_state ("options", "SendMTC", &RCConfiguration::set_send_mtc, &RCConfiguration::get_send_mtc);
60 }
61
62 void
63 ARDOUR_UI::toggle_send_mmc ()
64 {
65         ActionManager::toggle_config_state ("options", "SendMMC", &RCConfiguration::set_send_mmc, &RCConfiguration::get_send_mmc);
66 }
67
68 void
69 ARDOUR_UI::toggle_send_midi_clock ()
70 {
71         ActionManager::toggle_config_state ("options", "SendMidiClock", &RCConfiguration::set_send_midi_clock, &RCConfiguration::get_send_midi_clock);
72 }
73
74 void
75 ARDOUR_UI::toggle_use_mmc ()
76 {
77         ActionManager::toggle_config_state ("options", "UseMMC", &RCConfiguration::set_mmc_control, &RCConfiguration::get_mmc_control);
78 }
79
80 void
81 ARDOUR_UI::toggle_send_midi_feedback ()
82 {
83         ActionManager::toggle_config_state ("options", "SendMIDIfeedback", &RCConfiguration::set_midi_feedback, &RCConfiguration::get_midi_feedback);
84 }
85
86 void
87 ARDOUR_UI::toggle_auto_input ()
88 {
89         ActionManager::toggle_config_state_foo ("Transport", "ToggleAutoInput", mem_fun (session->config, &SessionConfiguration::set_auto_input), mem_fun (session->config, &SessionConfiguration::get_auto_input));
90 }
91
92 void
93 ARDOUR_UI::toggle_auto_play ()
94 {
95         ActionManager::toggle_config_state_foo ("Transport", "ToggleAutoPlay", mem_fun (session->config, &SessionConfiguration::set_auto_play), mem_fun (session->config, &SessionConfiguration::get_auto_play));
96 }
97
98 void
99 ARDOUR_UI::toggle_auto_return ()
100 {
101         ActionManager::toggle_config_state_foo ("Transport", "ToggleAutoReturn", mem_fun (session->config, &SessionConfiguration::set_auto_return), mem_fun (session->config, &SessionConfiguration::get_auto_return));
102 }
103
104 void
105 ARDOUR_UI::toggle_click ()
106 {
107         ActionManager::toggle_config_state ("Transport", "ToggleClick", &RCConfiguration::set_clicking, &RCConfiguration::get_clicking);
108 }
109
110 void
111 ARDOUR_UI::toggle_session_auto_loop ()
112 {
113         if (session) {
114                 if (session->get_play_loop()) {
115                         if (session->transport_rolling()) {
116                                 transport_roll();
117                         } else {
118                                 session->request_play_loop (false);
119                         }
120                 } else {
121                         session->request_play_loop (true);
122                 }
123         }
124 }
125
126 void
127 ARDOUR_UI::unset_dual_punch ()
128 {
129         Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
130
131         if (action) {
132                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
133                 if (tact) {
134                         ignore_dual_punch = true;
135                         tact->set_active (false);
136                         ignore_dual_punch = false;
137                 }
138         }
139 }
140
141 void
142 ARDOUR_UI::toggle_punch ()
143 {
144         if (ignore_dual_punch) {
145                 return;
146         }
147
148         Glib::RefPtr<Action> action = ActionManager::get_action ("Transport", "TogglePunch");
149
150         if (action) {
151
152                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(action);
153
154                 if (!tact) {
155                         return;
156                 }
157
158                 /* drive the other two actions from this one */
159
160                 Glib::RefPtr<Action> in_action = ActionManager::get_action ("Transport", "TogglePunchIn");
161                 Glib::RefPtr<Action> out_action = ActionManager::get_action ("Transport", "TogglePunchOut");
162
163                 if (in_action && out_action) {
164                         Glib::RefPtr<ToggleAction> tiact = Glib::RefPtr<ToggleAction>::cast_dynamic(in_action);
165                         Glib::RefPtr<ToggleAction> toact = Glib::RefPtr<ToggleAction>::cast_dynamic(out_action);
166                         tiact->set_active (tact->get_active());
167                         toact->set_active (tact->get_active());
168                 }
169         }
170 }
171
172 void
173 ARDOUR_UI::toggle_punch_in ()
174 {
175         ActionManager::toggle_config_state_foo ("Transport", "TogglePunchIn", mem_fun (session->config, &SessionConfiguration::set_punch_in), mem_fun (session->config, &SessionConfiguration::get_punch_in));
176 }
177
178 void
179 ARDOUR_UI::toggle_punch_out ()
180 {
181         ActionManager::toggle_config_state_foo ("Transport", "TogglePunchOut", mem_fun (session->config, &SessionConfiguration::set_punch_out), mem_fun (session->config, &SessionConfiguration::get_punch_out));
182 }
183
184 void
185 ARDOUR_UI::toggle_video_sync()
186 {
187         Glib::RefPtr<Action> act = ActionManager::get_action ("Transport", "ToggleVideoSync");
188         if (act) {
189                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
190                 session->config.set_use_video_sync (tact->get_active());
191         }
192 }
193
194 void
195 ARDOUR_UI::toggle_editing_space()
196 {
197         Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMaximalEditor");
198         if (act) {
199                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
200                 if (tact->get_active()) {
201                         maximise_editing_space ();
202                 } else {
203                         restore_editing_space ();
204                 }
205         }
206 }
207
208 void
209 ARDOUR_UI::mtc_port_changed ()
210 {
211         bool have_mtc;
212         bool have_midi_clock;
213
214         if (session) {
215                 if (session->mtc_port()) {
216                         have_mtc = true;
217                 } else {
218                         have_mtc = false;
219                 }
220                 if (session->midi_clock_port()) {
221                         have_midi_clock = true;
222                 } else {
223                         have_midi_clock = false;
224                 }
225         } else {
226                 have_mtc = false;
227                 have_midi_clock = false;
228         }
229
230         positional_sync_strings.clear ();
231         positional_sync_strings.push_back (slave_source_to_string (None));
232         if (have_mtc) {
233                 positional_sync_strings.push_back (slave_source_to_string (MTC));
234         }
235         if (have_midi_clock) {
236                 positional_sync_strings.push_back (slave_source_to_string (MIDIClock));
237         }
238         positional_sync_strings.push_back (slave_source_to_string (JACK));
239
240         set_popdown_strings (sync_option_combo, positional_sync_strings);
241 }
242
243 void
244 ARDOUR_UI::setup_session_options ()
245 {
246         mtc_port_changed ();
247
248         Config->ParameterChanged.connect (mem_fun (*this, &ARDOUR_UI::parameter_changed));
249 }
250
251 void
252 ARDOUR_UI::parameter_changed (std::string p)
253 {
254         ENSURE_GUI_THREAD (bind (mem_fun (*this, &ARDOUR_UI::parameter_changed), p));
255
256         if (p == "slave-source") {
257
258                 sync_option_combo.set_active_text (slave_source_to_string (Config->get_slave_source()));
259
260                 switch (Config->get_slave_source()) {
261                 case None:
262                         ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (true);
263                         ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (true);
264                         break;
265
266                 default:
267                         /* XXX need to make auto-play is off as well as insensitive */
268                         ActionManager::get_action ("Transport", "ToggleAutoPlay")->set_sensitive (false);
269                         ActionManager::get_action ("Transport", "ToggleAutoReturn")->set_sensitive (false);
270                         break;
271                 }
272
273         } else if (p == "send-mtc") {
274
275                 ActionManager::map_some_state ("options", "SendMTC", &RCConfiguration::get_send_mtc);
276
277         } else if (p == "send-mmc") {
278
279                 ActionManager::map_some_state ("options", "SendMMC", &RCConfiguration::get_send_mmc);
280
281         } else if (p == "use-osc") {
282
283 #ifdef HAVE_LIBLO
284                 if (Config->get_use_osc()) {
285                         osc->start ();
286                 } else {
287                         osc->stop ();
288                 }
289 #endif
290
291         } else if (p == "mmc-control") {
292                 ActionManager::map_some_state ("options", "UseMMC", &RCConfiguration::get_mmc_control);
293         } else if (p == "midi-feedback") {
294                 ActionManager::map_some_state ("options", "SendMIDIfeedback", &RCConfiguration::get_midi_feedback);
295         } else if (p == "auto-play") {
296                 ActionManager::map_some_state ("Transport", "ToggleAutoPlay", mem_fun (session->config, &SessionConfiguration::get_auto_play));
297         } else if (p == "auto-return") {
298                 ActionManager::map_some_state ("Transport", "ToggleAutoReturn", mem_fun (session->config, &SessionConfiguration::get_auto_return));
299         } else if (p == "auto-input") {
300                 ActionManager::map_some_state ("Transport", "ToggleAutoInput", mem_fun (session->config, &SessionConfiguration::get_auto_input));
301         } else if (p == "punch-out") {
302                 ActionManager::map_some_state ("Transport", "TogglePunchOut", mem_fun (session->config, &SessionConfiguration::get_punch_out));
303                 if (!session->config.get_punch_out()) {
304                         unset_dual_punch ();
305                 }
306         } else if (p == "punch-in") {
307                 ActionManager::map_some_state ("Transport", "TogglePunchIn", mem_fun (session->config, &SessionConfiguration::get_punch_in));
308                 if (!session->config.get_punch_in()) {
309                         unset_dual_punch ();
310                 }
311         } else if (p == "clicking") {
312                 ActionManager::map_some_state ("Transport", "ToggleClick", &RCConfiguration::get_clicking);
313         } else if (p == "jack-time-master") {
314                 ActionManager::map_some_state ("Transport",  "ToggleTimeMaster", mem_fun (session->config, &SessionConfiguration::get_jack_time_master));
315         } else if (p == "use-video-sync") {
316                 ActionManager::map_some_state ("Transport",  "ToggleVideoSync", mem_fun (session->config, &SessionConfiguration::get_use_video_sync));
317         } else if (p == "shuttle-behaviour") {
318
319                 switch (Config->get_shuttle_behaviour ()) {
320                 case Sprung:
321                         shuttle_style_button.set_active_text (_("sprung"));
322                         shuttle_fract = 0.0;
323                         shuttle_box.queue_draw ();
324                         if (session) {
325                                 if (session->transport_rolling()) {
326                                         shuttle_fract = SHUTTLE_FRACT_SPEED1;
327                                         session->request_transport_speed (1.0);
328                                 }
329                         }
330                         break;
331                 case Wheel:
332                         shuttle_style_button.set_active_text (_("wheel"));
333                         break;
334                 }
335
336         } else if (p == "shuttle-units") {
337
338                 switch (Config->get_shuttle_units()) {
339                 case Percentage:
340                         shuttle_units_button.set_label("% ");
341                         break;
342                 case Semitones:
343                         shuttle_units_button.set_label(_("ST"));
344                         break;
345                 }
346         } else if (p == "video-pullup" || p == "smpte-format") {
347                 if (session) {
348                         primary_clock.set (session->audible_frame(), true);
349                         secondary_clock.set (session->audible_frame(), true);
350                 } else {
351                         primary_clock.set (0, true);
352                         secondary_clock.set (0, true);
353                 }
354         } else if (p == "show-track-meters") {
355                 editor->toggle_meter_updating();
356         }
357 }