std::shared_ptr
[dcpomatic.git] / src / lib / playlist.h
1 /*
2     Copyright (C) 2013-2020 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #ifndef DCPOMATIC_PLAYLIST_H
22 #define DCPOMATIC_PLAYLIST_H
23
24 #include "util.h"
25 #include "frame_rate_change.h"
26 #include <libcxml/cxml.h>
27 #include <boost/signals2.hpp>
28 #include <boost/thread.hpp>
29 #include <list>
30
31 class Film;
32
33 struct ContentSorter
34 {
35         bool operator() (std::shared_ptr<Content> a, std::shared_ptr<Content> b);
36 };
37
38 /** @class Playlist
39  *  @brief A set of Content objects with knowledge of how they should be arranged into
40  *  a DCP.
41  */
42 class Playlist : public boost::noncopyable
43 {
44 public:
45         Playlist ();
46         ~Playlist ();
47
48         void as_xml (xmlpp::Node *, bool with_content_paths);
49         void set_from_xml (std::shared_ptr<const Film> film, cxml::ConstNodePtr node, int version, std::list<std::string>& notes);
50
51         void add (std::shared_ptr<const Film> film, std::shared_ptr<Content>);
52         void remove (std::shared_ptr<Content>);
53         void remove (ContentList);
54         void move_earlier (std::shared_ptr<const Film> film, std::shared_ptr<Content>);
55         void move_later (std::shared_ptr<const Film> film, std::shared_ptr<Content>);
56
57         ContentList content () const;
58
59         std::string video_identifier () const;
60
61         dcpomatic::DCPTime length (std::shared_ptr<const Film> film) const;
62         boost::optional<dcpomatic::DCPTime> start () const;
63         int64_t required_disk_space (std::shared_ptr<const Film> film, int j2k_bandwidth, int audio_channels, int audio_frame_rate) const;
64
65         int best_video_frame_rate () const;
66         dcpomatic::DCPTime video_end (std::shared_ptr<const Film> film) const;
67         dcpomatic::DCPTime text_end (std::shared_ptr<const Film> film) const;
68         FrameRateChange active_frame_rate_change (dcpomatic::DCPTime, int dcp_frame_rate) const;
69         std::string content_summary (std::shared_ptr<const Film> film, dcpomatic::DCPTimePeriod period) const;
70         std::pair<double, double> speed_up_range (int dcp_video_frame_rate) const;
71
72         void set_sequence (bool);
73         void maybe_sequence (std::shared_ptr<const Film> film);
74
75         void repeat (std::shared_ptr<const Film> film, ContentList, int);
76
77         /** Emitted when content has been added to or removed from the playlist; implies OrderChanged */
78         mutable boost::signals2::signal<void (ChangeType)> Change;
79         mutable boost::signals2::signal<void ()> OrderChange;
80         /** Emitted when the length might have changed; may sometimes be emitted when it has not */
81         mutable boost::signals2::signal<void ()> LengthChange;
82
83         mutable boost::signals2::signal<void (ChangeType, std::weak_ptr<Content>, int, bool)> ContentChange;
84
85 private:
86         void content_change (std::weak_ptr<const Film>, ChangeType, std::weak_ptr<Content>, int, bool);
87         void disconnect ();
88         void reconnect (std::shared_ptr<const Film> film);
89
90         mutable boost::mutex _mutex;
91         /** List of content.  Kept sorted in position order. */
92         ContentList _content;
93         bool _sequence;
94         bool _sequencing;
95         std::list<boost::signals2::connection> _content_connections;
96 };
97
98 #endif