]> git.sesse.net Git - casparcg/commitdiff
Initial XML format for scenes and timeline support for PSD
authorHelge Norberg <helge.norberg@svt.se>
Fri, 16 Aug 2013 12:26:24 +0000 (14:26 +0200)
committerHelge Norberg <helge.norberg@svt.se>
Fri, 16 Aug 2013 12:26:24 +0000 (14:26 +0200)
.gitignore
core/core.vcxproj
core/core.vcxproj.filters
core/producer/scene/scene_producer.cpp
core/producer/scene/scene_producer.h
core/producer/scene/xml_scene_producer.cpp [new file with mode: 0644]
core/producer/scene/xml_scene_producer.h [new file with mode: 0644]
core/producer/variable.h [new file with mode: 0644]
modules/psd/descriptor.cpp
modules/psd/psd_scene_producer.cpp
shell/server.cpp

index a3a3de79b96008912a89f87298488104f4a767a2..80ff62c6820d8fe349b64c739afeaea922eb89ab 100644 (file)
 freetype
 tmp
 bin
+x64
index 8ea75ed814f766711a917721808e6dfcc7f1ad2e..8b2286b54e81704f134eb09b1fea5fca2b990a7e 100644 (file)
     <ClInclude Include="producer\scene\const_producer.h" />\r
     <ClInclude Include="producer\scene\hotswap_producer.h" />\r
     <ClInclude Include="producer\scene\scene_producer.h" />\r
+    <ClInclude Include="producer\scene\xml_scene_producer.h" />\r
     <ClInclude Include="producer\text\text_producer.h" />\r
     <ClInclude Include="producer\text\utils\color.h" />\r
     <ClInclude Include="producer\text\utils\string_metrics.h" />\r
     <ClInclude Include="producer\text\utils\texture_atlas.h" />\r
     <ClInclude Include="producer\text\utils\texture_font.h" />\r
+    <ClInclude Include="producer\variable.h" />\r
     <ClInclude Include="video_channel.h" />\r
     <ClInclude Include="consumer\output.h" />\r
     <ClInclude Include="consumer\frame_consumer.h" />\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">../../StdAfx.h</PrecompiledHeaderFile>\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">../../StdAfx.h</PrecompiledHeaderFile>\r
     </ClCompile>\r
+    <ClCompile Include="producer\scene\xml_scene_producer.cpp">\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">../../StdAfx.h</PrecompiledHeaderFile>\r
+    </ClCompile>\r
     <ClCompile Include="producer\text\text_producer.cpp">\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">../../StdAfx.h</PrecompiledHeaderFile>\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">../../StdAfx.h</PrecompiledHeaderFile>\r
index a0725384cb0ba4f3e1f1c96870e76e8f2f9e0a53..15ca47fc6082f3c77d6fb96b682195327e9e2b95 100644 (file)
     <ClInclude Include="producer\scene\hotswap_producer.h">\r
       <Filter>source\producer\scene</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="producer\scene\xml_scene_producer.h">\r
+      <Filter>source\producer\scene</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="producer\variable.h">\r
+      <Filter>source\producer</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClCompile Include="producer\transition\transition_producer.cpp">\r
     <ClCompile Include="producer\scene\hotswap_producer.cpp">\r
       <Filter>source\producer\scene</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="producer\scene\xml_scene_producer.cpp">\r
+      <Filter>source\producer\scene</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
 </Project>
\ No newline at end of file
index d8f2df0dc1089610cfbfc89df53e10055c8c399b..6b1b6b8f0b5a579e7cb61559225a74085a0afc1d 100644 (file)
 
 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)
 {
+       clipping.width.bind(producer.get()->pixel_constraints().width);
+       clipping.height.bind(producer.get()->pixel_constraints().height);
 }
 
 adjustments::adjustments()
@@ -92,54 +90,53 @@ struct scene_producer::impl
        std::list<layer> layers_;
        interaction_aggregator aggregator_;
        binding<int64_t> frame_number_;
-       std::map<std::wstring, std::shared_ptr<parameter_holder_base>> parameters_;
+       binding<double> speed_;
+       double frame_fraction_;
        std::map<void*, timeline> timelines_;
+       std::map<std::wstring, std::shared_ptr<core::variable>> variables_;
 
        impl(int width, int height)
                : pixel_constraints_(width, height)
                , aggregator_([=] (double x, double y) { return collission_detect(x, y); })
+               , frame_fraction_(0)
        {
+               auto speed_variable = std::make_shared<core::variable_impl<double>>(L"", true, 1.0);
+               store_variable(L"scene_speed", speed_variable);
+               speed_ = speed_variable->value();
        }
 
        layer& create_layer(
                        const spl::shared_ptr<frame_producer>& producer, int x, int y, const std::wstring& name)
        {
-               layer& layer = create_layer(producer, x, y);
-               layer.name.set(name);
-
-               return layer;
-       }
-
-       layer& create_layer(
-                       const spl::shared_ptr<frame_producer>& producer, int x, int y)
-       {
-               layer& layer = create_layer(producer);
+               layer layer(name, producer);
 
                layer.position.x.set(x);
                layer.position.y.set(y);
 
-               return layer;
-       }
-
-       layer& create_layer(const spl::shared_ptr<frame_producer>& producer)
-       {
-               layer layer(producer);
-
                layers_.push_back(layer);
 
                return layers_.back();
        }
 
