<xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" vc:minVersion="1.1">
<xs:element name="scene">
<xs:complexType>
- <xs:sequence>
+ <xs:all>
<xs:element name="variables">
<xs:annotation>
<xs:documentation>
<xs:field xpath="@variable" />
</xs:unique>
</xs:element>
- </xs:sequence>
+ <xs:element name="tasks" minOccurs="0">
+ <xs:annotation>
+ <xs:documentation>
+ Tasks are scheduled to happen whenever a certain condition arises.
+ Use the at attribute to let the condition be that the timeline arrives at a specific frame
+ or the when attribute to specify a custom bool expression that when becomes true triggers the task.
+ </xs:documentation>
+ </xs:annotation>
+ <xs:complexType>
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
+ <xs:element name="call">
+ <xs:annotation><xs:documentation>Performs the equivalent of an AMCP CALL on the specified layer.</xs:documentation></xs:annotation>
+ <xs:complexType>
+ <xs:sequence maxOccurs="unbounded">
+ <xs:element name="arg" type="xs:string"><xs:annotation><xs:documentation>See the producer documentation for the possible arguments.</xs:documentation></xs:annotation></xs:element>
+ </xs:sequence>
+ <xs:attribute name="at" use="optional" type="xs:nonNegativeInteger"><xs:annotation><xs:documentation>Trigger the CALL when the timeline gets to this specific frame.</xs:documentation></xs:annotation></xs:attribute>
+ <xs:attribute name="when" use="optional" type="bool_expression"><xs:annotation><xs:documentation>Trigger the CALL when the specified bool expression becomes true.</xs:documentation></xs:annotation></xs:attribute>
+ <xs:attribute name="to_layer" use="required" type="identifier"><xs:annotation><xs:documentation>The producer on this layer will receive the CALL.</xs:documentation></xs:annotation></xs:attribute>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="cg_play">
+ <xs:annotation><xs:documentation>Performs the equivalent of a CG PLAY on the specified layer.</xs:documentation></xs:annotation>
+ <xs:complexType>
+ <xs:attribute name="at" use="optional" type="xs:nonNegativeInteger"><xs:annotation><xs:documentation>Trigger the CG PLAY when the timeline gets to this specific frame.</xs:documentation></xs:annotation></xs:attribute>
+ <xs:attribute name="when" use="optional" type="bool_expression"><xs:annotation><xs:documentation>Trigger the CG PLAY when the specified bool expression becomes true.</xs:documentation></xs:annotation></xs:attribute>
+ <xs:attribute name="to_layer" use="required" type="identifier"><xs:annotation><xs:documentation>The CG producer on this layer will receive the CG PLAY.</xs:documentation></xs:annotation></xs:attribute>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="cg_stop">
+ <xs:annotation><xs:documentation>Performs the equivalent of a CG STOP on the specified layer.</xs:documentation></xs:annotation>
+ <xs:complexType>
+ <xs:attribute name="at" use="optional" type="xs:nonNegativeInteger"><xs:annotation><xs:documentation>Trigger the CG STOP when the timeline gets to this specific frame.</xs:documentation></xs:annotation></xs:attribute>
+ <xs:attribute name="when" use="optional" type="bool_expression"><xs:annotation><xs:documentation>Trigger the CG STOP when the specified bool expression becomes true.</xs:documentation></xs:annotation></xs:attribute>
+ <xs:attribute name="to_layer" use="required" type="identifier"><xs:annotation><xs:documentation>The CG producer on this layer will receive the CG STOP.</xs:documentation></xs:annotation></xs:attribute>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="cg_next">
+ <xs:annotation><xs:documentation>Performs the equivalent of a CG NEXT on the specified layer.</xs:documentation></xs:annotation>
+ <xs:complexType>
+ <xs:attribute name="at" use="optional" type="xs:nonNegativeInteger"><xs:annotation><xs:documentation>Trigger the CG NEXT when the timeline gets to this specific frame.</xs:documentation></xs:annotation></xs:attribute>
+ <xs:attribute name="when" use="optional" type="bool_expression"><xs:annotation><xs:documentation>Trigger the CG NEXT when the specified bool expression becomes true.</xs:documentation></xs:annotation></xs:attribute>
+ <xs:attribute name="to_layer" use="required" type="identifier"><xs:annotation><xs:documentation>The CG producer on this layer will receive the CG NEXT.</xs:documentation></xs:annotation></xs:attribute>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="cg_invoke">
+ <xs:annotation><xs:documentation>Performs the equivalent of a CG INVOKE on the specified layer with the specified label.</xs:documentation></xs:annotation>
+ <xs:complexType>
+ <xs:attribute name="at" use="optional" type="xs:nonNegativeInteger"><xs:annotation><xs:documentation>Trigger the CG INVOKE when the timeline gets to this specific frame.</xs:documentation></xs:annotation></xs:attribute>
+ <xs:attribute name="when" use="optional" type="bool_expression"><xs:annotation><xs:documentation>Trigger the CG INVOKE when the specified bool expression becomes true.</xs:documentation></xs:annotation></xs:attribute>
+ <xs:attribute name="to_layer" use="required" type="identifier"><xs:annotation><xs:documentation>The CG producer on this layer will receive the CG INVOKE.</xs:documentation></xs:annotation></xs:attribute>
+ <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:choice>
+ </xs:complexType>
+ </xs:element>
+ </xs:all>
<xs:attribute type="xs:positiveInteger" name="width" use="required" />
<xs:attribute type="xs:positiveInteger" name="height" use="required" />
</xs:complexType>
layers_.reverse();
}
+ layer& get_layer(const std::wstring& name)
+ {
+ for (auto& layer : layers_)
+ if (layer.name.get() == name)
+ return layer;
+
+ CASPAR_THROW_EXCEPTION(user_error() << msg_info(name + L" not found in scene"));
+ }
+
void store_keyframe(void* timeline_identity, const keyframe& k)
{
timelines_[timeline_identity].keyframes.insert(std::make_pair(k.destination_frame, k));
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);
return impl_->create_layer(producer, 0, 0, name);
}
-void scene_producer::reverse_layers() {
+void scene_producer::reverse_layers()
+{
impl_->reverse_layers();
}
+layer& scene_producer::get_layer(const std::wstring& name)
+{
+ return impl_->get_layer(name);
+}
+
binding<int64_t> scene_producer::timeline_frame()
{
return impl_->timeline_frame();
impl_->add_mark(frame, action, label);
}
+void scene_producer::add_task(binding<bool> when, std::function<void ()> task)
+{
+ impl_->add_task(std::move(when), std::move(task));
+}
+
core::variable& scene_producer::get_variable(const std::wstring& name)
{
return impl_->get_variable(name);
layer& create_layer(
const spl::shared_ptr<frame_producer>& producer, const std::wstring& name);
void reverse_layers();
+ layer& get_layer(const std::wstring& name);
binding<int64_t> timeline_frame();
binding<double> speed();
store_keyframe(to_affect.identity(), k);
}
- void add_mark(int64_t frame, mark_action action, const std::wstring& label);
+ void add_mark(int64_t at_frame, mark_action action, const std::wstring& label);
+ void add_task(binding<bool> when, std::function<void ()> task);
core::variable& get_variable(const std::wstring& name) override;
const std::vector<std::wstring>& get_variables() const override;
#include <core/help/help_sink.h>
#include <future>
+#include <vector>
#include "scene_producer.h"
#include "scene_cg_proxy.h"
ptree_verify_element_name(k, L"keyframe");
- auto easing = k.second.get(L"<xmlattr>.easing", L"");
- auto at = ptree_get<int64_t>(k.second, L"<xmlattr>.at");
+ auto easing = k.second.get(L"<xmlattr>.easing", L"");
+ auto at = ptree_get<int64_t>(k.second, L"<xmlattr>.at");
auto keyframe_variable_name = L"timeline." + variable_name + L"." + boost::lexical_cast<std::wstring>(at);
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<std::wstring> call_params;
+
+ if (element_name == L"call")
+ {
+ for (auto& arg : task.second)
+ {
+ if (arg.first == L"<xmlattr>")
+ continue;
+
+ ptree_verify_element_name(arg, L"arg");
+ call_params.push_back(ptree_get_value<std::wstring>(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<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();
+
+ 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 weak_producer = static_cast<std::weak_ptr<frame_producer>>(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()");