From 8924d81e0aaf077d97012a326d5aeda577dbe057 Mon Sep 17 00:00:00 2001 From: Bruno Herbelin Date: Tue, 2 Jan 2024 10:38:37 +0100 Subject: [PATCH] BugFix Update linked sources and Texture view on Source change When source change stream (e.g. change pattern), Texture view was not updated, and sources with mask texture were not adapted. --- src/ImGuiVisitor.cpp | 18 +++++-- src/Session.cpp | 8 +++ src/Session.h | 11 +++-- src/TextureView.cpp | 113 ++++++++++++++++++++++++------------------- src/TextureView.h | 2 +- 5 files changed, 90 insertions(+), 62 deletions(-) diff --git a/src/ImGuiVisitor.cpp b/src/ImGuiVisitor.cpp index 0bb71ef..f565730 100644 --- a/src/ImGuiVisitor.cpp +++ b/src/ImGuiVisitor.cpp @@ -1471,6 +1471,8 @@ void ImGuiVisitor::visit (PatternSource& s) std::ostringstream oss; oss << s.name() << ": Pattern " << Pattern::get(p).label; Action::manager().store(oss.str()); + // ensure all sources are updated after the texture change of this one + Mixer::manager().session()->execute([](Source *so) { so->touch(Source::SourceUpdate_Mask); }); } } ImGui::EndCombo(); @@ -1527,6 +1529,8 @@ void ImGuiVisitor::visit (DeviceSource& s) oss << s.name() << " Device " << namedev; Action::manager().store(oss.str()); } + // ensure all sources are updated after the texture change of this one + Mixer::manager().session()->execute([](Source *so) { so->touch(Source::SourceUpdate_Mask); }); } } ImGui::EndCombo(); @@ -1594,6 +1598,8 @@ void ImGuiVisitor::visit (ScreenCaptureSource& s) oss << s.name() << " Window " << namedev; Action::manager().store(oss.str()); } + // ensure all sources are updated after the texture change of this one + Mixer::manager().session()->execute([](Source *so) { so->touch(Source::SourceUpdate_Mask); }); } } ImGui::EndCombo(); @@ -1778,11 +1784,7 @@ void ImGuiVisitor::visit (GenericStreamSource& s) // Editor std::string _description = s.description(); - if ( ImGuiToolkit::InputCodeMultiline("Pipeline", &_description, fieldsize, &numlines) ) { - info.reset(); - s.setDescription(_description); - Action::manager().store( s.name() + ": Change pipeline"); - } + bool changed = ImGuiToolkit::InputCodeMultiline("Pipeline", &_description, fieldsize, &numlines); ImVec2 botom = ImGui::GetCursorPos(); // Actions on the pipeline @@ -1792,9 +1794,15 @@ void ImGuiVisitor::visit (GenericStreamSource& s) ImGui::SetCursorPos( ImVec2(top.x + 0.9 * ImGui::GetFrameHeight(), botom.y - ImGui::GetFrameHeight())); if (ImGuiToolkit::IconButton(ICON_FA_PASTE, "Paste")) { _description = std::string ( ImGui::GetClipboardText() ); + changed = true; + } + + if (changed) { info.reset(); s.setDescription(_description); Action::manager().store( s.name() + ": Change pipeline"); + // ensure all sources are updated after the texture change of this one + Mixer::manager().session()->execute([](Source *so) { so->touch(Source::SourceUpdate_Mask); }); } if ( !s.failed() ) { diff --git a/src/Session.cpp b/src/Session.cpp index 40c8b2a..c7ad83b 100644 --- a/src/Session.cpp +++ b/src/Session.cpp @@ -1005,3 +1005,11 @@ void Session::applySnapshot(uint64_t key) } } + +void Session::execute(void (*func)(Source *)) +{ + for (SourceList::const_iterator it = sources_.cbegin(); it != sources_.cend(); ++it) { + func(*it); + } + +} diff --git a/src/Session.h b/src/Session.h index b2fd091..390cb64 100644 --- a/src/Session.h +++ b/src/Session.h @@ -72,19 +72,18 @@ public: // management of list of sources bool empty() const; uint size() const; + SourceList getDepthSortedList () const; + SourceIdList getIdList() const; + std::list getNameList(uint64_t exceptid=0) const; SourceList::iterator begin (); SourceList::iterator end (); SourceList::iterator find (Source *s); SourceList::iterator find (std::string name); SourceList::iterator find (Node *node); SourceList::iterator find (float depth_from, float depth_to); - SourceList getDepthSortedList () const; - SourceList::iterator find (uint64_t id); - SourceIdList getIdList() const; - - std::list getNameList(uint64_t exceptid=0) const; + // manage sources by #id (ordered index) SourceList::iterator at (int index); int index (SourceList::iterator it) const; void move (int current_index, int target_index); @@ -97,6 +96,8 @@ public: void update (float dt); uint64_t runtime() const; + void execute(void (*func)(Source *)); + // update mode (active or not) void setActive (bool on); inline bool active () { return active_; } diff --git a/src/TextureView.cpp b/src/TextureView.cpp index fe8de9b..1df85b2 100644 --- a/src/TextureView.cpp +++ b/src/TextureView.cpp @@ -243,9 +243,10 @@ void TextureView::update(float dt) View::update(dt); // a more complete update is requested (e.g. after switching to view) - if (View::need_deep_update_ > 0 || edit_source_ != Mixer::manager().currentSource()) { + if (View::need_deep_update_ > 0 || + (Mixer::manager().currentSource() != nullptr && edit_source_ != Mixer::manager().currentSource() )) { + // request update need_edit_update_ = true; - // change grid color const ImVec4 c = ImGuiToolkit::HighlightColor(); translation_grid_->setColor( glm::vec4(c.x, c.y, c.z, 0.3) ); @@ -505,8 +506,10 @@ std::pair TextureView::pick(glm::vec2 P) return pick; } -void TextureView::adjustBackground() +bool TextureView::adjustBackground() { + bool ret = false; + // by default consider edit source is null mask_node_->visible_ = false; float image_original_width = 1.f; @@ -515,52 +518,62 @@ void TextureView::adjustBackground() preview_surface_->setTextureIndex( Resource::getTextureTransparent() ); // if its a valid index - if (edit_source_ != nullptr && edit_source_->ready()) { - // update rendering frame to match edit source AR - image_original_width = edit_source_->frame()->aspectRatio(); - scale_crop_.x = (edit_source_->group(View::GEOMETRY)->crop_[1] - - edit_source_->group(View::GEOMETRY)->crop_[0]) - * 0.5f; - scale_crop_.y = (edit_source_->group(View::GEOMETRY)->crop_[2] - - edit_source_->group(View::GEOMETRY)->crop_[3]) - * 0.5f; - shift_crop_.x = edit_source_->group(View::GEOMETRY)->crop_[1] - scale_crop_.x; - shift_crop_.y = edit_source_->group(View::GEOMETRY)->crop_[3] + scale_crop_.y; - scale_crop_.x *= edit_source_->frame()->aspectRatio(); - shift_crop_.x *= edit_source_->frame()->aspectRatio(); + if (edit_source_ != nullptr) { + if (edit_source_->ready()) { + // update rendering frame to match edit source AR + image_original_width = edit_source_->frame()->aspectRatio(); + scale_crop_.x = (edit_source_->group(View::GEOMETRY)->crop_[1] + - edit_source_->group(View::GEOMETRY)->crop_[0]) + * 0.5f; + scale_crop_.y = (edit_source_->group(View::GEOMETRY)->crop_[2] + - edit_source_->group(View::GEOMETRY)->crop_[3]) + * 0.5f; + shift_crop_.x = edit_source_->group(View::GEOMETRY)->crop_[1] - scale_crop_.x; + shift_crop_.y = edit_source_->group(View::GEOMETRY)->crop_[3] + scale_crop_.y; + scale_crop_.x *= edit_source_->frame()->aspectRatio(); + shift_crop_.x *= edit_source_->frame()->aspectRatio(); - preview_surface_->setTextureIndex( edit_source_->frame()->texture() ); - preview_shader_->mask_texture = edit_source_->blendingShader()->mask_texture; - preview_surface_->scale_ = scale_crop_; - preview_surface_->translation_ = shift_crop_; + preview_surface_->setTextureIndex(edit_source_->frame()->texture()); + preview_shader_->mask_texture = edit_source_->blendingShader()->mask_texture; + preview_surface_->scale_ = scale_crop_; + preview_surface_->translation_ = shift_crop_; - // mask appearance - mask_node_->visible_ = edit_source_->maskShader()->mode == MaskShader::SHAPE && mask_cursor_shape_ > 0; + // mask appearance + mask_node_->visible_ = edit_source_->maskShader()->mode == MaskShader::SHAPE + && mask_cursor_shape_ > 0; - int shape = edit_source_->maskShader()->shape; - mask_circle_->visible_ = shape == MaskShader::ELLIPSE; - mask_square_->visible_ = shape == MaskShader::OBLONG || shape == MaskShader::RECTANGLE; - mask_horizontal_->visible_ = shape == MaskShader::HORIZONTAL; - mask_vertical_->visible_ = shape == MaskShader::VERTICAL; + int shape = edit_source_->maskShader()->shape; + mask_circle_->visible_ = shape == MaskShader::ELLIPSE; + mask_square_->visible_ = shape == MaskShader::OBLONG || shape == MaskShader::RECTANGLE; + mask_horizontal_->visible_ = shape == MaskShader::HORIZONTAL; + mask_vertical_->visible_ = shape == MaskShader::VERTICAL; - // symetrical shapes - if ( shape < MaskShader::HORIZONTAL){ - mask_node_->scale_ = scale_crop_ * glm::vec3(edit_source_->maskShader()->size, 1.f); - mask_node_->translation_ = glm::vec3(0.f); + // symetrical shapes + if (shape < MaskShader::HORIZONTAL) { + mask_node_->scale_ = scale_crop_ * glm::vec3(edit_source_->maskShader()->size, 1.f); + mask_node_->translation_ = glm::vec3(0.f); + } + // vertical + else if (shape > MaskShader::HORIZONTAL) { + mask_node_->scale_ = glm::vec3(1.f, scale_crop_.y, 1.f); + mask_node_->translation_ = glm::vec3(edit_source_->maskShader()->size.x + * scale_crop_.x, + 0.f, + 0.f); + } + // horizontal + else { + mask_node_->scale_ = glm::vec3(scale_crop_.x, 1.f, 1.f); + mask_node_->translation_ = glm::vec3(0.f, + edit_source_->maskShader()->size.y + * scale_crop_.y, + 0.f); + } + + mask_node_->translation_ += shift_crop_; } - // vertical - else if ( shape > MaskShader::HORIZONTAL ) { - mask_node_->scale_ = glm::vec3(1.f, scale_crop_.y, 1.f); - mask_node_->translation_ = glm::vec3(edit_source_->maskShader()->size.x * scale_crop_.x, 0.f, 0.f); - } - // horizontal - else { - mask_node_->scale_ = glm::vec3(scale_crop_.x, 1.f, 1.f); - mask_node_->translation_ = glm::vec3(0.f, edit_source_->maskShader()->size.y * scale_crop_.y, 0.f); - } - - mask_node_->translation_ += shift_crop_; - + else + ret = true; } // background scene @@ -576,6 +589,7 @@ void TextureView::adjustBackground() static glm::mat4 Tra = glm::scale(glm::translate(glm::identity(), glm::vec3( -32.f, -32.f, 0.f)), glm::vec3( 64.f, 64.f, 1.f)); preview_checker_->shader()->iTransform = Ar * Tra; + return ret; } Source *TextureView::getEditOrCurrentSource() @@ -607,16 +621,14 @@ Source *TextureView::getEditOrCurrentSource() void TextureView::draw() { // edit view needs to be updated (source changed) - if ( need_edit_update_ ) - { - need_edit_update_ = false; - + if (need_edit_update_) { // now, follow the change of current source // & remember source to edit edit_source_ = getEditOrCurrentSource(); // update background and frame to match editsource - adjustBackground(); + // & return true if still needs to edit update + need_edit_update_ = adjustBackground(); } // Display grid @@ -1121,9 +1133,8 @@ View::Cursor TextureView::grab (Source *s, glm::vec2 from, glm::vec2 to, std::pa edit_source_->maskShader()->size.x = val.x; else edit_source_->maskShader()->size = glm::max(glm::abs(glm::vec2(val)), glm::vec2(0.2)); -// edit_source_->maskShader()->size = glm::max( glm::min( glm::vec2(val), glm::vec2(2.f)), glm::vec2(hv?-2.f:0.2f)); - edit_source_->touch(Source::SourceUpdate_Mask); // update + edit_source_->touch(Source::SourceUpdate_Mask); need_edit_update_ = true; // action label info << "Texture Mask " << std::fixed << std::setprecision(3) << edit_source_->maskShader()->size.x; diff --git a/src/TextureView.h b/src/TextureView.h index db5d2b1..f066d7e 100644 --- a/src/TextureView.h +++ b/src/TextureView.h @@ -33,7 +33,7 @@ private: Source *edit_source_; bool need_edit_update_; Source *getEditOrCurrentSource(); - void adjustBackground(); + bool adjustBackground(); glm::vec3 scale_crop_; glm::vec3 shift_crop_;