From 965b1032a5e4ca92fe1ed9b622b7588530a9eb44 Mon Sep 17 00:00:00 2001 From: brunoherbelin Date: Mon, 8 Jun 2020 22:15:03 +0200 Subject: [PATCH] Fixed insertion of new source (after drop or pannel) to setup depth and mixing coordinates. --- Mixer.cpp | 21 ++++++++++++++++----- Mixer.h | 7 +++++-- RenderingManager.cpp | 3 +-- UserInterfaceManager.cpp | 4 ++-- View.cpp | 23 +++++++++++++++++++++++ View.h | 2 ++ 6 files changed, 49 insertions(+), 11 deletions(-) diff --git a/Mixer.cpp b/Mixer.cpp index 00bd55c..a23ed6b 100644 --- a/Mixer.cpp +++ b/Mixer.cpp @@ -186,6 +186,12 @@ void Mixer::update() float dt = static_cast( GST_TIME_AS_MSECONDS(current_time - update_time_) ) * 0.001f; update_time_ = current_time; + // insert source candidate for this session + if (candidate_sources_.size()>0) { + insertSource(candidate_sources_.front()); + candidate_sources_.pop_front(); + } + // update session and associated sources session_->update(dt); @@ -276,6 +282,11 @@ Source * Mixer::createSourceClone(std::string namesource) return s; } +void Mixer::addSource(Source *s) +{ + candidate_sources_.push_back(s); +} + void Mixer::insertSource(Source *s, bool makecurrent) { if ( s != nullptr ) @@ -283,14 +294,16 @@ void Mixer::insertSource(Source *s, bool makecurrent) // Add source to Session SourceList::iterator sit = session_->addSource(s); + // set a default depth to the new source + layer_.setDepth(s); + // set a default alpha to the new source + mixing_.setAlpha(s); + // add sources Nodes to all views mixing_.scene.ws()->attach(s->group(View::MIXING)); geometry_.scene.ws()->attach(s->group(View::GEOMETRY)); layer_.scene.ws()->attach(s->group(View::LAYER)); - // set a default depth to the new source - layer_.setDepth(s); - if (makecurrent) { // set this new source as current setCurrentSource( sit ); @@ -298,9 +311,7 @@ void Mixer::insertSource(Source *s, bool makecurrent) // switch to Mixing view to show source created setCurrentView(View::MIXING); current_view_->update(0); -// current_view_->restoreSettings(); current_view_->centerSource(s); - } } } diff --git a/Mixer.h b/Mixer.h index 7a81f8b..bf98ceb 100644 --- a/Mixer.h +++ b/Mixer.h @@ -33,13 +33,13 @@ public: // draw session and current view void draw(); - // manangement of sources + // creation of sources Source * createSourceFile(std::string path); Source * createSourceClone(std::string namesource); Source * createSourceRender(); // operations on sources - void insertSource(Source *s, bool makecurrent = true); + void addSource(Source *s); void deleteSource(Source *s); void renameSource(Source *s, const std::string &newname); @@ -76,6 +76,9 @@ protected: Session *back_session_; void swap(); + SourceList candidate_sources_; + void insertSource(Source *s, bool makecurrent = true); + void setCurrentSource(SourceList::iterator it); SourceList::iterator current_source_; int current_source_index_; diff --git a/RenderingManager.cpp b/RenderingManager.cpp index b2ed420..90d4227 100644 --- a/RenderingManager.cpp +++ b/RenderingManager.cpp @@ -323,9 +323,8 @@ void Rendering::FileDropped(GLFWwindow *, int path_count, const char* paths[]) if (filename.empty()) break; // try to create a source - Mixer::manager().insertSource ( Mixer::manager().createSourceFile( filename ) ); + Mixer::manager().addSource ( Mixer::manager().createSourceFile( filename ) ); } - UserInterface::manager().showPannel(); } diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index cdde95d..64b868e 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -1261,7 +1261,7 @@ void Navigator::RenderNewPannel() new_source_preview_.draw(ImGui::GetContentRegionAvail().x IMGUI_RIGHT_ALIGN); // or press Validate button if ( ImGui::Button("Import", ImVec2(pannel_width_ - padding_width_, 0)) ) { - Mixer::manager().insertSource(new_source_preview_.getSource()); + Mixer::manager().addSource(new_source_preview_.getSource()); selected_button[NAV_NEW] = false; } } @@ -1297,7 +1297,7 @@ void Navigator::RenderNewPannel() new_source_preview_.draw(ImGui::GetContentRegionAvail().x IMGUI_RIGHT_ALIGN); // ask to import the source in the mixer if ( ImGui::Button("Import", ImVec2(pannel_width_ - padding_width_, 0)) ) { - Mixer::manager().insertSource(new_source_preview_.getSource()); + Mixer::manager().addSource(new_source_preview_.getSource()); selected_button[NAV_NEW] = false; } } diff --git a/View.cpp b/View.cpp index c7a3ba1..f5b704b 100644 --- a/View.cpp +++ b/View.cpp @@ -175,6 +175,29 @@ View::Cursor MixingView::grab (glm::vec2 from, glm::vec2 to, Source *s, std::pai return Cursor(Cursor_ResizeAll, info.str() ); } +void MixingView::setAlpha(Source *s) +{ + if (!s) + return; + + // move the layer node of the source + Group *sourceNode = s->group(mode_); + glm::vec2 mix_pos = glm::vec2(sourceNode->translation_); + + for(NodeSet::iterator it = scene.ws()->begin(); it != scene.ws()->end(); it++) { + + if ( glm::distance(glm::vec2((*it)->translation_), mix_pos) < 0.001) { + mix_pos += glm::vec2(-0.03, 0.03); + } + } + + sourceNode->translation_.x = mix_pos.x; + sourceNode->translation_.y = mix_pos.y; + + // request update + s->touch(); +} + uint MixingView::textureMixingQuadratic() { static GLuint texid = 0; diff --git a/View.h b/View.h index b49d71f..a45b246 100644 --- a/View.h +++ b/View.h @@ -76,6 +76,8 @@ public: Cursor grab (glm::vec2 from, glm::vec2 to, Source *s, std::pair) override; + void setAlpha (Source *s); + private: uint textureMixingQuadratic(); };