]> git.sesse.net Git - casparcg/blobdiff - core/producer/scene/scene_producer.cpp
[scene_producer] Added possibility to CALL/CG PLAY/CG STOP/CG NEXT/CG INVOKE layers...
[casparcg] / core / producer / scene / scene_producer.cpp
index 708fd1428e8e1843ca1567c59cad60447c29644c..efcfa3516460e6f94b8149be1a0a8d44fc663b53 100644 (file)
 * Author: Helge Norberg, helge.norberg@svt.se
 */
 
-#include "../../stdafx.h"
+#include "../../StdAfx.h"
 
 #include <common/future.h>
+#include <common/prec_timer.h>
+
 #include <boost/algorithm/string/split.hpp>
 #include <boost/algorithm/string.hpp>
 
 
 #include "../../frame/draw_frame.h"
 #include "../../interaction/interaction_aggregator.h"
+#include "../text/text_producer.h"
 
 namespace caspar { namespace core { namespace scene {
 
-layer::layer(const spl::shared_ptr<frame_producer>& producer)
-       : producer(producer)
-{
-}
 layer::layer(const std::wstring& name, const spl::shared_ptr<frame_producer>& producer)
        : name(name), producer(producer)
 {
+       crop.lower_right.x.bind(producer.get()->pixel_constraints().width);
+       crop.lower_right.y.bind(producer.get()->pixel_constraints().height);
+       perspective.upper_right.x.bind(producer.get()->pixel_constraints().width);
+       perspective.lower_right.x.bind(producer.get()->pixel_constraints().width);
+       perspective.lower_right.y.bind(producer.get()->pixel_constraints().height);
+       perspective.lower_left.y.bind(producer.get()->pixel_constraints().height);
 }
 
 adjustments::adjustments()
@@ -46,89 +51,396 @@ adjustments::adjustments()
 {
 }
 
-struct scene_producer::impl
+struct timeline
 {
-       constraints pixel_constraints_;
-       std::list<layer> layers_;
-       interaction_aggregator aggregator_;
-       binding<int64_t> frame_number_;
+       std::map<int64_t, keyframe> keyframes;
 
-       impl(int width, int height)
-               : pixel_constraints_(width, height)
-               , aggregator_([=] (double x, double y) { return collission_detect(x, y); })
+       void on_frame(int64_t frame)
        {
+               auto before = --keyframes.upper_bound(frame);
+               bool found_before = before != keyframes.end() && before->first < frame;
+               auto after = keyframes.upper_bound(frame);
+               bool found_after = after != keyframes.end() && after->first > frame;
+               auto exact_frame = keyframes.find(frame);
+               bool found_exact_frame = exact_frame != keyframes.end();
+
+               if (found_exact_frame)
+               {
+                       exact_frame->second.on_destination_frame();
+
+                       auto next_frame = ++exact_frame;
+
+                       if (next_frame != keyframes.end() && next_frame->second.on_start_animate)
+                               next_frame->second.on_start_animate();
+               }
+               else if (found_after)
+               {
+                       int64_t start_frame = 0;
+
+                       if (found_before)
+                       {
+                               start_frame = before->first;
+                       }
+
+                       if (after->second.on_start_animate && frame == 0)
+                               after->second.on_start_animate();
+                       else if (after->second.on_animate_to)
+                               after->second.on_animate_to(start_frame, frame);
+               }
        }
+};
 
-       layer& create_layer(
-                       const spl::shared_ptr<frame_producer>& producer, int x, int y, const std::wstring& name)
+mark_action get_mark_action(const std::wstring& name)
+{
+       if (name == L"start")
+               return mark_action::start;
+       else if (name == L"stop")
+               return mark_action::stop;
+       else if (name == L"jump_to")
+               return mark_action::jump_to;
+       else if (name == L"remove")
+               return mark_action::remove;
+       else
+               CASPAR_THROW_EXCEPTION(user_error() << msg_info(L"Invalid mark_action " + name));
+}
+
+struct marker
+{
+       mark_action             action;
+       std::wstring    label_argument;
+
+       marker(mark_action action, const std::wstring& label_argument)
+               : action(action)
+               , label_argument(label_argument)
        {
-               layer& layer = create_layer(producer, x, y);
-               layer.name.set(name);
+       }
+};
 
-               return layer;
+struct scene_producer::impl
+{
+       std::wstring                                                                                    producer_name_;
+       std::wstring                                                                                    template_name_;
+       constraints                                                                                             pixel_constraints_;
+       video_format_desc                                                                               format_desc_;
+       std::list<layer>                                                                                layers_;
+       interaction_aggregator                                                                  aggregator_;
+       binding<double>                                                                                 frame_number_;
+       binding<int64_t>                                                                                timeline_frame_number_;
+       binding<double>                                                                                 speed_;
+       mutable tbb::atomic<int64_t>                                                    m_x_;
+       mutable tbb::atomic<int64_t>                                                    m_y_;
+       binding<int64_t>                                                                                mouse_x_;
+       binding<int64_t>                                                                                mouse_y_;
+       double                                                                                                  frame_fraction_         = 0.0;
+       std::map<void*, timeline>                                                               timelines_;
+       std::map<std::wstring, std::shared_ptr<core::variable>> variables_;
+       std::vector<std::wstring>                                                               variable_names_;
+       std::multimap<int64_t, marker>                                                  markers_by_frame_;
+       std::vector<std::shared_ptr<void>>                                              task_subscriptions_;
+       monitor::subject                                                                                monitor_subject_;
+       bool                                                                                                    paused_                         = true;
+       bool                                                                                                    removed_                        = false;
+       bool                                                                                                    going_to_mark_          = false;
+
+       impl(
+                       std::wstring producer_name,
+                       std::wstring template_name,
+                       int width,
+                       int height,
+                       const video_format_desc& format_desc)
+               : producer_name_(std::move(producer_name))
+               , template_name_(std::move(template_name))
+               , format_desc_(format_desc)
+               , aggregator_([=] (double x, double y) { return collission_detect(x, y); })
+       {
+               auto speed_variable = std::make_shared<core::variable_impl<double>>(L"1.0", true, 1.0);
+               store_variable(L"scene_speed", speed_variable);
+               speed_ = speed_variable->value();
+
+               auto frame_variable = std::make_shared<core::variable_impl<double>>(L"-1", true, -1);
+               store_variable(L"frame", frame_variable);
+               frame_number_ = frame_variable->value();
+
+               auto timeline_frame_variable = std::make_shared<core::variable_impl<int64_t>>(L"-1", false, -1);
+               store_variable(L"timeline_frame", timeline_frame_variable);
+               timeline_frame_number_ = timeline_frame_variable->value();
+
+               auto mouse_x_variable = std::make_shared<core::variable_impl<int64_t>>(L"0", false, 0);
+               auto mouse_y_variable = std::make_shared<core::variable_impl<int64_t>>(L"0", false, 0);
+               store_variable(L"mouse_x", mouse_x_variable);
+               store_variable(L"mouse_y", mouse_y_variable);
+               mouse_x_ = mouse_x_variable->value();
+               mouse_y_ = mouse_y_variable->value();
+               m_x_ = 0;
+               m_y_ = 0;
+
+               auto scene_width = std::make_shared<core::variable_impl<double>>(boost::lexical_cast<std::wstring>(width), false, width);
+               auto scene_height = std::make_shared<core::variable_impl<double>>(boost::lexical_cast<std::wstring>(height), false, height);
+               store_variable(L"scene_width", scene_width);
+               store_variable(L"scene_height", scene_height);
+               pixel_constraints_.width = scene_width->value();
+               pixel_constraints_.height = scene_height->value();
        }
 
        layer& create_layer(
-                       const spl::shared_ptr<frame_producer>& producer, int x, int y)
+                       const spl::shared_ptr<frame_producer>& producer, int x, int y, const std::wstring& name)
        {
-               layer& layer = create_layer(producer);
+               layer layer(name, producer);
 
                layer.position.x.set(x);
                layer.position.y.set(y);
 
-               return layer;
+               layers_.push_back(layer);
+
+               return layers_.back();
        }
 
-       layer& create_layer(const spl::shared_ptr<frame_producer>& producer)
+       void reverse_layers() {
+               layers_.reverse();
+       }
+
+       layer& get_layer(const std::wstring& name)
        {
-               layer layer(producer);
+               for (auto& layer : layers_)
+                       if (layer.name.get() == name)
+                               return layer;
 
-               layers_.push_back(layer);
+               CASPAR_THROW_EXCEPTION(user_error() << msg_info(name + L" not found in scene"));
+       }
 
-               return layers_.back();
+       void store_keyframe(void* timeline_identity, const keyframe& k)
+       {
+               timelines_[timeline_identity].keyframes.insert(std::make_pair(k.destination_frame, k));
+       }
+
+       void store_variable(
+                       const std::wstring& name, const std::shared_ptr<core::variable>& var)
+       {
+               variables_.insert(std::make_pair(name, var));
+               variable_names_.push_back(name);
+       }
+
+       void add_mark(int64_t frame, mark_action action, const std::wstring& label)
+       {
+               markers_by_frame_.insert(std::make_pair(frame, marker(action, label)));
+       }
+
+       void add_task(binding<bool> when, std::function<void ()> task)
+       {
+               auto subscription = when.on_change([=]
+               {
+                       if (when.get())
+                       {
+                               try
+                               {
+                                       task();
+                               }
+                               catch (...)
+                               {
+                                       CASPAR_LOG_CURRENT_EXCEPTION_AT_LEVEL(debug);
+                                       CASPAR_LOG(error) << print() << " Error when invoking scene task. Turn on log level debug for stacktrace.";
+                               }
+                       }
+               });
+
+               task_subscriptions_.push_back(std::move(subscription));
+       }
+
+       core::variable& get_variable(const std::wstring& name)
+       {
+               auto found = variables_.find(name);
+
+               if (found == variables_.end())
+                       CASPAR_THROW_EXCEPTION(user_error() << msg_info(name + L" not found in scene"));
+
+               return *found->second;
+       }
+
+       const std::vector<std::wstring>& get_variables() const
+       {
+               return variable_names_;
        }
 
-       binding<int64_t> frame()
+       binding<int64_t> timeline_frame()
        {
-               return frame_number_;
+               return timeline_frame_number_;
        }
 
        frame_transform get_transform(const layer& layer) const
        {
                frame_transform transform;
 
-               auto& pos = transform.image_transform.fill_translation;
-               auto& scale = transform.image_transform.fill_scale;
+               auto& anchor            = transform.image_transform.anchor;
+               auto& pos                       = transform.image_transform.fill_translation;
+               auto& scale                     = transform.image_transform.fill_scale;
+               auto& angle                     = transform.image_transform.angle;
+               auto& crop                      = transform.image_transform.crop;
+               auto& pers                      = transform.image_transform.perspective;
+
+               anchor[0]       = layer.anchor.x.get()                                                                          / layer.producer.get()->pixel_constraints().width.get();
+               anchor[1]       = layer.anchor.y.get()                                                                          / layer.producer.get()->pixel_constraints().height.get();
+               pos[0]          = layer.position.x.get()                                                                        / pixel_constraints_.width.get();
+               pos[1]          = layer.position.y.get()                                                                        / pixel_constraints_.height.get();
+               scale[0]        = layer.producer.get()->pixel_constraints().width.get()         / pixel_constraints_.width.get();
+               scale[1]        = layer.producer.get()->pixel_constraints().height.get()        / pixel_constraints_.height.get();
+               crop.ul[0]      = layer.crop.upper_left.x.get()                                                         / layer.producer.get()->pixel_constraints().width.get();
+               crop.ul[1]      = layer.crop.upper_left.y.get()                                                         / layer.producer.get()->pixel_constraints().height.get();
+               crop.lr[0]      = layer.crop.lower_right.x.get()                                                        / layer.producer.get()->pixel_constraints().width.get();
+               crop.lr[1]      = layer.crop.lower_right.y.get()                                                        / layer.producer.get()->pixel_constraints().height.get();
+               pers.ul[0]      = layer.perspective.upper_left.x.get()                                          / layer.producer.get()->pixel_constraints().width.get();
+               pers.ul[1]      = layer.perspective.upper_left.y.get()                                          / layer.producer.get()->pixel_constraints().height.get();
+               pers.ur[0]      = layer.perspective.upper_right.x.get()                                         / layer.producer.get()->pixel_constraints().width.get();
+               pers.ur[1]      = layer.perspective.upper_right.y.get()                                         / layer.producer.get()->pixel_constraints().height.get();
+               pers.lr[0]      = layer.perspective.lower_right.x.get()                                         / layer.producer.get()->pixel_constraints().width.get();
+               pers.lr[1]      = layer.perspective.lower_right.y.get()                                         / layer.producer.get()->pixel_constraints().height.get();
+               pers.ll[0]      = layer.perspective.lower_left.x.get()                                          / layer.producer.get()->pixel_constraints().width.get();
+               pers.ll[1]      = layer.perspective.lower_left.y.get()                                          / layer.producer.get()->pixel_constraints().height.get();
+
+               static const double PI = 3.141592653589793;
+
+               angle           = layer.rotation.get() * PI / 180.0;
+
+               transform.image_transform.opacity                               = layer.adjustments.opacity.get();
+               transform.image_transform.is_key                                = layer.is_key.get();
+               transform.image_transform.use_mipmap                    = layer.use_mipmap.get();
+               transform.image_transform.blend_mode                    = layer.blend_mode.get();
+               transform.image_transform.chroma.enable                 = layer.chroma_key.enable.get();
+               transform.image_transform.chroma.target_hue             = layer.chroma_key.target_hue.get();
+               transform.image_transform.chroma.hue_width              = layer.chroma_key.hue_width.get();
+               transform.image_transform.chroma.min_saturation = layer.chroma_key.min_saturation.get();
+               transform.image_transform.chroma.min_brightness = layer.chroma_key.min_brightness.get();
+               transform.image_transform.chroma.softness               = layer.chroma_key.softness.get();
+               transform.image_transform.chroma.spill                  = layer.chroma_key.spill.get();
+               transform.image_transform.chroma.spill_darken   = layer.chroma_key.spill_darken.get();
+
+               // Mark as sublayer, so it will be composited separately by the mixer.
+               transform.image_transform.layer_depth = 1;
 
-               pos[0] = static_cast<double>(layer.position.x.get()) / static_cast<double>(pixel_constraints_.width.get());
-               pos[1] = static_cast<double>(layer.position.y.get()) / static_cast<double>(pixel_constraints_.height.get());
-               scale[0] = static_cast<double>(layer.producer.get()->pixel_constraints().width.get())
-                               / static_cast<double>(pixel_constraints_.width.get());
-               scale[1] = static_cast<double>(layer.producer.get()->pixel_constraints().height.get())
-                               / static_cast<double>(pixel_constraints_.height.get());
+               return transform;
+       }
 
-               transform.image_transform.opacity = layer.adjustments.opacity.get();
-               transform.image_transform.is_key = layer.is_key.get();
+       boost::optional<std::pair<int64_t, marker>> find_first_stop_or_jump_or_remove(int64_t start_frame, int64_t end_frame)
+       {
+               auto lower = markers_by_frame_.lower_bound(start_frame);
+               auto upper = markers_by_frame_.upper_bound(end_frame);
 
-               return transform;
+               if (lower == markers_by_frame_.end())
+                       return boost::none;
+
+               for (auto iter = lower; iter != upper; ++iter)
+               {
+                       auto action = iter->second.action;
+
+                       if (action == mark_action::stop || action == mark_action::jump_to || action == mark_action::remove)
+                               return std::make_pair(iter->first, iter->second);
+               }
+
+               return boost::none;
+       }
+
+       boost::optional<std::pair<int64_t, marker>> find_first_start(int64_t start_frame)
+       {
+               auto lower = markers_by_frame_.lower_bound(start_frame);
+
+               if (lower == markers_by_frame_.end())
+                       return boost::none;
+
+               for (auto iter = lower; iter != markers_by_frame_.end(); ++iter)
+               {
+                       auto action = iter->second.action;
+
+                       if (action == mark_action::start)
+                               return std::make_pair(iter->first, iter->second);
+               }
+
+               return boost::none;
        }
 
        draw_frame render_frame()
        {
+               if (format_desc_.field_count == 1)
+                       return render_progressive_frame();
+               else
+               {
+                       prec_timer timer;
+                       timer.tick_millis(0);
+
+                       auto field1 = render_progressive_frame();
+
+                       timer.tick(0.5 / format_desc_.fps);
+
+                       auto field2 = render_progressive_frame();
+
+                       return draw_frame::interlace(field1, field2, format_desc_.field_mode);
+               }
+       }
+
+       void advance()
+       {
+               frame_fraction_ += speed_.get();
+
+               if (std::abs(frame_fraction_) >= 1.0)
+               {
+                       int64_t delta = static_cast<int64_t>(frame_fraction_);
+                       auto previous_frame = timeline_frame_number_.get();
+                       auto next_frame = timeline_frame_number_.get() + delta;
+                       auto marker = find_first_stop_or_jump_or_remove(previous_frame + 1, next_frame);
+
+                       if (marker && marker->second.action == mark_action::remove)
+                       {
+                               remove();
+                       }
+                       if (marker && !going_to_mark_)
+                       {
+                               if (marker->second.action == mark_action::stop)
+                               {
+                                       timeline_frame_number_.set(marker->first);
+                                       frame_fraction_ = 0.0;
+                                       paused_ = true;
+                               }
+                               else if (marker->second.action == mark_action::jump_to)
+                               {
+                                       go_to_marker(marker->second.label_argument, 0);
+                               }
+                       }
+                       else
+                       {
+                               timeline_frame_number_.set(next_frame);
+                               frame_fraction_ -= delta;
+                       }
+
+                       going_to_mark_ = false;
+               }
+       }
+
+       draw_frame render_progressive_frame()
+       {
+               if (removed_)
+                       return draw_frame::empty();
+
+               mouse_x_.set(m_x_);
+               mouse_y_.set(m_y_);
+
+               if (!paused_)
+                       advance();
+
+               frame_number_.set(frame_number_.get() + speed_.get());
+
+               for (auto& timeline : timelines_)
+                       timeline.second.on_frame(timeline_frame_number_.get());
+
                std::vector<draw_frame> frames;
 
-               BOOST_FOREACH(auto& layer, layers_)
+               for (auto& layer : layers_)
                {
                        if (layer.hidden.get())
                                continue;
 
                        draw_frame frame(layer.producer.get()->receive());
-                       frame.transform() = get_transform(layer);;
+                       frame.transform() = get_transform(layer);
                        frames.push_back(frame);
                }
 
-               frame_number_.set(frame_number_.get() + 1);
-
                return draw_frame(frames);
        }
 
@@ -139,12 +451,15 @@ struct scene_producer::impl
 
        bool collides(double x, double y) const
        {
-               return collission_detect(x, y);
+               m_x_ = static_cast<int64_t>(x * pixel_constraints_.width.get());
+               m_y_ = static_cast<int64_t>(y * pixel_constraints_.height.get());
+
+               return static_cast<bool>((collission_detect(x, y)));
        }
 
        boost::optional<interaction_target> collission_detect(double x, double y) const
        {
-               BOOST_FOREACH(auto& layer, layers_ | boost::adaptors::reversed)
+               for (auto& layer : layers_ | boost::adaptors::reversed)
                {
                        if (layer.hidden.get())
                                continue;
@@ -158,66 +473,158 @@ struct scene_producer::impl
                                && translated.second <= 1.0
                                && layer.producer.get()->collides(translated.first, translated.second))
                        {
-                               return std::make_pair(transform, layer.producer.get().get());
+                               return std::make_pair(transform, static_cast<interaction_sink*>(layer.producer.get().get()));
                        }
                }
 
                return boost::optional<interaction_target>();
        }
 
-       boost::unique_future<std::wstring> call(const std::vector<std::wstring>& params) 
+       std::future<std::wstring> call(const std::vector<std::wstring>& params)
        {
-               std::wstring result;
-               
-               if(params.size() >= 2)
+               if (!params.empty() && boost::ends_with(params.at(0), L"()"))
+                       return make_ready_future(handle_call(params));
+               else
+                       return make_ready_future(handle_variable_set(params));
+       }
+
+       std::wstring handle_variable_set(const std::vector<std::wstring>& params)
+       {
+               for (int i = 0; i + 1 < params.size(); i += 2)
                {
-                       struct layer_comparer
-                       {
-                               const std::wstring& str;
-                               explicit layer_comparer(const std::wstring& s) : str(s) {}
-                               bool operator()(const layer& val) { return boost::iequals(val.name.get(), str); }
-                       };
+                       auto found = variables_.find(boost::to_lower_copy(params.at(i)));
+
+                       if (found != variables_.end() && found->second->is_public())
+                               found->second->from_string(params.at(i + 1));
+               }
+
+               return L"";
+       }
+
+       std::wstring handle_call(const std::vector<std::wstring>& params)
+       {
+               auto call = params.at(0);
+
+               if (call == L"play()")
+                       go_to_marker(params.at(1), -1);
+               else if (call == L"remove()")
+                       remove();
+               else if (call == L"next()")
+                       next();
+               else
+                       CASPAR_THROW_EXCEPTION(user_error() << msg_info(L"Unknown call " + call));
+
+               return L"";
+       }
 
-                       auto it = std::find_if(layers_.begin(), layers_.end(), layer_comparer(params[0]));
-                       if(it != layers_.end())
+       void remove()
+       {
+               removed_ = true;
+               layers_.clear();
+       }
+
+       void next()
+       {
+               auto marker = find_first_start(timeline_frame_number_.get() + 1);
+
+               if (marker)
+               {
+                       timeline_frame_number_.set(marker->first - 1);
+                       frame_fraction_ = 0.0;
+                       paused_ = false;
+                       going_to_mark_ = true;
+               }
+               else
+               {
+                       remove();
+               }
+       }
+
+       void go_to_marker(const std::wstring& marker_name, int64_t offset)
+       {
+               for (auto& marker : markers_by_frame_)
+               {
+                       if (marker.second.label_argument == marker_name && marker.second.action == mark_action::start)
                        {
-                               auto params2 = params;
-                               params2.erase(params2.cbegin());
-                               (*it).producer.get()->call(params2);
+                               timeline_frame_number_.set(marker.first + offset);
+                               frame_fraction_ = 0.0;
+                               paused_ = false;
+                               going_to_mark_ = true;
+
+                               return;
                        }
                }
 
-               return async(launch::deferred, [=]{return result;});
+               if (marker_name == L"intro")
+               {
+                       timeline_frame_number_.set(offset);
+                       frame_fraction_ = 0.0;
+                       paused_ = false;
+                       going_to_mark_ = true;
+               }
+               else if (marker_name == L"outro")
+               {
+                       remove();
+               }
+               else
+                       CASPAR_LOG(info) << print() << L" no marker called " << marker_name << " found";
        }
 
        std::wstring print() const
        {
-               return L"scene[]";
+               return L"scene[type=" + name() + L" template=" + template_name_ + L"]";
        }
 
        std::wstring name() const
        {
-               return L"scene";
+               return producer_name_;
        }
-       
+
        boost::property_tree::wptree info() const
        {
                boost::property_tree::wptree info;
                info.add(L"type", L"scene");
-               return info;
-       }
+               info.add(L"producer-name", name());
+               info.add(L"template-name", template_name_);
+               info.add(L"frame-number", frame_number_.get());
+               info.add(L"timeline-frame-number", timeline_frame_number_.get());
 
-       void subscribe(const monitor::observable::observer_ptr& o)
-       {
+               for (auto& var : variables_)
+               {
+                       boost::property_tree::wptree variable_info;
+
+                       variable_info.add(L"name", var.first);
+                       variable_info.add(L"public", var.second->is_public());
+                       variable_info.add(L"value", var.second->to_string());
+
+                       info.add_child(L"variables.variable", variable_info);
+               }
+
+               for (auto& layer : layers_)
+               {
+                       boost::property_tree::wptree layer_info;
+
+                       layer_info.add(L"name", layer.name.get());
+                       layer_info.add_child(L"producer", layer.producer.get()->info());
+                       layer_info.add(L"x", layer.position.x.get());
+                       layer_info.add(L"y", layer.position.y.get());
+                       layer_info.add(L"width", layer.producer.get()->pixel_constraints().width.get());
+                       layer_info.add(L"height", layer.producer.get()->pixel_constraints().height.get());
+
+                       info.add_child(L"layers.layer", layer_info);
+               }
+
+               return info;
        }
 
-       void unsubscribe(const monitor::observable::observer_ptr& o)
+       monitor::subject& monitor_output()
        {
+               return monitor_subject_;
        }
 };
 
-scene_producer::scene_producer(int width, int height)
-       : impl_(new impl(width, height))
+scene_producer::scene_producer(std::wstring producer_name, std::wstring template_name, int width, int height, const video_format_desc& format_desc)
+       : impl_(new impl(std::move(producer_name), std::move(template_name), width, height, format_desc))
 {
 }
 
@@ -226,26 +633,30 @@ scene_producer::~scene_producer()
 }
 
 layer& scene_producer::create_layer(
-               const spl::shared_ptr<frame_producer>& producer, int x, int y)
+               const spl::shared_ptr<frame_producer>& producer, int x, int y, const std::wstring& name)
 {
-       return impl_->create_layer(producer, x, y);
+       return impl_->create_layer(producer, x, y, name);
 }
 
 layer& scene_producer::create_layer(
-               const spl::shared_ptr<frame_producer>& producer, int x, int y, const std::wstring& name)
+               const spl::shared_ptr<frame_producer>& producer, const std::wstring& name)
 {
-       return impl_->create_layer(producer, x, y, name);
+       return impl_->create_layer(producer, 0, 0, name);
 }
 
