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