Rename PRORES -> PRORES_HQ
[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 #define FORMATS 2
39
40
41 wxString format_names[] = {
42         _("MOV / ProRes"),
43         _("MP4 / H.264"),
44 };
45
46 wxString format_filters[] = {
47         _("MOV files (*.mov)|*.mov"),
48         _("MP4 files (*.mp4)|*.mp4"),
49 };
50
51 wxString format_extensions[] = {
52         "mov",
53         "mp4",
54 };
55
56 ExportFormat formats[] = {
57         ExportFormat::PRORES_HQ,
58         ExportFormat::H264_AAC,
59 };
60
61 ExportVideoFileDialog::ExportVideoFileDialog (wxWindow* parent, string name)
62         : TableDialog (parent, _("Export video file"), 2, 1, true)
63         , _initial_name (name)
64 {
65         auto& config = Config::instance()->export_config();
66
67         add (_("Format"), true);
68         _format = new wxChoice (this, wxID_ANY);
69         add (_format);
70         add_spacer ();
71         _mixdown = new CheckBox (this, _("Mix audio down to stereo"));
72         add (_mixdown, false);
73         add_spacer ();
74         _split_reels = new CheckBox (this, _("Write reels into separate files"));
75         add (_split_reels, false);
76         add_spacer ();
77         _split_streams = new CheckBox (this, _("Write each audio channel to its own stream"));
78         add (_split_streams, false);
79         _x264_crf_label[0] = add (_("Quality"), true);
80         _x264_crf = new wxSlider (this, wxID_ANY, config.x264_crf(), 0, 51, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
81         add (_x264_crf, false);
82         add_spacer ();
83         _x264_crf_label[1] = add (_("0 is best, 51 is worst"), false);
84         wxFont font = _x264_crf_label[1]->GetFont();
85         font.SetStyle(wxFONTSTYLE_ITALIC);
86         font.SetPointSize(font.GetPointSize() - 1);
87         _x264_crf_label[1]->SetFont(font);
88
89         add (_("Output file"), true);
90         /* Don't warn overwrite here, because on Linux (at least) if we specify a filename like foo
91            the wxFileDialog will check that foo exists, but we will add an extension so we actually
92            need to check if foo.mov (or similar) exists.  I can't find a way to make wxWidgets do this,
93            so disable its check and the caller will have to do it themselves.
94         */
95         _file = new FilePickerCtrl (this, _("Select output file"), format_filters[0], false, false);
96         _file->SetPath (_initial_name);
97         add (_file);
98
99         for (int i = 0; i < FORMATS; ++i) {
100                 _format->Append (format_names[i]);
101         }
102         for (int i = 0; i < FORMATS; ++i) {
103                 if (config.format() == formats[i]) {
104                         _format->SetSelection(i);
105                 }
106         }
107
108         _mixdown->SetValue(config.mixdown_to_stereo());
109         _split_reels->SetValue(config.split_reels());
110         _split_streams->SetValue(config.split_streams());
111
112         _x264_crf->Enable (false);
113         for (int i = 0; i < 2; ++i) {
114                 _x264_crf_label[i]->Enable (false);
115         }
116
117         _mixdown->Bind (wxEVT_CHECKBOX, bind(&ExportVideoFileDialog::mixdown_changed, this));
118         _split_reels->Bind (wxEVT_CHECKBOX, bind(&ExportVideoFileDialog::split_reels_changed, this));
119         _split_streams->Bind (wxEVT_CHECKBOX, bind(&ExportVideoFileDialog::split_streams_changed, this));
120         _x264_crf->Bind (wxEVT_SLIDER, bind(&ExportVideoFileDialog::x264_crf_changed, this));
121         _format->Bind (wxEVT_CHOICE, bind (&ExportVideoFileDialog::format_changed, this));
122         _file->Bind (wxEVT_FILEPICKER_CHANGED, bind (&ExportVideoFileDialog::file_changed, this));
123
124         format_changed ();
125
126         layout ();
127
128         auto ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
129         ok->Enable (false);
130 }
131
132
133 void
134 ExportVideoFileDialog::mixdown_changed()
135 {
136         Config::instance()->export_config().set_mixdown_to_stereo(_mixdown->GetValue());
137 }
138
139
140 void
141 ExportVideoFileDialog::split_reels_changed()
142 {
143         Config::instance()->export_config().set_split_reels(_split_reels->GetValue());
144 }
145
146
147 void
148 ExportVideoFileDialog::split_streams_changed()
149 {
150         Config::instance()->export_config().set_split_streams(_split_streams->GetValue());
151 }
152
153
154 void
155 ExportVideoFileDialog::x264_crf_changed()
156 {
157         Config::instance()->export_config().set_x264_crf(_x264_crf->GetValue());
158 }
159
160
161 void
162 ExportVideoFileDialog::format_changed ()
163 {
164         auto const selection = _format->GetSelection();
165         DCPOMATIC_ASSERT (selection >= 0 && selection < FORMATS);
166         _file->SetWildcard (format_filters[selection]);
167         _file->SetPath (_initial_name);
168         _x264_crf->Enable (selection == 1);
169         for (int i = 0; i < 2; ++i) {
170                 _x264_crf_label[i]->Enable (selection == 1);
171         }
172         _mixdown->Enable (selection != 2);
173
174         Config::instance()->export_config().set_format(formats[selection]);
175 }
176
177 boost::filesystem::path
178 ExportVideoFileDialog::path () const
179 {
180         wxFileName fn (_file->GetPath());
181         fn.SetExt (format_extensions[_format->GetSelection()]);
182         return wx_to_std (fn.GetFullPath());
183 }
184
185 ExportFormat
186 ExportVideoFileDialog::format () const
187 {
188         DCPOMATIC_ASSERT (_format->GetSelection() >= 0 && _format->GetSelection() < FORMATS);
189         return formats[_format->GetSelection()];
190 }
191
192 bool
193 ExportVideoFileDialog::mixdown_to_stereo () const
194 {
195         return _mixdown->GetValue ();
196 }
197
198 bool
199 ExportVideoFileDialog::split_reels () const
200 {
201         return _split_reels->GetValue ();
202 }
203
204 bool
205 ExportVideoFileDialog::split_streams () const
206 {
207         return _split_streams->GetValue ();
208 }
209
210 int
211 ExportVideoFileDialog::x264_crf () const
212 {
213         return _x264_crf->GetValue ();
214 }
215
216 void
217 ExportVideoFileDialog::file_changed ()
218 {
219         auto ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
220         DCPOMATIC_ASSERT (ok);
221         ok->Enable (path().is_absolute());
222 }