Clumsy DCI naming dialog.
[dcpomatic.git] / src / lib / film_state.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/film_state.h
21  *  @brief The state of a Film.  This is separate from Film so that
22  *  state can easily be copied and kept around for reference
23  *  by long-running jobs.  This avoids the jobs getting confused
24  *  by the user changing Film settings during their run.
25  */
26
27 #ifndef DVDOMATIC_FILM_STATE_H
28 #define DVDOMATIC_FILM_STATE_H
29
30 extern "C" {
31 #include <libavcodec/avcodec.h>
32 #include <libswscale/swscale.h>
33 }
34 #include "scaler.h"
35 #include "util.h"
36 #include "trim_action.h"
37
38 class Format;
39 class DCPContentType;
40 class Filter;
41
42 /** @class FilmState
43  *  @brief The state of a Film.
44  *
45  *  This is separate from Film so that state can easily be copied and
46  *  kept around for reference by long-running jobs.  This avoids the
47  *  jobs getting confused by the user changing Film settings during
48  *  their run.
49  */
50
51 class FilmState
52 {
53 public:
54         FilmState ()
55                 : use_dci_name (false)
56                 , dcp_content_type (0)
57                 , frames_per_second (0)
58                 , format (0)
59                 , scaler (Scaler::from_id ("bicubic"))
60                 , dcp_frames (0)
61                 , dcp_trim_action (CUT)
62                 , dcp_ab (false)
63                 , audio_gain (0)
64                 , audio_delay (0)
65                 , still_duration (10)
66                 , with_subtitles (false)
67                 , subtitle_offset (0)
68                 , subtitle_scale (1)
69                 , length (0)
70                 , audio_channels (0)
71                 , audio_sample_rate (0)
72                 , audio_sample_format (AV_SAMPLE_FMT_NONE)
73                 , has_subtitles (false)
74         {}
75
76         std::string file (std::string f) const;
77         std::string dir (std::string d) const;
78
79         std::string content_path () const;
80         ContentType content_type () const;
81         
82         bool content_is_dvd () const;
83
84         std::string thumb_file (int) const;
85         std::string thumb_base (int) const;
86         int thumb_frame (int) const;
87
88         int bytes_per_sample () const;
89         int target_sample_rate () const;
90         
91         void write_metadata (std::ofstream &) const;
92         void read_metadata (std::string, std::string);
93
94         Size cropped_size (Size) const;
95         int dcp_length () const;
96         std::string dci_name () const;
97
98         /** Complete path to directory containing the film metadata;
99             must not be relative.
100         */
101         std::string directory;
102         /** Name for DVD-o-matic */
103         std::string name;
104         bool use_dci_name;
105         /** File or directory containing content; may be relative to our directory
106          *  or an absolute path.
107          */
108         std::string content;
109         /** The type of content that this Film represents (feature, trailer etc.) */
110         DCPContentType const * dcp_content_type;
111         /** Frames per second of the source */
112         float frames_per_second;
113         /** The format to present this Film in (flat, scope, etc.) */
114         Format const * format;
115         Crop crop;
116         /** Video filters that should be used when generating DCPs */
117         std::vector<Filter const *> filters;
118         /** Scaler algorithm to use */
119         Scaler const * scaler;
120         /** Number of frames to put in the DCP, or 0 for all */
121         int dcp_frames;
122
123         TrimAction dcp_trim_action;
124                 
125         /** true to create an A/B comparison DCP, where the left half of the image
126             is the video without any filters or post-processing, and the right half
127             has the specified filters and post-processing.
128         */
129         bool dcp_ab;
130         /** Gain to apply to audio in dB */
131         float audio_gain;
132         /** Delay to apply to audio (positive moves audio later) in milliseconds */
133         int audio_delay;
134         /** Duration to make still-sourced films (in seconds) */
135         int still_duration;
136         bool with_subtitles;
137         /** y offset for placing subtitles, in source pixels; +ve is further down
138             the frame, -ve is further up.
139         */
140         int subtitle_offset;
141         float subtitle_scale;
142
143         /* DCI naming stuff */
144         std::string dci_name_prefix;
145         std::string audio_language;
146         std::string subtitle_language;
147         std::string territory;
148         std::string rating;
149         std::string studio;
150         std::string facility;
151         std::string package_type;
152
153         /* Data which is cached to speed things up */
154
155         /** Vector of frame indices for each of our `thumbnails' */
156         std::vector<int> thumbs;
157         /** Size, in pixels, of the source (ignoring cropping) */
158         Size size;
159         /** Length of the source in frames */
160         int length;
161         /** Number of audio channels */
162         int audio_channels;
163         /** Sample rate of the source audio, in Hz */
164         int audio_sample_rate;
165         /** Format of the audio samples */
166         AVSampleFormat audio_sample_format;
167         /** MD5 digest of our content file */
168         std::string content_digest;
169         /** true if the source has subtitles */
170         bool has_subtitles;
171
172 private:
173         std::string thumb_file_for_frame (int) const;
174         std::string thumb_base_for_frame (int) const;
175 };
176
177 #endif