Add fade in/out option to the content audio tab (#1026).
[dcpomatic.git] / src / lib / audio_content.h
index 92491bf89414745648a3658b6a022fe01fd06139..ba998a5ad5f62e414008c0474a56b226849ab142 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
 */
 
+
 /** @file  src/lib/audio_content.h
  *  @brief AudioContent and AudioContentProperty classes.
  */
 
+
 #ifndef DCPOMATIC_AUDIO_CONTENT_H
 #define DCPOMATIC_AUDIO_CONTENT_H
 
+
 #include "content_part.h"
 #include "audio_stream.h"
 #include "audio_mapping.h"
 
+
 /** @class AudioContentProperty
  *  @brief Names for properties of AudioContent.
  */
@@ -38,24 +42,30 @@ public:
        static int const STREAMS;
        static int const GAIN;
        static int const DELAY;
+       static int const FADE_IN;
+       static int const FADE_OUT;
 };
 
+
 class AudioContent : public ContentPart
 {
 public:
-       AudioContent (Content* parent);
-       AudioContent (Content* parent, std::vector<boost::shared_ptr<Content> >);
+       explicit AudioContent (Content* parent);
+       AudioContent (Content* parent, std::vector<std::shared_ptr<Content>>);
+       AudioContent (Content* parent, cxml::ConstNodePtr);
 
        void as_xml (xmlpp::Node *) const;
        std::string technical_summary () const;
+       void take_settings_from (std::shared_ptr<const AudioContent> c);
 
        AudioMapping mapping () const;
        void set_mapping (AudioMapping);
-       int resampled_frame_rate () const;
-       bool has_rate_above_48k () const;
-       std::vector<std::string> channel_names () const;
+       int resampled_frame_rate (std::shared_ptr<const Film> film) const;
+       std::vector<NamedChannel> channel_names () const;
 
+       /** Set gain in dB */
        void set_gain (double);
+       /** Set delay in milliseconds (positive moves audio later) */
        void set_delay (int);
 
        double gain () const {
@@ -68,7 +78,20 @@ public:
                return _delay;
        }
 
-       std::string processing_description () const;
+       dcpomatic::ContentTime fade_in () const {
+               boost::mutex::scoped_lock lm (_mutex);
+               return _fade_in;
+       }
+
+       dcpomatic::ContentTime fade_out () const {
+               boost::mutex::scoped_lock lm (_mutex);
+               return _fade_out;
+       }
+
+       void set_fade_in (dcpomatic::ContentTime time);
+       void set_fade_out (dcpomatic::ContentTime time);
+
+       std::string processing_description (std::shared_ptr<const Film> film) const;
 
        std::vector<AudioStreamPtr> streams () const {
                boost::mutex::scoped_lock lm (_mutex);
@@ -80,18 +103,28 @@ public:
        void set_streams (std::vector<AudioStreamPtr> streams);
        AudioStreamPtr stream () const;
 
-       void add_properties (std::list<UserProperty> &) const;
+       void add_properties (std::shared_ptr<const Film> film, std::list<UserProperty> &) const;
 
-       static boost::shared_ptr<AudioContent> from_xml (Content* parent, cxml::ConstNodePtr, int version);
+       void modify_position (std::shared_ptr<const Film> film, dcpomatic::DCPTime& pos) const;
+       void modify_trim_start (dcpomatic::ContentTime& pos) const;
 
-private:
+       /** @param frame frame within the whole (untrimmed) content.
+        *  @param frame_rate The frame rate of the audio (it may have been resampled).
+        *  @return a fade coefficient for @ref length samples starting at an offset @frame within
+        *  the content, or an empty vector if the given section has no fade.
+        */
+       std::vector<float> fade (AudioStreamPtr stream, Frame frame, Frame length, int frame_rate) const;
 
-       AudioContent (Content* parent, cxml::ConstNodePtr);
+       static std::shared_ptr<AudioContent> from_xml (Content* parent, cxml::ConstNodePtr, int version);
+
+private:
 
        /** Gain to apply to audio in dB */
-       double _gain;
+       double _gain = 0;
        /** Delay to apply to audio (positive moves audio later) in milliseconds */
-       int _delay;
+       int _delay = 0;
+       dcpomatic::ContentTime _fade_in;
+       dcpomatic::ContentTime _fade_out;
        std::vector<AudioStreamPtr> _streams;
 };