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;
57 binding<double> contrast;
58 binding<double> saturation;
59 binding<double> brightness;
66 binding<double> min_input;
67 binding<double> max_input;
68 binding<double> gamma;
69 binding<double> min_output;
70 binding<double> max_output;
78 binding<double> target_hue;
79 binding<double> hue_width;
80 binding<double> min_saturation;
81 binding<double> min_brightness;
82 binding<double> softness;
83 binding<double> spill_suppress;
84 binding<double> spill_suppress_saturation;
89 binding<std::wstring> name;
91 scene::coord position;
93 scene::corners perspective;
95 binding<double> rotation;
96 scene::adjustments adjustments;
98 binding<spl::shared_ptr<frame_producer>> producer;
100 binding<bool> is_key;
101 binding<bool> use_mipmap;
102 binding<core::blend_mode> blend_mode;
103 scene::chroma_key chroma_key;
104 binding<double> volume;
106 explicit layer(const std::wstring& name, const spl::shared_ptr<frame_producer>& producer);
111 std::function<void ()> on_start_animate;
112 std::function<void (int64_t start_frame, int64_t current_frame)> on_animate_to;
113 std::function<void ()> on_destination_frame;
114 int64_t destination_frame;
116 keyframe(int64_t destination_frame)
117 : destination_frame(destination_frame)
122 enum class mark_action
130 mark_action get_mark_action(const std::wstring& name);
132 class scene_producer : public frame_producer_base
135 scene_producer(std::wstring producer_name, std::wstring template_name, int width, int height, const video_format_desc& format_desc);
138 draw_frame receive_impl() override;
139 constraints& pixel_constraints() override;
140 void on_interaction(const interaction_event::ptr& event) override;
141 bool collides(double x, double y) const override;
142 std::wstring print() const override;
143 std::wstring name() const override;
144 std::future<std::wstring> call(const std::vector<std::wstring>& params) override;
145 boost::property_tree::wptree info() const override;
146 monitor::subject& monitor_output();
149 const spl::shared_ptr<frame_producer>& producer, int x, int y, const std::wstring& name);
151 const spl::shared_ptr<frame_producer>& producer, const std::wstring& name);
152 void reverse_layers();
153 layer& get_layer(const std::wstring& name);
155 binding<int64_t> timeline_frame();
156 binding<double> speed();
158 template<typename T> binding<T>& create_variable(
159 const std::wstring& name, bool is_public, const std::wstring& expr = L"")
161 std::shared_ptr<core::variable> var =
162 std::make_shared<core::variable_impl<T>>(expr, is_public);
164 store_variable(name, var);
171 binding<T>& to_affect,
174 const std::wstring& easing)
176 add_keyframe(to_affect, binding<T>(destination_value), at_frame, easing);
181 binding<T>& to_affect,
182 const binding<T>& destination_value,
184 const std::wstring& easing)
188 add_keyframe(to_affect, destination_value, at_frame);
192 tweener tween(easing);
193 keyframe k(at_frame);
195 std::shared_ptr<T> start_value(new T);
197 k.on_start_animate = [=]() mutable
199 *start_value = to_affect.get();
203 k.on_destination_frame = [=]() mutable
205 to_affect.bind(destination_value);
209 [=](int64_t start_frame, int64_t current_frame) mutable
211 auto relative_frame = current_frame - start_frame;
212 auto duration = at_frame - start_frame;
213 auto tweened = static_cast<T>(tween(
214 static_cast<double>(relative_frame),
216 destination_value.get() - *start_value,
217 static_cast<double>(duration)));
219 to_affect.set(tweened);
221 //CASPAR_LOG(info) << relative_frame << L" " << *start_value << L" " << duration << L" " << tweened;
224 store_keyframe(to_affect.identity(), k);
228 void add_keyframe(binding<T>& to_affect, T set_value, int64_t at_frame)
230 add_keyframe(to_affect, binding<T>(set_value), at_frame);
234 void add_keyframe(binding<T>& to_affect, const binding<T>& set_value, int64_t at_frame)
236 keyframe k(at_frame);
238 k.on_destination_frame = [=]() mutable
240 to_affect.bind(set_value);
243 store_keyframe(to_affect.identity(), k);
246 void add_mark(int64_t at_frame, mark_action action, const std::wstring& label);
247 void add_task(binding<bool> when, std::function<void ()> task);
249 core::variable& get_variable(const std::wstring& name) override;
250 const std::vector<std::wstring>& get_variables() const override;
252 void store_keyframe(void* timeline_identity, const keyframe& k);
254 const std::wstring& name, const std::shared_ptr<core::variable>& var);
257 std::unique_ptr<impl> impl_;