]> git.sesse.net Git - casparcg/commitdiff
[scene] Added task type that lets the scene go to a specific start mark whenever...
authorHelge Norberg <helge.norberg@svt.se>
Tue, 21 Feb 2017 18:51:50 +0000 (19:51 +0100)
committerHelge Norberg <helge.norberg@svt.se>
Tue, 21 Feb 2017 18:51:50 +0000 (19:51 +0100)
core/producer/scene/scene.xsd
core/producer/scene/xml_scene_producer.cpp

index 4fcffe0bbc0222dd7f8f6edf57acb1092864540b..a33e222ee9cdf985e14312cbf9d6a35cec9f42ed 100644 (file)
                   <xs:attribute name="label" use="required" type="nonEmptyString"><xs:annotation><xs:documentation>The label that will be invoked.</xs:documentation></xs:annotation></xs:attribute>
                 </xs:complexType>
               </xs:element>
+              <xs:element name="goto_mark">
+                <xs:annotation><xs:documentation>Makes the scene go to a specific start mark given a specific condition becoming true.</xs:documentation></xs:annotation>
+                <xs:complexType>
+                  <xs:attribute name="when" use="required" type="bool_expression"><xs:annotation><xs:documentation>Go to the start mark when the specified bool expression becomes true.</xs:documentation></xs:annotation></xs:attribute>
+                  <xs:attribute name="label" use="required" type="nonEmptyString"><xs:annotation><xs:documentation>The label of the start mark that the scene should go to.</xs:documentation></xs:annotation></xs:attribute>
+                </xs:complexType>
+              </xs:element>
             </xs:choice>
           </xs:complexType>
         </xs:element>
index 10c4aca6db751395504ac21c4bad8dc005423b86..f1cebd1af84bdb22e9722fb4f60b57a9029bad33 100644 (file)
@@ -260,6 +260,18 @@ spl::shared_ptr<core::frame_producer> create_xml_scene_producer(
        {
                for (auto& task : root | witerate_children(L"scene.tasks") | welement_context_iteration)
                {
+                       auto at_frame = task.second.get_optional<int64_t>(L"<xmlattr>.at");
+                       auto when = task.second.get_optional<std::wstring>(L"<xmlattr>.when");
+
+                       binding<bool> condition;
+
+                       if (at_frame)
+                               condition = scene->timeline_frame() == *at_frame;
+                       else if (when)
+                               condition = scene->create_variable<bool>(L"tasks.task_" + boost::lexical_cast<std::wstring>(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& element_name = task.first;
 
                        std::vector<std::wstring> call_params;
@@ -286,32 +298,37 @@ spl::shared_ptr<core::frame_producer> create_xml_scene_producer(
                                call_params.push_back(L"invoke()");
                                call_params.push_back(ptree_get<std::wstring>(task.second, L"<xmlattr>.label"));
                        }
-                       else
-                               CASPAR_THROW_EXCEPTION(user_error() << msg_info(L"Only valid element names in <tasks /> are call, cg_play, cg_stop, cg_next and cg_invoke"));
-
-                       auto at_frame   = task.second.get_optional<int64_t>(L"<xmlattr>.at");
-                       auto when               = task.second.get_optional<std::wstring>(L"<xmlattr>.when");
-                       auto to_layer   = ptree_get<std::wstring>(task.second, L"<xmlattr>.to_layer");
-                       auto producer   = scene->get_layer(to_layer).producer.get();
+                       else if (element_name == L"goto_mark")
+                       {
+                               auto mark_label = ptree_get<std::wstring>(task.second, L"<xmlattr>.label");
+                               auto weak_scene = static_cast<std::weak_ptr<scene_producer>>(scene);
 
-                       binding<bool> condition;
+                               scene->add_task(std::move(condition), [=]
+                               {
+                                       auto strong = weak_scene.lock();
 
-                       if (at_frame)
-                               condition = scene->timeline_frame() == *at_frame;
-                       else if (when)
-                               condition = scene->create_variable<bool>(L"tasks.task_" + boost::lexical_cast<std::wstring>(task_id), false, *when);
+                                       if (strong)
+                                               strong->call({ L"play()", mark_label });
+                               });
+                       }
                        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<std::weak_ptr<frame_producer>>(producer);
+                               CASPAR_THROW_EXCEPTION(user_error() << msg_info(L"Only valid element names in <tasks /> are call, cg_play, cg_stop, cg_next, cg_invoke and goto_mark"));
 
-                       scene->add_task(std::move(condition), [=]
+                       if (!call_params.empty())
                        {
-                               auto strong = weak_producer.lock();
+                               auto to_layer = ptree_get<std::wstring>(task.second, L"<xmlattr>.to_layer");
+                               auto producer = scene->get_layer(to_layer).producer.get();
+
+                               auto weak_producer = static_cast<std::weak_ptr<frame_producer>>(producer);
 
-                               if (strong)
-                                       strong->call(call_params);
-                       });
+                               scene->add_task(std::move(condition), [=]
+                               {
+                                       auto strong = weak_producer.lock();
+
+                                       if (strong)
+                                               strong->call(call_params);
+                               });
+                       }
 
                        ++task_id;
                }