Merge remote-tracking branch 'origin/main' into v2.17.x
[dcpomatic.git] / src / lib / dcp_content_type.cc
1 /*
2     Copyright (C) 2012-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 /** @file src/content_type.cc
22  *  @brief A description of the type of content for a DCP (e.g. feature, trailer etc.)
23  */
24
25 #include "dcp_content_type.h"
26 #include "dcpomatic_assert.h"
27
28 #include "i18n.h"
29
30
31 using std::string;
32 using std::vector;
33 using boost::optional;
34
35
36 vector<DCPContentType> DCPContentType::_dcp_content_types;
37
38
39 DCPContentType::DCPContentType (string p, dcp::ContentKind k, string d)
40         : _pretty_name (p)
41         , _libdcp_kind (k)
42         , _isdcf_name (d)
43 {
44
45 }
46
47
48 void
49 DCPContentType::setup_dcp_content_types ()
50 {
51         /// TRANSLATORS: these are the types that a DCP can have, explained in some
52         /// more detail here: https://registry-page.isdcf.com/contenttypes/
53         _dcp_content_types = {
54                 DCPContentType(_("Feature"), dcp::ContentKind::FEATURE, N_("FTR")),
55                 DCPContentType(_("Short"), dcp::ContentKind::SHORT, N_("SHR")),
56                 DCPContentType(_("Trailer"), dcp::ContentKind::TRAILER, N_("TLR")),
57                 DCPContentType(_("Test"), dcp::ContentKind::TEST, N_("TST")),
58                 DCPContentType(_("Transitional"), dcp::ContentKind::TRANSITIONAL, N_("XSN")),
59                 DCPContentType(_("Rating"), dcp::ContentKind::RATING, N_("RTG")),
60                 DCPContentType(_("Teaser"), dcp::ContentKind::TEASER, N_("TSR")),
61                 DCPContentType(_("Policy"), dcp::ContentKind::POLICY, N_("POL")),
62                 DCPContentType(_("Public Service Announcement"), dcp::ContentKind::PUBLIC_SERVICE_ANNOUNCEMENT, N_("PSA")),
63                 DCPContentType(_("Advertisement"), dcp::ContentKind::ADVERTISEMENT, N_("ADV")),
64                 DCPContentType(_("Clip"), dcp::ContentKind::CLIP, N_("CLP")),
65                 DCPContentType(_("Promo"), dcp::ContentKind::PROMO, N_("PRO")),
66                 DCPContentType(_("Stereo card"), dcp::ContentKind::STEREOCARD, N_("STR")),
67                 DCPContentType(_("Episode"), dcp::ContentKind::EPISODE, N_("EPS")),
68                 DCPContentType(_("Highlights"), dcp::ContentKind::HIGHLIGHTS, N_("HLT")),
69                 DCPContentType(_("Event"), dcp::ContentKind::EVENT, N_("EVT")),
70         };
71 }
72
73
74 DCPContentType const *
75 DCPContentType::from_isdcf_name (string n)
76 {
77         for (auto& i: _dcp_content_types) {
78                 if (i.isdcf_name() == n) {
79                         return &i;
80                 }
81         }
82
83         return nullptr;
84 }
85
86
87 DCPContentType const *
88 DCPContentType::from_libdcp_kind (dcp::ContentKind kind)
89 {
90         for (auto& i: _dcp_content_types) {
91                 if (i.libdcp_kind() == kind) {
92                         return &i;
93                 }
94         }
95
96         DCPOMATIC_ASSERT (false);
97         return nullptr;
98 }
99
100
101 DCPContentType const *
102 DCPContentType::from_index (int n)
103 {
104         DCPOMATIC_ASSERT (n >= 0 && n < int(_dcp_content_types.size()));
105         return &_dcp_content_types[n];
106 }
107
108
109 optional<int>
110 DCPContentType::as_index (DCPContentType const * c)
111 {
112         vector<DCPContentType>::size_type i = 0;
113         while (i < _dcp_content_types.size() && &_dcp_content_types[i] != c) {
114                 ++i;
115         }
116
117         if (i == _dcp_content_types.size()) {
118                 return {};
119         }
120
121         return i;
122 }
123
124
125 vector<DCPContentType const *>
126 DCPContentType::all ()
127 {
128         vector<DCPContentType const *> raw;
129         for (auto& type: _dcp_content_types) {
130                 raw.push_back (&type);
131         }
132         return raw;
133 }