Have GUI Option reflect current state (in case toggle fails)
[ardour.git] / gtk2_ardour / session_option_editor.cc
1 /*
2     Copyright (C) 2000-2010 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 #include "ardour/session.h"
21
22 #include "gui_thread.h"
23 #include "session_option_editor.h"
24 #include "search_path_option.h"
25 #include "i18n.h"
26
27 using namespace std;
28 using namespace ARDOUR;
29 using namespace Timecode;
30
31 SessionOptionEditor::SessionOptionEditor (Session* s)
32         : OptionEditor (&(s->config), _("Session Properties"))
33         , _session_config (&(s->config))
34 {
35         set_session (s);
36
37         set_name ("SessionProperties");
38
39         /* TIMECODE*/
40
41         add_option (_("Timecode"), new OptionEditorHeading (_("Timecode Settings")));
42
43         ComboOption<TimecodeFormat>* smf = new ComboOption<TimecodeFormat> (
44                 "timecode-format",
45                 _("Timecode frames-per-second"),
46                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_timecode_format),
47                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_timecode_format)
48                 );
49
50         smf->add (timecode_23976, _("23.976"));
51         smf->add (timecode_24, _("24"));
52         smf->add (timecode_24976, _("24.975"));
53         smf->add (timecode_25, _("25"));
54         smf->add (timecode_2997, _("29.97"));
55         smf->add (timecode_2997drop, _("29.97 drop"));
56         smf->add (timecode_30, _("30"));
57         smf->add (timecode_30drop, _("30 drop"));
58         smf->add (timecode_5994, _("59.94"));
59         smf->add (timecode_60, _("60"));
60
61         add_option (_("Timecode"), smf);
62
63         _vpu = new ComboOption<float> (
64                 "video-pullup",
65                 _("Pull-up / pull-down"),
66                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_video_pullup),
67                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_video_pullup)
68                 );
69
70         _vpu->add (4.1667 + 0.1, _("4.1667 + 0.1%"));
71         _vpu->add (4.1667, _("4.1667"));
72         _vpu->add (4.1667 - 0.1, _("4.1667 - 0.1%"));
73         _vpu->add (0.1, _("0.1"));
74         _vpu->add (0, _("none"));
75         _vpu->add (-0.1, _("-0.1"));
76         _vpu->add (-4.1667 + 0.1, _("-4.1667 + 0.1%"));
77         _vpu->add (-4.1667, _("-4.1667"));
78         _vpu->add (-4.1667 - 0.1, _("-4.1667 - 0.1%"));
79
80         add_option (_("Timecode"), _vpu);
81
82         add_option (_("Sync"), new BoolOption (
83                             "use-video-file-fps",
84                             _("Use Video File's FPS Instead of Timecode Value for Timeline and Video Monitor."),
85                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_use_video_file_fps),
86                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_use_video_file_fps)
87                             ));
88
89         add_option (_("Sync"), new BoolOption (
90                             "videotimeline-pullup",
91                             _("Apply Pull-Up/Down to Video Timeline and Video Monitor (Unless using JACK-sync)."),
92                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_videotimeline_pullup),
93                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_videotimeline_pullup)
94                             ));
95
96         add_option (_("Timecode"), new OptionEditorHeading (_("Ext Timecode Offsets")));
97
98         ClockOption* sco = new ClockOption (
99                 "slave-timecode-offset",
100                 _("Slave Timecode offset"),
101                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_slave_timecode_offset),
102                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_slave_timecode_offset)
103                 );
104
105         sco->set_session (_session);
106         sco->clock().set_negative_allowed (true);
107         Gtkmm2ext::UI::instance()->set_tip (sco->tip_widget(), _("The specified offset is added to the received timecode (MTC or LTC)."));
108
109         add_option (_("Timecode"), sco);
110
111         ClockOption* gco = new ClockOption (
112                 "timecode-generator-offset",
113                 _("Timecode Generator offset"),
114                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_timecode_generator_offset),
115                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_timecode_generator_offset)
116                 );
117
118         gco->set_session (_session);
119         gco->clock().set_negative_allowed (true);
120         Gtkmm2ext::UI::instance()->set_tip (gco->tip_widget(), _("Specify an offset which is added to the generated timecode (so far only LTC)."));
121
122         add_option (_("Timecode"), gco);
123
124         add_option (_("Timecode"), new OptionEditorHeading (_("JACK Transport/Time Settings")));
125
126         add_option (_("Timecode"), new BoolOption (
127                             "jack-time-master",
128                             string_compose (_("%1 is JACK Time Master (provides Bar|Beat|Tick and other information to JACK)"), PROGRAM_NAME),
129                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_jack_time_master),
130                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_jack_time_master)
131                             ));
132
133         /* FADES */
134
135         add_option (_("Fades"), new SpinOption<float> (
136                 _("destructive-xfade-seconds"),
137                 _("Destructive crossfade length"),
138                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_destructive_xfade_msecs),
139                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_destructive_xfade_msecs),
140                 0, 1000, 1, 10,
141                 _("ms")
142                             ));
143
144         add_option (_("Fades"), new BoolOption (
145                             "use-region-fades",
146                             _("Region fades active"),
147                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_use_region_fades),
148                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_use_region_fades)
149                             ));
150
151         add_option (_("Fades"), new BoolOption (
152                             "show-region-fades",
153                             _("Region fades visible"),
154                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_show_region_fades),
155                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_show_region_fades)
156                             ));
157
158         /* Media */
159
160         add_option (_("Media"), new OptionEditorHeading (_("Audio file format")));
161
162         ComboOption<SampleFormat>* sf = new ComboOption<SampleFormat> (
163                 "native-file-data-format",
164                 _("Sample format"),
165                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_native_file_data_format),
166                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_native_file_data_format)
167                 );
168
169         sf->add (FormatFloat, _("32-bit floating point"));
170         sf->add (FormatInt24, _("24-bit integer"));
171         sf->add (FormatInt16, _("16-bit integer"));
172
173         add_option (_("Media"), sf);
174
175         ComboOption<HeaderFormat>* hf = new ComboOption<HeaderFormat> (
176                 "native-file-header-format",
177                 _("File type"),
178                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_native_file_header_format),
179                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_native_file_header_format)
180                 );
181
182         hf->add (BWF, _("Broadcast WAVE (4GB size limit)"));
183 #ifdef HAVE_RF64_RIFF
184         hf->add (MBWF, _("Broadcast RF64"));
185 #endif  
186         hf->add (WAVE, _("WAVE (4GB size limit)"));
187         hf->add (WAVE64, _("WAVE-64"));
188         hf->add (CAF, _("CAF"));
189         hf->add (RF64, _("RF64"));
190 #ifdef HAVE_RF64_RIFF
191         hf->add (RF64_WAV, _("RF64 (WAV compatible)"));
192 #endif
193
194         add_option (_("Media"), hf);
195
196         add_option (_("Locations"), new OptionEditorHeading (_("File locations")));
197
198         SearchPathOption* spo = new SearchPathOption ("audio-search-path", _("Search for audio files in:"),
199                                                       _session->path(),
200                                                       sigc::mem_fun (*_session_config, &SessionConfiguration::get_audio_search_path),
201                                                       sigc::mem_fun (*_session_config, &SessionConfiguration::set_audio_search_path));
202         add_option (_("Locations"), spo);
203
204         spo = new SearchPathOption ("midi-search-path", _("Search for MIDI files in:"),
205                                     _session->path(),
206                                     sigc::mem_fun (*_session_config, &SessionConfiguration::get_midi_search_path),
207                                     sigc::mem_fun (*_session_config, &SessionConfiguration::set_midi_search_path));
208
209         add_option (_("Locations"), spo);
210
211         /* File Naming  */
212
213         add_option (_("Filenames"), new OptionEditorHeading (_("File Naming")));
214
215         BoolOption *bo;
216
217         bo = new RouteDisplayBoolOption (
218                         "track-name-number",
219                         _("Prefix Track number"),
220                         sigc::mem_fun (*_session_config, &SessionConfiguration::get_track_name_number),
221                         sigc::mem_fun (*_session_config, &SessionConfiguration::set_track_name_number)
222                         );
223         Gtkmm2ext::UI::instance()->set_tip (bo->tip_widget(),
224                         _("Adds the current track number to the beginning of the recorded file name."));
225         add_option (_("Filenames"), bo);
226
227         bo = new BoolOption (
228                         "track-name-take",
229                         _("Prefix Take Name"),
230                         sigc::mem_fun (*_session_config, &SessionConfiguration::get_track_name_take),
231                         sigc::mem_fun (*_session_config, &SessionConfiguration::set_track_name_take)
232                         );
233         Gtkmm2ext::UI::instance()->set_tip (bo->tip_widget(),
234                         _("Adds the Take Name to the beginning of the recorded file name."));
235         add_option (_("Filenames"), bo);
236
237         _take_name = new EntryOption (
238                 "take-name",
239                 _("Take Name"),
240                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_take_name),
241                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_take_name)
242                 );
243         _take_name->set_invalid_chars(".");
244         _take_name->set_sensitive(_session_config->get_track_name_take());
245
246         add_option (_("Filenames"), _take_name);
247
248         /* Monitoring */
249
250         add_option (_("Monitoring"), new BoolOption (
251                             "auto-input",
252                             _("Track Input Monitoring automatically follows transport state (\"auto-input\")"),
253                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_auto_input),
254                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_auto_input)
255                             ));
256
257         add_option (_("Monitoring"), new BoolOption (
258                             "have-monitor-section",
259                             _("Use monitor section in this session"),
260                             sigc::mem_fun (*this, &SessionOptionEditor::get_use_monitor_section),
261                             sigc::mem_fun (*this, &SessionOptionEditor::set_use_monitor_section)
262                             ));
263         /* Meterbridge */
264         add_option (_("Meterbridge"), new OptionEditorHeading (_("Route Display")));
265
266         add_option (_("Meterbridge"), new BoolOption (
267                             "show-midi-on-meterbridge",
268                             _("Show Midi Tracks"),
269                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_show_midi_on_meterbridge),
270                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_show_midi_on_meterbridge)
271                             ));
272
273         add_option (_("Meterbridge"), new BoolOption (
274                             "show-busses-on-meterbridge",
275                             _("Show Busses"),
276                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_show_busses_on_meterbridge),
277                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_show_busses_on_meterbridge)
278                             ));
279
280         add_option (_("Meterbridge"), new BoolOption (
281                             "show-master-on-meterbridge",
282                             _("Include Master Bus"),
283                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_show_master_on_meterbridge),
284                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_show_master_on_meterbridge)
285                             ));
286
287         add_option (_("Meterbridge"), new OptionEditorHeading (_("Button Area")));
288
289         add_option (_("Meterbridge"), new BoolOption (
290                             "show-rec-on-meterbridge",
291                             _("Rec-enable Button"),
292                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_show_rec_on_meterbridge),
293                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_show_rec_on_meterbridge)
294                             ));
295
296         add_option (_("Meterbridge"), new BoolOption (
297                             "show-mute-on-meterbridge",
298                             _("Mute Button"),
299                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_show_mute_on_meterbridge),
300                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_show_mute_on_meterbridge)
301                             ));
302
303         add_option (_("Meterbridge"), new BoolOption (
304                             "show-solo-on-meterbridge",
305                             _("Solo Button"),
306                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_show_solo_on_meterbridge),
307                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_show_solo_on_meterbridge)
308                             ));
309
310         add_option (_("Meterbridge"), new BoolOption (
311                             "show-monitor-on-meterbridge",
312                             _("Monitor Buttons"),
313                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_show_monitor_on_meterbridge),
314                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_show_monitor_on_meterbridge)
315                             ));
316
317         add_option (_("Meterbridge"), new OptionEditorHeading (_("Name Labels")));
318
319         add_option (_("Meterbridge"), new BoolOption (
320                             "show-name-on-meterbridge",
321                             _("Track Name"),
322                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_show_name_on_meterbridge),
323                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_show_name_on_meterbridge)
324                             ));
325
326         /* Misc */
327
328         add_option (_("Misc"), new OptionEditorHeading (_("MIDI Options")));
329
330         add_option (_("Misc"), new BoolOption (
331                                 "midi-copy-is-fork",
332                                 _("MIDI region copies are independent"),
333                                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_midi_copy_is_fork),
334                                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_midi_copy_is_fork)
335                                 ));
336
337         ComboOption<InsertMergePolicy>* li = new ComboOption<InsertMergePolicy> (
338                         "insert-merge-policy",
339                         _("Policy for handling overlapping notes\n on the same MIDI channel"),
340                         sigc::mem_fun (*_session_config, &SessionConfiguration::get_insert_merge_policy),
341                         sigc::mem_fun (*_session_config, &SessionConfiguration::set_insert_merge_policy)
342                         );
343
344         li->add (InsertMergeReject, _("never allow them"));
345         li->add (InsertMergeRelax, _("don't do anything in particular"));
346         li->add (InsertMergeReplace, _("replace any overlapped existing note"));
347         li->add (InsertMergeTruncateExisting, _("shorten the overlapped existing note"));
348         li->add (InsertMergeTruncateAddition, _("shorten the overlapping new note"));
349         li->add (InsertMergeExtend, _("replace both overlapping notes with a single note"));
350
351         add_option (_("Misc"), li);
352
353         add_option (_("Misc"), new OptionEditorHeading (_("Glue to bars and beats")));
354
355         add_option (_("Misc"), new BoolOption (
356                                 "glue-new-markers-to-bars-and-beats",
357                                 _("Glue new markers to bars and beats"),
358                                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_glue_new_markers_to_bars_and_beats),
359                                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_glue_new_markers_to_bars_and_beats)
360                                 ));
361
362         add_option (_("Misc"), new BoolOption (
363                                 "glue-new-regions-to-bars-and-beats",
364                                 _("Glue new regions to bars and beats"),
365                                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_glue_new_regions_to_bars_and_beats),
366                                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_glue_new_regions_to_bars_and_beats)
367                                 ));
368
369         add_option (_("Misc"), new OptionEditorHeading (_("Defaults")));
370
371         Gtk::Button* btn = Gtk::manage (new Gtk::Button (_("Use these settings as defaults")));
372         btn->signal_clicked().connect (sigc::mem_fun (*this, &SessionOptionEditor::save_defaults));
373         add_option (_("Misc"), new FooOption (btn));
374
375 }
376
377 void
378 SessionOptionEditor::parameter_changed (std::string const & p)
379 {
380         OptionEditor::parameter_changed (p);
381         if (p == "external-sync") {
382                 if (Config->get_sync_source() == Engine) {
383                         _vpu->set_sensitive(!_session_config->get_external_sync());
384                 } else {
385                         _vpu->set_sensitive(true);
386                 }
387         }
388         else if (p == "timecode-format") {
389                 /* update offset clocks */
390                 parameter_changed("timecode-generator-offset");
391                 parameter_changed("slave-timecode-offset");
392         }
393         else if (p == "track-name-take") {
394                 _take_name->set_sensitive(_session_config->get_track_name_take());
395         }
396 }
397
398 /* the presence of absence of a monitor section is not really a regular session
399  * property so we provide these two functions to act as setter/getter slots
400  */
401
402 bool
403 SessionOptionEditor::set_use_monitor_section (bool yn)
404 {
405         bool had_monitor_section = _session->monitor_out() != 0;
406
407         if (yn) {
408                 _session->add_monitor_section ();
409         } else {
410                 _session->remove_monitor_section ();
411         }
412
413         /* store this choice for any new sessions */
414         
415         Config->set_use_monitor_bus (yn);
416
417         return had_monitor_section != (_session->monitor_out() != 0);
418 }
419
420 bool
421 SessionOptionEditor::get_use_monitor_section ()
422 {
423         return _session->monitor_out() != 0;
424 }
425
426 void
427 SessionOptionEditor::save_defaults ()
428 {
429         _session->save_default_options();
430 }