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"
28 #include "../binding.h"
29 #include "../variable.h"
31 namespace caspar { namespace core {
59 binding<double> opacity;
66 binding<core::chroma::type> key;
67 binding<double> threshold;
68 binding<double> softness;
69 binding<double> spill;
74 binding<std::wstring> name;
76 scene::coord position;
78 scene::corners perspective;
79 binding<double> rotation;
80 scene::adjustments adjustments;
81 binding<spl::shared_ptr<frame_producer>> producer;
84 binding<bool> use_mipmap;
85 binding<core::blend_mode> blend_mode;
86 scene::chroma_key chroma_key;
88 explicit layer(const std::wstring& name, const spl::shared_ptr<frame_producer>& producer);
93 std::function<void ()> on_start_animate;
94 std::function<void (int64_t start_frame, int64_t current_frame)> on_animate_to;
95 std::function<void ()> on_destination_frame;
96 int64_t destination_frame;
98 keyframe(int64_t destination_frame)
99 : destination_frame(destination_frame)
104 class scene_producer : public frame_producer_base
107 scene_producer(int width, int height);
110 class draw_frame receive_impl() override;
111 constraints& pixel_constraints() override;
112 void on_interaction(const interaction_event::ptr& event) override;
113 bool collides(double x, double y) const override;
114 std::wstring print() const override;
115 std::wstring name() const override;
116 std::future<std::wstring> call(const std::vector<std::wstring>& params) override;
117 boost::property_tree::wptree info() const override;
118 monitor::subject& monitor_output();
121 const spl::shared_ptr<frame_producer>& producer, int x, int y, const std::wstring& name);
123 const spl::shared_ptr<frame_producer>& producer, const std::wstring& name);
124 binding<int64_t> frame();
125 binding<double> speed();
127 template<typename T> binding<T>& create_variable(
128 const std::wstring& name, bool is_public, const std::wstring& expr = L"")
130 std::shared_ptr<core::variable> var =
131 std::make_shared<core::variable_impl<T>>(expr, is_public);
133 store_variable(name, var);
140 binding<T>& to_affect,
143 const std::wstring& easing)
145 add_keyframe(to_affect, binding<T>(destination_value), at_frame, easing);
150 binding<T>& to_affect,
151 const binding<T>& destination_value,
153 const std::wstring& easing)
157 add_keyframe(to_affect, destination_value, at_frame);
161 tweener tween(easing);
162 keyframe k(at_frame);
164 std::shared_ptr<T> start_value(new T);
166 k.on_start_animate = [=]() mutable
168 *start_value = to_affect.get();
172 k.on_destination_frame = [=]() mutable
174 to_affect.bind(destination_value);
178 [=](int64_t start_frame, int64_t current_frame) mutable
180 auto relative_frame = current_frame - start_frame;
181 auto duration = at_frame - start_frame;
182 auto tweened = static_cast<T>(tween(
183 static_cast<double>(relative_frame),
185 destination_value.get() - *start_value,
186 static_cast<double>(duration)));
188 to_affect.set(tweened);
190 //CASPAR_LOG(info) << relative_frame << L" " << *start_value << L" " << duration << L" " << tweened;
193 store_keyframe(to_affect.identity(), k);
197 void add_keyframe(binding<T>& to_affect, T set_value, int64_t at_frame)
199 add_keyframe(to_affect, binding<T>(set_value), at_frame);
203 void add_keyframe(binding<T>& to_affect, const binding<T>& set_value, int64_t at_frame)
205 keyframe k(at_frame);
207 k.on_destination_frame = [=]() mutable
209 to_affect.bind(set_value);
212 store_keyframe(to_affect.identity(), k);
215 core::variable& get_variable(const std::wstring& name) override;
216 const std::vector<std::wstring>& get_variables() const override;
218 void store_keyframe(void* timeline_identity, const keyframe& k);
220 const std::wstring& name, const std::shared_ptr<core::variable>& var);
223 std::unique_ptr<impl> impl_;
226 spl::shared_ptr<frame_producer> create_dummy_scene_producer(const spl::shared_ptr<frame_factory>& frame_factory, const video_format_desc& format_desc, const std::vector<std::wstring>& params);