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