90% done with external sync design changes (GUI now has toggle switch for ext/int...
[ardour.git] / gtk2_ardour / session_option_editor.cc
1 #include "ardour/session.h"
2 #include "ardour/io.h"
3 #include "ardour/auditioner.h"
4 #include "ardour/audioengine.h"
5 #include "ardour/port.h"
6 #include "session_option_editor.h"
7 #include "port_matrix.h"
8 #include "i18n.h"
9
10 using namespace std;
11 using namespace sigc;
12 using namespace ARDOUR;
13
14 class OptionsPortMatrix : public PortMatrix
15 {
16 public:
17         OptionsPortMatrix (Gtk::Window* parent, ARDOUR::Session& session)
18                 : PortMatrix (parent, session, DataType::AUDIO)
19         {
20                 _port_group.reset (new PortGroup (""));
21                 _ports[OURS].add_group (_port_group);
22
23                 setup_all_ports ();
24         }
25
26         void setup_ports (int dim)
27         {
28                 cerr << _session.the_auditioner()->output()->n_ports() << "\n";
29
30                 if (dim == OURS) {
31                         _port_group->clear ();
32                         _port_group->add_bundle (_session.click_io()->bundle());
33                         _port_group->add_bundle (_session.the_auditioner()->output()->bundle());
34                 } else {
35                         _ports[OTHER].gather (_session, true);
36                 }
37         }
38
39         void set_state (ARDOUR::BundleChannel c[2], bool s)
40         {
41                 Bundle::PortList const & our_ports = c[OURS].bundle->channel_ports (c[OURS].channel);
42                 Bundle::PortList const & other_ports = c[OTHER].bundle->channel_ports (c[OTHER].channel);
43
44                 if (c[OURS].bundle == _session.click_io()->bundle()) {
45
46                         for (ARDOUR::Bundle::PortList::const_iterator i = our_ports.begin(); i != our_ports.end(); ++i) {
47                                 for (ARDOUR::Bundle::PortList::const_iterator j = other_ports.begin(); j != other_ports.end(); ++j) {
48
49                                         Port* f = _session.engine().get_port_by_name (*i);
50                                         assert (f);
51
52                                         if (s) {
53                                                 _session.click_io()->connect (f, *j, 0);
54                                         } else {
55                                                 _session.click_io()->disconnect (f, *j, 0);
56                                         }
57                                 }
58                         }
59                 }
60         }
61
62         PortMatrixNode::State get_state (ARDOUR::BundleChannel c[2]) const
63         {
64                 Bundle::PortList const & our_ports = c[OURS].bundle->channel_ports (c[OURS].channel);
65                 Bundle::PortList const & other_ports = c[OTHER].bundle->channel_ports (c[OTHER].channel);
66
67                 if (c[OURS].bundle == _session.click_io()->bundle()) {
68
69                         for (ARDOUR::Bundle::PortList::const_iterator i = our_ports.begin(); i != our_ports.end(); ++i) {
70                                 for (ARDOUR::Bundle::PortList::const_iterator j = other_ports.begin(); j != other_ports.end(); ++j) {
71                                         Port* f = _session.engine().get_port_by_name (*i);
72                                         assert (f);
73
74                                         if (f->connected_to (*j)) {
75                                                 return PortMatrixNode::ASSOCIATED;
76                                         } else {
77                                                 return PortMatrixNode::NOT_ASSOCIATED;
78                                         }
79                                 }
80                         }
81
82                 } else {
83
84                         /* XXX */
85
86                 }
87
88                 return PortMatrixNode::NOT_ASSOCIATED;
89         }
90
91         bool list_is_global (int dim) const {
92                 return (dim == OTHER);
93         }
94
95         bool can_remove_channels (boost::shared_ptr<Bundle>) const {
96                 return false;
97         }
98
99         void remove_channel (ARDOUR::BundleChannel) {}
100
101         std::string disassociation_verb () const {
102                 return _("Disassociate");
103         }
104
105 private:
106         /* see PortMatrix: signal flow from 0 to 1 (out to in) */
107         enum {
108                 OURS = 0,
109                 OTHER = 1,
110         };
111
112         boost::shared_ptr<PortGroup> _port_group;
113
114 };
115
116
117 class ConnectionOptions : public OptionEditorBox
118 {
119 public:
120         ConnectionOptions (Gtk::Window* parent, ARDOUR::Session* s)
121                 : _port_matrix (parent, *s)
122         {
123                 _box->pack_start (_port_matrix);
124         }
125
126         void parameter_changed (string const &)
127         {
128
129         }
130
131         void set_state_from_config ()
132         {
133
134         }
135
136 private:
137         OptionsPortMatrix _port_matrix;
138 };
139
140 SessionOptionEditor::SessionOptionEditor (Session* s)
141         : OptionEditor (&(s->config), _("Session Preferences"))
142         , _session_config (&(s->config))
143 {
144         /* FADES */
145
146         ComboOption<CrossfadeModel>* cfm = new ComboOption<CrossfadeModel> (
147                 "xfade-model",
148                 _("Crossfades are created"),
149                 mem_fun (*_session_config, &SessionConfiguration::get_xfade_model),
150                 mem_fun (*_session_config, &SessionConfiguration::set_xfade_model)
151                 );
152
153         cfm->add (FullCrossfade, _("to span entire overlap"));
154         cfm->add (ShortCrossfade, _("short"));
155
156         add_option (_("Fades"), cfm);
157
158         add_option (_("Fades"), new SpinOption<float> (
159                 _("short-xfade-seconds"),
160                 _("Short crossfade length"),
161                 mem_fun (*_session_config, &SessionConfiguration::get_short_xfade_seconds),
162                 mem_fun (*_session_config, &SessionConfiguration::set_short_xfade_seconds),
163                 0, 1000, 1, 10,
164                 _("ms"), 0.001
165                             ));
166
167         add_option (_("Fades"), new SpinOption<float> (
168                 _("destructive-xfade-seconds"),
169                 _("Destructive crossfade length"),
170                 mem_fun (*_session_config, &SessionConfiguration::get_destructive_xfade_msecs),
171                 mem_fun (*_session_config, &SessionConfiguration::set_destructive_xfade_msecs),
172                 0, 1000, 1, 10,
173                 _("ms")
174                             ));
175
176         add_option (_("Fades"), new BoolOption (
177                             "auto-xfade",
178                             _("Create crossfades automatically"),
179                             mem_fun (*_session_config, &SessionConfiguration::get_auto_xfade),
180                             mem_fun (*_session_config, &SessionConfiguration::set_auto_xfade)
181                             ));
182
183         add_option (_("Fades"), new BoolOption (
184                             "xfades-active",
185                             _("Crossfades active"),
186                             mem_fun (*_session_config, &SessionConfiguration::get_xfades_active),
187                             mem_fun (*_session_config, &SessionConfiguration::set_xfades_active)
188                             ));
189
190         add_option (_("Fades"), new BoolOption (
191                             "xfades-visible",
192                             _("Crossfades visible"),
193                             mem_fun (*_session_config, &SessionConfiguration::get_xfades_visible),
194                             mem_fun (*_session_config, &SessionConfiguration::set_xfades_visible)
195                             ));
196
197         add_option (_("Fades"), new BoolOption (
198                             "use-region-fades",
199                             _("Region fades active"),
200                             mem_fun (*_session_config, &SessionConfiguration::get_use_region_fades),
201                             mem_fun (*_session_config, &SessionConfiguration::set_use_region_fades)
202                             ));
203
204         add_option (_("Fades"), new BoolOption (
205                             "show-region-fades",
206                             _("Region fades visible"),
207                             mem_fun (*_session_config, &SessionConfiguration::get_show_region_fades),
208                             mem_fun (*_session_config, &SessionConfiguration::set_show_region_fades)
209                             ));
210
211         /* SYNC */
212
213         ComboOption<uint32_t>* spf = new ComboOption<uint32_t> (
214                 "subframes-per-frame",
215                 _("Subframes per frame"),
216                 mem_fun (*_session_config, &SessionConfiguration::get_subframes_per_frame),
217                 mem_fun (*_session_config, &SessionConfiguration::set_subframes_per_frame)
218                 );
219
220         spf->add (80, _("80"));
221         spf->add (100, _("100"));
222
223         add_option (_("Sync"), spf);
224
225         ComboOption<SyncSource>* ssrc = new ComboOption<SyncSource> (
226                 "sync-source",
227                 _("External sync source"),
228                 mem_fun (*_session_config, &SessionConfiguration::get_sync_source),
229                 mem_fun (*_session_config, &SessionConfiguration::set_sync_source)
230                 );
231         
232         s->MTC_PortChanged.connect (bind (mem_fun (*this, &SessionOptionEditor::populate_sync_options), s, ssrc));
233         s->MIDIClock_PortChanged.connect (bind (mem_fun (*this, &SessionOptionEditor::populate_sync_options), s, ssrc));
234         populate_sync_options (s, ssrc);
235
236         add_option (_("Sync"), ssrc);
237
238         ComboOption<TimecodeFormat>* smf = new ComboOption<TimecodeFormat> (
239                 "timecode-format",
240                 _("Timecode frames-per-second"),
241                 mem_fun (*_session_config, &SessionConfiguration::get_timecode_format),
242                 mem_fun (*_session_config, &SessionConfiguration::set_timecode_format)
243                 );
244
245         smf->add (timecode_23976, _("23.976"));
246         smf->add (timecode_24, _("24"));
247         smf->add (timecode_24976, _("24.976"));
248         smf->add (timecode_25, _("25"));
249         smf->add (timecode_2997, _("29.97"));
250         smf->add (timecode_2997drop, _("29.97 drop"));
251         smf->add (timecode_30, _("30"));
252         smf->add (timecode_30drop, _("30 drop"));
253         smf->add (timecode_5994, _("59.94"));
254         smf->add (timecode_60, _("60"));
255
256         add_option (_("Sync"), smf);
257
258         add_option (_("Sync"), new BoolOption (
259                             "timecode-source-is-synced",
260                             _("Timecode source is synced"),
261                             mem_fun (*_session_config, &SessionConfiguration::get_timecode_source_is_synced),
262                             mem_fun (*_session_config, &SessionConfiguration::set_timecode_source_is_synced)
263                             ));
264
265         ComboOption<float>* vpu = new ComboOption<float> (
266                 "video-pullup",
267                 _("Pull-up / pull-down"),
268                 mem_fun (*_session_config, &SessionConfiguration::get_video_pullup),
269                 mem_fun (*_session_config, &SessionConfiguration::set_video_pullup)
270                 );
271
272         vpu->add (4.1667 + 0.1, _("4.1667 + 0.1%"));
273         vpu->add (4.1667, _("4.1667"));
274         vpu->add (4.1667 - 0.1, _("4.1667 - 0.1%"));
275         vpu->add (0.1, _("0.1"));
276         vpu->add (0, _("none"));
277         vpu->add (-0.1, _("-0.1"));
278         vpu->add (-4.1667 + 0.1, _("-4.1667 + 0.1%"));
279         vpu->add (-4.1667, _("-4.1667"));
280         vpu->add (-4.1667 - 0.1, _("-4.1667 - 0.1%"));
281
282         add_option (_("Sync"), vpu);
283
284         /* MISC */
285
286         add_option (_("Misc"), new OptionEditorHeading (_("Audio file format")));
287
288         ComboOption<SampleFormat>* sf = new ComboOption<SampleFormat> (
289                 "native-file-data-format",
290                 _("Sample format"),
291                 mem_fun (*_session_config, &SessionConfiguration::get_native_file_data_format),
292                 mem_fun (*_session_config, &SessionConfiguration::set_native_file_data_format)
293                 );
294
295         sf->add (FormatFloat, _("32-bit floating point"));
296         sf->add (FormatInt24, _("24-bit integer"));
297         sf->add (FormatInt16, _("16-bit integer"));
298
299         add_option (_("Misc"), sf);
300
301         ComboOption<HeaderFormat>* hf = new ComboOption<HeaderFormat> (
302                 "native-file-header-format",
303                 _("File type"),
304                 mem_fun (*_session_config, &SessionConfiguration::get_native_file_header_format),
305                 mem_fun (*_session_config, &SessionConfiguration::set_native_file_header_format)
306                 );
307
308         hf->add (BWF, _("Broadcast WAVE"));
309         hf->add (WAVE, _("WAVE"));
310         hf->add (WAVE64, _("WAVE-64"));
311         hf->add (CAF, _("CAF"));
312
313         add_option (_("Misc"), hf);
314
315         add_option (_("Misc"), new OptionEditorHeading (_("Layering")));
316
317         ComboOption<LayerModel>* lm = new ComboOption<LayerModel> (
318                 "layer-model",
319                 _("Layering model in overlaid mode"),
320                 mem_fun (*_session_config, &SessionConfiguration::get_layer_model),
321                 mem_fun (*_session_config, &SessionConfiguration::set_layer_model)
322                 );
323
324         lm->add (LaterHigher, _("later is higher"));
325         lm->add (MoveAddHigher, _("most recently moved or added is higher"));
326         lm->add (AddHigher, _("most recently added is higher"));
327
328         add_option (_("Misc"), lm);
329
330         add_option (_("Misc"), new OptionEditorHeading (_("Broadcast WAVE metadata")));
331
332         add_option (_("Misc"), new EntryOption (
333                             "bwf-country-code",
334                             _("Country code"),
335                             mem_fun (*_session_config, &SessionConfiguration::get_bwf_country_code),
336                             mem_fun (*_session_config, &SessionConfiguration::set_bwf_country_code)
337                             ));
338
339         add_option (_("Misc"), new EntryOption (
340                             "bwf-organization-code",
341                             _("Organization code"),
342                             mem_fun (*_session_config, &SessionConfiguration::get_bwf_organization_code),
343                             mem_fun (*_session_config, &SessionConfiguration::set_bwf_organization_code)
344                             ));
345
346         add_option (_("Connections"), new ConnectionOptions (this, s));
347 }
348
349 void
350 SessionOptionEditor::populate_sync_options (Session* s, Option* opt)
351 {
352         ComboOption<SyncSource>* sync_opt = dynamic_cast<ComboOption<SyncSource>* > (opt);
353
354         vector<SyncSource> sync_opts = s->get_available_sync_options ();
355
356         sync_opt->clear ();
357
358         for (vector<SyncSource>::iterator i = sync_opts.begin(); i != sync_opts.end(); ++i) {
359                 sync_opt->add (*i, sync_source_to_string (*i));
360         }
361 }
362