94c2253dee88883ea12b418b66cd9edddf4f8185
[dcpomatic.git] / src / lib / format.h
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/format.h
21  *  @brief Classes to describe a format (aspect ratio) that a Film should
22  *  be shown in.
23  */
24
25 #include <string>
26 #include <vector>
27 #include "util.h"
28
29 class Playlist;
30
31 class Format
32 {
33 public:
34         Format (libdcp::Size dcp, std::string id, std::string n, std::string d, std::string e)
35                 : _dcp_size (dcp)
36                 , _id (id)
37                 , _nickname (n)
38                 , _dci_name (d)
39                 , _description (e)
40         {}
41
42         /** @return the aspect ratio multiplied by 100
43          *  (e.g. 239 for Cinemascope 2.39:1)
44          */
45         virtual int ratio_as_integer (boost::shared_ptr<const Playlist> f) const = 0;
46
47         /** @return the ratio as a floating point number */
48         virtual float ratio_as_float (boost::shared_ptr<const Playlist> f) const = 0;
49
50         /** @return the ratio of the container (including any padding) as a floating point number */
51         float container_ratio_as_float () const;
52
53         int dcp_padding (boost::shared_ptr<const Playlist>) const;
54
55         /** @return size in pixels of the images that we should
56          *  put in a DCP for this ratio.  This size will not correspond
57          *  to the ratio when we are doing things like 16:9 in a Flat frame.
58          */
59         libdcp::Size dcp_size () const {
60                 return _dcp_size;
61         }
62
63         std::string id () const {
64                 return _id;
65         }
66
67         /** @return Full name to present to the user */
68         virtual std::string name () const = 0;
69
70         /** @return Nickname (e.g. Flat, Scope) */
71         std::string nickname () const {
72                 return _nickname;
73         }
74
75         std::string dci_name () const {
76                 return _dci_name;
77         }
78
79         std::string description () const {
80                 return _description;
81         }
82
83         std::string as_metadata () const;
84
85         static Format const * from_nickname (std::string n);
86         static Format const * from_metadata (std::string m);
87         static Format const * from_id (std::string i);
88         static std::vector<Format const *> all ();
89         static void setup_formats ();
90
91 protected:      
92         /** libdcp::Size in pixels of the images that we should
93          *  put in a DCP for this ratio.  This size will not correspond
94          *  to the ratio when we are doing things like 16:9 in a Flat frame.
95          */
96         libdcp::Size _dcp_size;
97         /** id for use in metadata */
98         std::string _id;
99         /** nickname (e.g. Flat, Scope) */
100         std::string _nickname;
101         std::string _dci_name;
102         std::string _description;
103
104 private:        
105         /** all available formats */
106         static std::vector<Format const *> _formats;
107 };
108
109 /** @class FixedFormat
110  *  @brief Class to describe a format whose ratio is fixed regardless
111  *  of source size.
112  */
113 class FixedFormat : public Format
114 {
115 public:
116         FixedFormat (int, libdcp::Size, std::string, std::string, std::string, std::string);
117
118         int ratio_as_integer (boost::shared_ptr<const Playlist>) const {
119                 return _ratio;
120         }
121
122         float ratio_as_float (boost::shared_ptr<const Playlist>) const {
123                 return _ratio / 100.0;
124         }
125
126         std::string name () const;
127         
128 private:
129
130         /** Ratio expressed as the actual ratio multiplied by 100 */
131         int _ratio;
132 };
133
134 class VariableFormat : public Format
135 {
136 public:
137         VariableFormat (libdcp::Size, std::string, std::string, std::string, std::string);
138
139         int ratio_as_integer (boost::shared_ptr<const Playlist> f) const;
140         float ratio_as_float (boost::shared_ptr<const Playlist> f) const;
141
142         std::string name () const;
143 };