From 134617bbd1950101887e73ddcc6918a9cb098a2e Mon Sep 17 00:00:00 2001 From: Bruno Date: Wed, 3 Mar 2021 22:39:36 +0100 Subject: [PATCH] Created new Object MixingGoup --- CMakeLists.txt | 1 + Mixer.cpp | 1 + MixingGroup.cpp | 115 ++++++++++++++++++++++++++++++++++++++++++++++++ MixingGroup.h | 33 ++++++++++++++ MixingView.cpp | 39 ++++++++-------- MixingView.h | 11 ++--- Scene.cpp | 19 ++++---- Source.cpp | 13 +++--- Source.h | 14 +++--- 9 files changed, 202 insertions(+), 44 deletions(-) create mode 100644 MixingGroup.cpp create mode 100644 MixingGroup.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4575a79..a91b219 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -275,6 +275,7 @@ set(VMIX_SRCS RenderView.cpp GeometryView.cpp MixingView.cpp + MixingGroup.cpp LayerView.cpp TextureView.cpp TransitionView.cpp diff --git a/Mixer.cpp b/Mixer.cpp index 6775093..da14cc7 100644 --- a/Mixer.cpp +++ b/Mixer.cpp @@ -683,6 +683,7 @@ void Mixer::groupSelection() // avoid name duplicates renameSource(group, "group"); + Mixer::manager().setCurrentSource(group); } void Mixer::renameSource(Source *s, const std::string &newname) diff --git a/MixingGroup.cpp b/MixingGroup.cpp new file mode 100644 index 0000000..708d810 --- /dev/null +++ b/MixingGroup.cpp @@ -0,0 +1,115 @@ +#include +#include + +#include + +#include "Source.h" +#include "Decorations.h" +#include "Log.h" + +#include "MixingGroup.h" + +// utility to sort Sources in MixingView in a clockwise order +// in reference to a center point +struct clockwise_centered { + clockwise_centered(glm::vec2 c) : center(c) { } + bool operator() (Source * first, Source * second) { + glm::vec2 pos_first = glm::vec2(first->group(View::MIXING)->translation_)-center; + float angle_first = glm::orientedAngle( glm::normalize(pos_first), glm::vec2(1.f, 0.f) ); + glm::vec2 pos_second = glm::vec2(second->group(View::MIXING)->translation_)-center; + float angle_second = glm::orientedAngle( glm::normalize(pos_second), glm::vec2(1.f, 0.f) ); + return (angle_first < angle_second); + } + glm::vec2 center; +}; + +MixingGroup::MixingGroup (SourceList sources) : root_(nullptr), lines_(nullptr), center_(nullptr), pos_(glm::vec2(0.f, 0.f)) +{ + // fill the vector of sources with the given list + for (auto it = sources.begin(); it != sources.end(); it++){ + (*it)->mixinggroup_ = this; + sources_.push_back(*it); + // compute barycenter (1) + pos_ += glm::vec2((*it)->group(View::MIXING)->translation_); + } + // compute barycenter (2) + pos_ /= sources_.size(); + + // sort the vector of sources in clockwise order around the center pos_ + std::sort(sources_.begin(), sources_.end(), clockwise_centered(pos_)); + + root_ = new Group; + center_ = new Symbol(Symbol::CIRCLE_POINT); + center_->color = glm::vec4(0.f, 1.f, 0.f, 0.8f); + center_->translation_ = glm::vec3(pos_, 0.f); + root_->attach(center_); + createLineStrip(); +} + +void MixingGroup::detach (Source *s) +{ + // find the source + std::vector::iterator its = std::find(sources_.begin(), sources_.end(), s); + // ok, its in the list ! + if (its != sources_.end()) { + // erase the source from the list + sources_.erase(its); + + // clear index, delete lines_, and recreate path and index with remaining sources + createLineStrip(); + } +} + +void MixingGroup::update (Source *s) +{ + // find the source + std::vector::iterator its = std::find(sources_.begin(), sources_.end(), s); + + if (its != sources_.end() && lines_) { + + lines_->editPath(index_points_[s], glm::vec2(s->group(View::MIXING)->translation_));// +// lines_->editPath(0, glm::vec2(s->group(View::MIXING)->translation_)); + + } + +} + +void MixingGroup::draw () +{ + +} + +//void MixingGroup::grab (glm::vec2 from, glm::vec2 to, std::pair) +//{ + +//} + + +void MixingGroup::createLineStrip() +{ + if (lines_) { + root_->detach(lines_); + delete lines_; + } + + index_points_.clear(); + + if (sources_.size() > 1) { + std::vector path; + auto it = sources_.begin(); + // link sources + for (; it != sources_.end(); it++){ + index_points_[*it] = path.size(); + path.push_back(glm::vec2((*it)->group(View::MIXING)->translation_)); + } +// // loop +// it = sources_.begin(); +// index_points_[*it] = path.size(); +// path.push_back(glm::vec2((*it)->group(View::MIXING)->translation_)); + // create + lines_ = new LineLoop(path, 2.f); + lines_->shader()->color = glm::vec4(0.f, 1.f, 0.f, 0.8f); + + root_->attach(lines_); + } +} diff --git a/MixingGroup.h b/MixingGroup.h new file mode 100644 index 0000000..b4c5cda --- /dev/null +++ b/MixingGroup.h @@ -0,0 +1,33 @@ +#ifndef MIXINGGROUP_H +#define MIXINGGROUP_H + +#include + +#include "View.h" + +class LineLoop; +class Symbol; + +class MixingGroup +{ + Group *root_; + LineLoop *lines_; + Symbol *center_; + glm::vec2 pos_; + std::vector sources_; + std::map< Source *, uint> index_points_; + + void createLineStrip(); + +public: + MixingGroup (SourceList sources); + + inline Node *node () { return root_; } + + void detach (Source *s); + void update (Source *s); + + void draw (); +}; + +#endif // MIXINGGROUP_H diff --git a/MixingView.cpp b/MixingView.cpp index e8a2db6..f00517a 100644 --- a/MixingView.cpp +++ b/MixingView.cpp @@ -18,9 +18,15 @@ #include "Decorations.h" #include "UserInterfaceManager.h" #include "Log.h" +#include "MixingGroup.h" #include "MixingView.h" +// internal utility +float sin_quad_texture(float x, float y); +uint textureMixingQuadratic(); + + MixingView::MixingView() : View(MIXING), limbo_scale_(MIXING_LIMBO_SCALE) { @@ -96,14 +102,7 @@ MixingView::MixingView() : View(MIXING), limbo_scale_(MIXING_LIMBO_SCALE) stashCircle_->color = glm::vec4( COLOR_STASH_CIRCLE, 0.6f ); // scene.bg()->attach(stashCircle_); -// points_.push_back(glm::vec2(0.f, 0.f)); -// points_.push_back(glm::vec2(0.f, 1.f)); -// points_.push_back(glm::vec2(1.f, 1.f)); -// points_.push_back(glm::vec2(1.f, 0.f)); -// lines_ = new LineStrip(points_, 1.f); -// scene.fg()->attach(lines_); - lines_ = nullptr; } @@ -129,6 +128,11 @@ void MixingView::draw() // special action of Mixing view if (ImGui::Selectable( ICON_FA_DRAW_POLYGON " Link" )){ + // TODO create MixingGroup + MixingGroup *mg = new MixingGroup(Mixer::selection().getCopy()); + groups_.push_back(mg); + scene.fg()->attach(mg->node()); + Mixer::selection().clear(); } ImGui::Separator(); @@ -141,7 +145,7 @@ void MixingView::draw() (*it)->touch(); } } - if (ImGui::Selectable( ICON_FA_EXPAND_ARROWS_ALT " Expand to hide" )){ + if (ImGui::Selectable( ICON_FA_EXPAND_ARROWS_ALT " Expand & Hide" )){ SourceList::iterator it = Mixer::selection().begin(); for (; it != Mixer::selection().end(); it++) { (*it)->setAlpha(0.f); @@ -326,6 +330,12 @@ View::Cursor MixingView::grab (Source *s, glm::vec2 from, glm::vec2 to, std::pai // compute delta translation s->group(mode_)->translation_ = s->stored_status_->translation_ + gl_Position_to - gl_Position_from; + // manage mixing groups + if (s->mixinggroup_ != nullptr) { + s->mixinggroup_->update(s); + + } + // // diagonal translation with SHIFT // if (UserInterface::manager().shiftModifier()) { // s->group(mode_)->translation_.y = s->group(mode_)->translation_.x * s->stored_status_->translation_.y / s->stored_status_->translation_.x; @@ -421,17 +431,6 @@ void MixingView::updateSelectionOverlay() // slightly extend the boundary of the selection overlay_selection_frame_->scale_ = glm::vec3(1.f) + glm::vec3(0.01f, 0.01f, 1.f) / overlay_selection_->scale_; -// if (lines_) { -// scene.fg()->detach(lines_); -// delete lines_; -// } - -// points_.push_back(glm::vec2(0.f, 0.f)); -// points_.push_back(glm::vec2(0.f, 1.f)); -// points_.push_back(glm::vec2(1.f, 1.f)); -// points_.push_back(glm::vec2(1.f, 0.f)); -// lines_ = new LineStrip(points_, 1.f); -// scene.fg()->attach(lines_); } } @@ -448,7 +447,7 @@ float sin_quad_texture(float x, float y) { return 0.5f + 0.5f * cos( M_PI * CLAMP( D * sqrt(D), 0.f, 1.f ) ); } -uint MixingView::textureMixingQuadratic() +uint textureMixingQuadratic() { static GLuint texid = 0; if (texid == 0) { diff --git a/MixingView.h b/MixingView.h index cceb545..16b829f 100644 --- a/MixingView.h +++ b/MixingView.h @@ -3,6 +3,8 @@ #include "View.h" +class MixingGroup; + class MixingView : public View { public: @@ -22,7 +24,8 @@ public: inline float limboScale() { return limbo_scale_; } private: - uint textureMixingQuadratic(); + void updateSelectionOverlay() override; + float limbo_scale_; Group *slider_root_; @@ -33,10 +36,8 @@ private: Mesh *mixingCircle_; Mesh *circle_; - // TEST - std::vector points_; - class LineStrip *lines_; - void updateSelectionOverlay() override; + // linked sources + std::list< MixingGroup *> groups_; }; diff --git a/Scene.cpp b/Scene.cpp index 57cb4d6..f15a51e 100644 --- a/Scene.cpp +++ b/Scene.cpp @@ -1,5 +1,13 @@ +#include +#include +#include +#include + +#include + +#include + #include "defines.h" -#include "Scene.h" #include "Shader.h" #include "Primitives.h" #include "Visitor.h" @@ -8,14 +16,7 @@ #include "GlmToolkit.h" #include "SessionVisitor.h" -#include - -#include -#include -#include -#include - -#include +#include "Scene.h" // Node Node::Node() : initialized_(false), visible_(true), refcount_(0) diff --git a/Source.cpp b/Source.cpp index 0abb3e5..e60308a 100644 --- a/Source.cpp +++ b/Source.cpp @@ -4,20 +4,19 @@ #include #include -#include "Source.h" - #include "defines.h" #include "FrameBuffer.h" #include "Decorations.h" #include "Resource.h" -#include "Session.h" #include "SearchVisitor.h" #include "ImageShader.h" #include "ImageProcessingShader.h" #include "SystemToolkit.h" #include "SessionVisitor.h" #include "Log.h" -#include "Mixer.h" +#include "MixingGroup.h" + +#include "Source.h" Source::Source() : initialized_(false), symbol_(nullptr), active_(true), locked_(false), need_update_(true), workspace_(STAGE) { @@ -179,7 +178,6 @@ Source::Source() : initialized_(false), symbol_(nullptr), active_(true), locked_ // empty transition node groups_[View::TRANSITION] = new Group; - // // locker switch button : locked / unlocked icons locker_ = new Switch; lock_ = new Handles(Handles::LOCKED); @@ -204,6 +202,7 @@ Source::Source() : initialized_(false), symbol_(nullptr), active_(true), locked_ // for drawing in mixing view mixingshader_ = new ImageShader; mixingshader_->stipple = 1.0; + mixinggroup_ = nullptr; // create media surface: // - textured with original texture from media player @@ -228,6 +227,10 @@ Source::~Source() (*it)->detach(); clones_.clear(); + // inform group + if (mixinggroup_) + mixinggroup_->detach(this); + // delete objects delete stored_status_; if (renderbuffer_) diff --git a/Source.h b/Source.h index 10d8ff8..567a6e4 100644 --- a/Source.h +++ b/Source.h @@ -20,6 +20,7 @@ class Frame; class Handles; class Symbol; class CloneSource; +class MixingGroup; typedef std::list CloneList; @@ -28,6 +29,7 @@ class Source friend class CloneSource; friend class View; friend class MixingView; + friend class MixingGroup; friend class GeometryView; friend class LayerView; friend class TextureView; @@ -52,8 +54,8 @@ public: // Display mode typedef enum { - UNINITIALIZED = 0, - VISIBLE = 1, + UNINITIALIZED = 0, + VISIBLE = 1, SELECTED = 2, CURRENT = 3 } Mode; @@ -106,8 +108,8 @@ public: // Workspace typedef enum { - BACKGROUND = 0, - STAGE = 1, + BACKGROUND = 0, + STAGE = 1, FOREGROUND = 2 } Workspace; inline Workspace workspace () const { return workspace_; } @@ -135,7 +137,6 @@ public: float alpha () const; void setAlpha (float a); - struct hasNode: public std::unary_function { bool operator()(const Source* elem) const; @@ -247,6 +248,9 @@ protected: // clones CloneList clones_; + + // Mixing + MixingGroup *mixinggroup_; };