Default to 14fL luminance in the GUI.
[dcpomatic.git] / src / wx / metadata_dialog.cc
1 /*
2     Copyright (C) 2021 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 "dcpomatic_button.h"
24 #include "dcpomatic_choice.h"
25 #include "editable_list.h"
26 #include "full_language_tag_dialog.h"
27 #include "language_tag_widget.h"
28 #include "metadata_dialog.h"
29 #include "rating_dialog.h"
30 #include "region_subtag_widget.h"
31 #include "wx_util.h"
32 #include "lib/film.h"
33 #include <dcp/warnings.h>
34 LIBDCP_DISABLE_WARNINGS
35 #include <wx/notebook.h>
36 #include <wx/spinctrl.h>
37 #include <wx/wx.h>
38 LIBDCP_ENABLE_WARNINGS
39 #include <boost/bind.hpp>
40 #include <boost/weak_ptr.hpp>
41
42
43 using std::weak_ptr;
44 using std::vector;
45 using boost::optional;
46
47
48 MetadataDialog::MetadataDialog (wxWindow* parent, weak_ptr<Film> weak_film)
49         : wxDialog (parent, wxID_ANY, _("Metadata"))
50         , WeakFilm (weak_film)
51 {
52         for (auto system: dcp::rating_systems()) {
53                 _rating_system_agency_to_name[system.agency] = system.name;
54         }
55 }
56
57
58 void
59 MetadataDialog::setup ()
60 {
61         auto notebook = new wxNotebook (this, wxID_ANY);
62
63         auto prepare = [notebook](std::function<void (wxPanel*, wxSizer*)> setup, wxString name) {
64                 auto panel = new wxPanel (notebook, wxID_ANY);
65                 auto sizer = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
66                 sizer->AddGrowableCol (1, 1);
67                 setup (panel, sizer);
68                 auto overall_sizer = new wxBoxSizer (wxVERTICAL);
69                 overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
70                 panel->SetSizer (overall_sizer);
71                 notebook->AddPage (panel, name);
72         };
73
74         prepare (boost::bind(&MetadataDialog::setup_standard, this, _1, _2), _("Standard"));
75         prepare (boost::bind(&MetadataDialog::setup_advanced, this, _1, _2), _("Advanced"));
76
77         auto overall_sizer = new wxBoxSizer (wxVERTICAL);
78         overall_sizer->Add (notebook, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
79
80         auto buttons = CreateSeparatedButtonSizer (wxCLOSE);
81         if (buttons) {
82                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
83         }
84
85         SetSizer (overall_sizer);
86         overall_sizer->Layout ();
87         overall_sizer->SetSizeHints (this);
88
89         _sign_language_video_language->Changed.connect (boost::bind(&MetadataDialog::sign_language_video_language_changed, this));
90         _enable_release_territory->bind(&MetadataDialog::enable_release_territory_changed, this);
91         _release_territory->Changed.connect(boost::bind(&MetadataDialog::release_territory_changed, this, _1));
92         _enable_facility->bind(&MetadataDialog::enable_facility_changed, this);
93         _facility->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::facility_changed, this));
94         _enable_studio->bind(&MetadataDialog::enable_studio_changed, this);
95         _studio->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::studio_changed, this));
96         _enable_chain->bind(&MetadataDialog::enable_chain_changed, this);
97         _chain->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::chain_changed, this));
98         _temp_version->bind(&MetadataDialog::temp_version_changed, this);
99         _pre_release->bind(&MetadataDialog::pre_release_changed, this);
100         _red_band->bind(&MetadataDialog::red_band_changed, this);
101         _two_d_version_of_three_d->bind(&MetadataDialog::two_d_version_of_three_d_changed, this);
102         _enable_luminance->bind(&MetadataDialog::enable_luminance_changed, this);
103         _luminance_value->Bind (wxEVT_SPINCTRLDOUBLE, boost::bind(&MetadataDialog::luminance_changed, this));
104         _luminance_unit->Bind (wxEVT_CHOICE, boost::bind(&MetadataDialog::luminance_changed, this));
105
106         _film_changed_connection = film()->Change.connect(boost::bind(&MetadataDialog::film_changed, this, _1, _2));
107
108         film_changed (ChangeType::DONE, Film::Property::RELEASE_TERRITORY);
109         film_changed (ChangeType::DONE, Film::Property::SIGN_LANGUAGE_VIDEO_LANGUAGE);
110         film_changed (ChangeType::DONE, Film::Property::FACILITY);
111         film_changed (ChangeType::DONE, Film::Property::STUDIO);
112         film_changed (ChangeType::DONE, Film::Property::TEMP_VERSION);
113         film_changed (ChangeType::DONE, Film::Property::PRE_RELEASE);
114         film_changed (ChangeType::DONE, Film::Property::RED_BAND);
115         film_changed (ChangeType::DONE, Film::Property::TWO_D_VERSION_OF_THREE_D);
116         film_changed (ChangeType::DONE, Film::Property::CHAIN);
117         film_changed (ChangeType::DONE, Film::Property::LUMINANCE);
118
119         setup_sensitivity ();
120 }
121
122
123 void
124 MetadataDialog::film_changed (ChangeType type, Film::Property property)
125 {
126         if (type != ChangeType::DONE) {
127                 return;
128         }
129
130         if (property == Film::Property::SIGN_LANGUAGE_VIDEO_LANGUAGE) {
131                 _sign_language_video_language->set (film()->sign_language_video_language());
132         } else if (property == Film::Property::RELEASE_TERRITORY) {
133                 auto rt = film()->release_territory();
134                 checked_set (_enable_release_territory, static_cast<bool>(rt));
135                 if (rt) {
136                         _release_territory_copy = *rt;
137                         checked_set(_release_territory, *_release_territory_copy);
138                 }
139         } else if (property == Film::Property::FACILITY) {
140                 checked_set (_enable_facility, static_cast<bool>(film()->facility()));
141                 if (film()->facility()) {
142                         checked_set (_facility, *film()->facility());
143                 }
144         } else if (property == Film::Property::STUDIO) {
145                 checked_set (_enable_studio, static_cast<bool>(film()->studio()));
146                 if (film()->studio()) {
147                         checked_set (_studio, *film()->studio());
148                 }
149         } else if (property == Film::Property::CHAIN) {
150                 checked_set (_enable_chain, static_cast<bool>(film()->chain()));
151                 if (film()->chain()) {
152                         checked_set (_chain, *film()->chain());
153                 }
154         } else if (property == Film::Property::TEMP_VERSION) {
155                 checked_set (_temp_version, film()->temp_version());
156         } else if (property == Film::Property::PRE_RELEASE) {
157                 checked_set (_pre_release, film()->pre_release());
158         } else if (property == Film::Property::RED_BAND) {
159                 checked_set (_red_band, film()->red_band());
160         } else if (property == Film::Property::TWO_D_VERSION_OF_THREE_D) {
161                 checked_set (_two_d_version_of_three_d, film()->two_d_version_of_three_d());
162         } else if (property == Film::Property::LUMINANCE) {
163                 auto lum = film()->luminance();
164                 checked_set (_enable_luminance, static_cast<bool>(lum));
165                 if (lum) {
166                         checked_set (_luminance_value, lum->value());
167                         switch (lum->unit()) {
168                         case dcp::Luminance::Unit::CANDELA_PER_SQUARE_METRE:
169                                 checked_set (_luminance_unit, 0);
170                                 break;
171                         case dcp::Luminance::Unit::FOOT_LAMBERT:
172                                 checked_set (_luminance_unit, 1);
173                                 break;
174                         }
175                 } else {
176                         checked_set(_luminance_value, 14);
177                         checked_set (_luminance_unit, 1);
178                 }
179         }
180 }
181
182
183 void
184 MetadataDialog::setup_standard (wxPanel* panel, wxSizer* sizer)
185 {
186         _enable_release_territory = new CheckBox(panel, _("Release territory"));
187         sizer->Add (_enable_release_territory, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
188         _release_territory = new RegionSubtagWidget(panel, _("Release territory for this DCP"), film()->release_territory());
189         sizer->Add(_release_territory->sizer(), 0, wxEXPAND);
190
191         vector<EditableListColumn> columns;
192         columns.push_back(EditableListColumn("Agency", 200, true));
193         columns.push_back(EditableListColumn("Label", 400, true));
194         _ratings = new EditableList<dcp::Rating, RatingDialog> (
195                 panel,
196                 columns,
197                 boost::bind(&MetadataDialog::ratings, this),
198                 boost::bind(&MetadataDialog::set_ratings, this, _1),
199                 [this](dcp::Rating r, int c) {
200                         if (c == 0) {
201                                 auto iter = _rating_system_agency_to_name.find(r.agency);
202                                 if (iter != _rating_system_agency_to_name.end()) {
203                                         return iter->second;
204                                 }
205                                 return r.agency;
206                         }
207                         return r.label;
208                 },
209                 EditableListTitle::VISIBLE,
210                 EditableListButton::NEW | EditableListButton::EDIT | EditableListButton::REMOVE
211                 );
212         _ratings->SetMinSize(wxSize(600, -1));
213 }
214
215
216 void
217 MetadataDialog::release_territory_changed(optional<dcp::LanguageTag::RegionSubtag> tag)
218 {
219         if (tag) {
220                 _release_territory_copy = *tag;
221                 film()->set_release_territory(*tag);
222         }
223 }
224
225
226 void
227 MetadataDialog::setup_sensitivity ()
228 {
229         _sign_language_video_language->enable (film()->has_sign_language_video_channel());
230         auto const enabled = _enable_release_territory->GetValue();
231         _release_territory->enable(enabled);
232         _facility->Enable (_enable_facility->GetValue());
233         _chain->Enable (_enable_chain->GetValue());
234         _studio->Enable (_enable_studio->GetValue());
235         _luminance_value->Enable (_enable_luminance->GetValue());
236         _luminance_unit->Enable (_enable_luminance->GetValue());
237 }
238
239
240 void
241 MetadataDialog::enable_release_territory_changed ()
242 {
243         setup_sensitivity ();
244         if (_enable_release_territory->GetValue()) {
245                 film()->set_release_territory (_release_territory->get().get_value_or(dcp::LanguageTag::RegionSubtag("US")));
246         } else {
247                 film()->set_release_territory ();
248         }
249 }
250
251
252 void
253 MetadataDialog::setup_advanced (wxPanel* panel, wxSizer* sizer)
254 {
255         add_label_to_sizer (sizer, panel, _("Sign language video language"), true, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT);
256         _sign_language_video_language = new LanguageTagWidget (panel, _("Language used for any sign language video track"), {}, {});
257         sizer->Add (_sign_language_video_language->sizer(), 1, wxEXPAND);
258
259         _enable_facility = new CheckBox(panel, _("Facility"));
260         sizer->Add (_enable_facility, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
261         _facility = new wxTextCtrl (panel, wxID_ANY);
262         sizer->Add (_facility, 1, wxEXPAND);
263
264         _enable_studio = new CheckBox(panel, _("Studio"));
265         sizer->Add (_enable_studio, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
266         _studio = new wxTextCtrl (panel, wxID_ANY);
267         sizer->Add (_studio, 1, wxEXPAND);
268
269         _enable_chain = new CheckBox(panel, _("Chain"));
270         sizer->Add (_enable_chain, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
271         _chain = new wxTextCtrl (panel, wxID_ANY);
272         sizer->Add (_chain, 1, wxEXPAND);
273
274         _temp_version = new CheckBox(panel, _("Temporary version"));
275         sizer->Add (_temp_version, 0, wxALIGN_CENTER_VERTICAL);
276         sizer->AddSpacer (0);
277
278         _pre_release = new CheckBox(panel, _("Pre-release"));
279         sizer->Add (_pre_release, 0, wxALIGN_CENTER_VERTICAL);
280         sizer->AddSpacer (0);
281
282         _red_band = new CheckBox(panel, _("Red band"));
283         sizer->Add (_red_band, 0, wxALIGN_CENTER_VERTICAL);
284         sizer->AddSpacer (0);
285
286         _two_d_version_of_three_d = new CheckBox(panel, _("2D version of 3D DCP"));
287         sizer->Add (_two_d_version_of_three_d, 0, wxALIGN_CENTER_VERTICAL);
288         sizer->AddSpacer (0);
289
290         _enable_luminance = new CheckBox(panel, _("Luminance"));
291         sizer->Add (_enable_luminance, 0, wxALIGN_CENTER_VERTICAL);
292         {
293                 auto s = new wxBoxSizer (wxHORIZONTAL);
294                 _luminance_value = new wxSpinCtrlDouble (panel, wxID_ANY);
295                 _luminance_value->SetRange (0.1, 32.0);
296                 _luminance_value->SetDigits (1);
297                 _luminance_value->SetIncrement (0.1);
298                 s->Add (_luminance_value, 0);
299                 _luminance_unit = new Choice(panel);
300                 s->Add (_luminance_unit, 0, wxLEFT, DCPOMATIC_SIZER_X_GAP);
301                 sizer->Add (s, 1, wxEXPAND);
302         }
303
304         _luminance_unit->add(_("candela per m²"));
305         _luminance_unit->add(_("foot lambert"));
306 }
307
308
309 void
310 MetadataDialog::facility_changed ()
311 {
312         film()->set_facility (wx_to_std(_facility->GetValue()));
313 }
314
315
316 void
317 MetadataDialog::enable_facility_changed ()
318 {
319         setup_sensitivity ();
320         if (_enable_facility->GetValue()) {
321                 film()->set_facility (wx_to_std(_facility->GetValue()));
322         } else {
323                 film()->set_facility ();
324         }
325 }
326
327
328 void
329 MetadataDialog::studio_changed ()
330 {
331         film()->set_studio (wx_to_std(_studio->GetValue()));
332 }
333
334
335 void
336 MetadataDialog::enable_studio_changed ()
337 {
338         setup_sensitivity ();
339         if (_enable_studio->GetValue()) {
340                 film()->set_studio (wx_to_std(_studio->GetValue()));
341         } else {
342                 film()->set_studio ();
343         }
344 }
345
346
347 void
348 MetadataDialog::temp_version_changed ()
349 {
350         film()->set_temp_version(_temp_version->GetValue());
351 }
352
353
354 void
355 MetadataDialog::pre_release_changed ()
356 {
357         film()->set_pre_release(_pre_release->GetValue());
358 }
359
360
361 void
362 MetadataDialog::red_band_changed ()
363 {
364         film()->set_red_band(_red_band->GetValue());
365 }
366
367
368 void
369 MetadataDialog::two_d_version_of_three_d_changed ()
370 {
371         film()->set_two_d_version_of_three_d(_two_d_version_of_three_d->GetValue());
372 }
373
374
375 void
376 MetadataDialog::chain_changed ()
377 {
378         film()->set_chain (wx_to_std(_chain->GetValue()));
379 }
380
381
382 void
383 MetadataDialog::enable_chain_changed ()
384 {
385         setup_sensitivity ();
386         if (_enable_chain->GetValue()) {
387                 chain_changed ();
388         } else {
389                 film()->set_chain ();
390         }
391 }
392
393
394 void
395 MetadataDialog::enable_luminance_changed ()
396 {
397         setup_sensitivity ();
398         if (_enable_luminance->GetValue()) {
399                 luminance_changed ();
400         } else {
401                 film()->set_luminance ();
402         }
403 }
404
405
406 void
407 MetadataDialog::luminance_changed ()
408 {
409         dcp::Luminance::Unit unit;
410         DCPOMATIC_ASSERT(_luminance_unit->get());
411         switch (*_luminance_unit->get()) {
412         case 0:
413                 unit = dcp::Luminance::Unit::CANDELA_PER_SQUARE_METRE;
414                 break;
415         case 1:
416                 unit = dcp::Luminance::Unit::FOOT_LAMBERT;
417                 break;
418         default:
419                 DCPOMATIC_ASSERT (false);
420         }
421
422         film()->set_luminance (dcp::Luminance(_luminance_value->GetValue(), unit));
423 }
424
425
426 void
427 MetadataDialog::sign_language_video_language_changed ()
428 {
429         film()->set_sign_language_video_language(_sign_language_video_language->get());
430 }
431
432
433 vector<dcp::Rating>
434 MetadataDialog::ratings() const
435 {
436         return film()->ratings();
437 }
438
439
440 void
441 MetadataDialog::set_ratings(vector<dcp::Rating> r)
442 {
443         film()->set_ratings(r);
444 }
445