]> git.sesse.net Git - casparcg/blob - core/producer/scene/scene_producer.h
Merge branch '2.1.0' of https://github.com/CasparCG/Server into 2.1.0
[casparcg] / core / producer / scene / scene_producer.h
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
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.
10 *
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.
15 *
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/>.
18 *
19 * Author: Helge Norberg, helge.norberg@svt.se
20 */
21
22 #pragma once
23
24 #include "../frame_producer.h"
25
26 #include "../binding.h"
27
28 namespace caspar { namespace core { namespace scene {
29
30 struct coord
31 {
32         binding<double> x;
33         binding<double> y;
34 };
35
36 struct adjustments
37 {
38         binding<double> opacity;
39
40         adjustments();
41 };
42
43 struct layer
44 {
45         binding<std::wstring> name;
46         coord position;
47         adjustments adjustments;
48         binding<spl::shared_ptr<frame_producer>> producer;
49         binding<bool> hidden;
50         binding<bool> is_key;
51
52         explicit layer(const spl::shared_ptr<frame_producer>& producer);
53         layer(const std::wstring& name, const spl::shared_ptr<frame_producer>& producer);
54 };
55
56 template<typename T> class parameter_holder;
57
58 class parameter_holder_base
59 {
60 public:
61         virtual ~parameter_holder_base()
62         {
63         }
64
65         virtual void set(const std::wstring& raw_value) = 0;
66
67         template<typename T>
68         binding<T>& value()
69         {
70                 return dynamic_cast<parameter_holder<T>>(*this).value();
71         }
72 };
73
74 template<typename T>
75 class parameter_holder : public parameter_holder_base
76 {
77         binding<T> value_;
78 public:
79         parameter_holder(T initial_value)
80                 : value_(initial_value)
81         {
82         }
83
84         binding<T>& value()
85         {
86                 return value_;
87         }
88
89         virtual void set(const std::wstring& raw_value)
90         {
91                 value_.set(boost::lexical_cast<T>(raw_value));
92         }
93 };
94
95 class scene_producer : public frame_producer_base
96 {
97 public:
98         scene_producer(int width, int height);
99         ~scene_producer();
100
101         class draw_frame receive_impl() override;
102         constraints& pixel_constraints() override;
103         void on_interaction(const interaction_event::ptr& event) override;
104         bool collides(double x, double y) const override;
105         std::wstring print() const override;
106         std::wstring name() const override;
107         boost::unique_future<std::wstring>      call(const std::vector<std::wstring>& params) override;
108         boost::property_tree::wptree info() const override;
109         void subscribe(const monitor::observable::observer_ptr& o) override;
110         void unsubscribe(const monitor::observable::observer_ptr& o) override;
111         layer& create_layer(
112                         const spl::shared_ptr<frame_producer>& producer, int x, int y);
113         layer& create_layer(
114                         const spl::shared_ptr<frame_producer>& producer, int x, int y, const std::wstring& name);
115         layer& create_layer(const spl::shared_ptr<frame_producer>& producer);
116         binding<int64_t> frame();
117
118         template<typename T> binding<T>& create_parameter(const std::wstring& name, T initial_value = T())
119         {
120                 auto param = std::make_shared<parameter_holder<T>>(initial_value);
121
122                 store_parameter(name, param);
123
124                 return param->value();
125         }
126 private:
127         void store_parameter(
128                         const std::wstring& name,
129                         const std::shared_ptr<parameter_holder_base>& param);
130
131         struct impl;
132         std::unique_ptr<impl> impl_;
133 };
134
135 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);
136
137 }}}