2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG 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 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG 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.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Helge Norberg, helge.norberg@svt.se
24 #include <common/log.h>
26 #include "../frame_producer.h"
27 #include "../../fwd.h"
29 #include "../binding.h"
30 #include "../variable.h"
32 namespace caspar { namespace core { namespace scene {
56 binding<double> opacity;
64 binding<double> target_hue;
65 binding<double> hue_width;
66 binding<double> min_saturation;
67 binding<double> min_brightness;
68 binding<double> softness;
69 binding<double> spill;
70 binding<double> spill_darken;
75 binding<std::wstring> name;
77 scene::coord position;
79 scene::corners perspective;
80 binding<double> rotation;
81 scene::adjustments adjustments;
82 binding<spl::shared_ptr<frame_producer>> producer;
85 binding<bool> use_mipmap;
86 binding<core::blend_mode> blend_mode;
87 scene::chroma_key chroma_key;
89 explicit layer(const std::wstring& name, const spl::shared_ptr<frame_producer>& producer);
94 std::function<void ()> on_start_animate;
95 std::function<void (int64_t start_frame, int64_t current_frame)> on_animate_to;
96 std::function<void ()> on_destination_frame;
97 int64_t destination_frame;
99 keyframe(int64_t destination_frame)
100 : destination_frame(destination_frame)
105 enum class mark_action
113 mark_action get_mark_action(const std::wstring& name);
115 class scene_producer : public frame_producer_base
118 scene_producer(std::wstring producer_name, int width, int height, const video_format_desc& format_desc);
121 draw_frame receive_impl() override;
122 constraints& pixel_constraints() override;
123 void on_interaction(const interaction_event::ptr& event) override;
124 bool collides(double x, double y) const override;
125 std::wstring print() const override;
126 std::wstring name() const override;
127 std::future<std::wstring> call(const std::vector<std::wstring>& params) override;
128 boost::property_tree::wptree info() const override;
129 monitor::subject& monitor_output();
132 const spl::shared_ptr<frame_producer>& producer, int x, int y, const std::wstring& name);
134 const spl::shared_ptr<frame_producer>& producer, const std::wstring& name);
135 void reverse_layers();
137 binding<int64_t> timeline_frame();
138 binding<double> speed();
140 template<typename T> binding<T>& create_variable(
141 const std::wstring& name, bool is_public, const std::wstring& expr = L"")
143 std::shared_ptr<core::variable> var =
144 std::make_shared<core::variable_impl<T>>(expr, is_public);
146 store_variable(name, var);
153 binding<T>& to_affect,
156 const std::wstring& easing)
158 add_keyframe(to_affect, binding<T>(destination_value), at_frame, easing);
163 binding<T>& to_affect,
164 const binding<T>& destination_value,
166 const std::wstring& easing)
170 add_keyframe(to_affect, destination_value, at_frame);
174 tweener tween(easing);
175 keyframe k(at_frame);
177 std::shared_ptr<T> start_value(new T);
179 k.on_start_animate = [=]() mutable
181 *start_value = to_affect.get();
185 k.on_destination_frame = [=]() mutable
187 to_affect.bind(destination_value);
191 [=](int64_t start_frame, int64_t current_frame) mutable
193 auto relative_frame = current_frame - start_frame;
194 auto duration = at_frame - start_frame;
195 auto tweened = static_cast<T>(tween(
196 static_cast<double>(relative_frame),
198 destination_value.get() - *start_value,
199 static_cast<double>(duration)));
201 to_affect.set(tweened);
203 //CASPAR_LOG(info) << relative_frame << L" " << *start_value << L" " << duration << L" " << tweened;
206 store_keyframe(to_affect.identity(), k);
210 void add_keyframe(binding<T>& to_affect, T set_value, int64_t at_frame)
212 add_keyframe(to_affect, binding<T>(set_value), at_frame);
216 void add_keyframe(binding<T>& to_affect, const binding<T>& set_value, int64_t at_frame)
218 keyframe k(at_frame);
220 k.on_destination_frame = [=]() mutable
222 to_affect.bind(set_value);
225 store_keyframe(to_affect.identity(), k);
228 void add_mark(int64_t frame, mark_action action, const std::wstring& label);
230 core::variable& get_variable(const std::wstring& name) override;
231 const std::vector<std::wstring>& get_variables() const override;
233 void store_keyframe(void* timeline_identity, const keyframe& k);
235 const std::wstring& name, const std::shared_ptr<core::variable>& var);
238 std::unique_ptr<impl> impl_;