5defe27e9d3e1dfe9d5f26358f9bc444070539cf
[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 (ARDOUR::Session& session)
18                 : PortMatrix (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         {
93                 return (dim == OTHER);
94         }
95
96         void add_channel (boost::shared_ptr<ARDOUR::Bundle>) {}
97         bool can_remove_channels (int) const {
98                 return false;
99         }
100         void remove_channel (ARDOUR::BundleChannel) {}
101         bool can_rename_channels (int) const {
102                 return false;
103         }
104
105         std::string disassociation_verb () const {
106                 return _("Disassociate");
107         }
108         
109 private:
110         /* see PortMatrix: signal flow from 0 to 1 (out to in) */
111         enum {
112                 OURS = 0,
113                 OTHER = 1,
114         };
115
116         boost::shared_ptr<PortGroup> _port_group;
117
118 };
119
120
121 class ConnectionOptions : public OptionEditorBox
122 {
123 public:
124         ConnectionOptions (ARDOUR::Session* s)
125                 : _port_matrix (*s)
126         {
127                 _box->pack_start (_port_matrix);
128         }
129
130         void parameter_changed (string const & p)
131         {
132
133         }
134
135         void set_state_from_config ()
136         {
137
138         }
139
140 private:
141         OptionsPortMatrix _port_matrix;
142 };
143
144 SessionOptionEditor::SessionOptionEditor (Session* s)
145         : OptionEditor (&(s->config), _("Session Preferences")),
146           _session_config (&(s->config))
147 {
148         /* FADES */
149
150         ComboOption<CrossfadeModel>* cfm = new ComboOption<CrossfadeModel> (
151                 "xfade-model",
152                 _("Crossfades are created"),
153                 mem_fun (*_session_config, &SessionConfiguration::get_xfade_model),
154                 mem_fun (*_session_config, &SessionConfiguration::set_xfade_model)
155                 );
156
157         cfm->add (FullCrossfade, _("to span entire overlap"));
158         cfm->add (ShortCrossfade, _("short"));
159
160         add_option (_("Fades"), cfm);
161
162         add_option (_("Fades"), new SpinOption<float> (
163                 _("short-xfade-seconds"),
164                 _("Short crossfade length"),
165                 mem_fun (*_session_config, &SessionConfiguration::get_short_xfade_seconds),
166                 mem_fun (*_session_config, &SessionConfiguration::set_short_xfade_seconds),
167                 0, 1000, 1, 10,
168                 _("ms"), 0.001
169                             ));
170
171         add_option (_("Fades"), new SpinOption<float> (
172                 _("destructive-xfade-seconds"),
173                 _("Destructive crossfade length"),
174                 mem_fun (*_session_config, &SessionConfiguration::get_destructive_xfade_msecs),
175                 mem_fun (*_session_config, &SessionConfiguration::set_destructive_xfade_msecs),
176                 0, 1000, 1, 10,
177                 _("ms")
178                             ));
179
180         add_option (_("Fades"), new BoolOption (
181                             "auto-xfade",
182                             _("Create crossfades automatically"),
183                             mem_fun (*_session_config, &SessionConfiguration::get_auto_xfade),
184                             mem_fun (*_session_config, &SessionConfiguration::set_auto_xfade)
185                             ));
186
187         add_option (_("Fades"), new BoolOption (
188                             "xfades-active",
189                             _("Crossfades active"),
190                             mem_fun (*_session_config, &SessionConfiguration::get_xfades_active),
191                             mem_fun (*_session_config, &SessionConfiguration::set_xfades_active)
192                             ));
193
194         add_option (_("Fades"), new BoolOption (
195                             "xfades-visible",
196                             _("Crossfades visible"),
197                             mem_fun (*_session_config, &SessionConfiguration::get_xfades_visible),
198                             mem_fun (*_session_config, &SessionConfiguration::set_xfades_visible)
199                             ));
200
201         add_option (_("Fades"), new BoolOption (
202                             "use-region-fades",
203                             _("Region fades active"),
204                             mem_fun (*_session_config, &SessionConfiguration::get_use_region_fades),
205                             mem_fun (*_session_config, &SessionConfiguration::set_use_region_fades)
206                             ));
207
208         add_option (_("Fades"), new BoolOption (
209                             "show-region-fades",
210                             _("Region fades visible"),
211                             mem_fun (*_session_config, &SessionConfiguration::get_show_region_fades),
212                             mem_fun (*_session_config, &SessionConfiguration::set_show_region_fades)
213                             ));
214
215         /* SYNC */
216
217         ComboOption<uint32_t>* spf = new ComboOption<uint32_t> (
218                 "subframes-per-frame",
219                 _("Subframes per frame"),
220                 mem_fun (*_session_config, &SessionConfiguration::get_subframes_per_frame),
221                 mem_fun (*_session_config, &SessionConfiguration::set_subframes_per_frame)
222                 );
223
224         spf->add (80, _("80"));
225         spf->add (100, _("100"));
226
227         add_option (_("Sync"), spf);
228
229         ComboOption<SmpteFormat>* smf = new ComboOption<SmpteFormat> (
230                 "smpte-format",
231                 _("Timecode frames-per-second"),
232                 mem_fun (*_session_config, &SessionConfiguration::get_smpte_format),
233                 mem_fun (*_session_config, &SessionConfiguration::set_smpte_format)
234                 );
235
236         smf->add (smpte_23976, _("23.976"));
237         smf->add (smpte_24, _("24"));
238         smf->add (smpte_24976, _("24.976"));
239         smf->add (smpte_25, _("25"));
240         smf->add (smpte_2997, _("29.97"));
241         smf->add (smpte_2997drop, _("29.97 drop"));
242         smf->add (smpte_30, _("30"));
243         smf->add (smpte_30drop, _("30 drop"));
244         smf->add (smpte_5994, _("59.94"));
245         smf->add (smpte_60, _("60"));
246
247         add_option (_("Sync"), smf);
248                 
249         add_option (_("Sync"), new BoolOption (
250                             "timecode-source-is-synced",
251                             _("Timecode source is synced"),
252                             mem_fun (*_session_config, &SessionConfiguration::get_timecode_source_is_synced),
253                             mem_fun (*_session_config, &SessionConfiguration::set_timecode_source_is_synced)
254                             ));
255
256         ComboOption<float>* vpu = new ComboOption<float> (
257                 "video-pullup",
258                 _("Pull-up / pull-down"),
259                 mem_fun (*_session_config, &SessionConfiguration::get_video_pullup),
260                 mem_fun (*_session_config, &SessionConfiguration::set_video_pullup)
261                 );
262
263         vpu->add (4.1667 + 0.1, _("4.1667 + 0.1%"));
264         vpu->add (4.1667, _("4.1667"));
265         vpu->add (4.1667 - 0.1, _("4.1667 - 0.1%"));
266         vpu->add (0.1, _("0.1"));
267         vpu->add (0, _("none"));
268         vpu->add (-0.1, _("-0.1"));
269         vpu->add (-4.1667 + 0.1, _("-4.1667 + 0.1%"));
270         vpu->add (-4.1667, _("-4.1667"));
271         vpu->add (-4.1667 - 0.1, _("-4.1667 - 0.1%"));
272                 
273         add_option (_("Sync"), vpu);
274         
275         /* MISC */
276
277         add_option (_("Misc"), new OptionEditorHeading (_("Audio file format")));
278
279         ComboOption<SampleFormat>* sf = new ComboOption<SampleFormat> (
280                 "native-file-data-format",
281                 _("Sample format"),
282                 mem_fun (*_session_config, &SessionConfiguration::get_native_file_data_format),
283                 mem_fun (*_session_config, &SessionConfiguration::set_native_file_data_format)
284                 );
285
286         sf->add (FormatFloat, _("32-bit floating point"));
287         sf->add (FormatInt24, _("24-bit integer"));
288         sf->add (FormatInt16, _("16-bit integer"));
289
290         add_option (_("Misc"), sf);
291
292         ComboOption<HeaderFormat>* hf = new ComboOption<HeaderFormat> (
293                 "native-file-header-format",
294                 _("File type"),
295                 mem_fun (*_session_config, &SessionConfiguration::get_native_file_header_format),
296                 mem_fun (*_session_config, &SessionConfiguration::set_native_file_header_format)
297                 );
298
299         hf->add (BWF, _("Broadcast WAVE"));
300         hf->add (WAVE, _("WAVE"));
301         hf->add (WAVE64, _("WAVE-64"));
302         hf->add (CAF, _("CAF"));
303
304         add_option (_("Misc"), hf);
305
306         add_option (_("Misc"), new OptionEditorHeading (_("Layering")));
307
308         ComboOption<LayerModel>* lm = new ComboOption<LayerModel> (
309                 "layer-model",
310                 _("Layering model"),
311                 mem_fun (*_session_config, &SessionConfiguration::get_layer_model),
312                 mem_fun (*_session_config, &SessionConfiguration::set_layer_model)
313                 );
314
315         lm->add (LaterHigher, _("later is higher"));
316         lm->add (MoveAddHigher, _("most recently moved or added is higher"));
317         lm->add (AddHigher, _("most recently added is higher"));
318
319         add_option (_("Misc"), lm);
320         
321         add_option (_("Misc"), new OptionEditorHeading (_("Broadcast WAVE metadata")));
322         
323         add_option (_("Misc"), new EntryOption (
324                             "bwf-country-code",
325                             _("Country code"),
326                             mem_fun (*_session_config, &SessionConfiguration::get_bwf_country_code),
327                             mem_fun (*_session_config, &SessionConfiguration::set_bwf_country_code)
328                             ));
329
330         add_option (_("Misc"), new EntryOption (
331                             "bwf-organization-code",
332                             _("Organization code"),
333                             mem_fun (*_session_config, &SessionConfiguration::get_bwf_organization_code),
334                             mem_fun (*_session_config, &SessionConfiguration::set_bwf_organization_code)
335                             ));
336
337         add_option (_("Connections"), new ConnectionOptions (s));
338 }