implement TC offset for slave&generator.
[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         ComboOption<uint32_t>* spf = new ComboOption<uint32_t> (
64                 "subframes-per-frame",
65                 _("Subframes per frame"),
66                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_subframes_per_frame),
67                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_subframes_per_frame)
68                 );
69
70         spf->add (80, _("80"));
71         spf->add (100, _("100"));
72
73         add_option (_("Timecode"), spf);
74
75         _vpu = new ComboOption<float> (
76                 "video-pullup",
77                 _("Pull-up / pull-down"),
78                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_video_pullup),
79                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_video_pullup)
80                 );
81
82         _vpu->add (4.1667 + 0.1, _("4.1667 + 0.1%"));
83         _vpu->add (4.1667, _("4.1667"));
84         _vpu->add (4.1667 - 0.1, _("4.1667 - 0.1%"));
85         _vpu->add (0.1, _("0.1"));
86         _vpu->add (0, _("none"));
87         _vpu->add (-0.1, _("-0.1"));
88         _vpu->add (-4.1667 + 0.1, _("-4.1667 + 0.1%"));
89         _vpu->add (-4.1667, _("-4.1667"));
90         _vpu->add (-4.1667 - 0.1, _("-4.1667 - 0.1%"));
91
92         add_option (_("Timecode"), _vpu);
93
94
95         add_option (_("Timecode"), new OptionEditorHeading (_("Ext Timecode Offsets")));
96
97         ClockOption* sco = new ClockOption (
98                 "slave-timecode-offset",
99                 _("Slave Timecode offset"),
100                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_slave_timecode_offset),
101                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_slave_timecode_offset)
102                 );
103
104         sco->set_session (_session);
105         sco->clock().set_negative_allowed (true);
106
107         add_option (_("Timecode"), sco);
108
109         ClockOption* gco = new ClockOption (
110                 "timecode-generator-offset",
111                 _("Timecode Generator offset"),
112                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_timecode_generator_offset),
113                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_timecode_generator_offset)
114                 );
115
116         gco->set_session (_session);
117         gco->clock().set_negative_allowed (true);
118
119         add_option (_("Timecode"), gco);
120
121         add_option (_("Timecode"), new OptionEditorHeading (_("JACK Transport/Time Settings")));
122
123         add_option (_("Timecode"), new BoolOption (
124                             "jack-time-master",
125                             string_compose (_("%1 is JACK Time Master (provides Bar|Beat|Tick and other information to JACK)"), PROGRAM_NAME),
126                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_jack_time_master),
127                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_jack_time_master)
128                             ));
129
130         /* FADES */
131
132         ComboOption<CrossfadeModel>* cfm = new ComboOption<CrossfadeModel> (
133                 "xfade-model",
134                 _("Crossfades are created"),
135                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_xfade_model),
136                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_xfade_model)
137                 );
138
139         cfm->add (FullCrossfade, _("to span entire overlap"));
140         cfm->add (ShortCrossfade, _("short"));
141
142         add_option (_("Fades"), cfm);
143
144         ComboOption<CrossfadeChoice>* cfc = new ComboOption<CrossfadeChoice> (
145                 "xfade-choice",
146                 _("Crossfade type"),
147                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_xfade_choice),
148                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_xfade_choice)
149                 );
150
151         cfc->add (ConstantPowerMinus3dB, _("constant power (-3dB)"));
152         cfc->add (ConstantPowerMinus6dB, _("constant power (-6dB)"));
153         cfc->add (RegionFades, _("use existing region fade shape"));
154
155         add_option (_("Fades"), cfc);
156
157         add_option (_("Fades"), new SpinOption<float> (
158                 _("short-xfade-seconds"),
159                 _("Short crossfade length"),
160                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_short_xfade_seconds),
161                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_short_xfade_seconds),
162                 0, 1000, 1, 10,
163                 _("ms"), 0.001
164                             ));
165
166         add_option (_("Fades"), new SpinOption<float> (
167                 _("destructive-xfade-seconds"),
168                 _("Destructive crossfade length"),
169                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_destructive_xfade_msecs),
170                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_destructive_xfade_msecs),
171                 0, 1000, 1, 10,
172                 _("ms")
173                             ));
174
175         add_option (_("Fades"), new BoolOption (
176                             "auto-xfade",
177                             _("Create crossfades automatically"),
178                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_auto_xfade),
179                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_auto_xfade)
180                             ));
181
182         add_option (_("Fades"), new BoolOption (
183                             "use-region-fades",
184                             _("Region fades active"),
185                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_use_region_fades),
186                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_use_region_fades)
187                             ));
188
189         add_option (_("Fades"), new BoolOption (
190                             "show-region-fades",
191                             _("Region fades visible"),
192                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_show_region_fades),
193                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_show_region_fades)
194                             ));
195
196         /* Media */
197
198         add_option (_("Media"), new OptionEditorHeading (_("Audio file format")));
199
200         ComboOption<SampleFormat>* sf = new ComboOption<SampleFormat> (
201                 "native-file-data-format",
202                 _("Sample format"),
203                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_native_file_data_format),
204                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_native_file_data_format)
205                 );
206
207         sf->add (FormatFloat, _("32-bit floating point"));
208         sf->add (FormatInt24, _("24-bit integer"));
209         sf->add (FormatInt16, _("16-bit integer"));
210
211         add_option (_("Media"), sf);
212
213         ComboOption<HeaderFormat>* hf = new ComboOption<HeaderFormat> (
214                 "native-file-header-format",
215                 _("File type"),
216                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_native_file_header_format),
217                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_native_file_header_format)
218                 );
219
220         hf->add (BWF, _("Broadcast WAVE"));
221         hf->add (WAVE, _("WAVE"));
222         hf->add (WAVE64, _("WAVE-64"));
223         hf->add (CAF, _("CAF"));
224
225         add_option (_("Media"), hf);
226
227         add_option (_("Media"), new OptionEditorHeading (_("File locations")));
228
229         SearchPathOption* spo = new SearchPathOption ("audio-search-path", _("Search for audio files in:"),
230                                                       sigc::mem_fun (*_session_config, &SessionConfiguration::get_audio_search_path),
231                                                       sigc::mem_fun (*_session_config, &SessionConfiguration::set_audio_search_path));
232         add_option (_("Media"), spo);
233
234         spo = new SearchPathOption ("midi-search-path", _("Search for MIDI files in:"),
235                                     sigc::mem_fun (*_session_config, &SessionConfiguration::get_midi_search_path),
236                                     sigc::mem_fun (*_session_config, &SessionConfiguration::set_midi_search_path));
237
238         add_option (_("Media"), spo);
239
240         /* Monitoring */
241
242         add_option (_("Monitoring"), new BoolOption (
243                             "auto-input",
244                             _("Monitoring automatically follows transport state (\"auto-input\")"),
245                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_auto_input),
246                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_auto_input)
247                             ));
248
249         add_option (_("Monitoring"), new BoolOption (
250                             "have-monitor-section",
251                             _("Use monitor section in this session"),
252                             sigc::mem_fun (*this, &SessionOptionEditor::get_use_monitor_section),
253                             sigc::mem_fun (*this, &SessionOptionEditor::set_use_monitor_section)
254                             ));
255
256         /* Misc */
257
258         add_option (_("Misc"), new OptionEditorHeading (_("MIDI Options")));
259
260         add_option (_("Misc"), new BoolOption (
261                             "midi-copy-is-fork",
262                             _("MIDI region copies are independent"),
263                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_midi_copy_is_fork),
264                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_midi_copy_is_fork)
265                             ));
266
267         ComboOption<InsertMergePolicy>* li = new ComboOption<InsertMergePolicy> (
268                 "insert-merge-policy",
269                 _("Policy for handling overlapping notes\n on the same MIDI channel"),
270                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_insert_merge_policy),
271                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_insert_merge_policy)
272                 );
273
274         li->add (InsertMergeReject, _("never allow them"));
275         li->add (InsertMergeRelax, _("don't do anything in particular"));
276         li->add (InsertMergeReplace, _("replace any overlapped existing note"));
277         li->add (InsertMergeTruncateExisting, _("shorten the overlapped existing note"));
278         li->add (InsertMergeTruncateAddition, _("shorten the overlapping new note"));
279         li->add (InsertMergeExtend, _("replace both overlapping notes with a single note"));
280
281         add_option (_("Misc"), li);
282
283         add_option (_("Misc"), new OptionEditorHeading (_("Glue to bars and beats")));
284
285         add_option (_("Misc"), new BoolOption (
286                             "glue-new-markers-to-bars-and-beats",
287                             _("Glue new markers to bars and beats"),
288                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_glue_new_markers_to_bars_and_beats),
289                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_glue_new_markers_to_bars_and_beats)
290                             ));
291
292         add_option (_("Misc"), new BoolOption (
293                             "glue-new-regions-to-bars-and-beats",
294                             _("Glue new regions to bars and beats"),
295                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_glue_new_regions_to_bars_and_beats),
296                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_glue_new_regions_to_bars_and_beats)
297                             ));
298 }
299
300 void
301 SessionOptionEditor::parameter_changed (std::string const & p)
302 {
303         OptionEditor::parameter_changed (p);
304         if (p == "external-sync") {
305                 if (Config->get_sync_source() == JACK) {
306                         _vpu->set_sensitive(!_session_config->get_external_sync());
307                 } else {
308                         _vpu->set_sensitive(true);
309                 }
310         }
311         if (p == "timecode-format") {
312                 /* update offset clocks */
313                 parameter_changed("timecode-generator-offset");
314                 parameter_changed("slave-timecode-offset");
315         }
316 }
317
318 /* the presence of absence of a monitor section is not really a regular session
319  * property so we provide these two functions to act as setter/getter slots
320  */
321
322 bool
323 SessionOptionEditor::set_use_monitor_section (bool yn)
324 {
325         bool had_monitor_section = _session->monitor_out();
326
327         if (yn) {
328                 _session->add_monitor_section ();
329         } else {
330                 _session->remove_monitor_section ();
331         }
332
333         return had_monitor_section != yn;
334 }
335
336 bool
337 SessionOptionEditor::get_use_monitor_section ()
338 {
339         return _session->monitor_out() != 0;
340 }