-       void store_parameter(
-                       const std::wstring& name,
-                       const std::shared_ptr<parameter_holder_base>& param)
+       void store_keyframe(void* timeline_identity, const keyframe& k)
        {
-               parameters_.insert(std::make_pair(boost::to_lower_copy(name), param));
+               timelines_[timeline_identity].keyframes.insert(std::make_pair(k.destination_frame, k));
        }
 
-       void store_keyframe(void* timeline_identity, const keyframe& k)
+       void store_variable(
+                       const std::wstring& name, const std::shared_ptr<core::variable>& var)
        {
-               timelines_[timeline_identity].keyframes.insert(std::make_pair(k.destination_frame, k));
+               variables_.insert(std::make_pair(name, var));
+       }
+
+       core::variable& get_variable(const std::wstring& name)
+       {
+               auto found = variables_.find(name);
+
+               if (found == variables_.end())
+                       CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(name + L" not found in scene"));
+
+               return *found->second;
        }
 
        binding<int64_t> frame()
@@ -184,7 +181,14 @@ struct scene_producer::impl
                        frames.push_back(frame);
                }
 
-               ++frame_number_;
+               frame_fraction_ += speed_.get();
+
+               if (std::abs(frame_fraction_) >= 1.0)
+               {
+                       int64_t delta = static_cast<int64_t>(frame_fraction_);
+                       frame_number_.set(frame_number_.get() + delta);
+                       frame_fraction_ -= delta;
+               }
 
                return draw_frame(frames);
        }
@@ -226,10 +230,10 @@ struct scene_producer::impl
        {
                for (int i = 0; i + 1 < params.size(); i += 2)
                {
-                       auto found = parameters_.find(boost::to_lower_copy(params[i]));
+                       auto found = variables_.find(boost::to_lower_copy(params[i]));
 
-                       if (found != parameters_.end())
-                               found->second->set(params[i + 1]);
+                       if (found != variables_.end() && found->second->is_public())
+                               found->second->from_string(params[i + 1]);
                }
 
                return wrap_as_future(std::wstring(L""));
@@ -270,12 +274,6 @@ scene_producer::~scene_producer()
 {
 }
 
-layer& scene_producer::create_layer(
-               const spl::shared_ptr<frame_producer>& producer, int x, int y)
-{
-       return impl_->create_layer(producer, x, y);
-}
-
 layer& scene_producer::create_layer(
                const spl::shared_ptr<frame_producer>& producer, int x, int y, const std::wstring& name)
 {
@@ -283,9 +281,9 @@ layer& scene_producer::create_layer(
 }
 
 layer& scene_producer::create_layer(
-               const spl::shared_ptr<frame_producer>& producer)
+               const spl::shared_ptr<frame_producer>& producer, const std::wstring& name)
 {
-       return impl_->create_layer(producer);
+       return impl_->create_layer(producer, 0, 0, name);
 }
 
 binding<int64_t> scene_producer::frame()
@@ -340,19 +338,23 @@ void scene_producer::unsubscribe(const monitor::observable::observer_ptr& o)
        impl_->unsubscribe(o);
 }
 
-void scene_producer::store_parameter(
-               const std::wstring& name,
-               const std::shared_ptr<parameter_holder_base>& param)
+void scene_producer::store_keyframe(void* timeline_identity, const keyframe& k)
 {
-       impl_->store_parameter(name, param);
+       impl_->store_keyframe(timeline_identity, k);
 }
 
-void scene_producer::store_keyframe(void* timeline_identity, const keyframe& k)
+void scene_producer::store_variable(
+               const std::wstring& name, const std::shared_ptr<core::variable>& var)
 {
-       impl_->store_keyframe(timeline_identity, k);
+       impl_->store_variable(name, var);
 }
 
-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)
+core::variable& scene_producer::get_variable(const std::wstring& name)
+{
+       return impl_->get_variable(name);
+}
+
+spl::shared_ptr<core::frame_producer> create_dummy_scene_producer(const spl::shared_ptr<core::frame_factory>& frame_factory, const video_format_desc& format_desc, const std::vector<std::wstring>& params)
 {
        if (params.size() < 1 || !boost::iequals(params.at(0), L"[SCENE]"))
                return core::frame_producer::empty();
@@ -393,18 +395,24 @@ spl::shared_ptr<frame_producer> create_dummy_scene_producer(const spl::shared_pt
        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);
+       scene->create_layer(create_producer(frame_factory, format_desc, sub_params), 10, 10, L"freehand");
        sub_params.clear();
 
-       scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"BLUE")), 110, 10);
+       auto& color_layer = scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"RED")), 110, 10, L"color");
+       color_layer.producer.get()->pixel_constraints().width.set(1000);
+       color_layer.producer.get()->pixel_constraints().height.set(550);
 
        //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")));
