Use release territory from Interop/SMPTE metadata instead of ISDCF metadata dialogue.
[dcpomatic.git] / src / wx / smpte_metadata_dialog.cc
1 /*
2     Copyright (C) 2019-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 "content_version_dialog.h"
23 #include "editable_list.h"
24 #include "language_tag_dialog.h"
25 #include "language_tag_widget.h"
26 #include "smpte_metadata_dialog.h"
27 #include "rating_dialog.h"
28 #include "lib/film.h"
29 #include <dcp/types.h>
30 #include <wx/gbsizer.h>
31 #include <wx/spinctrl.h>
32
33
34 using std::string;
35 using std::vector;
36 using boost::optional;
37 using std::shared_ptr;
38 using std::weak_ptr;
39 #if BOOST_VERSION >= 106100
40 using namespace boost::placeholders;
41 #endif
42
43
44 static string
45 ratings_column (dcp::Rating r, int c)
46 {
47         if (c == 0) {
48                 return r.agency;
49         }
50
51         return r.label;
52 }
53
54
55 static string
56 content_versions_column (string v, int)
57 {
58         return v;
59 }
60
61
62 void
63 SMPTEMetadataDialog::setup_standard (wxPanel* panel, wxSizer* sizer)
64 {
65         MetadataDialog::setup_standard (panel, sizer);
66
67         add_label_to_sizer (sizer, panel, _("Title language"), true, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
68         _name_language = new LanguageTagWidget(
69                 panel,
70                 wxString::Format(_("The language that the film's title (\"%s\") is in"), std_to_wx(film()->name())),
71                 film()->name_language()
72                 );
73         sizer->Add (_name_language->sizer(), 0, wxEXPAND);
74
75         {
76                 int flags = wxALIGN_TOP | wxRIGHT | wxTOP;
77 #ifdef __WXOSX__
78                 flags |= wxALIGN_RIGHT;
79 #endif
80                 auto m = create_label (panel, _("Ratings"), true);
81                 sizer->Add (m, 0, flags, DCPOMATIC_SIZER_GAP);
82         }
83
84         vector<EditableListColumn> columns;
85         columns.push_back (EditableListColumn("Agency", 200, true));
86         columns.push_back (EditableListColumn("Label", 50, true));
87         _ratings = new EditableList<dcp::Rating, RatingDialog> (
88                 panel,
89                 columns,
90                 boost::bind(&SMPTEMetadataDialog::ratings, this),
91                 boost::bind(&SMPTEMetadataDialog::set_ratings, this, _1),
92                 boost::bind(&ratings_column, _1, _2),
93                 true,
94                 false
95                 );
96         sizer->Add (_ratings, 1, wxEXPAND);
97 }
98
99
100 void
101 SMPTEMetadataDialog::setup_advanced (wxPanel* panel, wxSizer* sizer)
102 {
103         MetadataDialog::setup_advanced (panel, sizer);
104
105         add_label_to_sizer (sizer, panel, _("Version number"), true, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
106         _version_number = new wxSpinCtrl (panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 1000);
107         sizer->Add (_version_number, 0);
108
109         add_label_to_sizer (sizer, panel, _("Status"), true, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
110         _status = new wxChoice (panel, wxID_ANY);
111         sizer->Add (_status, 0);
112
113         _enable_chain = new wxCheckBox (panel, wxID_ANY, _("Chain"));
114         sizer->Add (_enable_chain, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
115         _chain = new wxTextCtrl (panel, wxID_ANY);
116         sizer->Add (_chain, 1, wxEXPAND);
117
118         _enable_distributor = new wxCheckBox (panel, wxID_ANY, _("Distributor"));
119         sizer->Add (_enable_distributor, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
120         _distributor = new wxTextCtrl (panel, wxID_ANY);
121         sizer->Add (_distributor, 1, wxEXPAND);
122
123         _enable_facility = new wxCheckBox (panel, wxID_ANY, _("Facility"));
124         sizer->Add (_enable_facility, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
125         _facility = new wxTextCtrl (panel, wxID_ANY);
126         sizer->Add (_facility, 1, wxEXPAND);
127
128         add_label_to_sizer (sizer, panel, _("Luminance"), true, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
129         {
130                 auto s = new wxBoxSizer (wxHORIZONTAL);
131                 _luminance_value = new wxSpinCtrlDouble (panel, wxID_ANY);
132                 _luminance_value->SetDigits (1);
133                 _luminance_value->SetIncrement (0.1);
134                 s->Add (_luminance_value, 0);
135                 _luminance_unit = new wxChoice (panel, wxID_ANY);
136                 s->Add (_luminance_unit, 0, wxLEFT, DCPOMATIC_SIZER_X_GAP);
137                 sizer->Add (s, 1, wxEXPAND);
138         }
139
140         {
141                 int flags = wxALIGN_TOP | wxRIGHT | wxTOP;
142 #ifdef __WXOSX__
143                 flags |= wxALIGN_RIGHT;
144 #endif
145                 auto m = create_label (panel, _("Content versions"), true);
146                 sizer->Add (m, 0, flags, DCPOMATIC_SIZER_GAP);
147         }
148
149         vector<EditableListColumn> columns;
150         columns.push_back (EditableListColumn("Version", 350, true));
151         _content_versions = new EditableList<string, ContentVersionDialog> (
152                 panel,
153                 columns,
154                 boost::bind(&SMPTEMetadataDialog::content_versions, this),
155                 boost::bind(&SMPTEMetadataDialog::set_content_versions, this, _1),
156                 boost::bind(&content_versions_column, _1, _2),
157                 true,
158                 false
159                 );
160         sizer->Add (_content_versions, 1, wxEXPAND);
161 }
162
163
164 SMPTEMetadataDialog::SMPTEMetadataDialog (wxWindow* parent, weak_ptr<Film> weak_film)
165         : MetadataDialog (parent, weak_film)
166 {
167
168 }
169
170
171 void
172 SMPTEMetadataDialog::setup ()
173 {
174         MetadataDialog::setup ();
175
176         _status->Append (_("Temporary"));
177         _status->Append (_("Pre-release"));
178         _status->Append (_("Final"));
179
180         _luminance_unit->Append (wxString::FromUTF8(_("candela per m²")));
181         _luminance_unit->Append (_("foot lambert"));
182
183         _name_language->Changed.connect (boost::bind(&SMPTEMetadataDialog::name_language_changed, this, _1));
184         _version_number->Bind (wxEVT_SPINCTRL, boost::bind(&SMPTEMetadataDialog::version_number_changed, this));
185         _status->Bind (wxEVT_CHOICE, boost::bind(&SMPTEMetadataDialog::status_changed, this));
186         _enable_chain->Bind (wxEVT_CHECKBOX, boost::bind(&SMPTEMetadataDialog::enable_chain_changed, this));
187         _chain->Bind (wxEVT_TEXT, boost::bind(&SMPTEMetadataDialog::chain_changed, this));
188         _enable_distributor->Bind (wxEVT_CHECKBOX, boost::bind(&SMPTEMetadataDialog::enable_distributor_changed, this));
189         _distributor->Bind (wxEVT_TEXT, boost::bind(&SMPTEMetadataDialog::distributor_changed, this));
190         _enable_facility->Bind (wxEVT_CHECKBOX, boost::bind(&SMPTEMetadataDialog::enable_facility_changed, this));
191         _facility->Bind (wxEVT_TEXT, boost::bind(&SMPTEMetadataDialog::facility_changed, this));
192         _luminance_value->Bind (wxEVT_SPINCTRLDOUBLE, boost::bind(&SMPTEMetadataDialog::luminance_changed, this));
193         _luminance_unit->Bind (wxEVT_CHOICE, boost::bind(&SMPTEMetadataDialog::luminance_changed, this));
194
195         film_changed (ChangeType::DONE, Film::Property::NAME_LANGUAGE);
196         film_changed (ChangeType::DONE, Film::Property::VERSION_NUMBER);
197         film_changed (ChangeType::DONE, Film::Property::STATUS);
198         film_changed (ChangeType::DONE, Film::Property::CHAIN);
199         film_changed (ChangeType::DONE, Film::Property::DISTRIBUTOR);
200         film_changed (ChangeType::DONE, Film::Property::FACILITY);
201         film_changed (ChangeType::DONE, Film::Property::CONTENT_VERSIONS);
202         film_changed (ChangeType::DONE, Film::Property::LUMINANCE);
203
204         setup_sensitivity ();
205 }
206
207
208 void
209 SMPTEMetadataDialog::film_changed (ChangeType type, Film::Property property)
210 {
211         MetadataDialog::film_changed (type, property);
212
213         if (type != ChangeType::DONE || film()->interop()) {
214                 return;
215         }
216
217         if (property == Film::Property::NAME_LANGUAGE) {
218                 _name_language->set (film()->name_language());
219         } else if (property == Film::Property::VERSION_NUMBER) {
220                 checked_set (_version_number, film()->version_number());
221         } else if (property == Film::Property::STATUS) {
222                 switch (film()->status()) {
223                 case dcp::Status::TEMP:
224                         checked_set (_status, 0);
225                         break;
226                 case dcp::Status::PRE:
227                         checked_set (_status, 1);
228                         break;
229                 case dcp::Status::FINAL:
230                         checked_set (_status, 2);
231                         break;
232                 }
233         } else if (property == Film::Property::CHAIN) {
234                 checked_set (_enable_chain, static_cast<bool>(film()->chain()));
235                 if (film()->chain()) {
236                         checked_set (_chain, *film()->chain());
237                 }
238         } else if (property == Film::Property::DISTRIBUTOR) {
239                 checked_set (_enable_distributor, static_cast<bool>(film()->distributor()));
240                 if (film()->distributor()) {
241                         checked_set (_distributor, *film()->distributor());
242                 }
243         } else if (property == Film::Property::FACILITY) {
244                 checked_set (_enable_facility, static_cast<bool>(film()->facility()));
245                 if (film()->facility()) {
246                         checked_set (_facility, *film()->facility());
247                 }
248         } else if (property == Film::Property::LUMINANCE) {
249                 auto lum = film()->luminance();
250                 if (lum) {
251                         checked_set (_luminance_value, lum->value());
252                         switch (lum->unit()) {
253                         case dcp::Luminance::Unit::CANDELA_PER_SQUARE_METRE:
254                                 checked_set (_luminance_unit, 0);
255                                 break;
256                         case dcp::Luminance::Unit::FOOT_LAMBERT:
257                                 checked_set (_luminance_unit, 1);
258                                 break;
259                         }
260                 } else {
261                         checked_set (_luminance_value, 4.5);
262                         checked_set (_luminance_unit, 1);
263                 }
264         }
265 }
266
267
268 vector<dcp::Rating>
269 SMPTEMetadataDialog::ratings () const
270 {
271         return film()->ratings ();
272 }
273
274
275 void
276 SMPTEMetadataDialog::set_ratings (vector<dcp::Rating> r)
277 {
278         film()->set_ratings (r);
279 }
280
281
282 vector<string>
283 SMPTEMetadataDialog::content_versions () const
284 {
285         return film()->content_versions ();
286 }
287
288
289 void
290 SMPTEMetadataDialog::set_content_versions (vector<string> cv)
291 {
292         film()->set_content_versions (cv);
293 }
294
295
296 void
297 SMPTEMetadataDialog::name_language_changed (dcp::LanguageTag tag)
298 {
299         film()->set_name_language (tag);
300 }
301
302
303 void
304 SMPTEMetadataDialog::version_number_changed ()
305 {
306         film()->set_version_number (_version_number->GetValue());
307 }
308
309
310 void
311 SMPTEMetadataDialog::status_changed ()
312 {
313         switch (_status->GetSelection()) {
314         case 0:
315                 film()->set_status(dcp::Status::TEMP);
316                 break;
317         case 1:
318                 film()->set_status(dcp::Status::PRE);
319                 break;
320         case 2:
321                 film()->set_status(dcp::Status::FINAL);
322                 break;
323         }
324 }
325
326
327 void
328 SMPTEMetadataDialog::chain_changed ()
329 {
330         film()->set_chain (wx_to_std(_chain->GetValue()));
331 }
332
333
334 void
335 SMPTEMetadataDialog::distributor_changed ()
336 {
337         film()->set_distributor (wx_to_std(_distributor->GetValue()));
338 }
339
340
341 void
342 SMPTEMetadataDialog::facility_changed ()
343 {
344         film()->set_facility (wx_to_std(_facility->GetValue()));
345 }
346
347
348 void
349 SMPTEMetadataDialog::luminance_changed ()
350 {
351         dcp::Luminance::Unit unit;
352         switch (_luminance_unit->GetSelection()) {
353         case 0:
354                 unit = dcp::Luminance::Unit::CANDELA_PER_SQUARE_METRE;
355                 break;
356         case 1:
357                 unit = dcp::Luminance::Unit::FOOT_LAMBERT;
358                 break;
359         default:
360                 DCPOMATIC_ASSERT (false);
361         }
362
363         film()->set_luminance (dcp::Luminance(_luminance_value->GetValue(), unit));
364 }
365
366
367 void
368 SMPTEMetadataDialog::setup_sensitivity ()
369 {
370         MetadataDialog::setup_sensitivity ();
371
372         _chain->Enable (_enable_chain->GetValue());
373         _distributor->Enable (_enable_distributor->GetValue());
374         _facility->Enable (_enable_facility->GetValue());
375 }
376
377
378 void
379 SMPTEMetadataDialog::enable_chain_changed ()
380 {
381         setup_sensitivity ();
382         if (_enable_chain->GetValue()) {
383                 film()->set_chain (wx_to_std(_chain->GetValue()));
384         } else {
385                 film()->set_chain ();
386         }
387 }
388
389
390 void
391 SMPTEMetadataDialog::enable_distributor_changed ()
392 {
393         setup_sensitivity ();
394         if (_enable_distributor->GetValue()) {
395                 film()->set_distributor (wx_to_std(_distributor->GetValue()));
396         } else {
397                 film()->set_distributor ();
398         }
399 }
400
401
402 void
403 SMPTEMetadataDialog::enable_facility_changed ()
404 {
405         setup_sensitivity ();
406         if (_enable_facility->GetValue()) {
407                 film()->set_facility (wx_to_std(_facility->GetValue()));
408         } else {
409                 film()->set_facility ();
410         }
411 }
412
413