]> git.sesse.net Git - casparcg/blobdiff - core/producer/scene/scene_producer.h
[scene] Added missing mixer features
[casparcg] / core / producer / scene / scene_producer.h
index 530a6f5036394453b22abac1cbab77ab699f8e2d..08b2e7fb6f704d0608ef996846facac3c2445954 100644 (file)
 
 #pragma once
 
+#include <common/log.h>
+
 #include "../frame_producer.h"
+#include "../../fwd.h"
 
 #include "../binding.h"
+#include "../variable.h"
 
 namespace caspar { namespace core { namespace scene {
 
@@ -33,32 +37,81 @@ struct coord
        binding<double> y;
 };
 
+struct rect
+{
+       coord upper_left;
+       coord lower_right;
+};
+
+struct corners
+{
+       coord upper_left;
+       coord upper_right;
+       coord lower_right;
+       coord lower_left;
+};
+
 struct adjustments
 {
        binding<double> opacity;
+       binding<double> contrast;
+       binding<double> saturation;
+       binding<double> brightness;
 
        adjustments();
 };
 
+struct levels
+{
+       binding<double> min_input;
+       binding<double> max_input;
+       binding<double> gamma;
+       binding<double> min_output;
+       binding<double> max_output;
+
+       levels();
+};
+
+struct chroma_key
+{
+       binding<bool>   enable;
+       binding<double> target_hue;
+       binding<double> hue_width;
+       binding<double> min_saturation;
+       binding<double> min_brightness;
+       binding<double> softness;
+       binding<double> spill_suppress;
+       binding<double> spill_suppress_saturation;
+};
+
 struct layer
 {
-       binding<std::wstring> name;
-       coord position;
-       adjustments adjustments;
-       binding<spl::shared_ptr<frame_producer>> producer;
-       binding<bool> hidden;
-       binding<bool> is_key;
-
-       explicit layer(const spl::shared_ptr<frame_producer>& producer);
-       layer(const std::wstring& name, const spl::shared_ptr<frame_producer>& producer);
+       binding<std::wstring>                                           name;
+       scene::coord                                                            anchor;
+       scene::coord                                                            position;
+       scene::rect                                                                     crop;
+       scene::corners                                                          perspective;
+       scene::rect                                                                     clip;
+       binding<double>                                                         rotation;
+       scene::adjustments                                                      adjustments;
+       scene::levels                                                           levels;
+       binding<spl::shared_ptr<frame_producer>>        producer;
+       binding<bool>                                                           hidden;
+       binding<bool>                                                           is_key;
+       binding<bool>                                                           use_mipmap;
+       binding<core::blend_mode>                                       blend_mode;
+       scene::chroma_key                                                       chroma_key;
+       binding<double>                                                         volume;
+
+       explicit layer(const std::wstring& name, const spl::shared_ptr<frame_producer>& producer);
 };
 
 struct keyframe
 {
-       std::function<void ()> on_start_animate;
-       std::function<void (int64_t start_frame, int64_t current_frame)> on_animate_to;
-       std::function<void ()> on_destination_frame;
-       int64_t destination_frame;
+       std::function<void ()>                                                                                          on_start_animate;
+       std::function<void (int64_t start_frame, int64_t current_frame)>        on_animate_to;
+       std::function<void ()>                                                                                          on_destination_frame;
+       int64_t                                                                                                                         destination_frame;
 public:
        keyframe(int64_t destination_frame)
                : destination_frame(destination_frame)
@@ -66,75 +119,51 @@ public:
        }
 };
 
-template<typename T> class parameter_holder;
-
-class parameter_holder_base
+enum class mark_action
 {
-public:
-       virtual ~parameter_holder_base()
-       {
-       }
-
-       virtual void set(const std::wstring& raw_value) = 0;
-
-       template<typename T>
-       binding<T>& value()
-       {
-               return dynamic_cast<parameter_holder<T>>(*this).value();
-       }
+       start,
+       stop,
+       jump_to,
+       remove
 };
 
-template<typename T>
-class parameter_holder : public parameter_holder_base
-{
-       binding<T> value_;
-public:
-       parameter_holder(T initial_value)
-               : value_(initial_value)
-       {
-       }
-
-       binding<T>& value()
-       {
-               return value_;
-       }
-
-       virtual void set(const std::wstring& raw_value)
-       {
-               value_.set(boost::lexical_cast<T>(raw_value));
-       }
-};
+mark_action get_mark_action(const std::wstring& name);
 
 class scene_producer : public frame_producer_base
 {
 public:
-       scene_producer(int width, int height);
+       scene_producer(std::wstring producer_name, std::wstring template_name, int width, int height, const video_format_desc& format_desc);
        ~scene_producer();
 
-       class draw_frame receive_impl() override;
+       draw_frame receive_impl() override;
        constraints& pixel_constraints() override;
        void on_interaction(const interaction_event::ptr& event) override;
        bool collides(double x, double y) const override;
        std::wstring print() const override;
        std::wstring name() const override;
-       boost::unique_future<std::wstring>      call(const std::vector<std::wstring>& params) override;
+       std::future<std::wstring> call(const std::vector<std::wstring>& params) override;
        boost::property_tree::wptree info() const override;
-       void subscribe(const monitor::observable::observer_ptr& o) override;
-       void unsubscribe(const monitor::observable::observer_ptr& o) override;
-       layer& create_layer(
-                       const spl::shared_ptr<frame_producer>& producer, int x, int y);
+       monitor::subject& monitor_output();
+
        layer& create_layer(
                        const spl::shared_ptr<frame_producer>& producer, int x, int y, const std::wstring& name);
-       layer& create_layer(const spl::shared_ptr<frame_producer>& producer);
-       binding<int64_t> frame();
+       layer& create_layer(
+                       const spl::shared_ptr<frame_producer>& producer, const std::wstring& name);
+       void reverse_layers();
+       layer& get_layer(const std::wstring& name);
+
+       binding<int64_t> timeline_frame();
+       binding<double> speed();
 
-       template<typename T> binding<T>& create_parameter(const std::wstring& name, T initial_value = T())
+       template<typename T> binding<T>& create_variable(
+                       const std::wstring& name, bool is_public, const std::wstring& expr = L"")
        {
-               auto param = std::make_shared<parameter_holder<T>>(initial_value);
+               std::shared_ptr<core::variable> var =
+                               std::make_shared<core::variable_impl<T>>(expr, is_public);
 
-               store_parameter(name, param);
+               store_variable(name, var);
 
-               return param->value();
+               return var->as<T>();
        }
 
        template<typename T>
@@ -154,6 +183,12 @@ public:
                        int64_t at_frame,
                        const std::wstring& easing)
        {
+               if (easing.empty())
+               {
+                       add_keyframe(to_affect, destination_value, at_frame);
+                       return;
+               }
+
                tweener tween(easing);
                keyframe k(at_frame);
 
@@ -182,8 +217,8 @@ public:
                                                        static_cast<double>(duration)));
 
                                        to_affect.set(tweened);
