Supporters update.
[dcpomatic.git] / src / wx / export_video_file_dialog.cc
1 /*
2     Copyright (C) 2017-2020 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 #include "check_box.h"
23 #include "export_video_file_dialog.h"
24 #include "file_picker_ctrl.h"
25 #include "wx_util.h"
26 #include "lib/config.h"
27 #include <dcp/warnings.h>
28 LIBDCP_DISABLE_WARNINGS
29 #include <wx/filepicker.h>
30 LIBDCP_ENABLE_WARNINGS
31 #include <boost/bind/bind.hpp>
32
33
34 using std::string;
35 using boost::bind;
36
37
38 int constexpr FORMATS = 3;
39
40
41 wxString format_names[] = {
42         _("MOV / ProRes 4444"),
43         _("MOV / ProRes HQ"),
44         _("MP4 / H.264"),
45 };
46
47 wxString format_filters[] = {
48         _("MOV files (*.mov)|*.mov"),
49         _("MOV files (*.mov)|*.mov"),
50         _("MP4 files (*.mp4)|*.mp4"),
51 };
52
53 wxString format_extensions[] = {
54         "mov",
55         "mov",
56         "mp4",
57 };
58
59 ExportFormat formats[] = {
60         ExportFormat::PRORES_4444,
61         ExportFormat::PRORES_HQ,
62         ExportFormat::H264_AAC,
63 };
64
65 ExportVideoFileDialog::ExportVideoFileDialog (wxWindow* parent, string name)
66         : TableDialog (parent, _("Export video file"), 2, 1, true)
67         , _initial_name (name)
68 {
69         auto& config = Config::instance()->export_config();
70
71         add (_("Format"), true);
72         _format = new wxChoice (this, wxID_ANY);
73         add (_format);
74         add_spacer ();
75         _mixdown = new CheckBox (this, _("Mix audio down to stereo"));
76         add (_mixdown, false);
77         add_spacer ();
78         _split_reels = new CheckBox (this, _("Write reels into separate files"));
79         add (_split_reels, false);
80         add_spacer ();
81         _split_streams = new CheckBox (this, _("Write each audio channel to its own stream"));
82         add (_split_streams, false);
83         _x264_crf_label[0] = add (_("Quality"), true);
84         _x264_crf = new wxSlider (this, wxID_ANY, config.x264_crf(), 0, 51, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
85         add (_x264_crf, false);
86         add_spacer ();
87         _x264_crf_label[1] = add (_("0 is best, 51 is worst"), false);
88         wxFont font = _x264_crf_label[1]->GetFont();
89         font.SetStyle(wxFONTSTYLE_ITALIC);
90         font.SetPointSize(font.GetPointSize() - 1);
91         _x264_crf_label[1]->SetFont(font);
92
93         add (_("Output file"), true);
94         /* Don't warn overwrite here, because on Linux (at least) if we specify a filename like foo
95            the wxFileDialog will check that foo exists, but we will add an extension so we actually
96            need to check if foo.mov (or similar) exists.  I can't find a way to make wxWidgets do this,
97            so disable its check and the caller will have to do it themselves.
98         */
99         _file = new FilePickerCtrl(this, _("Select output file"), format_filters[0], false, false, "ExportVideoPath", _initial_name);
100         add (_file);
101
102         for (int i = 0; i < FORMATS; ++i) {
103                 _format->Append (format_names[i]);
104         }
105         for (int i = 0; i < FORMATS; ++i) {
106                 if (config.format() == formats[i]) {
107                         _format->SetSelection(i);
108                 }
109         }
110
111         _mixdown->SetValue(config.mixdown_to_stereo());
112         _split_reels->SetValue(config.split_reels());
113         _split_streams->SetValue(config.split_streams());
114
115         _x264_crf->Enable (false);
116         for (int i = 0; i < 2; ++i) {
117                 _x264_crf_label[i]->Enable (false);
118         }
119
120         _mixdown->bind(&ExportVideoFileDialog::mixdown_changed, this);
121         _split_reels->bind(&ExportVideoFileDialog::split_reels_changed, this);
122         _split_streams->bind(&ExportVideoFileDialog::split_streams_changed, this);
123         _x264_crf->Bind (wxEVT_SLIDER, bind(&ExportVideoFileDialog::x264_crf_changed, this));
124         _format->Bind (wxEVT_CHOICE, bind (&ExportVideoFileDialog::format_changed, this));
125         _file->Bind (wxEVT_FILEPICKER_CHANGED, bind (&ExportVideoFileDialog::file_changed, this));
126
127         format_changed ();
128
129         layout ();
130
131         auto ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
132         ok->Enable (false);
133 }
134
135
136 void
137 ExportVideoFileDialog::mixdown_changed()
138 {
139         Config::instance()->export_config().set_mixdown_to_stereo(_mixdown->GetValue());
140 }
141
142
143 void
144 ExportVideoFileDialog::split_reels_changed()
145 {
146         Config::instance()->export_config().set_split_reels(_split_reels->GetValue());
147 }
148
149
150 void
151 ExportVideoFileDialog::split_streams_changed()
152 {
153         Config::instance()->export_config().set_split_streams(_split_streams->GetValue());
154 }
155
156
157 void
158 ExportVideoFileDialog::x264_crf_changed()
159 {
160         Config::instance()->export_config().set_x264_crf(_x264_crf->GetValue());
161 }
162
163
164 void
165 ExportVideoFileDialog::format_changed ()
166 {
167         auto const selection = _format->GetSelection();
168         DCPOMATIC_ASSERT (selection >= 0 && selection < FORMATS);
169         _file->set_wildcard(format_filters[selection]);
170         _x264_crf->Enable (formats[selection] == ExportFormat::H264_AAC);
171         for (int i = 0; i < 2; ++i) {
172                 _x264_crf_label[i]->Enable(formats[selection] == ExportFormat::H264_AAC);
173         }
174
175         Config::instance()->export_config().set_format(formats[selection]);
176 }
177
178 boost::filesystem::path
179 ExportVideoFileDialog::path () const
180 {
181         auto path = _file->path();
182         DCPOMATIC_ASSERT(path);
183         wxFileName fn(std_to_wx(path->string()));
184         fn.SetExt (format_extensions[_format->GetSelection()]);
185         return wx_to_std (fn.GetFullPath());
186 }
187
188 ExportFormat
189 ExportVideoFileDialog::format () const
190 {
191         DCPOMATIC_ASSERT (_format->GetSelection() >= 0 && _format->GetSelection() < FORMATS);
192         return formats[_format->GetSelection()];
193 }
194
195 bool
196 ExportVideoFileDialog::mixdown_to_stereo () const
197 {
198         return _mixdown->GetValue ();
199 }
200
201 bool
202 ExportVideoFileDialog::split_reels () const
203 {
204         return _split_reels->GetValue ();
205 }
206
207 bool
208 ExportVideoFileDialog::split_streams () const
209 {
210         return _split_streams->GetValue ();
211 }
212
213 int
214 ExportVideoFileDialog::x264_crf () const
215 {
216         return _x264_crf->GetValue ();
217 }
218
219 void
220 ExportVideoFileDialog::file_changed ()
221 {
222         auto ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
223         DCPOMATIC_ASSERT (ok);
224         ok->Enable (path().is_absolute());
225 }