Tweak properties dialogue layout and add a note of how many J2K frames have already...
[dcpomatic.git] / src / lib / film.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.h
21  *  @brief A representation of a piece of video (with sound), including naming,
22  *  the source content file, and how it should be presented in a DCP.
23  */
24
25 #ifndef DVDOMATIC_FILM_H
26 #define DVDOMATIC_FILM_H
27
28 #include <string>
29 #include <vector>
30 #include <inttypes.h>
31 #include <boost/thread/mutex.hpp>
32 #include <sigc++/signal.h>
33 extern "C" {
34 #include <libavcodec/avcodec.h>
35 }
36 #include "dcp_content_type.h"
37 #include "film_state.h"
38
39 class Format;
40 class Job;
41 class Filter;
42 class Log;
43 class ExamineContentJob;
44
45 /** @class Film
46  *  @brief A representation of a video with sound.
47  *
48  *  A representation of a piece of video (with sound), including naming,
49  *  the source content file, and how it should be presented in a DCP.
50  */
51 class Film
52 {
53 public:
54         Film (std::string d, bool must_exist = true);
55         Film (Film const &);
56         ~Film ();
57
58         void write_metadata () const;
59
60         /** @return complete path to directory containing the film metadata */
61         std::string directory () const {
62                 return _state.directory;
63         }
64
65         std::string content () const;
66         ContentType content_type () const;
67
68         /** @return name for DVD-o-matic */
69         std::string name () const {
70                 return _state.name;
71         }
72
73         /** @return number of pixels to crop from the sides of the original picture */
74         Crop crop () const {
75                 return _state.crop;
76         }
77
78         /** @return the format to present this film in (flat, scope, etc.) */
79         Format const * format () const {
80                 return _state.format;
81         }
82
83         /** @return video filters that should be used when generating DCPs */
84         std::vector<Filter const *> filters () const {
85                 return _state.filters;
86         }
87
88         /** @return scaler algorithm to use */
89         Scaler const * scaler () const {
90                 return _state.scaler;
91         }
92
93         /** @return number of frames to put in the DCP, or 0 for all */
94         int dcp_frames () const {
95                 return _state.dcp_frames;
96         }
97
98         TrimAction dcp_trim_action () const {
99                 return _state.dcp_trim_action;
100         }
101
102         /** @return true to create an A/B comparison DCP, where the left half of the image
103          *  is the video without any filters or post-processing, and the right half
104          *  has the specified filters and post-processing.
105          */
106         bool dcp_ab () const {
107                 return _state.dcp_ab;
108         }
109
110         float audio_gain () const {
111                 return _state.audio_gain;
112         }
113
114         int audio_delay () const {
115                 return _state.audio_delay;
116         }
117
118         int still_duration () const {
119                 return _state.still_duration;
120         }
121         
122         void set_filters (std::vector<Filter const *> const &);
123
124         void set_scaler (Scaler const *);
125
126         /** @return the type of content that this Film represents (feature, trailer etc.) */
127         DCPContentType const * dcp_content_type () {
128                 return _state.dcp_content_type;
129         }
130
131         void set_dcp_frames (int);
132         void set_dcp_trim_action (TrimAction);
133         void set_dcp_ab (bool);
134         
135         void set_name (std::string);
136         void set_content (std::string);
137         void set_top_crop (int);
138         void set_bottom_crop (int);
139         void set_left_crop (int);
140         void set_right_crop (int);
141         void set_format (Format const *);
142         void set_dcp_content_type (DCPContentType const *);
143         void set_audio_gain (float);
144         void set_audio_delay (int);
145         void set_still_duration (int);
146
147         /** @return size, in pixels, of the source (ignoring cropping) */
148         Size size () const {
149                 return _state.size;
150         }
151
152         /** @return length, in video frames */
153         int length () const {
154                 return _state.length;
155         }
156
157         /** @return nnumber of video frames per second */
158         float frames_per_second () const {
159                 return _state.frames_per_second;
160         }
161
162         /** @return number of audio channels */
163         int audio_channels () const {
164                 return _state.audio_channels;
165         }
166
167         /** @return audio sample rate, in Hz */
168         int audio_sample_rate () const {
169                 return _state.audio_sample_rate;
170         }
171
172         /** @return format of the audio samples */
173         AVSampleFormat audio_sample_format () const {
174                 return _state.audio_sample_format;
175         }
176         
177         std::string j2k_dir () const;
178
179         std::vector<std::string> audio_files () const;
180
181         void update_thumbs_pre_gui ();
182         void update_thumbs_post_gui ();
183         int num_thumbs () const;
184         int thumb_frame (int) const;
185         std::string thumb_file (int) const;
186
187         void copy_from_dvd_post_gui ();
188         void examine_content ();
189         void examine_content_post_gui ();
190         void send_dcp_to_tms ();
191         void copy_from_dvd ();
192
193         /** @return true if our metadata has been modified since it was last saved */
194         bool dirty () const {
195                 return _dirty;
196         }
197
198         void make_dcp (bool, int freq = 0);
199
200         enum Property {
201                 NONE,
202                 NAME,
203                 CONTENT,
204                 DCP_CONTENT_TYPE,
205                 FORMAT,
206                 CROP,
207                 FILTERS,
208                 SCALER,
209                 DCP_FRAMES,
210                 DCP_TRIM_ACTION,
211                 DCP_AB,
212                 AUDIO_GAIN,
213                 AUDIO_DELAY,
214                 THUMBS,
215                 SIZE,
216                 LENGTH,
217                 FRAMES_PER_SECOND,
218                 AUDIO_CHANNELS,
219                 AUDIO_SAMPLE_RATE,
220                 STILL_DURATION
221         };
222
223         boost::shared_ptr<FilmState> state_copy () const;
224
225         /** @return Logger.
226          *  It is safe to call this from any thread.
227          */
228         Log* log () const {
229                 return _log;
230         }
231
232         int encoded_frames () const;
233
234         /** Emitted when some metadata property has changed */
235         mutable sigc::signal1<void, Property> Changed;
236         
237 private:
238         void read_metadata ();
239         std::string metadata_file () const;
240         void update_dimensions ();
241         void signal_changed (Property);
242
243         /** The majority of our state.  Kept in a separate object
244          *  so that it can easily be copied for passing onto long-running
245          *  jobs (which then have an unchanging set of parameters).
246          */
247         FilmState _state;
248
249         /** true if our metadata has changed since it was last written to disk */
250         mutable bool _dirty;
251
252         /** Log to write to */
253         Log* _log;
254
255         /** Any running ExamineContentJob, or 0 */
256         boost::shared_ptr<ExamineContentJob> _examine_content_job;
257 };
258
259 #endif