Merge remote-tracking branch 'origin/master' into export-dialog
[ardour.git] / gtk2_ardour / export_format_dialog.h
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Sakari Bergen
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #ifndef __export_format_dialog_h__
22 #define __export_format_dialog_h__
23
24 #include "ardour/types.h"
25 #include "ardour/export_format_manager.h"
26 #include "ardour/export_format_compatibility.h"
27 #include "ardour/export_formats.h"
28
29 #include "pbd/xml++.h"
30 #include "pbd/signals.h"
31
32 #include "ardour_dialog.h"
33 #include "audio_clock.h"
34
35 #include <gtkmm.h>
36
37 class ExportFormatDialog : public ArdourDialog, public PBD::ScopedConnectionList {
38   private:
39
40         typedef ARDOUR::WeakExportFormatCompatibilityPtr WeakCompatPtr;
41         typedef ARDOUR::WeakExportFormatPtr WeakFormatPtr;
42         typedef ARDOUR::ExportFormatManager::WeakQualityPtr WeakQualityPtr;
43         typedef ARDOUR::ExportFormatManager::WeakSampleRatePtr WeakSampleRatePtr;
44         typedef ARDOUR::ExportFormatManager::WeakSampleFormatPtr WeakSampleFormatPtr;
45         typedef ARDOUR::ExportFormatManager::WeakDitherTypePtr WeakDitherTypePtr;
46
47         typedef boost::shared_ptr<ARDOUR::ExportFormatSpecification> FormatPtr;
48
49
50   public:
51
52         explicit ExportFormatDialog (FormatPtr format, bool new_dialog = false);
53         ~ExportFormatDialog ();
54
55         void set_session (ARDOUR::Session* s);
56
57   private:
58
59         FormatPtr                   format;
60         ARDOUR::ExportFormatManager manager;
61
62         XMLNode & original_state;
63
64         ARDOUR::AnyTime silence_start;
65         ARDOUR::AnyTime silence_end;
66
67         void end_dialog ();
68         void revert ();
69
70         /*** Init functions ***/
71
72         void load_state (FormatPtr spec);
73         void init_format_table ();
74         void init_encoding_option_widgets ();
75
76         /*** Interactive selections ***/
77
78         /* These are connected to signals from GUI components, and should change element states  */
79
80         void update_compatibility_selection (std::string const & path);
81         void update_quality_selection ();
82         void update_format_selection ();
83         void update_sample_rate_selection ();
84         void update_sample_format_selection ();
85         void update_dither_type_selection ();
86
87         template<typename ColsT>
88         void update_selection (Glib::RefPtr<Gtk::ListStore> & list, Gtk::TreeView & view, ColsT & cols);
89
90         /* These are connected to signals from elements, and should only update the gui */
91
92         void change_compatibility_selection (bool select, WeakCompatPtr compat);
93
94         void change_quality_selection (bool select, WeakQualityPtr quality);
95         void change_format_selection (bool select, WeakFormatPtr format);
96         void change_sample_rate_selection (bool select, WeakSampleRatePtr rate);
97         void change_sample_format_selection (bool select, WeakSampleFormatPtr format);
98         void change_dither_type_selection (bool select, WeakDitherTypePtr type);
99
100         template<typename T, typename ColsT>
101         void change_selection (bool select, boost::weak_ptr<T> w_ptr, Glib::RefPtr<Gtk::ListStore> & list, Gtk::TreeView & view, ColsT & cols);
102
103         void change_quality_compatibility (bool compatibility, WeakQualityPtr quality);
104         void change_format_compatibility (bool compatibility, WeakFormatPtr format);
105         void change_sample_rate_compatibility (bool compatibility, WeakSampleRatePtr rate);
106         void change_sample_format_compatibility (bool compatibility, WeakSampleFormatPtr format);
107         void change_dither_type_compatibility (bool compatibility, WeakDitherTypePtr type);
108
109         template<typename T, typename ColsT>
110         void change_compatibility (bool compatibility, boost::weak_ptr<T> w_ptr, Glib::RefPtr<Gtk::ListStore> & list, ColsT & cols,
111                                    std::string const & c_incompatible = "red", std::string const & c_compatible = "white");
112
113         void update_description();
114
115         uint32_t applying_changes_from_engine;
116
117         /*** Non-interactive selections ***/
118
119         void update_name ();
120
121         void update_trim_start_selection ();
122         void update_trim_end_selection ();
123
124         void update_normalize_selection ();
125         void update_silence_start_selection ();
126         void update_silence_end_selection ();
127
128         void update_clock (AudioClock & clock, ARDOUR::AnyTime const & time);
129         void update_time (ARDOUR::AnyTime & time, AudioClock const & clock);
130
131         void update_src_quality_selection ();
132         void update_tagging_selection ();
133
134         /*** Encoding options */
135
136         void change_encoding_options (ARDOUR::ExportFormatPtr ptr);
137
138         void empty_encoding_option_table ();
139         void remove_widget (Gtk::Widget & to_remove, Gtk::Container * remove_from);
140
141         void show_linear_enconding_options (boost::shared_ptr<ARDOUR::ExportFormatLinear> ptr);
142         void show_ogg_enconding_options (boost::shared_ptr<ARDOUR::ExportFormatOggVorbis> ptr);
143         void show_flac_enconding_options (boost::shared_ptr<ARDOUR::ExportFormatFLAC> ptr);
144         void show_bwf_enconding_options (boost::shared_ptr<ARDOUR::ExportFormatBWF> ptr);
145
146         void fill_sample_format_lists (boost::shared_ptr<ARDOUR::HasSampleFormat> ptr);
147
148         /*** GUI components ***/
149
150         /* Name, new and remove */
151
152         Gtk::HBox  name_hbox;
153
154         Gtk::Label name_label;
155         Gtk::Entry name_entry;
156         Gtk::Label name_generated_part;
157
158         /* Normalize */
159
160         Gtk::HBox        normalize_hbox;
161         Gtk::CheckButton normalize_checkbox;
162         Gtk::SpinButton  normalize_spinbutton;
163         Gtk::Adjustment  normalize_adjustment;
164         Gtk::Label       normalize_db_label;
165
166         /* Silence  */
167
168         Gtk::Table       silence_table;
169
170         Gtk::CheckButton trim_start_checkbox;
171         Gtk::CheckButton silence_start_checkbox;
172         AudioClock       silence_start_clock;
173
174         Gtk::CheckButton trim_end_checkbox;
175         Gtk::CheckButton silence_end_checkbox;
176         AudioClock       silence_end_clock;
177
178         /* Upload */
179         
180         Gtk::CheckButton upload_checkbox;
181         Gtk::Label       command_label;
182         Gtk::Entry       command_entry;
183
184         /* Format table */
185
186         struct CompatibilityCols : public Gtk::TreeModelColumnRecord
187         {
188           public:
189                 Gtk::TreeModelColumn<ARDOUR::ExportFormatCompatibilityPtr>  ptr;
190                 Gtk::TreeModelColumn<bool>                                  selected;
191                 Gtk::TreeModelColumn<std::string>                           label;
192
193                 CompatibilityCols () { add(ptr); add(selected); add(label); }
194         };
195         CompatibilityCols            compatibility_cols;
196         Glib::RefPtr<Gtk::ListStore> compatibility_list;
197
198         /* Hack to disallow row selection in compatibilities */
199         void prohibit_compatibility_selection ();
200         sigc::connection compatibility_select_connection;
201
202         struct QualityCols : public Gtk::TreeModelColumnRecord
203         {
204           public:
205                 Gtk::TreeModelColumn<ARDOUR::ExportFormatManager::QualityPtr>  ptr;
206                 Gtk::TreeModelColumn<std::string>                            color;
207                 Gtk::TreeModelColumn<std::string>                            label;
208
209                 QualityCols () { add(ptr); add(color); add(label); }
210         };
211         QualityCols                  quality_cols;
212         Glib::RefPtr<Gtk::ListStore> quality_list;
213
214         struct FormatCols : public Gtk::TreeModelColumnRecord
215         {
216           public:
217                 Gtk::TreeModelColumn<ARDOUR::ExportFormatPtr>  ptr;
218                 Gtk::TreeModelColumn<std::string>              color;
219                 Gtk::TreeModelColumn<std::string>              label;
220
221                 FormatCols () { add(ptr); add(color); add(label); }
222         };
223         FormatCols                   format_cols;
224         Glib::RefPtr<Gtk::ListStore> format_list;
225
226         struct SampleRateCols : public Gtk::TreeModelColumnRecord
227         {
228           public:
229                 Gtk::TreeModelColumn<ARDOUR::ExportFormatManager::SampleRatePtr>  ptr;
230                 Gtk::TreeModelColumn<std::string>                               color;
231                 Gtk::TreeModelColumn<std::string>                               label;
232
233                 SampleRateCols () { add(ptr); add(color); add(label); }
234         };
235         SampleRateCols               sample_rate_cols;
236         Glib::RefPtr<Gtk::ListStore> sample_rate_list;
237
238         Gtk::Table       format_table;
239
240         Gtk::Label       compatibility_label;
241         Gtk::Label       quality_label;
242         Gtk::Label       format_label;
243         Gtk::Label       sample_rate_label;
244
245         Gtk::TreeView    compatibility_view;
246         Gtk::TreeView    quality_view;
247         Gtk::TreeView    format_view;
248         Gtk::TreeView    sample_rate_view;
249
250         /* SRC quality combo */
251
252         struct SRCQualityCols : public Gtk::TreeModelColumnRecord
253         {
254           public:
255                 Gtk::TreeModelColumn<ARDOUR::ExportFormatBase::SRCQuality>  id;
256                 Gtk::TreeModelColumn<std::string>                         label;
257
258                 SRCQualityCols () { add(id); add(label); }
259         };
260         SRCQualityCols               src_quality_cols;
261         Glib::RefPtr<Gtk::ListStore> src_quality_list;
262
263         Gtk::Label      src_quality_label;
264         Gtk::ComboBox   src_quality_combo;
265
266         /* Common encoding option components */
267
268         Gtk::VBox   encoding_options_vbox;
269         Gtk::Label  encoding_options_label;
270
271         Gtk::Table  encoding_options_table;
272
273         /* Other common components */
274
275         Gtk::Button * revert_button;
276         Gtk::Button * close_button;
277
278         /*** Changing encoding option stuff ***/
279
280         /* Linear */
281
282         struct SampleFormatCols : public Gtk::TreeModelColumnRecord
283         {
284           public:
285                 Gtk::TreeModelColumn<ARDOUR::HasSampleFormat::SampleFormatPtr>   ptr;
286                 Gtk::TreeModelColumn<std::string>                              color;
287                 Gtk::TreeModelColumn<std::string>                              label;
288
289                 SampleFormatCols () { add(ptr); add(color); add(label); }
290         };
291         SampleFormatCols             sample_format_cols;
292         Glib::RefPtr<Gtk::ListStore> sample_format_list;
293
294         struct DitherTypeCols : public Gtk::TreeModelColumnRecord
295         {
296           public:
297                 Gtk::TreeModelColumn<ARDOUR::HasSampleFormat::DitherTypePtr>   ptr;
298                 Gtk::TreeModelColumn<std::string>                            color;
299                 Gtk::TreeModelColumn<std::string>                            label;
300
301                 DitherTypeCols () { add(ptr); add (color); add(label); }
302         };
303         DitherTypeCols               dither_type_cols;
304         Glib::RefPtr<Gtk::ListStore> dither_type_list;
305
306         Gtk::Label  sample_format_label;
307         Gtk::Label  dither_label;
308
309         Gtk::CheckButton with_cue;
310         Gtk::CheckButton with_toc;
311
312         Gtk::VBox cue_toc_vbox;
313
314         void update_with_toc ();
315         void update_with_cue ();
316         void update_upload ();
317         void update_command ();
318
319         Gtk::TreeView sample_format_view;
320         Gtk::TreeView dither_type_view;
321
322         /* Tagging */
323
324         Gtk::CheckButton  tag_checkbox;
325
326 };
327
328 #endif /* __export_format_dialog_h__ */