Don't overlap simultaneous video content in the timeline. Fix keep-aligned for separ...
[dcpomatic.git] / src / lib / dcp_content_type.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file src/content_type.cc
21  *  @brief A description of the type of content for a DCP (e.g. feature, trailer etc.)
22  */
23
24 #include <cassert>
25 #include "dcp_content_type.h"
26
27 #include "i18n.h"
28
29 using namespace std;
30
31 vector<DCPContentType const *> DCPContentType::_dcp_content_types;
32
33 DCPContentType::DCPContentType (string p, libdcp::ContentKind k, string d)
34         : _pretty_name (p)
35         , _libdcp_kind (k)
36         , _dci_name (d)
37 {
38
39 }
40
41 void
42 DCPContentType::setup_dcp_content_types ()
43 {
44         _dcp_content_types.push_back (new DCPContentType (_("Feature"), libdcp::FEATURE, N_("FTR")));
45         _dcp_content_types.push_back (new DCPContentType (_("Short"), libdcp::SHORT, N_("SHR")));
46         _dcp_content_types.push_back (new DCPContentType (_("Trailer"), libdcp::TRAILER, N_("TLR")));
47         _dcp_content_types.push_back (new DCPContentType (_("Test"), libdcp::TEST, N_("TST")));
48         _dcp_content_types.push_back (new DCPContentType (_("Transitional"), libdcp::TRANSITIONAL, N_("XSN")));
49         _dcp_content_types.push_back (new DCPContentType (_("Rating"), libdcp::RATING, N_("RTG")));
50         _dcp_content_types.push_back (new DCPContentType (_("Teaser"), libdcp::TEASER, N_("TSR")));
51         _dcp_content_types.push_back (new DCPContentType (_("Policy"), libdcp::POLICY, N_("POL")));
52         _dcp_content_types.push_back (new DCPContentType (_("Public Service Announcement"), libdcp::PUBLIC_SERVICE_ANNOUNCEMENT, N_("PSA")));
53         _dcp_content_types.push_back (new DCPContentType (_("Advertisement"), libdcp::ADVERTISEMENT, N_("ADV")));
54 }
55
56 DCPContentType const *
57 DCPContentType::from_pretty_name (string n)
58 {
59         for (vector<DCPContentType const *>::const_iterator i = _dcp_content_types.begin(); i != _dcp_content_types.end(); ++i) {
60                 if ((*i)->pretty_name() == n) {
61                         return *i;
62                 }
63         }
64
65         return 0;
66 }
67
68 DCPContentType const *
69 DCPContentType::from_dci_name (string n)
70 {
71         for (vector<DCPContentType const *>::const_iterator i = _dcp_content_types.begin(); i != _dcp_content_types.end(); ++i) {
72                 if ((*i)->dci_name() == n) {
73                         return *i;
74                 }
75         }
76
77         return 0;
78 }
79
80 DCPContentType const *
81 DCPContentType::from_index (int n)
82 {
83         assert (n >= 0 && n < int (_dcp_content_types.size ()));
84         return _dcp_content_types[n];
85 }
86
87 int
88 DCPContentType::as_index (DCPContentType const * c)
89 {
90         vector<DCPContentType*>::size_type i = 0;
91         while (i < _dcp_content_types.size() && _dcp_content_types[i] != c) {
92                 ++i;
93         }
94
95         if (i == _dcp_content_types.size ()) {
96                 return -1;
97         }
98
99         return i;
100 }
101
102 vector<DCPContentType const *>
103 DCPContentType::all ()
104 {
105         return _dcp_content_types;
106 }