X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=core%2Fproducer%2Fscene%2Fscene_producer.cpp;h=efcfa3516460e6f94b8149be1a0a8d44fc663b53;hb=62c7da66319a85de98331bcf9dded7490ab62884;hp=f5f2a625edf0b0257f329578f703799009d78183;hpb=7655718811e2643e1b6c35950dc8898b9b55b110;p=casparcg diff --git a/core/producer/scene/scene_producer.cpp b/core/producer/scene/scene_producer.cpp index f5f2a625e..efcfa3516 100644 --- a/core/producer/scene/scene_producer.cpp +++ b/core/producer/scene/scene_producer.cpp @@ -119,6 +119,7 @@ struct marker struct scene_producer::impl { std::wstring producer_name_; + std::wstring template_name_; constraints pixel_constraints_; video_format_desc format_desc_; std::list layers_; @@ -135,14 +136,20 @@ struct scene_producer::impl std::map> variables_; std::vector variable_names_; std::multimap markers_by_frame_; + std::vector> task_subscriptions_; monitor::subject monitor_subject_; bool paused_ = true; bool removed_ = false; bool going_to_mark_ = false; - impl(std::wstring producer_name, int width, int height, const video_format_desc& format_desc) + 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)) - , pixel_constraints_(width, height) + , template_name_(std::move(template_name)) , format_desc_(format_desc) , aggregator_([=] (double x, double y) { return collission_detect(x, y); }) { @@ -166,6 +173,13 @@ struct scene_producer::impl mouse_y_ = mouse_y_variable->value(); m_x_ = 0; m_y_ = 0; + + auto scene_width = std::make_shared>(boost::lexical_cast(width), false, width); + auto scene_height = std::make_shared>(boost::lexical_cast(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( @@ -185,6 +199,15 @@ struct scene_producer::impl 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)); @@ -202,6 +225,27 @@ struct scene_producer::impl markers_by_frame_.insert(std::make_pair(frame, marker(action, label))); } + void add_task(binding when, std::function 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); @@ -528,7 +572,7 @@ struct scene_producer::impl std::wstring print() const { - return L"scene[type=" + name() + L"]"; + return L"scene[type=" + name() + L" template=" + template_name_ + L"]"; } std::wstring name() const @@ -541,6 +585,7 @@ struct scene_producer::impl boost::property_tree::wptree info; info.add(L"type", L"scene"); 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()); @@ -578,8 +623,8 @@ struct scene_producer::impl } }; -scene_producer::scene_producer(std::wstring producer_name, int width, int height, const video_format_desc& format_desc) - : impl_(new impl(std::move(producer_name), width, height, format_desc)) +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)) { } @@ -599,10 +644,16 @@ layer& scene_producer::create_layer( 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 scene_producer::timeline_frame() { return impl_->timeline_frame(); @@ -666,6 +717,11 @@ void scene_producer::add_mark(int64_t frame, mark_action action, const std::wstr impl_->add_mark(frame, action, label); } +void scene_producer::add_task(binding when, std::function 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);