-       auto& text_layer = scene->create_layer(text_area);
+       auto& upper_left = scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"scene/upper_left")), L"upper_left");
+       auto& upper_right = scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"scene/upper_right")), L"upper_right");
+       auto& lower_left = scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"scene/lower_left")), L"lower_left");
+       auto& lower_right = scene->create_layer(create_producer(frame_factory, format_desc, create_param(L"scene/lower_right")), L"lower_right");
+       auto& text_layer = scene->create_layer(text_area, L"text_area");
+       upper_left.adjustments.opacity.bind(text_layer.adjustments.opacity);
+       upper_right.adjustments.opacity.bind(text_layer.adjustments.opacity);
+       lower_left.adjustments.opacity.bind(text_layer.adjustments.opacity);
+       lower_right.adjustments.opacity.bind(text_layer.adjustments.opacity);
 
        /*
        binding<double> panel_x = (scene->frame()
@@ -429,6 +437,11 @@ spl::shared_ptr<frame_producer> create_dummy_scene_producer(const spl::shared_pt
        binding<double> panel_y(500.0);
        scene->add_keyframe(panel_y, panel_y.get(), 50 * 4);
        scene->add_keyframe(panel_y, 720.0, 50 * 5, L"easeinexpo");
+
+       scene->add_keyframe(text_layer.adjustments.opacity, 1.0, 100);
+       scene->add_keyframe(text_layer.adjustments.opacity, 0.0, 125, L"linear");
+       scene->add_keyframe(text_layer.adjustments.opacity, 1.0, 150, L"linear");
+
        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;
@@ -440,7 +453,7 @@ spl::shared_ptr<frame_producer> create_dummy_scene_producer(const spl::shared_pt
        text_layer.position.x = upper_left.position.x + upper_left.producer.get()->pixel_constraints().width + padding;
        text_layer.position.y = upper_left.position.y + upper_left.producer.get()->pixel_constraints().height + padding + text_area->current_bearing_y().as<double>();
 
-       text_area->text().bind(scene->create_parameter<std::wstring>(L"text"));
+       text_area->text().bind(scene->create_variable<std::wstring>(L"text", true));
 
        auto params2 = params;
        params2.erase(params2.begin());
index 530a6f5036394453b22abac1cbab77ab699f8e2d..718dabfcf99db1dbc5281f37236f7ebda3aabc9b 100644 (file)
 
 #pragma once
 
+#include <common/log.h>
+
 #include "../frame_producer.h"
 
 #include "../binding.h"
+#include "../variable.h"
+
+namespace caspar { namespace core {
+
+class frame_factory;
 
-namespace caspar { namespace core { namespace scene {
+namespace scene {
 
 struct coord
 {
@@ -33,6 +40,13 @@ struct coord
        binding<double> y;
 };
 
+struct rect
+{
+       coord upper_left;
+       binding<double> width;
+       binding<double> height;
+};
+
 struct adjustments
 {
        binding<double> opacity;
@@ -44,13 +58,13 @@ struct layer
 {
        binding<std::wstring> name;
        coord position;
+       rect clipping;
        adjustments adjustments;
        binding<spl::shared_ptr<frame_producer>> producer;
        binding<bool> hidden;
        binding<bool> is_key;
 
-       explicit layer(const spl::shared_ptr<frame_producer>& producer);
-       layer(const std::wstring& name, const spl::shared_ptr<frame_producer>& producer);
+       explicit layer(const std::wstring& name, const spl::shared_ptr<frame_producer>& producer);
 };
 
 struct keyframe
@@ -66,45 +80,6 @@ public:
        }
 };
 
-template<typename T> class parameter_holder;
-
-class parameter_holder_base
-{
-public:
-       virtual ~parameter_holder_base()
-       {
-       }
-
-       virtual void set(const std::wstring& raw_value) = 0;
-
-       template<typename T>
-       binding<T>& value()
-       {
-               return dynamic_cast<parameter_holder<T>>(*this).value();
-       }
-};
-
-template<typename T>
-class parameter_holder : public parameter_holder_base
-{
-       binding<T> value_;
-public:
-       parameter_holder(T initial_value)
-               : value_(initial_value)
-       {
-       }
-
-       binding<T>& value()
-       {
-               return value_;
-       }
-
-       virtual void set(const std::wstring& raw_value)
-       {
-               value_.set(boost::lexical_cast<T>(raw_value));
-       }
-};
-
 class scene_producer : public frame_producer_base
 {
 public:
@@ -121,20 +96,22 @@ public:
        boost::property_tree::wptree info() const override;
        void subscribe(const monitor::observable::observer_ptr& o) override;
        void unsubscribe(const monitor::observable::observer_ptr& o) override;
-       layer& create_layer(
-                       const spl::shared_ptr<frame_producer>& producer, int x, int y);
        layer& create_layer(
                        const spl::shared_ptr<frame_producer>& producer, int x, int y, const std::wstring& name);
-       layer& create_layer(const spl::shared_ptr<frame_producer>& producer);
+       layer& create_layer(
+                       const spl::shared_ptr<frame_producer>& producer, const std::wstring& name);
        binding<int64_t> frame();
+       binding<double> speed();
 
-       template<typename T> binding<T>& create_parameter(const std::wstring& name, T initial_value = T())
+       template<typename T> binding<T>& create_variable(
+                       const std::wstring& name, bool is_public, const std::wstring& expr = L"")
        {
-               auto param = std::make_shared<parameter_holder<T>>(initial_value);
+               std::shared_ptr<core::variable> var =
+                               std::make_shared<core::variable_impl<T>>(expr, is_public);
 
-               store_parameter(name, param);
+               store_variable(name, var);
 
-               return param->value();
+               return var->as<T>();
        }
 
        template<typename T>
@@ -154,6 +131,12 @@ public:
                        int64_t at_frame,
                        const std::wstring& easing)
        {
+               if (easing.empty())
+               {
+                       add_keyframe(to_affect, destination_value, at_frame);
+                       return;
+               }
+
                tweener tween(easing);
                keyframe k(at_frame);
 
@@ -207,16 +190,17 @@ public:
 
                store_keyframe(to_affect.identity(), k);
        }
+
+       core::variable& get_variable(const std::wstring& name);
 private:
-       void store_parameter(
-                       const std::wstring& name,
-                       const std::shared_ptr<parameter_holder_base>& param);
        void store_keyframe(void* timeline_identity, const keyframe& k);
+       void store_variable(
+                       const std::wstring& name, const std::shared_ptr<core::variable>& var);
 
        struct impl;
        std::unique_ptr<impl> impl_;
 };
 
-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);
+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);
 
 }}}
diff --git a/core/producer/scene/xml_scene_producer.cpp b/core/producer/scene/xml_scene_producer.cpp
new file mode 100644 (file)
index 0000000..666926b
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* This file is part of CasparCG (www.casparcg.com).
+*
+* CasparCG is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* CasparCG is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
+*
+* Author: Helge Norberg, helge.norberg@svt.se
+*/
+
+#include "../../stdafx.h"
+
+#include "xml_scene_producer.h"
+
+#include <boost/filesystem.hpp>
+#include <boost/property_tree/ptree.hpp>
+#include <boost/property_tree/xml_parser.hpp>
+
+#include <common/env.h>
+#include <core/producer/frame_producer.h>
+
+#include "scene_producer.h"
+
+namespace caspar { namespace core { namespace scene {
+
+spl::shared_ptr<core::frame_producer> create_xml_scene_producer(
+               const spl::shared_ptr<core::frame_factory>& frame_factory,
+               const core::video_format_desc& format_desc,
+               const std::vector<std::wstring>& params)
+{
+       if (params.empty())
+               return core::frame_producer::empty();
+
+       std::wstring filename = env::media_folder() + L"\\" + params[0] + L".xml";
+       
+       if (!boost::filesystem::is_regular_file(boost::filesystem::path(filename)))
+               return core::frame_producer::empty();
+
+       boost::property_tree::wptree root;
+       std::wifstream file(filename);
+       boost::property_tree::read_xml(
+                       file,
+                       root,
+                       boost::property_tree::xml_parser::trim_whitespace
+                                       | boost::property_tree::xml_parser::no_comments);
+
+       int width = root.get<int>(L"scene.<xmlattr>.width");
+       int height = root.get<int>(L"scene.<xmlattr>.height");
+
+       auto scene = spl::make_shared<scene_producer>(width, height);
+
+       BOOST_FOREACH(auto elem, root.get_child(L"scene.variables"))
+       {
+               auto type = elem.second.get<std::wstring>(L"<xmlattr>.type");
+
+               if (type == L"double")
+                       scene->create_variable<double>(
+                                       L"variable." + elem.second.get<std::wstring>(L"<xmlattr>.id"),
+                                       false,
+                                       elem.second.get_value<std::wstring>());
+       }
+
+       BOOST_FOREACH(auto elem, root.get_child(L"scene.layers"))
+       {
+               auto id = elem.second.get<std::wstring>(L"<xmlattr>.id");
+               auto producer = create_producer(frame_factory, format_desc, elem.second.get<std::wstring>(L"producer"));
+               auto& layer = scene->create_layer(producer, 0, 0, id);
+               auto variable_prefix = L"layer." + id + L".";
+
+               layer.hidden = scene->create_variable<bool>(variable_prefix + L"hidden", false, elem.second.get(L"hidden", L"false"));
+               layer.position.x = scene->create_variable<double>(variable_prefix + L"x", false, elem.second.get<std::wstring>(L"x"));
+               layer.position.y = scene->create_variable<double>(variable_prefix + L"y", false, elem.second.get<std::wstring>(L"y"));
+
+               scene->create_variable<double>(variable_prefix + L"width", false) = layer.producer.get()->pixel_constraints().width;
+               scene->create_variable<double>(variable_prefix + L"height", false) = layer.producer.get()->pixel_constraints().height;
+       }
+
+       BOOST_FOREACH(auto& elem, root.get_child(L"scene.timelines"))
+       {
+               auto& variable = scene->get_variable(elem.second.get<std::wstring>(L"<xmlattr>.variable"));
+
+               BOOST_FOREACH(auto& k, elem.second)
+               {
+                       if (k.first == L"<xmlattr>")
+                               continue;
+
+                       auto easing = k.second.get(L"<xmlattr>.easing", L"");
+                       auto at = k.second.get<int64_t>(L"<xmlattr>.at");
+
+                       if (variable.is<double>())
+                               scene->add_keyframe(variable.as<double>(), k.second.get_value<double>(), at, easing);
+                       else if (variable.is<int>())
+                               scene->add_keyframe(variable.as<int>(), k.second.get_value<int>(), at, easing);
+               }
+       }
+
+       BOOST_FOREACH(auto& elem, root.get_child(L"scene.parameters"))
+       {
+               auto& variable = scene->get_variable(elem.second.get<std::wstring>(L"<xmlattr>.variable"));
+               auto id = elem.second.get<std::wstring>(L"<xmlattr>.id");
+
+               if (variable.is<double>())
+                       scene->create_variable<double>(id, true) = variable.as<double>();
+               else if (variable.is<std::wstring>())
+                       scene->create_variable<std::wstring>(id, true) = variable.as<std::wstring>();
+       }
+
+       return scene;
+}
+
+}}}
diff --git a/core/producer/scene/xml_scene_producer.h b/core/producer/scene/xml_scene_producer.h
new file mode 100644 (file)
index 0000000..0a2b07b
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* This file is part of CasparCG (www.casparcg.com).
+*
+* CasparCG is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* CasparCG is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
+*
+* Author: Helge Norberg, helge.norberg@svt.se
+*/
+
+#pragma once
+
+#include <vector>
+#include <string>
+
+#include <common/memory.h>
+
+namespace caspar { namespace core {
+
+class frame_producer;
+class frame_factory;
+struct video_format_desc;
+
+namespace scene {
+
+spl::shared_ptr<core::frame_producer> create_xml_scene_producer(const spl::shared_ptr<core::frame_factory>& frame_factory, const core::video_format_desc& format_desc, const std::vector<std::wstring>& params);
+
+}}}
diff --git a/core/producer/variable.h b/core/producer/variable.h
new file mode 100644 (file)
index 0000000..5cc0cc7
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* This file is part of CasparCG (www.casparcg.com).
+*
+* CasparCG is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* CasparCG is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
+*
+* Author: Helge Norberg, helge.norberg@svt.se
+*/
+
+#pragma once
+
+#include <string>
+#include <typeinfo>
+
+#include <boost/lexical_cast.hpp>
+
+#include "binding.h"
+
+namespace caspar { namespace core {
+
+template<typename T> class variable_impl;
+
+class variable
+{
+private:
+       std::wstring original_expr_;
+       bool is_public_;
+public:
+       variable(const std::wstring& expr, bool is_public)
+               : original_expr_(expr), is_public_(is_public)
+       {
+       }
+
+       virtual ~variable()
+       {
+       }
+
+       const std::wstring& original_expr() const
+       {
+               return original_expr_;
+       }
+
+       bool is_public() const
+       {
+               return is_public_;
+       }
+
+       template<typename T>
+       bool is() const
+       {
+               return is(typeid(T));
+       }
+
+       template<typename T>
+       binding<T>& as()
+       {
+               return dynamic_cast<variable_impl<T>&>(*this).value();
+       }
+
+       virtual void from_string(const std::wstring& raw_value) = 0;
+       virtual std::wstring to_string() const = 0;
+private:
+       virtual bool is(const std::type_info& type) const = 0;
+};
+
+template<typename T>
+class variable_impl : public variable
+{
+private:
+       binding<T> value_;
+public:
+       variable_impl(const std::wstring& expr, bool is_public, T initial_value = T())
+               : variable(expr, is_public)
+               , value_(initial_value)
+       {
+       }
+
+       binding<T>& value()
+       {
+               return value_;
+       }
+
+       virtual void from_string(const std::wstring& raw_value)
+       {
+               value_.set(boost::lexical_cast<T>(raw_value));
+       }
+
+       virtual std::wstring to_string() const
+       {
+               return boost::lexical_cast<std::wstring>(value_.get());
+       }
+private:
+       virtual bool is(const std::type_info& type) const
+       {
+               return typeid(T) == type;
+       }
+};
+
+}}
index 79f797150fec2897d0eea3270ff5ba90b5b29060..7e96fdb908c83fbe0fcb42e98195892de33bc4e3 100644 (file)
@@ -113,7 +113,7 @@ void descriptor::read_value(const std::wstring& key, BEFileInputStream& stream)
 
        case 'long':
                {
-                       context_->stack.back()->put(key, stream.read_long());
+                       context_->stack.back()->put(key, static_cast<long>(stream.read_long()));
                }
                break;
 
