X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=core%2Fproducer%2Fscene%2Fxml_scene_producer.cpp;h=10c4aca6db751395504ac21c4bad8dc005423b86;hb=62c7da66319a85de98331bcf9dded7490ab62884;hp=3c1bc18ca13d1da9e30d66774bb01f4b52cd29f3;hpb=e580cd2784dbd9910605367c46977d5eebdea1fe;p=casparcg diff --git a/core/producer/scene/xml_scene_producer.cpp b/core/producer/scene/xml_scene_producer.cpp index 3c1bc18ca..10c4aca6d 100644 --- a/core/producer/scene/xml_scene_producer.cpp +++ b/core/producer/scene/xml_scene_producer.cpp @@ -38,6 +38,7 @@ #include #include +#include #include "scene_producer.h" #include "scene_cg_proxy.h" @@ -236,8 +237,8 @@ spl::shared_ptr create_xml_scene_producer( ptree_verify_element_name(k, L"keyframe"); - auto easing = k.second.get(L".easing", L""); - auto at = ptree_get(k.second, L".at"); + auto easing = k.second.get(L".easing", L""); + auto at = ptree_get(k.second, L".at"); auto keyframe_variable_name = L"timeline." + variable_name + L"." + boost::lexical_cast(at); @@ -254,6 +255,68 @@ spl::shared_ptr create_xml_scene_producer( return scene->get_variable(name); }; + int task_id = 0; + if (root.get_child_optional(L"scene.tasks")) + { + for (auto& task : root | witerate_children(L"scene.tasks") | welement_context_iteration) + { + auto& element_name = task.first; + + std::vector call_params; + + if (element_name == L"call") + { + for (auto& arg : task.second) + { + if (arg.first == L"") + continue; + + ptree_verify_element_name(arg, L"arg"); + call_params.push_back(ptree_get_value(arg.second)); + } + } + else if (element_name == L"cg_play") + call_params.push_back(L"play()"); + else if (element_name == L"cg_stop") + call_params.push_back(L"stop()"); + else if (element_name == L"cg_next") + call_params.push_back(L"next()"); + else if (element_name == L"cg_invoke") + { + call_params.push_back(L"invoke()"); + call_params.push_back(ptree_get(task.second, L".label")); + } + else + CASPAR_THROW_EXCEPTION(user_error() << msg_info(L"Only valid element names in are call, cg_play, cg_stop, cg_next and cg_invoke")); + + auto at_frame = task.second.get_optional(L".at"); + auto when = task.second.get_optional(L".when"); + auto to_layer = ptree_get(task.second, L".to_layer"); + auto producer = scene->get_layer(to_layer).producer.get(); + + binding condition; + + if (at_frame) + condition = scene->timeline_frame() == *at_frame; + else if (when) + condition = scene->create_variable(L"tasks.task_" + boost::lexical_cast(task_id), false, *when); + else + CASPAR_THROW_EXCEPTION(user_error() << msg_info(L"Task elements must have either an at attribute or a when attribute")); + + auto weak_producer = static_cast>(producer); + + scene->add_task(std::move(condition), [=] + { + auto strong = weak_producer.lock(); + + if (strong) + strong->call(call_params); + }); + + ++task_id; + } + } + for (auto& var_name : scene->get_variables()) { CASPAR_SCOPED_CONTEXT_MSG(L"/scene/variables/variable[@id=" + var_name + L"]/text()");