Various incomplete hacks on regions / audio mapping.
[dcpomatic.git] / src / lib / playlist.h
1 /* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
2
3 /*
4     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
5
6     This program 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     This program 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 this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 */
21
22 #ifndef DCPOMATIC_PLAYLIST_H
23 #define DCPOMATIC_PLAYLIST_H
24
25 #include <list>
26 #include <boost/shared_ptr.hpp>
27 #include <boost/enable_shared_from_this.hpp>
28 #include "video_source.h"
29 #include "audio_source.h"
30 #include "video_sink.h"
31 #include "audio_sink.h"
32 #include "ffmpeg_content.h"
33 #include "audio_mapping.h"
34
35 class Content;
36 class FFmpegContent;
37 class FFmpegDecoder;
38 class ImageMagickContent;
39 class ImageMagickDecoder;
40 class SndfileContent;
41 class SndfileDecoder;
42 class Job;
43 class Film;
44
45 /** @class Playlist
46  *  @brief A set of content files (video and audio), with knowledge of how they should be arranged into
47  *  a DCP.
48  *
49  * This class holds Content objects, and it knows how they should be arranged.  At the moment
50  * the ordering is implicit; video content is placed sequentially, and audio content is taken
51  * from the video unless any sound-only files are present.  If sound-only files exist, they
52  * are played simultaneously (i.e. they can be split up into multiple files for different channels)
53  */
54
55 class Playlist
56 {
57 public:
58         Playlist ();
59         Playlist (boost::shared_ptr<const Playlist>);
60
61         void as_xml (xmlpp::Node *);
62         void set_from_xml (boost::shared_ptr<const cxml::Node>);
63
64         void add (boost::shared_ptr<Content>);
65         void remove (boost::shared_ptr<Content>);
66
67         bool has_subtitles () const;
68
69         struct Region
70         {
71                 Region ()
72                         : time (0)
73                 {}
74                 
75                 Region (boost::shared_ptr<Content> c, Time t, Playlist* p);
76                 Region (boost::shared_ptr<const cxml::Node>, Playlist* p);
77
78                 void as_xml (xmlpp::Node *) const;
79                 
80                 boost::shared_ptr<Content> content;
81                 Time time;
82                 /* XXX: obviously not used for video-only; there should
83                    really by AudioRegion / VideoRegion etc.
84                 */
85                 AudioMapping audio_mapping;
86                 boost::signals2::connection connection;
87         };
88
89         typedef std::vector<boost::shared_ptr<Region> > RegionList;
90         
91         RegionList regions () const {
92                 return _regions;
93         }
94
95         std::string audio_digest () const;
96         std::string video_digest () const;
97
98         int loop () const {
99                 return _loop;
100         }
101         
102         void set_loop (int l);
103
104         Time length (boost::shared_ptr<const Film>) const;
105         int best_dcp_frame_rate () const;
106
107         mutable boost::signals2::signal<void ()> Changed;
108         mutable boost::signals2::signal<void (boost::weak_ptr<Content>, int)> ContentChanged;
109         
110 private:
111         void content_changed (boost::weak_ptr<Content>, int);
112
113         RegionList _regions;
114         int _loop;
115 };
116
117 #endif