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 "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_dialog.h"
33 #include <dcp/warnings.h>
34 LIBDCP_DISABLE_WARNINGS
35 #include <wx/notebook.h>
36 #include <wx/spinctrl.h>
38 LIBDCP_ENABLE_WARNINGS
39 #include <boost/bind.hpp>
40 #include <boost/weak_ptr.hpp>
47 MetadataDialog::MetadataDialog (wxWindow* parent, weak_ptr<Film> weak_film)
48 : wxDialog (parent, wxID_ANY, _("Metadata"))
49 , WeakFilm (weak_film)
51 for (auto system: dcp::rating_systems()) {
52 _rating_system_agency_to_name[system.agency] = system.name;
58 MetadataDialog::setup ()
60 auto notebook = new wxNotebook (this, wxID_ANY);
62 auto prepare = [notebook](std::function<void (wxPanel*, wxSizer*)> setup, wxString name) {
63 auto panel = new wxPanel (notebook, wxID_ANY);
64 auto sizer = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
65 sizer->AddGrowableCol (1, 1);
67 auto overall_sizer = new wxBoxSizer (wxVERTICAL);
68 overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
69 panel->SetSizer (overall_sizer);
70 notebook->AddPage (panel, name);
73 prepare (boost::bind(&MetadataDialog::setup_standard, this, _1, _2), _("Standard"));
74 prepare (boost::bind(&MetadataDialog::setup_advanced, this, _1, _2), _("Advanced"));
76 auto overall_sizer = new wxBoxSizer (wxVERTICAL);
77 overall_sizer->Add (notebook, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
79 auto buttons = CreateSeparatedButtonSizer (wxCLOSE);
81 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
84 SetSizer (overall_sizer);
85 overall_sizer->Layout ();
86 overall_sizer->SetSizeHints (this);
88 _sign_language_video_language->Changed.connect (boost::bind(&MetadataDialog::sign_language_video_language_changed, this));
89 _edit_release_territory->Bind (wxEVT_BUTTON, boost::bind(&MetadataDialog::edit_release_territory, this));
90 _enable_release_territory->bind(&MetadataDialog::enable_release_territory_changed, this);
91 _enable_facility->bind(&MetadataDialog::enable_facility_changed, this);
92 _facility->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::facility_changed, this));
93 _enable_studio->bind(&MetadataDialog::enable_studio_changed, this);
94 _studio->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::studio_changed, this));
95 _enable_chain->bind(&MetadataDialog::enable_chain_changed, this);
96 _chain->Bind (wxEVT_TEXT, boost::bind(&MetadataDialog::chain_changed, this));
97 _temp_version->bind(&MetadataDialog::temp_version_changed, this);
98 _pre_release->bind(&MetadataDialog::pre_release_changed, this);
99 _red_band->bind(&MetadataDialog::red_band_changed, this);
100 _two_d_version_of_three_d->bind(&MetadataDialog::two_d_version_of_three_d_changed, this);
101 _enable_luminance->bind(&MetadataDialog::enable_luminance_changed, this);
102 _luminance_value->Bind (wxEVT_SPINCTRLDOUBLE, boost::bind(&MetadataDialog::luminance_changed, this));
103 _luminance_unit->Bind (wxEVT_CHOICE, boost::bind(&MetadataDialog::luminance_changed, this));
105 _film_changed_connection = film()->Change.connect(boost::bind(&MetadataDialog::film_changed, this, _1, _2));
107 film_changed (ChangeType::DONE, Film::Property::RELEASE_TERRITORY);
108 film_changed (ChangeType::DONE, Film::Property::SIGN_LANGUAGE_VIDEO_LANGUAGE);
109 film_changed (ChangeType::DONE, Film::Property::FACILITY);
110 film_changed (ChangeType::DONE, Film::Property::STUDIO);
111 film_changed (ChangeType::DONE, Film::Property::TEMP_VERSION);
112 film_changed (ChangeType::DONE, Film::Property::PRE_RELEASE);
113 film_changed (ChangeType::DONE, Film::Property::RED_BAND);
114 film_changed (ChangeType::DONE, Film::Property::TWO_D_VERSION_OF_THREE_D);
115 film_changed (ChangeType::DONE, Film::Property::CHAIN);
116 film_changed (ChangeType::DONE, Film::Property::LUMINANCE);
118 setup_sensitivity ();
123 MetadataDialog::film_changed (ChangeType type, Film::Property property)
125 if (type != ChangeType::DONE) {
129 if (property == Film::Property::SIGN_LANGUAGE_VIDEO_LANGUAGE) {
130 _sign_language_video_language->set (film()->sign_language_video_language());
131 } else if (property == Film::Property::RELEASE_TERRITORY) {
132 auto rt = film()->release_territory();
133 checked_set (_enable_release_territory, static_cast<bool>(rt));
135 _release_territory = *rt;
136 checked_set (_release_territory_text, std_to_wx(*dcp::LanguageTag::get_subtag_description(*_release_territory)));
138 } else if (property == Film::Property::FACILITY) {
139 checked_set (_enable_facility, static_cast<bool>(film()->facility()));
140 if (film()->facility()) {
141 checked_set (_facility, *film()->facility());
143 } else if (property == Film::Property::STUDIO) {
144 checked_set (_enable_studio, static_cast<bool>(film()->studio()));
145 if (film()->studio()) {
146 checked_set (_studio, *film()->studio());
148 } else if (property == Film::Property::CHAIN) {
149 checked_set (_enable_chain, static_cast<bool>(film()->chain()));
150 if (film()->chain()) {
151 checked_set (_chain, *film()->chain());
153 } else if (property == Film::Property::TEMP_VERSION) {
154 checked_set (_temp_version, film()->temp_version());
155 } else if (property == Film::Property::PRE_RELEASE) {
156 checked_set (_pre_release, film()->pre_release());
157 } else if (property == Film::Property::RED_BAND) {
158 checked_set (_red_band, film()->red_band());
159 } else if (property == Film::Property::TWO_D_VERSION_OF_THREE_D) {
160 checked_set (_two_d_version_of_three_d, film()->two_d_version_of_three_d());
161 } else if (property == Film::Property::LUMINANCE) {
162 auto lum = film()->luminance();
163 checked_set (_enable_luminance, static_cast<bool>(lum));
165 checked_set (_luminance_value, lum->value());
166 switch (lum->unit()) {
167 case dcp::Luminance::Unit::CANDELA_PER_SQUARE_METRE:
168 checked_set (_luminance_unit, 0);
170 case dcp::Luminance::Unit::FOOT_LAMBERT:
171 checked_set (_luminance_unit, 1);
175 checked_set (_luminance_unit, 1);
182 MetadataDialog::setup_standard (wxPanel* panel, wxSizer* sizer)
184 _enable_release_territory = new CheckBox(panel, _("Release territory"));
185 sizer->Add (_enable_release_territory, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
187 auto s = new wxBoxSizer (wxHORIZONTAL);
188 _release_territory_text = new wxStaticText (panel, wxID_ANY, wxT(""));
189 s->Add (_release_territory_text, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
190 _edit_release_territory = new Button (panel, _("Edit..."));
191 s->Add (_edit_release_territory, 0, wxLEFT, DCPOMATIC_SIZER_GAP);
192 sizer->Add (s, 0, wxEXPAND);
195 vector<EditableListColumn> columns;
196 columns.push_back(EditableListColumn("Agency", 200, true));
197 columns.push_back(EditableListColumn("Label", 400, true));
198 _ratings = new EditableList<dcp::Rating, RatingDialog> (
201 boost::bind(&MetadataDialog::ratings, this),
202 boost::bind(&MetadataDialog::set_ratings, this, _1),
203 [this](dcp::Rating r, int c) {
205 auto iter = _rating_system_agency_to_name.find(r.agency);
206 if (iter != _rating_system_agency_to_name.end()) {
213 EditableListTitle::VISIBLE,
214 EditableListButton::NEW | EditableListButton::EDIT | EditableListButton::REMOVE
216 _ratings->SetMinSize(wxSize(600, -1));
221 MetadataDialog::edit_release_territory ()
223 DCPOMATIC_ASSERT (film()->release_territory());
224 auto d = new RegionSubtagDialog(this, *film()->release_territory());
228 _release_territory = *tag;
229 film()->set_release_territory(*tag);
236 MetadataDialog::setup_sensitivity ()
238 _sign_language_video_language->enable (film()->has_sign_language_video_channel());
239 auto const enabled = _enable_release_territory->GetValue();
240 _release_territory_text->Enable (enabled);
241 _edit_release_territory->Enable (enabled);
242 _facility->Enable (_enable_facility->GetValue());
243 _chain->Enable (_enable_chain->GetValue());
244 _studio->Enable (_enable_studio->GetValue());
245 _luminance_value->Enable (_enable_luminance->GetValue());
246 _luminance_unit->Enable (_enable_luminance->GetValue());
251 MetadataDialog::enable_release_territory_changed ()
253 setup_sensitivity ();
254 if (_enable_release_territory->GetValue()) {
255 film()->set_release_territory (_release_territory.get_value_or(dcp::LanguageTag::RegionSubtag("US")));
257 film()->set_release_territory ();
263 MetadataDialog::setup_advanced (wxPanel* panel, wxSizer* sizer)
265 add_label_to_sizer (sizer, panel, _("Sign language video language"), true, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT);
266 _sign_language_video_language = new LanguageTagWidget (panel, _("Language used for any sign language video track"), {}, {});
267 sizer->Add (_sign_language_video_language->sizer(), 1, wxEXPAND);
269 _enable_facility = new CheckBox(panel, _("Facility"));
270 sizer->Add (_enable_facility, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
271 _facility = new wxTextCtrl (panel, wxID_ANY);
272 sizer->Add (_facility, 1, wxEXPAND);
274 _enable_studio = new CheckBox(panel, _("Studio"));
275 sizer->Add (_enable_studio, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
276 _studio = new wxTextCtrl (panel, wxID_ANY);
277 sizer->Add (_studio, 1, wxEXPAND);
279 _enable_chain = new CheckBox(panel, _("Chain"));
280 sizer->Add (_enable_chain, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
281 _chain = new wxTextCtrl (panel, wxID_ANY);
282 sizer->Add (_chain, 1, wxEXPAND);
284 _temp_version = new CheckBox(panel, _("Temporary version"));
285 sizer->Add (_temp_version, 0, wxALIGN_CENTER_VERTICAL);
286 sizer->AddSpacer (0);
288 _pre_release = new CheckBox(panel, _("Pre-release"));
289 sizer->Add (_pre_release, 0, wxALIGN_CENTER_VERTICAL);
290 sizer->AddSpacer (0);
292 _red_band = new CheckBox(panel, _("Red band"));
293 sizer->Add (_red_band, 0, wxALIGN_CENTER_VERTICAL);
294 sizer->AddSpacer (0);
296 _two_d_version_of_three_d = new CheckBox(panel, _("2D version of 3D DCP"));
297 sizer->Add (_two_d_version_of_three_d, 0, wxALIGN_CENTER_VERTICAL);
298 sizer->AddSpacer (0);
300 _enable_luminance = new CheckBox(panel, _("Luminance"));
301 sizer->Add (_enable_luminance, 0, wxALIGN_CENTER_VERTICAL);
303 auto s = new wxBoxSizer (wxHORIZONTAL);
304 _luminance_value = new wxSpinCtrlDouble (panel, wxID_ANY);
305 _luminance_value->SetRange (0.1, 32.0);
306 _luminance_value->SetDigits (1);
307 _luminance_value->SetIncrement (0.1);
308 s->Add (_luminance_value, 0);
309 _luminance_unit = new Choice(panel);
310 s->Add (_luminance_unit, 0, wxLEFT, DCPOMATIC_SIZER_X_GAP);
311 sizer->Add (s, 1, wxEXPAND);
314 _luminance_unit->add(_("candela per m²"));
315 _luminance_unit->add(_("foot lambert"));
320 MetadataDialog::facility_changed ()
322 film()->set_facility (wx_to_std(_facility->GetValue()));
327 MetadataDialog::enable_facility_changed ()
329 setup_sensitivity ();
330 if (_enable_facility->GetValue()) {
331 film()->set_facility (wx_to_std(_facility->GetValue()));
333 film()->set_facility ();
339 MetadataDialog::studio_changed ()
341 film()->set_studio (wx_to_std(_studio->GetValue()));
346 MetadataDialog::enable_studio_changed ()
348 setup_sensitivity ();
349 if (_enable_studio->GetValue()) {
350 film()->set_studio (wx_to_std(_studio->GetValue()));
352 film()->set_studio ();
358 MetadataDialog::temp_version_changed ()
360 film()->set_temp_version(_temp_version->GetValue());
365 MetadataDialog::pre_release_changed ()
367 film()->set_pre_release(_pre_release->GetValue());
372 MetadataDialog::red_band_changed ()
374 film()->set_red_band(_red_band->GetValue());
379 MetadataDialog::two_d_version_of_three_d_changed ()
381 film()->set_two_d_version_of_three_d(_two_d_version_of_three_d->GetValue());
386 MetadataDialog::chain_changed ()
388 film()->set_chain (wx_to_std(_chain->GetValue()));
393 MetadataDialog::enable_chain_changed ()
395 setup_sensitivity ();
396 if (_enable_chain->GetValue()) {
399 film()->set_chain ();
405 MetadataDialog::enable_luminance_changed ()
407 setup_sensitivity ();
408 if (_enable_luminance->GetValue()) {
409 luminance_changed ();
411 film()->set_luminance ();
417 MetadataDialog::luminance_changed ()
419 dcp::Luminance::Unit unit;
420 DCPOMATIC_ASSERT(_luminance_unit->get());
421 switch (*_luminance_unit->get()) {
423 unit = dcp::Luminance::Unit::CANDELA_PER_SQUARE_METRE;
426 unit = dcp::Luminance::Unit::FOOT_LAMBERT;
429 DCPOMATIC_ASSERT (false);
432 film()->set_luminance (dcp::Luminance(_luminance_value->GetValue(), unit));
437 MetadataDialog::sign_language_video_language_changed ()
439 film()->set_sign_language_video_language(_sign_language_video_language->get());
444 MetadataDialog::ratings() const
446 return film()->ratings();
451 MetadataDialog::set_ratings(vector<dcp::Rating> r)
453 film()->set_ratings(r);