e1b05852cf8c0e614fcfb74d5a5754101ae4c85f
[dcpomatic.git] / src / lib / dcp_content_type.cc
1 /*
2     Copyright (C) 2012-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 /** @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 using namespace std;
31
32 vector<DCPContentType const *> DCPContentType::_dcp_content_types;
33
34 DCPContentType::DCPContentType (string p, dcp::ContentKind k, string d)
35         : _pretty_name (p)
36         , _libdcp_kind (k)
37         , _isdcf_name (d)
38 {
39
40 }
41
42 void
43 DCPContentType::setup_dcp_content_types ()
44 {
45         _dcp_content_types.push_back (new DCPContentType(_("Feature"), dcp::ContentKind::FEATURE, N_("FTR")));
46         _dcp_content_types.push_back (new DCPContentType(_("Short"), dcp::ContentKind::SHORT, N_("SHR")));
47         _dcp_content_types.push_back (new DCPContentType(_("Trailer"), dcp::ContentKind::TRAILER, N_("TLR")));
48         _dcp_content_types.push_back (new DCPContentType(_("Test"), dcp::ContentKind::TEST, N_("TST")));
49         _dcp_content_types.push_back (new DCPContentType(_("Transitional"), dcp::ContentKind::TRANSITIONAL, N_("XSN")));
50         _dcp_content_types.push_back (new DCPContentType(_("Rating"), dcp::ContentKind::RATING, N_("RTG")));
51         _dcp_content_types.push_back (new DCPContentType(_("Teaser"), dcp::ContentKind::TEASER, N_("TSR")));
52         _dcp_content_types.push_back (new DCPContentType(_("Policy"), dcp::ContentKind::POLICY, N_("POL")));
53         _dcp_content_types.push_back (new DCPContentType(_("Public Service Announcement"), dcp::ContentKind::PUBLIC_SERVICE_ANNOUNCEMENT, N_("PSA")));
54         _dcp_content_types.push_back (new DCPContentType(_("Advertisement"), dcp::ContentKind::ADVERTISEMENT, N_("ADV")));
55         _dcp_content_types.push_back (new DCPContentType(_("Episode"), dcp::ContentKind::EPISODE, N_("EPS")));
56         _dcp_content_types.push_back (new DCPContentType(_("Promo"), dcp::ContentKind::PROMO, N_("PRO")));
57 }
58
59 DCPContentType const *
60 DCPContentType::from_isdcf_name (string n)
61 {
62         for (auto i: _dcp_content_types) {
63                 if (i->isdcf_name() == n) {
64                         return i;
65                 }
66         }
67
68         return 0;
69 }
70
71 DCPContentType const *
72 DCPContentType::from_libdcp_kind (dcp::ContentKind kind)
73 {
74         for (auto i: _dcp_content_types) {
75                 if (i->libdcp_kind() == kind) {
76                         return i;
77                 }
78         }
79
80         DCPOMATIC_ASSERT (false);
81         return 0;
82 }
83
84
85 DCPContentType const *
86 DCPContentType::from_index (int n)
87 {
88         DCPOMATIC_ASSERT (n >= 0 && n < int (_dcp_content_types.size ()));
89         return _dcp_content_types[n];
90 }
91
92 int
93 DCPContentType::as_index (DCPContentType const * c)
94 {
95         vector<DCPContentType*>::size_type i = 0;
96         while (i < _dcp_content_types.size() && _dcp_content_types[i] != c) {
97                 ++i;
98         }
99
100         if (i == _dcp_content_types.size ()) {
101                 return -1;
102         }
103
104         return i;
105 }
106
107 vector<DCPContentType const *>
108 DCPContentType::all ()
109 {
110         return _dcp_content_types;
111 }