Another stab at the logic for selecting regions for operations, to ensure that edit...
[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 #include "ardour/io.h"
22 #include "ardour/auditioner.h"
23 #include "ardour/audioengine.h"
24 #include "ardour/port.h"
25
26 #include "gui_thread.h"
27 #include "session_option_editor.h"
28 #include "search_path_option.h"
29 #include "i18n.h"
30
31 using namespace std;
32 using namespace ARDOUR;
33
34 SessionOptionEditor::SessionOptionEditor (Session* s)
35         : OptionEditor (&(s->config), _("Session Properties"))
36         , _session_config (&(s->config))
37 {
38         set_session (s);
39         
40         set_name ("SessionProperties");
41
42         /* TIMECODE*/
43
44         ComboOption<SyncSource>* ssrc = new ComboOption<SyncSource> (
45                 "sync-source",
46                 _("External timecode source"),
47                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_sync_source),
48                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_sync_source)
49                 );
50         
51         s->config.ParameterChanged.connect (_session_connections, invalidator (*this), ui_bind (&SessionOptionEditor::follow_sync_state, this, _1, s, ssrc), gui_context());
52
53         populate_sync_options (s, ssrc);
54         follow_sync_state (string ("external-sync"), s, ssrc);
55
56         add_option (_("Timecode"), ssrc);
57
58         add_option (_("Timecode"), new OptionEditorHeading (_("Timecode Settings")));
59
60
61         ComboOption<TimecodeFormat>* smf = new ComboOption<TimecodeFormat> (
62                 "timecode-format",
63                 _("Timecode frames-per-second"),
64                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_timecode_format),
65                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_timecode_format)
66                 );
67
68         smf->add (timecode_23976, _("23.976"));
69         smf->add (timecode_24, _("24"));
70         smf->add (timecode_24976, _("24.976"));
71         smf->add (timecode_25, _("25"));
72         smf->add (timecode_2997, _("29.97"));
73         smf->add (timecode_2997drop, _("29.97 drop"));
74         smf->add (timecode_30, _("30"));
75         smf->add (timecode_30drop, _("30 drop"));
76         smf->add (timecode_5994, _("59.94"));
77         smf->add (timecode_60, _("60"));
78
79         add_option (_("Timecode"), smf);
80
81         ComboOption<uint32_t>* spf = new ComboOption<uint32_t> (
82                 "subframes-per-frame",
83                 _("Subframes per frame"),
84                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_subframes_per_frame),
85                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_subframes_per_frame)
86                 );
87
88         spf->add (80, _("80"));
89         spf->add (100, _("100"));
90
91         add_option (_("Timecode"), spf);
92
93         add_option (_("Timecode"), new BoolOption (
94                             "timecode-source-is-synced",
95                             _("Timecode source shares sample clock with audio interface"),
96                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_timecode_source_is_synced),
97                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_timecode_source_is_synced)
98                             ));
99
100         ComboOption<float>* vpu = new ComboOption<float> (
101                 "video-pullup",
102                 _("Pull-up / pull-down"),
103                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_video_pullup),
104                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_video_pullup)
105                 );
106
107         vpu->add (4.1667 + 0.1, _("4.1667 + 0.1%"));
108         vpu->add (4.1667, _("4.1667"));
109         vpu->add (4.1667 - 0.1, _("4.1667 - 0.1%"));
110         vpu->add (0.1, _("0.1"));
111         vpu->add (0, _("none"));
112         vpu->add (-0.1, _("-0.1"));
113         vpu->add (-4.1667 + 0.1, _("-4.1667 + 0.1%"));
114         vpu->add (-4.1667, _("-4.1667"));
115         vpu->add (-4.1667 - 0.1, _("-4.1667 - 0.1%"));
116
117         add_option (_("Timecode"), vpu);
118
119         ClockOption* co = new ClockOption (
120                 "timecode-offset",
121                 _("Timecode Offset"),
122                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_timecode_offset),
123                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_timecode_offset)
124                 );
125
126         co->set_session (_session);
127         
128         add_option (_("Timecode"), co);
129
130         add_option (_("Timecode"), new BoolOption (
131                             "timecode-offset-negative",
132                             _("Timecode Offset Negative"),
133                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_timecode_offset_negative),
134                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_timecode_offset_negative)
135                             ));
136
137         /* FADES */
138
139         ComboOption<CrossfadeModel>* cfm = new ComboOption<CrossfadeModel> (
140                 "xfade-model",
141                 _("Crossfades are created"),
142                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_xfade_model),
143                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_xfade_model)
144                 );
145
146         cfm->add (FullCrossfade, _("to span entire overlap"));
147         cfm->add (ShortCrossfade, _("short"));
148
149         add_option (_("Fades"), cfm);
150
151         add_option (_("Fades"), new SpinOption<float> (
152                 _("short-xfade-seconds"),
153                 _("Short crossfade length"),
154                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_short_xfade_seconds),
155                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_short_xfade_seconds),
156                 0, 1000, 1, 10,
157                 _("ms"), 0.001
158                             ));
159
160         add_option (_("Fades"), new SpinOption<float> (
161                 _("destructive-xfade-seconds"),
162                 _("Destructive crossfade length"),
163                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_destructive_xfade_msecs),
164                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_destructive_xfade_msecs),
165                 0, 1000, 1, 10,
166                 _("ms")
167                             ));
168
169         add_option (_("Fades"), new BoolOption (
170                             "auto-xfade",
171                             _("Create crossfades automatically"),
172                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_auto_xfade),
173                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_auto_xfade)
174                             ));
175
176         add_option (_("Fades"), new BoolOption (
177                             "xfades-active",
178                             _("Crossfades active"),
179                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_xfades_active),
180                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_xfades_active)
181                             ));
182
183         add_option (_("Fades"), new BoolOption (
184                             "xfades-visible",
185                             _("Crossfades visible"),
186                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_xfades_visible),
187                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_xfades_visible)
188                             ));
189
190         add_option (_("Fades"), new BoolOption (
191                             "use-region-fades",
192                             _("Region fades active"),
193                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_use_region_fades),
194                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_use_region_fades)
195                             ));
196
197         add_option (_("Fades"), new BoolOption (
198                             "show-region-fades",
199                             _("Region fades visible"),
200                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_show_region_fades),
201                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_show_region_fades)
202                             ));
203
204         /* Media */
205
206         add_option (_("Media"), new OptionEditorHeading (_("Audio file format")));
207
208         ComboOption<SampleFormat>* sf = new ComboOption<SampleFormat> (
209                 "native-file-data-format",
210                 _("Sample format"),
211                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_native_file_data_format),
212                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_native_file_data_format)
213                 );
214
215         sf->add (FormatFloat, _("32-bit floating point"));
216         sf->add (FormatInt24, _("24-bit integer"));
217         sf->add (FormatInt16, _("16-bit integer"));
218
219         add_option (_("Media"), sf);
220
221         ComboOption<HeaderFormat>* hf = new ComboOption<HeaderFormat> (
222                 "native-file-header-format",
223                 _("File type"),
224                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_native_file_header_format),
225                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_native_file_header_format)
226                 );
227
228         hf->add (BWF, _("Broadcast WAVE"));
229         hf->add (WAVE, _("WAVE"));
230         hf->add (WAVE64, _("WAVE-64"));
231         hf->add (CAF, _("CAF"));
232
233         add_option (_("Media"), hf);
234         
235         add_option (_("Media"), new OptionEditorHeading (_("File locations")));
236
237         SearchPathOption* spo = new SearchPathOption ("audio-search-path", _("Search for audio files in:"),
238                                                       sigc::mem_fun (*_session_config, &SessionConfiguration::get_audio_search_path),
239                                                       sigc::mem_fun (*_session_config, &SessionConfiguration::set_audio_search_path));
240         add_option (_("Media"), spo);
241
242         spo = new SearchPathOption ("midi-search-path", _("Search for MIDI files in:"),
243                                     sigc::mem_fun (*_session_config, &SessionConfiguration::get_midi_search_path),
244                                     sigc::mem_fun (*_session_config, &SessionConfiguration::set_midi_search_path));
245
246         add_option (_("Media"), spo);
247
248         /* Misc */
249
250         add_option (_("Misc"), new OptionEditorHeading (_("Layering (in overlaid mode)")));
251
252         ComboOption<LayerModel>* lm = new ComboOption<LayerModel> (
253                 "layer-model",
254                 _("Layering model"),
255                 sigc::mem_fun (*_session_config, &SessionConfiguration::get_layer_model),
256                 sigc::mem_fun (*_session_config, &SessionConfiguration::set_layer_model)
257                 );
258
259         lm->add (LaterHigher, _("later is higher"));
260         lm->add (MoveAddHigher, _("most recently moved or added is higher"));
261         lm->add (AddHigher, _("most recently added is higher"));
262
263         add_option (_("Misc"), lm);
264
265         add_option (_("Misc"), new OptionEditorHeading (_("MIDI Note Overlaps")));
266
267         ComboOption<InsertMergePolicy>* li = new ComboOption<InsertMergePolicy> (
268                 "insert-merge-policy",
269                 _("Policy for handling same note\nand channel overlaps"),
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 (_("Broadcast WAVE metadata")));
284
285         add_option (_("Misc"), new EntryOption (
286                             "bwf-country-code",
287                             _("Country code"),
288                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_bwf_country_code),
289                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_bwf_country_code)
290                             ));
291
292         add_option (_("Misc"), new EntryOption (
293                             "bwf-organization-code",
294                             _("Organization code"),
295                             sigc::mem_fun (*_session_config, &SessionConfiguration::get_bwf_organization_code),
296                             sigc::mem_fun (*_session_config, &SessionConfiguration::set_bwf_organization_code)
297                             ));
298 }
299
300 void
301 SessionOptionEditor::populate_sync_options (Session* s, Option* opt)
302 {
303         ComboOption<SyncSource>* sync_opt = dynamic_cast<ComboOption<SyncSource>* > (opt);
304
305         vector<SyncSource> sync_opts = s->get_available_sync_options ();
306
307         sync_opt->clear ();
308
309         for (vector<SyncSource>::iterator i = sync_opts.begin(); i != sync_opts.end(); ++i) {
310                 sync_opt->add (*i, sync_source_to_string (*i));
311         }
312 }
313
314 void
315 SessionOptionEditor::follow_sync_state (std::string p, Session* s, Option* opt)
316 {
317         ComboOption<SyncSource>* sync_opt = dynamic_cast<ComboOption<SyncSource>* > (opt);
318         if (p == "external-sync") {
319                 if (s->config.get_external_sync()) {
320                         sync_opt->set_sensitive (false);
321                 } else {
322                         sync_opt->set_sensitive (true);
323                 }
324         }
325 }