Add fade in/out option to the content audio tab (#1026).
[dcpomatic.git] / src / lib / audio_content.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 /** @file  src/lib/audio_content.h
23  *  @brief AudioContent and AudioContentProperty classes.
24  */
25
26
27 #ifndef DCPOMATIC_AUDIO_CONTENT_H
28 #define DCPOMATIC_AUDIO_CONTENT_H
29
30
31 #include "content_part.h"
32 #include "audio_stream.h"
33 #include "audio_mapping.h"
34
35
36 /** @class AudioContentProperty
37  *  @brief Names for properties of AudioContent.
38  */
39 class AudioContentProperty
40 {
41 public:
42         static int const STREAMS;
43         static int const GAIN;
44         static int const DELAY;
45         static int const FADE_IN;
46         static int const FADE_OUT;
47 };
48
49
50 class AudioContent : public ContentPart
51 {
52 public:
53         explicit AudioContent (Content* parent);
54         AudioContent (Content* parent, std::vector<std::shared_ptr<Content>>);
55         AudioContent (Content* parent, cxml::ConstNodePtr);
56
57         void as_xml (xmlpp::Node *) const;
58         std::string technical_summary () const;
59         void take_settings_from (std::shared_ptr<const AudioContent> c);
60
61         AudioMapping mapping () const;
62         void set_mapping (AudioMapping);
63         int resampled_frame_rate (std::shared_ptr<const Film> film) const;
64         std::vector<NamedChannel> channel_names () const;
65
66         /** Set gain in dB.
67          *  @param double g New gain in dB.
68          */
69         void set_gain (double g);
70         void set_delay (int);
71
72         double gain () const {
73                 boost::mutex::scoped_lock lm (_mutex);
74                 return _gain;
75         }
76
77         int delay () const {
78                 boost::mutex::scoped_lock lm (_mutex);
79                 return _delay;
80         }
81
82         dcpomatic::ContentTime fade_in () const {
83                 boost::mutex::scoped_lock lm (_mutex);
84                 return _fade_in;
85         }
86
87         dcpomatic::ContentTime fade_out () const {
88                 boost::mutex::scoped_lock lm (_mutex);
89                 return _fade_out;
90         }
91
92         void set_fade_in (dcpomatic::ContentTime time);
93         void set_fade_out (dcpomatic::ContentTime time);
94
95         std::string processing_description (std::shared_ptr<const Film> film) const;
96
97         std::vector<AudioStreamPtr> streams () const {
98                 boost::mutex::scoped_lock lm (_mutex);
99                 return _streams;
100         }
101
102         void add_stream (AudioStreamPtr stream);
103         void set_stream (AudioStreamPtr stream);
104         void set_streams (std::vector<AudioStreamPtr> streams);
105         AudioStreamPtr stream () const;
106
107         void add_properties (std::shared_ptr<const Film> film, std::list<UserProperty> &) const;
108
109         void modify_position (std::shared_ptr<const Film> film, dcpomatic::DCPTime& pos) const;
110         void modify_trim_start (dcpomatic::ContentTime& pos) const;
111
112         /** @param frame frame within the whole (untrimmed) content.
113          *  @param frame_rate The frame rate of the audio (it may have been resampled).
114          *  @return a fade coefficient for @ref length samples starting at an offset @frame within
115          *  the content, or an empty vector if the given section has no fade.
116          */
117         std::vector<float> fade (Frame frame, Frame length, int frame_rate) const;
118
119         static std::shared_ptr<AudioContent> from_xml (Content* parent, cxml::ConstNodePtr, int version);
120
121 private:
122
123         /** Gain to apply to audio in dB */
124         double _gain = 0;
125         /** Delay to apply to audio (positive moves audio later) in milliseconds */
126         int _delay = 0;
127         dcpomatic::ContentTime _fade_in;
128         dcpomatic::ContentTime _fade_out;
129         std::vector<AudioStreamPtr> _streams;
130 };
131
132 #endif