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_suppress;
70 binding<double> spill_suppress_saturation;
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, std::wstring template_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();
136 layer& get_layer(const std::wstring& name);
138 binding<int64_t> timeline_frame();
139 binding<double> speed();
141 template<typename T> binding<T>& create_variable(
142 const std::wstring& name, bool is_public, const std::wstring& expr = L"")
144 std::shared_ptr<core::variable> var =
145 std::make_shared<core::variable_impl<T>>(expr, is_public);
147 store_variable(name, var);
154 binding<T>& to_affect,
157 const std::wstring& easing)
159 add_keyframe(to_affect, binding<T>(destination_value), at_frame, easing);
164 binding<T>& to_affect,
165 const binding<T>& destination_value,
167 const std::wstring& easing)
171 add_keyframe(to_affect, destination_value, at_frame);
175 tweener tween(easing);
176 keyframe k(at_frame);
178 std::shared_ptr<T> start_value(new T);
180 k.on_start_animate = [=]() mutable
182 *start_value = to_affect.get();
186 k.on_destination_frame = [=]() mutable
188 to_affect.bind(destination_value);
192 [=](int64_t start_frame, int64_t current_frame) mutable
194 auto relative_frame = current_frame - start_frame;
195 auto duration = at_frame - start_frame;
196 auto tweened = static_cast<T>(tween(
197 static_cast<double>(relative_frame),
199 destination_value.get() - *start_value,
200 static_cast<double>(duration)));
202 to_affect.set(tweened);
204 //CASPAR_LOG(info) << relative_frame << L" " << *start_value << L" " << duration << L" " << tweened;
207 store_keyframe(to_affect.identity(), k);
211 void add_keyframe(binding<T>& to_affect, T set_value, int64_t at_frame)
213 add_keyframe(to_affect, binding<T>(set_value), at_frame);
217 void add_keyframe(binding<T>& to_affect, const binding<T>& set_value, int64_t at_frame)
219 keyframe k(at_frame);
221 k.on_destination_frame = [=]() mutable
223 to_affect.bind(set_value);
226 store_keyframe(to_affect.identity(), k);
229 void add_mark(int64_t at_frame, mark_action action, const std::wstring& label);
230 void add_task(binding<bool> when, std::function<void ()> task);
232 core::variable& get_variable(const std::wstring& name) override;
233 const std::vector<std::wstring>& get_variables() const override;
235 void store_keyframe(void* timeline_identity, const keyframe& k);
237 const std::wstring& name, const std::shared_ptr<core::variable>& var);
240 std::unique_ptr<impl> impl_;