@@ -129,7 +129,7 @@ void descriptor::read_value(const std::wstring& key, BEFileInputStream& stream)
                        unsigned long count = stream.read_long();
                        for(int i = 0; i < count; ++i)
                        {
-                               read_value(L"", stream);
+                               read_value(L"li", stream);
                        }
                }
                break;
index 66e55f346452faeb8e40d21d04d4665aff77bf0a..e67ee9d1809a6f65aa64db7258e88f2ba1a30fab 100644 (file)
 
 #include <common/env.h>
 #include <common/memory.h>
+#include <common/log.h>
 
 #include <boost/filesystem.hpp>
 #include <boost/foreach.hpp>
 #include <boost/thread/future.hpp>
 #include <boost/algorithm/string.hpp>
+#include <boost/rational.hpp>
 
 namespace caspar { namespace psd {
 
@@ -91,18 +93,22 @@ core::text::text_info get_text_info(const boost::property_tree::wptree& ptree)
                        caspar::core::scene::layer* layer;
                        int link_id;
                        bool is_master;
-               };              
+                       double adjustment_x;
+                       double adjustment_y;
+               };
 
                std::vector<linked_layer_record> layers;
                std::vector<linked_layer_record> masters;
 
        public:
-               void add(caspar::core::scene::layer* layer, int link_group, bool master)
+               void add(caspar::core::scene::layer* layer, int link_group, bool master, double adjustment_x, double adjustment_y)
                {
                        linked_layer_record rec;
                        rec.layer = layer;
                        rec.link_id = link_group;
                        rec.is_master = master;
+                       rec.adjustment_x = adjustment_x;
+                       rec.adjustment_y = adjustment_y;
                        layers.push_back(rec);
 
                        if(rec.is_master)
@@ -125,50 +131,50 @@ core::text::text_info get_text_info(const boost::property_tree::wptree& ptree)
                                        if(r.link_id == master.link_id && r.layer != master.layer)
                                        {
                                                {       //x-coords
-                                                       double slave_left = r.layer->position.x.get();
+                                                       double slave_left = r.layer->position.x.get() + r.adjustment_x;
                                                        double slave_right = slave_left + r.layer->producer.get()->pixel_constraints().width.get();
 
-                                                       double master_left = master.layer->position.x.get();
+                                                       double master_left = master.layer->position.x.get() + master.adjustment_x;
                                                        double master_right = master_left + master.layer->producer.get()->pixel_constraints().width.get();
 
                                                        if((slave_left >= master_left && slave_right <= master_right) || (slave_left <= master_left && slave_right >= master_right))
                                                        {
                                                                //change width of slave
-                                                               r.layer->position.x = master.layer->position.x + (slave_left - master_left);
-                                                               r.layer->producer.get()->pixel_constraints().width = master.layer->producer.get()->pixel_constraints().width + (slave_right - slave_left - master_right + master_left); 
+                                                               r.layer->position.x.bind(master.layer->position.x - r.adjustment_x + master.adjustment_x + (slave_left - master_left));
+                                                               r.layer->producer.get()->pixel_constraints().width.bind(master.layer->producer.get()->pixel_constraints().width + (slave_right - slave_left - master_right + master_left)); 
                                                        }
                                                        else if(slave_left >= master_right)
                                                        {
                                                                //push slave ahead of master
-                                                               r.layer->position.x = master.layer->position.x + master.layer->producer.get()->pixel_constraints().width + (slave_left - master_right);
+                                                               r.layer->position.x.bind(master.layer->position.x - r.adjustment_x + master.adjustment_x + master.layer->producer.get()->pixel_constraints().width + (slave_left - master_right));
                                                        }
                                                        else if(slave_right <= master_left)
                                                        {
-                                                               r.layer->position.x = master.layer->position.x - (master_left - slave_left);
+                                                               r.layer->position.x.bind(master.layer->position.x - r.adjustment_x + master.adjustment_x - (master_left - slave_left));
                                                        }
                                                }
 
                                                {       //y-coords
-                                                       double slave_top = r.layer->position.y.get();
+                                                       double slave_top = r.layer->position.y.get() + r.adjustment_y;
                                                        double slave_bottom = slave_top + r.layer->producer.get()->pixel_constraints().height.get();
 
-                                                       double master_top = master.layer->position.y.get();
+                                                       double master_top = master.layer->position.y.get() + master.adjustment_y;
                                                        double master_bottom = master_top + master.layer->producer.get()->pixel_constraints().height.get();
 
                                                        if((slave_top >= master_top && slave_bottom <= master_bottom) || (slave_top <= master_top && slave_bottom >= master_bottom))
                                                        {
-                                                               //change width of slave
-                                                               r.layer->position.y = master.layer->position.y + (slave_top - master_top);
-                                                               r.layer->producer.get()->pixel_constraints().height = master.layer->producer.get()->pixel_constraints().height + (slave_bottom - slave_top - master_bottom + master_top); 
+                                                               //change height of slave
+                                                               r.layer->position.y.bind(master.layer->position.y - r.adjustment_y + master.adjustment_y + (slave_top - master_top));
+                                                               r.layer->producer.get()->pixel_constraints().height.bind(master.layer->producer.get()->pixel_constraints().height + (slave_bottom - slave_top - master_bottom + master_top)); 
                                                        }
                                                        else if(slave_top >= master_bottom)
                                                        {
                                                                //push slave ahead of master
-                                                               r.layer->position.y = master.layer->position.y + master.layer->producer.get()->pixel_constraints().height + (slave_top - master_bottom);
+                                                               r.layer->position.y.bind(master.layer->position.y - r.adjustment_y + master.adjustment_y + master.layer->producer.get()->pixel_constraints().height + (slave_top - master_bottom));
                                                        }
                                                        else if(slave_bottom <= master_top)
                                                        {
-                                                               r.layer->position.y = master.layer->position.y - (master_top - slave_top);
+                                                               r.layer->position.y.bind(master.layer->position.y - r.adjustment_y + master.adjustment_y - (master_top - slave_top));
                                                        }
                                                }
 
@@ -178,6 +184,108 @@ core::text::text_info get_text_info(const boost::property_tree::wptree& ptree)
                }
        };
 
