C++11 tidying.
[dcpomatic.git] / src / lib / playlist.h
1 /*
2     Copyright (C) 2013-2021 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
22 #ifndef DCPOMATIC_PLAYLIST_H
23 #define DCPOMATIC_PLAYLIST_H
24
25
26 #include "change_signaller.h"
27 #include "frame_rate_change.h"
28 #include "util.h"
29 #include <libcxml/cxml.h>
30 #include <boost/signals2.hpp>
31 #include <boost/thread.hpp>
32 #include <list>
33
34
35 class Film;
36
37
38 struct ContentSorter
39 {
40         bool operator() (std::shared_ptr<Content> a, std::shared_ptr<Content> b);
41 };
42
43
44 /** @class Playlist
45  *  @brief A set of Content objects with knowledge of how they should be arranged into
46  *  a DCP.
47  */
48 class Playlist
49 {
50 public:
51         Playlist ();
52         ~Playlist ();
53
54         Playlist (Playlist const&) = delete;
55         Playlist& operator= (Playlist const&) = delete;
56
57         void as_xml (xmlpp::Node *, bool with_content_paths);
58         void set_from_xml (std::shared_ptr<const Film> film, cxml::ConstNodePtr node, int version, std::list<std::string>& notes);
59
60         void add (std::shared_ptr<const Film> film, std::shared_ptr<Content>);
61         void remove (std::shared_ptr<Content>);
62         void remove (ContentList);
63         void move_earlier (std::shared_ptr<const Film> film, std::shared_ptr<Content>);
64         void move_later (std::shared_ptr<const Film> film, std::shared_ptr<Content>);
65
66         ContentList content () const;
67
68         std::string video_identifier () const;
69
70         dcpomatic::DCPTime length (std::shared_ptr<const Film> film) const;
71         boost::optional<dcpomatic::DCPTime> start () const;
72         int64_t required_disk_space (std::shared_ptr<const Film> film, int j2k_bandwidth, int audio_channels, int audio_frame_rate) const;
73
74         int best_video_frame_rate () const;
75         dcpomatic::DCPTime video_end (std::shared_ptr<const Film> film) const;
76         dcpomatic::DCPTime text_end (std::shared_ptr<const Film> film) const;
77         FrameRateChange active_frame_rate_change (dcpomatic::DCPTime, int dcp_frame_rate) const;
78         std::string content_summary (std::shared_ptr<const Film> film, dcpomatic::DCPTimePeriod period) const;
79         std::pair<double, double> speed_up_range (int dcp_video_frame_rate) const;
80
81         void set_sequence (bool);
82         void maybe_sequence (std::shared_ptr<const Film> film);
83
84         void repeat (std::shared_ptr<const Film> film, ContentList, int);
85
86         /** Emitted when content has been added to or removed from the playlist; implies OrderChange */
87         mutable boost::signals2::signal<void (ChangeType)> Change;
88         mutable boost::signals2::signal<void ()> OrderChange;
89         /** Emitted when the length might have changed; may sometimes be emitted when it has not */
90         mutable boost::signals2::signal<void ()> LengthChange;
91
92         mutable boost::signals2::signal<void (ChangeType, std::weak_ptr<Content>, int, bool)> ContentChange;
93
94 private:
95         void content_change (std::weak_ptr<const Film>, ChangeType, std::weak_ptr<Content>, int, bool);
96         void disconnect ();
97         void reconnect (std::shared_ptr<const Film> film);
98
99         mutable boost::mutex _mutex;
100         /** List of content.  Kept sorted in position order. */
101         ContentList _content;
102         bool _sequence = true;
103         bool _sequencing = false;
104         std::list<boost::signals2::connection> _content_connections;
105 };
106
107
108 #endif