-                                       
-                                       CASPAR_LOG(info) << relative_frame << L" " << *start_value << L" " << duration << L" " << tweened;
+
+                                       //CASPAR_LOG(info) << relative_frame << L" " << *start_value << L" " << duration << L" " << tweened;
                                };
 
                store_keyframe(to_affect.identity(), k);
@@ -207,16 +242,19 @@ public:
 
                store_keyframe(to_affect.identity(), k);
        }
+
+       void add_mark(int64_t at_frame, mark_action action, const std::wstring& label);
+       void add_task(binding<bool> when, std::function<void ()> task);
+
+       core::variable& get_variable(const std::wstring& name) override;
+       const std::vector<std::wstring>& get_variables() const override;
 private:
-       void store_parameter(
-                       const std::wstring& name,
-                       const std::shared_ptr<parameter_holder_base>& param);
        void store_keyframe(void* timeline_identity, const keyframe& k);
+       void store_variable(
+                       const std::wstring& name, const std::shared_ptr<core::variable>& var);
 
        struct impl;
        std::unique_ptr<impl> impl_;
 };
 
-spl::shared_ptr<frame_producer> create_dummy_scene_producer(const spl::shared_ptr<class frame_factory>& frame_factory, const video_format_desc& format_desc, const std::vector<std::wstring>& params);
-
 }}}