-layer& scene_producer::create_layer(
-               const spl::shared_ptr<frame_producer>& producer)
+void scene_producer::reverse_layers()
 {
-       return impl_->create_layer(producer);
+       impl_->reverse_layers();
 }
 
-binding<int64_t> scene_producer::frame()
+layer& scene_producer::get_layer(const std::wstring& name)
 {
-       return impl_->frame();
+       return impl_->get_layer(name);
+}
+
+binding<int64_t> scene_producer::timeline_frame()
+{
+       return impl_->timeline_frame();
 }
 
 draw_frame scene_producer::receive_impl()
@@ -280,88 +691,45 @@ boost::property_tree::wptree scene_producer::info() const
        return impl_->info();
 }
 
-boost::unique_future<std::wstring> scene_producer::call(const std::vector<std::wstring>& params) 
+std::future<std::wstring> scene_producer::call(const std::vector<std::wstring>& params)
 {
        return impl_->call(params);
 }
 
-void scene_producer::subscribe(const monitor::observable::observer_ptr& o)
+monitor::subject& scene_producer::monitor_output()
 {
-       impl_->subscribe(o);
+       return impl_->monitor_output();
 }
 
-void scene_producer::unsubscribe(const monitor::observable::observer_ptr& o)
+void scene_producer::store_keyframe(void* timeline_identity, const keyframe& k)
 {
-       impl_->unsubscribe(o);
+       impl_->store_keyframe(timeline_identity, k);
 }
 
