Remove unused code.
[dcpomatic.git] / src / lib / content.h
1 /*
2     Copyright (C) 2013-2014 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/lib/content.h
21  *  @brief Content class.
22  */
23
24 #ifndef DCPOMATIC_CONTENT_H
25 #define DCPOMATIC_CONTENT_H
26
27 #include "types.h"
28 #include "dcpomatic_time.h"
29 #include <libxml++/libxml++.h>
30 #include <libcxml/cxml.h>
31 #include <boost/filesystem.hpp>
32 #include <boost/signals2.hpp>
33 #include <boost/thread/mutex.hpp>
34 #include <boost/enable_shared_from_this.hpp>
35
36 namespace cxml {
37         class Node;
38 }
39
40 class Job;
41 class Film;
42
43 class ContentProperty
44 {
45 public:
46         static int const PATH;
47         static int const POSITION;
48         static int const LENGTH;
49         static int const TRIM_START;
50         static int const TRIM_END;
51 };
52
53 /** @class Content
54  *  @brief A piece of content represented by one or more files on disk.
55  */
56 class Content : public boost::enable_shared_from_this<Content>, public boost::noncopyable
57 {
58 public:
59         Content (boost::shared_ptr<const Film>);
60         Content (boost::shared_ptr<const Film>, DCPTime);
61         Content (boost::shared_ptr<const Film>, boost::filesystem::path);
62         Content (boost::shared_ptr<const Film>, cxml::ConstNodePtr);
63         Content (boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
64         virtual ~Content () {}
65
66         /** Examine the content to establish digest, frame rates and any other
67          *  useful metadata.
68          *  @param job Job to use to report progress, or 0.
69          *  @param calculate_digest True to calculate a digest for the content's file(s).
70          */
71         virtual void examine (boost::shared_ptr<Job> job, bool calculate_digest);
72         
73         /** @return Quick one-line summary of the content, as will be presented in the
74          *  film editor.
75          */
76         virtual std::string summary () const = 0;
77         
78         /** @return Technical details of this content; these are written to logs to
79          *  help with debugging.
80          */
81         virtual std::string technical_summary () const;
82         
83         virtual void as_xml (xmlpp::Node *) const;
84         virtual DCPTime full_length () const = 0;
85         virtual std::string identifier () const;
86
87         boost::shared_ptr<Content> clone () const;
88
89         void set_path (boost::filesystem::path);
90
91         std::string path_summary () const;
92
93         std::vector<boost::filesystem::path> paths () const {
94                 boost::mutex::scoped_lock lm (_mutex);
95                 return _paths;
96         }
97
98         size_t number_of_paths () const {
99                 boost::mutex::scoped_lock lm (_mutex);
100                 return _paths.size ();
101         }
102
103         boost::filesystem::path path (size_t i) const {
104                 boost::mutex::scoped_lock lm (_mutex);
105                 return _paths[i];
106         }
107         
108         bool paths_valid () const;
109
110         /** @return MD5 digest of the content's file(s) */
111         boost::optional<std::string> digest () const {
112                 boost::mutex::scoped_lock lm (_mutex);
113                 return _digest;
114         }
115
116         void set_position (DCPTime);
117
118         /** DCPTime that this content starts; i.e. the time that the first
119          *  bit of the content (trimmed or not) will happen.
120          */
121         DCPTime position () const {
122                 boost::mutex::scoped_lock lm (_mutex);
123                 return _position;
124         }
125
126         void set_trim_start (DCPTime);
127
128         DCPTime trim_start () const {
129                 boost::mutex::scoped_lock lm (_mutex);
130                 return _trim_start;
131         }
132
133         void set_trim_end (DCPTime);
134         
135         DCPTime trim_end () const {
136                 boost::mutex::scoped_lock lm (_mutex);
137                 return _trim_end;
138         }
139         
140         DCPTime end () const {
141                 return position() + length_after_trim();
142         }
143
144         DCPTime length_after_trim () const;
145         
146         void set_change_signals_frequent (bool f) {
147                 _change_signals_frequent = f;
148         }
149
150         boost::shared_ptr<const Film> film () const {
151                 return _film.lock ();
152         }
153
154         boost::signals2::signal<void (boost::weak_ptr<Content>, int, bool)> Changed;
155
156 protected:
157         void signal_changed (int);
158
159         boost::weak_ptr<const Film> _film;
160
161         /** _mutex which should be used to protect accesses, as examine
162          *  jobs can update content state in threads other than the main one.
163          */
164         mutable boost::mutex _mutex;
165
166         /** Paths of our data files */
167         std::vector<boost::filesystem::path> _paths;
168         
169 private:
170         boost::optional<std::string> _digest;
171         DCPTime _position;
172         DCPTime _trim_start;
173         DCPTime _trim_end;
174         bool _change_signals_frequent;
175 };
176
177 #endif