0baf667fc119a6b78d295c7ae3649917ea046337
[dcpomatic.git] / src / lib / playlist.h
1 /*
2     Copyright (C) 2013 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 #ifndef DCPOMATIC_PLAYLIST_H
21 #define DCPOMATIC_PLAYLIST_H
22
23 #include "util.h"
24 #include "frame_rate_change.h"
25 #include <libcxml/cxml.h>
26 #include <boost/shared_ptr.hpp>
27 #include <boost/signals2.hpp>
28 #include <list>
29
30 class Film;
31
32 struct ContentSorter
33 {
34         bool operator() (boost::shared_ptr<Content> a, boost::shared_ptr<Content> b);
35 };
36
37 /** @class Playlist
38  *  @brief A set of Content objects with knowledge of how they should be arranged into
39  *  a DCP.
40  */
41 class Playlist : public boost::noncopyable
42 {
43 public:
44         Playlist ();
45         ~Playlist ();
46
47         void as_xml (xmlpp::Node *);
48         void set_from_xml (boost::shared_ptr<const Film>, cxml::ConstNodePtr, int, std::list<std::string> &);
49
50         void add (boost::shared_ptr<Content>);
51         void remove (boost::shared_ptr<Content>);
52         void remove (ContentList);
53         void move_earlier (boost::shared_ptr<Content>);
54         void move_later (boost::shared_ptr<Content>);
55
56         ContentList content () const;
57
58         std::string video_identifier () const;
59
60         DCPTime length () const;
61         boost::optional<DCPTime> start () const;
62         int64_t required_disk_space (int j2k_bandwidth, int audio_channels, int audio_frame_rate) const;
63
64         int best_dcp_frame_rate () const;
65         DCPTime video_end () const;
66         FrameRateChange active_frame_rate_change (DCPTime, int dcp_frame_rate) const;
67
68         void set_sequence_video (bool);
69         void maybe_sequence_video ();
70
71         void repeat (ContentList, int);
72
73         /** Emitted when content has been added to or removed from the playlist */
74         mutable boost::signals2::signal<void ()> Changed;
75         /** Emitted when something about a piece of our content has changed;
76          *  these emissions include when the position of the content changes.
77          *  Third parameter is true if signals are currently being emitted frequently.
78          */
79         mutable boost::signals2::signal<void (boost::weak_ptr<Content>, int, bool)> ContentChanged;
80
81 private:
82         void content_changed (boost::weak_ptr<Content>, int, bool);
83         void reconnect ();
84
85         /** List of content.  Kept sorted in position order. */
86         ContentList _content;
87         bool _sequence_video;
88         bool _sequencing_video;
89         std::list<boost::signals2::connection> _content_connections;
90 };
91
92 #endif