2 Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 #include "dcpomatic_button.h"
23 #include "dcpomatic_choice.h"
24 #include "editable_list.h"
25 #include "full_language_tag_dialog.h"
26 #include "language_tag_widget.h"
27 #include "metadata_dialog.h"
28 #include "rating_dialog.h"
31 #include <dcp/warnings.h>
32 LIBDCP_DISABLE_WARNINGS
33 #include <wx/notebook.h>
34 #include <wx/spinctrl.h>
36 LIBDCP_ENABLE_WARNINGS
37 #include <boost/bind.hpp>
38 #include <boost/weak_ptr.hpp>
45 MetadataDialog::MetadataDialog (wxWindow* parent, weak_ptr<Film> weak_film)
46 : wxDialog (parent, wxID_ANY, _("Metadata"))
47 , WeakFilm (weak_film)
49 for (auto system: dcp::rating_systems()) {
50 _rating_system_agency_to_name[system.agency] = system.name;
56 MetadataDialog::setup ()
58 auto notebook = new wxNotebook (this, wxID_ANY);
60 auto prepare = [notebook](std::function<void (wxPanel*, wxSizer*)> setup, wxString name) {
61 auto panel = new wxPanel (notebook, wxID_ANY);
62 auto sizer = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
63 sizer->AddGrowableCol (1, 1);
65 auto overall_sizer = new wxBoxSizer (wxVERTICAL);
66 overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
67 panel->SetSizer (overall_sizer);
68 notebook->AddPage (panel, name);
71 prepare (boost::bind(&MetadataDialog::setup_standard, this, _1, _2), _("Standard"));
72 prepare (boost::bind(&MetadataDialog::setup_advanced, this, _1, _2), _("Advanced"));
74 auto overall_sizer = new wxBoxSizer (wxVERTICAL);
75 overall_sizer->Add (notebook, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
77 auto buttons = CreateSeparatedButtonSizer (wxCLOSE);
79 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
82 SetSizer (overall_sizer);
83 overall_sizer->Layout ();
84 overall_sizer->SetSizeHints (this);
86 _sign_language_video_language->Changed.connect (boost::bind(&MetadataDialog::sign_language_video_language_changed, this));
87 _edit_release_territory->Bind (wxEVT_BUTTON, boost::bind(&MetadataDialog::edit_release_territory, this));
88 _enable_release_territory->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::enable_release_territory_changed, this));
89 _enable_facility->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::enable_facility_changed, this));
90 _facility->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::facility_changed, this));
91 _enable_studio->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::enable_studio_changed, this));
92 _studio->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::studio_changed, this));
93 _enable_chain->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::enable_chain_changed, this));
94 _chain->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::chain_changed, this));
95 _temp_version->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::temp_version_changed, this));
96 _pre_release->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::pre_release_changed, this));
97 _red_band->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::red_band_changed, this));
98 _two_d_version_of_three_d->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::two_d_version_of_three_d_changed, this));
99 _enable_luminance->Bind (wxEVT_CHECKBOX, boost::bind(&MetadataDialog::enable_luminance_changed, this));
100 _luminance_value->Bind (wxEVT_SPINCTRLDOUBLE, boost::bind(&MetadataDialog::luminance_changed, this));
101 _luminance_unit->Bind (wxEVT_CHOICE, boost::bind(&MetadataDialog::luminance_changed, this));
103 _film_changed_connection = film()->Change.connect(boost::bind(&MetadataDialog::film_changed, this, _1, _2));
105 film_changed (ChangeType::DONE, Film::Property::RELEASE_TERRITORY);
106 film_changed (ChangeType::DONE, Film::Property::SIGN_LANGUAGE_VIDEO_LANGUAGE);
107 film_changed (ChangeType::DONE, Film::Property::FACILITY);
108 film_changed (ChangeType::DONE, Film::Property::STUDIO);
109 film_changed (ChangeType::DONE, Film::Property::TEMP_VERSION);
110 film_changed (ChangeType::DONE, Film::Property::PRE_RELEASE);
111 film_changed (ChangeType::DONE, Film::Property::RED_BAND);
112 film_changed (ChangeType::DONE, Film::Property::TWO_D_VERSION_OF_THREE_D);
113 film_changed (ChangeType::DONE, Film::Property::CHAIN);
114 film_changed (ChangeType::DONE, Film::Property::LUMINANCE);
116 setup_sensitivity ();
121 MetadataDialog::film_changed (ChangeType type, Film::Property property)
123 if (type != ChangeType::DONE) {
127 if (property == Film::Property::SIGN_LANGUAGE_VIDEO_LANGUAGE) {
128 _sign_language_video_language->set (film()->sign_language_video_language());
129 } else if (property == Film::Property::RELEASE_TERRITORY) {
130 auto rt = film()->release_territory();
131 checked_set (_enable_release_territory, static_cast<bool>(rt));
133 _release_territory = *rt;
134 checked_set (_release_territory_text, std_to_wx(*dcp::LanguageTag::get_subtag_description(*_release_territory)));
136 } else if (property == Film::Property::FACILITY) {
137 checked_set (_enable_facility, static_cast<bool>(film()->facility()));
138 if (film()->facility()) {
139 checked_set (_facility, *film()->facility());
141 } else if (property == Film::Property::STUDIO) {
142 checked_set (_enable_studio, static_cast<bool>(film()->studio()));
143 if (film()->studio()) {
144 checked_set (_studio, *film()->studio());
146 } else if (property == Film::Property::CHAIN) {
147 checked_set (_enable_chain, static_cast<bool>(film()->chain()));
148 if (film()->chain()) {
149 checked_set (_chain, *film()->chain());
151 } else if (property == Film::Property::TEMP_VERSION) {
152 checked_set (_temp_version, film()->temp_version());
153 } else if (property == Film::Property::PRE_RELEASE) {
154 checked_set (_pre_release, film()->pre_release());
155 } else if (property == Film::Property::RED_BAND) {
156 checked_set (_red_band, film()->red_band());
157 } else if (property == Film::Property::TWO_D_VERSION_OF_THREE_D) {
158 checked_set (_two_d_version_of_three_d, film()->two_d_version_of_three_d());
159 } else if (property == Film::Property::LUMINANCE) {
160 auto lum = film()->luminance();
161 checked_set (_enable_luminance, static_cast<bool>(lum));
163 checked_set (_luminance_value, lum->value());
164 switch (lum->unit()) {
165 case dcp::Luminance::Unit::CANDELA_PER_SQUARE_METRE:
166 checked_set (_luminance_unit, 0);
168 case dcp::Luminance::Unit::FOOT_LAMBERT:
169 checked_set (_luminance_unit, 1);
173 checked_set (_luminance_unit, 1);
180 MetadataDialog::setup_standard (wxPanel* panel, wxSizer* sizer)
182 _enable_release_territory = new wxCheckBox (panel, wxID_ANY, _("Release territory"));
183 sizer->Add (_enable_release_territory, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
185 auto s = new wxBoxSizer (wxHORIZONTAL);
186 _release_territory_text = new wxStaticText (panel, wxID_ANY, wxT(""));
187 s->Add (_release_territory_text, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
188 _edit_release_territory = new Button (panel, _("Edit..."));
189 s->Add (_edit_release_territory, 0, wxLEFT, DCPOMATIC_SIZER_GAP);
190 sizer->Add (s, 0, wxEXPAND);
193 vector<EditableListColumn> columns;
194 columns.push_back(EditableListColumn("Agency", 200, true));
195 columns.push_back(EditableListColumn("Label", 400, true));
196 _ratings = new EditableList<dcp::Rating, RatingDialog> (
199 boost::bind(&MetadataDialog::ratings, this),
200 boost::bind(&MetadataDialog::set_ratings, this, _1),
201 [this](dcp::Rating r, int c) {
203 auto iter = _rating_system_agency_to_name.find(r.agency);
204 if (iter != _rating_system_agency_to_name.end()) {
211 EditableListTitle::VISIBLE,
212 EditableListButton::NEW | EditableListButton::EDIT | EditableListButton::REMOVE
214 _ratings->SetMinSize(wxSize(600, -1));
219 MetadataDialog::edit_release_territory ()
221 DCPOMATIC_ASSERT (film()->release_territory());
222 auto d = new RegionSubtagDialog(this, *film()->release_territory());
226 _release_territory = *tag;
227 film()->set_release_territory(*tag);
234 MetadataDialog::setup_sensitivity ()
236 _sign_language_video_language->enable (film()->has_sign_language_video_channel());
237 auto const enabled = _enable_release_territory->GetValue();
238 _release_territory_text->Enable (enabled);
239 _edit_release_territory->Enable (enabled);
240 _facility->Enable (_enable_facility->GetValue());
241 _chain->Enable (_enable_chain->GetValue());
242 _studio->Enable (_enable_studio->GetValue());
243 _luminance_value->Enable (_enable_luminance->GetValue());
244 _luminance_unit->Enable (_enable_luminance->GetValue());
249 MetadataDialog::enable_release_territory_changed ()
251 setup_sensitivity ();
252 if (_enable_release_territory->GetValue()) {
253 film()->set_release_territory (_release_territory.get_value_or(dcp::LanguageTag::RegionSubtag("US")));
255 film()->set_release_territory ();
261 MetadataDialog::setup_advanced (wxPanel* panel, wxSizer* sizer)
263 add_label_to_sizer (sizer, panel, _("Sign language video language"), true, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT);
264 _sign_language_video_language = new LanguageTagWidget (panel, _("Language used for any sign language video track"), {}, {});
265 sizer->Add (_sign_language_video_language->sizer(), 1, wxEXPAND);
267 _enable_facility = new wxCheckBox (panel, wxID_ANY, _("Facility"));
268 sizer->Add (_enable_facility, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
269 _facility = new wxTextCtrl (panel, wxID_ANY);
270 sizer->Add (_facility, 1, wxEXPAND);
272 _enable_studio = new wxCheckBox (panel, wxID_ANY, _("Studio"));
273 sizer->Add (_enable_studio, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
274 _studio = new wxTextCtrl (panel, wxID_ANY);
275 sizer->Add (_studio, 1, wxEXPAND);
277 _enable_chain = new wxCheckBox (panel, wxID_ANY, _("Chain"));
278 sizer->Add (_enable_chain, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
279 _chain = new wxTextCtrl (panel, wxID_ANY);
280 sizer->Add (_chain, 1, wxEXPAND);
282 _temp_version = new wxCheckBox (panel, wxID_ANY, _("Temporary version"));
283 sizer->Add (_temp_version, 0, wxALIGN_CENTER_VERTICAL);
284 sizer->AddSpacer (0);
286 _pre_release = new wxCheckBox (panel, wxID_ANY, _("Pre-release"));
287 sizer->Add (_pre_release, 0, wxALIGN_CENTER_VERTICAL);
288 sizer->AddSpacer (0);
290 _red_band = new wxCheckBox (panel, wxID_ANY, _("Red band"));
291 sizer->Add (_red_band, 0, wxALIGN_CENTER_VERTICAL);
292 sizer->AddSpacer (0);
294 _two_d_version_of_three_d = new wxCheckBox (panel, wxID_ANY, _("2D version of 3D DCP"));
295 sizer->Add (_two_d_version_of_three_d, 0, wxALIGN_CENTER_VERTICAL);
296 sizer->AddSpacer (0);
298 _enable_luminance = new wxCheckBox (panel, wxID_ANY, _("Luminance"));
299 sizer->Add (_enable_luminance, 0, wxALIGN_CENTER_VERTICAL);
301 auto s = new wxBoxSizer (wxHORIZONTAL);
302 _luminance_value = new wxSpinCtrlDouble (panel, wxID_ANY);
303 _luminance_value->SetRange (0.1, 32.0);
304 _luminance_value->SetDigits (1);
305 _luminance_value->SetIncrement (0.1);
306 s->Add (_luminance_value, 0);
307 _luminance_unit = new Choice(panel);
308 s->Add (_luminance_unit, 0, wxLEFT, DCPOMATIC_SIZER_X_GAP);
309 sizer->Add (s, 1, wxEXPAND);
312 _luminance_unit->add(_("candela per m²"));
313 _luminance_unit->add(_("foot lambert"));
318 MetadataDialog::facility_changed ()
320 film()->set_facility (wx_to_std(_facility->GetValue()));
325 MetadataDialog::enable_facility_changed ()
327 setup_sensitivity ();
328 if (_enable_facility->GetValue()) {
329 film()->set_facility (wx_to_std(_facility->GetValue()));
331 film()->set_facility ();
337 MetadataDialog::studio_changed ()
339 film()->set_studio (wx_to_std(_studio->GetValue()));
344 MetadataDialog::enable_studio_changed ()
346 setup_sensitivity ();
347 if (_enable_studio->GetValue()) {
348 film()->set_studio (wx_to_std(_studio->GetValue()));
350 film()->set_studio ();
356 MetadataDialog::temp_version_changed ()
358 film()->set_temp_version(_temp_version->GetValue());
363 MetadataDialog::pre_release_changed ()
365 film()->set_pre_release(_pre_release->GetValue());
370 MetadataDialog::red_band_changed ()
372 film()->set_red_band(_red_band->GetValue());
377 MetadataDialog::two_d_version_of_three_d_changed ()
379 film()->set_two_d_version_of_three_d(_two_d_version_of_three_d->GetValue());
384 MetadataDialog::chain_changed ()
386 film()->set_chain (wx_to_std(_chain->GetValue()));
391 MetadataDialog::enable_chain_changed ()
393 setup_sensitivity ();
394 if (_enable_chain->GetValue()) {
397 film()->set_chain ();
403 MetadataDialog::enable_luminance_changed ()
405 setup_sensitivity ();
406 if (_enable_luminance->GetValue()) {
407 luminance_changed ();
409 film()->set_luminance ();
415 MetadataDialog::luminance_changed ()
417 dcp::Luminance::Unit unit;
418 DCPOMATIC_ASSERT(_luminance_unit->get());
419 switch (*_luminance_unit->get()) {
421 unit = dcp::Luminance::Unit::CANDELA_PER_SQUARE_METRE;
424 unit = dcp::Luminance::Unit::FOOT_LAMBERT;
427 DCPOMATIC_ASSERT (false);
430 film()->set_luminance (dcp::Luminance(_luminance_value->GetValue(), unit));
435 MetadataDialog::sign_language_video_language_changed ()
437 film()->set_sign_language_video_language(_sign_language_video_language->get());
442 MetadataDialog::ratings() const
444 return film()->ratings();
449 MetadataDialog::set_ratings(vector<dcp::Rating> r)
451 film()->set_ratings(r);