-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)
+void scene_producer::store_variable(
+               const std::wstring& name, const std::shared_ptr<core::variable>& var)
 {
-       if (params.size() < 1 || !boost::iequals(params.at(0), L"[SCENE]"))
-               return core::frame_producer::empty();
-
-       auto scene = spl::make_shared<scene_producer>(format_desc.width, format_desc.height);
+       impl_->store_variable(name, var);
+}
 
-       binding<double> text_width(10);
-       binding<double> padding(1);
-       binding<double> panel_width = padding + text_width + padding;
-       binding<double> panel_height(50);
+void scene_producer::add_mark(int64_t frame, mark_action action, const std::wstring& label)
+{
+       impl_->add_mark(frame, action, label);
+}
 
-       auto subscription = panel_width.on_change([&]
-       {
-               CASPAR_LOG(info) << "Panel width: " << panel_width.get();
-       });
+void scene_producer::add_task(binding<bool> when, std::function<void ()> task)
+{
+       impl_->add_task(std::move(when), std::move(task));
+}
 
-       text_width.set(20);
-       text_width.set(10);
-       padding.set(2);
-       text_width.set(20);
+core::variable& scene_producer::get_variable(const std::wstring& name)
+{
+       return impl_->get_variable(name);
+}
 
-       auto create_param = [](std::wstring elem) -> std::vector<std::wstring>
-       {
-               std::vector<std::wstring> result;
-               result.push_back(elem);
-               return result;
-       };
-
-       auto& car_layer = scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"car")));
-       car_layer.hidden = scene->frame() % 50 > 25 || !(scene->frame() < 1000);
-       std::vector<std::wstring> sub_params;
-       sub_params.push_back(L"[FREEHAND]");
-       sub_params.push_back(L"640");
-       sub_params.push_back(L"360");
-       scene->create_layer(create_producer(frame_factory, format_desc, sub_params), 10, 10);
-       sub_params.clear();
-
-       scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"BLUE")), 110, 10);
-
-       //scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"SP")), 50, 50);
-
-       auto& upper_left = scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"scene/upper_left")));
-       auto& upper_right = scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"scene/upper_right")));
-       auto& lower_left = scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"scene/lower_left")));
-       auto& lower_right = scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"scene/lower_right")));
-
-       binding<double> panel_x = (scene->frame()
-                       .as<double>()
-                       .transformed([](double v) { return std::sin(v / 20.0); })
-                       * 20.0
-                       + 40.0)
-                       .transformed([](double v) { return std::floor(v); }); // snap to pixels instead of subpixels
-       binding<double> panel_y = when(car_layer.hidden).then(500.0).otherwise(-panel_x + 300);
-       upper_left.position.x = panel_x;
-       upper_left.position.y = panel_y;
-       upper_right.position.x = upper_left.position.x + upper_left.producer.get()->pixel_constraints().width + panel_width;
-       upper_right.position.y = upper_left.position.y;
-       lower_left.position.x = upper_left.position.x;
-       lower_left.position.y = upper_left.position.y + upper_left.producer.get()->pixel_constraints().height + panel_height;
-       lower_right.position.x = upper_right.position.x;
-       lower_right.position.y = lower_left.position.y;
-
-       text_width.set(500);
-       panel_height.set(50);
-
-       return scene;
+const std::vector<std::wstring>& scene_producer::get_variables() const
+{
+       return impl_->get_variables();
 }
 
 }}}