+int64_t get_frame_number(
+               const core::video_format_desc& format_desc,
+               const boost::rational<int>& at_second)
+{
+       return static_cast<int64_t>(
+                       boost::rational_cast<double>(at_second) * format_desc.fps);
+}
+
+boost::rational<int> get_rational(const boost::property_tree::wptree& node)
+{
+       return boost::rational<int>(
+                       node.get<int>(L"numerator"), node.get<int>(L"denominator"));
+}
+
+void create_timelines(
+               const spl::shared_ptr<core::scene::scene_producer>& scene,
+               const core::video_format_desc& format_desc,
+               core::scene::layer& layer,
+               const layer_ptr& psd_layer,
+               double adjustment_x,
+               double adjustment_y)
+{
+       auto timeline = psd_layer->timeline_data();
+       auto start = get_rational(timeline.get_child(L"timeScope.Strt"));
+       auto end_offset = get_rational(timeline.get_child(L"timeScope.outTime"));
+       auto end = start + end_offset;
+       auto start_frame = get_frame_number(format_desc, start);
+       auto end_frame = get_frame_number(format_desc, end);
+
+       layer.hidden = scene->frame() < start_frame || scene->frame() > end_frame;
+
+       auto tracklist = timeline.get_child_optional(L"trackList");
+
+       if (!tracklist)
+               return;
+
+       double original_pos_x = psd_layer->rect().left;
+       double original_pos_y = psd_layer->rect().top;
+
+       BOOST_FOREACH(auto& track, *tracklist)
+       {
+               auto track_id = track.second.get<std::wstring>(L"stdTrackID");
+
+               if (track_id == L"sheetPositionTrack")
+               {
+                       BOOST_FOREACH(auto& key, track.second.get_child(L"keyList"))
+                       {
+                               bool tween = key.second.get<std::wstring>(L"animInterpStyle")
+                                               == L"Lnr ";
+                               auto time = get_rational(key.second.get_child(L"time"));
+                               auto hrzn = key.second.get<double>(L"animKey.Hrzn");
+                               auto vrtc = key.second.get<double>(L"animKey.Vrtc");
+                               auto x = original_pos_x + hrzn + adjustment_x;
+                               auto y = original_pos_y + vrtc + adjustment_y;
+                               auto frame = get_frame_number(format_desc, time);
+
+                               if (frame == 0) // Consider as initial value (rewind)
+                               {
+                                       layer.position.x.set(x);
+                                       layer.position.y.set(y);
+                               }
+
+                               frame = start_frame + frame; // translate to global timeline
+
+                               if (tween)
+                               {
+                                       scene->add_keyframe(layer.position.x, x, frame, L"easeOutSine");
+                                       scene->add_keyframe(layer.position.y, y, frame, L"easeOutSine");
+                               }
+                               else
+                               {
+                                       scene->add_keyframe(layer.position.x, x, frame);
+                                       scene->add_keyframe(layer.position.y, y, frame);
+                               }
+                       }
+               }
+               else if (track_id == L"opacityTrack")
+               {
+                       auto& opacity = layer.adjustments.opacity;
+
+                       BOOST_FOREACH(auto& key, track.second.get_child(L"keyList"))
+                       {
+                               bool tween = key.second.get<std::wstring>(L"animInterpStyle")
+                                               == L"Lnr ";
+                               auto time = get_rational(key.second.get_child(L"time"));
+                               auto opct = key.second.get<double>(L"animKey.Opct.#Prc") / 100.0;
+                               auto frame = get_frame_number(format_desc, time);
+
+                               if (frame == 0) // Consider as initial value (rewind)
+                                       opacity.set(opct);
+
+                               frame = start_frame + frame; // translate to global timeline
+
+                               if (tween)
+                                       scene->add_keyframe(opacity, opct, frame, L"easeOutSine");
+                               else
+                                       scene->add_keyframe(opacity, opct, frame);
+                       }
+               }
+       }
+}
+
 spl::shared_ptr<core::frame_producer> create_psd_scene_producer(const spl::shared_ptr<core::frame_factory>& frame_factory, const core::video_format_desc& format_desc, const std::vector<std::wstring>& params)
 {
        std::wstring filename = env::media_folder() + L"\\" + params[0] + L".psd";
@@ -206,12 +314,17 @@ spl::shared_ptr<core::frame_producer> create_psd_scene_producer(const spl::share
                        
                        core::text::string_metrics metrics = text_producer->measure_string(str);
                        
-                       auto& new_layer = root->create_layer(text_producer, (*it)->rect().left - 2, (*it)->rect().top + metrics.bearingY, (*it)->name());       //the 2 offset is just a hack for now. don't know why our text is rendered 2 px to the right of that in photoshop
+                       auto adjustment_x = -2;
+                       auto adjustment_y = metrics.bearingY;
+                       auto& new_layer = root->create_layer(text_producer, (*it)->rect().left + adjustment_x, (*it)->rect().top + adjustment_y, (*it)->name());        //the 2 offset is just a hack for now. don't know why our text is rendered 2 px to the right of that in photoshop
                        new_layer.adjustments.opacity.set((*it)->opacity() / 255.0);
                        new_layer.hidden.set(!(*it)->visible());
 
+                       if ((*it)->has_timeline())
+                               create_timelines(root, format_desc, new_layer, (*it), adjustment_x, adjustment_y);
+
                        if((*it)->link_group_id() != 0)
-                               link_constructor.add(&new_layer, (*it)->link_group_id(), true);
+                               link_constructor.add(&new_layer, (*it)->link_group_id(), (*it)->is_position_protected(), -adjustment_x, -adjustment_y);
 
                        text_producers_by_layer_name.push_back(std::make_pair((*it)->name(), text_producer));
                }
@@ -220,13 +333,13 @@ spl::shared_ptr<core::frame_producer> create_psd_scene_producer(const spl::share
                        std::wstring layer_name = (*it)->name();
                        std::shared_ptr<core::frame_producer> layer_producer;
 
-                       if (boost::algorithm::istarts_with(layer_name, L"[producer]"))
+                       /*if (boost::algorithm::istarts_with(layer_name, L"[producer]"))
                        {
                                auto hotswap = std::make_shared<core::hotswap_producer>((*it)->rect().width(), (*it)->rect().height());
                                hotswap->producer().set(core::create_producer(frame_factory, format_desc, layer_name.substr(10)));
                                layer_producer = hotswap;
                        }
-                       else
+                       else*/
                        {
                                core::pixel_format_desc pfd(core::pixel_format::bgra);
                                pfd.planes.push_back(core::pixel_format_desc::plane((*it)->rect().width(), (*it)->rect().height(), 4));
@@ -237,12 +350,15 @@ spl::shared_ptr<core::frame_producer> create_psd_scene_producer(const spl::share
                                layer_producer = core::create_const_producer(core::draw_frame(std::move(frame)), (*it)->rect().width(), (*it)->rect().height());
                        }
 
-                       auto& new_layer = root->create_layer(spl::make_shared_ptr(layer_producer), (*it)->rect().left, (*it)->rect().top);
+                       auto& new_layer = root->create_layer(spl::make_shared_ptr(layer_producer), (*it)->rect().left, (*it)->rect().top, (*it)->name());
                        new_layer.adjustments.opacity.set((*it)->opacity() / 255.0);
                        new_layer.hidden.set(!(*it)->visible());
 
+                       if ((*it)->has_timeline())
+                               create_timelines(root, format_desc, new_layer, (*it), 0, 0);
+
                        if((*it)->link_group_id() != 0)
-                               link_constructor.add(&new_layer, (*it)->link_group_id(), false);
+                               link_constructor.add(&new_layer, (*it)->link_group_id(), (*it)->is_position_protected(), 0, 0);
                }
        }
 
@@ -250,7 +366,7 @@ spl::shared_ptr<core::frame_producer> create_psd_scene_producer(const spl::share
 
        // Reset all dynamic text fields to empty strings and expose them as a scene parameter.
        BOOST_FOREACH(auto& text_layer, text_producers_by_layer_name)
-               text_layer.second->text().bind(root->create_parameter<std::wstring>(text_layer.first, L""));
+               text_layer.second->text().bind(root->create_variable<std::wstring>(boost::to_lower_copy(text_layer.first), true, L""));
 
        auto params2 = params;
        params2.erase(params2.cbegin());
index 3b3e9b50c346dcd0236cfe43654d1714bbfd47ea..0a6f3e96850bf1559b412288f03fe4f4ea43d2ff 100644 (file)
@@ -34,6 +34,7 @@
 #include <core/producer/stage.h>
 #include <core/producer/frame_producer.h>
 #include <core/producer/scene/scene_producer.h>
+#include <core/producer/scene/xml_scene_producer.h>
 #include <core/producer/text/text_producer.h>
 #include <core/consumer/output.h>
 
@@ -108,6 +109,7 @@ struct server::impl : boost::noncopyable
                core::text::init();
 
                register_producer_factory(&core::scene::create_dummy_scene_producer);
+               register_producer_factory(&core::scene::create_xml_scene_producer);
                register_producer_factory(&core::create_text_producer);
 
                setup_channels(env::properties());