diff --git a/CMakeLists.txt b/CMakeLists.txt index 86ad45d..0563969 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -292,6 +292,7 @@ set(VMIX_SRCS TextureView.cpp TransitionView.cpp Source.cpp + CloneSource.cpp SourceCallback.cpp SourceList.cpp Session.cpp diff --git a/CloneSource.cpp b/CloneSource.cpp new file mode 100644 index 0000000..963aafa --- /dev/null +++ b/CloneSource.cpp @@ -0,0 +1,129 @@ +/* + * This file is part of vimix - video live mixer + * + * **Copyright** (C) 2019-2022 Bruno Herbelin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +**/ + +#include + +#include "Log.h" +#include "Resource.h" +#include "Visitor.h" +#include "Decorations.h" + +#include "CloneSource.h" + + +CloneSource *Source::clone(uint64_t id) +{ + CloneSource *s = new CloneSource(this, id); + + clones_.push_back(s); + + return s; +} + + +CloneSource::CloneSource(Source *origin, uint64_t id) : Source(id), origin_(origin) +{ + name_ = origin->name(); + // set symbol + symbol_ = new Symbol(Symbol::CLONE, glm::vec3(0.75f, 0.75f, 0.01f)); + symbol_->scale_.y = 1.5f; +} + +CloneSource::~CloneSource() +{ + if (origin_) + origin_->clones_.remove(this); +} + +CloneSource *CloneSource::clone(uint64_t id) +{ + // do not clone a clone : clone the original instead + if (origin_) + return origin_->clone(id); + else + return nullptr; +} + +void CloneSource::init() +{ + if (origin_ && origin_->mode_ > Source::UNINITIALIZED) { + + // get the texture index from framebuffer of view, apply it to the surface + texturesurface_->setTextureIndex( origin_->texture() ); + + // create Frame buffer matching size of session + FrameBuffer *renderbuffer = new FrameBuffer( origin_->frame()->resolution(), true); + + // set the renderbuffer of the source and attach rendering nodes + attach(renderbuffer); + + // deep update to reorder + ++View::need_deep_update_; + + // done init + Log::Info("Source %s cloning source %s.", name().c_str(), origin_->name().c_str() ); + } +} + +void CloneSource::setActive (bool on) +{ + active_ = on; + + groups_[View::RENDERING]->visible_ = active_; + groups_[View::GEOMETRY]->visible_ = active_; + groups_[View::LAYER]->visible_ = active_; + + if (origin_) { + if ( mode_ > Source::UNINITIALIZED) + origin_->touch(); + + // change visibility of active surface (show preview of origin when inactive) + if (activesurface_) { + if (active_) + activesurface_->setTextureIndex(Resource::getTextureTransparent()); + else + activesurface_->setTextureIndex(origin_->texture()); + } + } +} + +uint CloneSource::texture() const +{ + if (origin_ != nullptr) + return origin_->texture(); + else + return Resource::getTextureBlack(); +} + +void CloneSource::accept(Visitor& v) +{ + Source::accept(v); + if (!failed()) + v.visit(*this); +} + +glm::ivec2 CloneSource::icon() const +{ + return glm::ivec2(ICON_SOURCE_CLONE); +} + +std::string CloneSource::info() const +{ + return std::string("clone of '") + origin_->name() + "'"; +} diff --git a/CloneSource.h b/CloneSource.h new file mode 100644 index 0000000..4ee4c8a --- /dev/null +++ b/CloneSource.h @@ -0,0 +1,39 @@ +#ifndef CLONESOURCE_H +#define CLONESOURCE_H + +#include "Source.h" + +class CloneSource : public Source +{ + friend class Source; + +public: + ~CloneSource(); + + // implementation of source API + void setActive (bool on) override; + bool playing () const override { return true; } + void play (bool) override {} + bool playable () const override { return false; } + void replay () override {} + uint texture() const override; + bool failed() const override { return origin_ == nullptr; } + void accept (Visitor& v) override; + + CloneSource *clone(uint64_t id = 0) override; + inline void detach() { origin_ = nullptr; } + inline Source *origin() const { return origin_; } + + glm::ivec2 icon() const override; + std::string info() const override; + +protected: + // only Source class can create new CloneSource via clone(); + CloneSource(Source *origin, uint64_t id = 0); + + void init() override; + Source *origin_; +}; + + +#endif // CLONESOURCE_H diff --git a/DeviceSource.cpp b/DeviceSource.cpp index cefa8b0..2515166 100644 --- a/DeviceSource.cpp +++ b/DeviceSource.cpp @@ -25,16 +25,18 @@ #include #include -#include "DeviceSource.h" #include "defines.h" +#include "Log.h" #include "ImageShader.h" #include "ImageProcessingShader.h" #include "Resource.h" #include "Decorations.h" #include "Stream.h" #include "Visitor.h" -#include "Log.h" +#include "CloneSource.h" + +#include "DeviceSource.h" #ifndef NDEBUG #define DEVICE_DEBUG diff --git a/ImGuiVisitor.cpp b/ImGuiVisitor.cpp index 6eb24ab..4c2ca27 100644 --- a/ImGuiVisitor.cpp +++ b/ImGuiVisitor.cpp @@ -42,6 +42,7 @@ #include "ImageProcessingShader.h" #include "MediaPlayer.h" #include "MediaSource.h" +#include "CloneSource.h" #include "SessionSource.h" #include "PatternSource.h" #include "DeviceSource.h" diff --git a/InfoVisitor.cpp b/InfoVisitor.cpp index f057a57..02139e6 100644 --- a/InfoVisitor.cpp +++ b/InfoVisitor.cpp @@ -38,6 +38,7 @@ #include "ImageProcessingShader.h" #include "MediaPlayer.h" #include "MediaSource.h" +#include "CloneSource.h" #include "SessionSource.h" #include "PatternSource.h" #include "DeviceSource.h" diff --git a/Mixer.cpp b/Mixer.cpp index b1d360d..7c034cb 100644 --- a/Mixer.cpp +++ b/Mixer.cpp @@ -42,6 +42,7 @@ #include "SessionCreator.h" #include "SessionVisitor.h" #include "SessionSource.h" +#include "CloneSource.h" #include "MediaSource.h" #include "PatternSource.h" #include "DeviceSource.h" diff --git a/SessionCreator.cpp b/SessionCreator.cpp index 82fb588..a89fd64 100644 --- a/SessionCreator.cpp +++ b/SessionCreator.cpp @@ -25,6 +25,7 @@ #include "Primitives.h" #include "Mesh.h" #include "Source.h" +#include "CloneSource.h" #include "MediaSource.h" #include "SessionSource.h" #include "StreamSource.h" diff --git a/SessionVisitor.cpp b/SessionVisitor.cpp index 02e244f..3eab5c2 100644 --- a/SessionVisitor.cpp +++ b/SessionVisitor.cpp @@ -28,6 +28,7 @@ using namespace tinyxml2; #include "Scene.h" #include "Decorations.h" #include "Source.h" +#include "CloneSource.h" #include "MediaSource.h" #include "Session.h" #include "SessionSource.h" diff --git a/Source.cpp b/Source.cpp index 5a97e88..0cfc40c 100644 --- a/Source.cpp +++ b/Source.cpp @@ -24,6 +24,7 @@ #include #include "defines.h" +#include "Log.h" #include "FrameBuffer.h" #include "Decorations.h" #include "Resource.h" @@ -32,9 +33,9 @@ #include "ImageProcessingShader.h" #include "BaseToolkit.h" #include "SystemToolkit.h" -#include "Log.h" #include "MixingGroup.h" +#include "CloneSource.h" #include "Source.h" SourceCore::SourceCore() @@ -901,104 +902,4 @@ void Source::clearMixingGroup() } -CloneSource *Source::clone(uint64_t id) -{ - CloneSource *s = new CloneSource(this, id); - - clones_.push_back(s); - - return s; -} - - -CloneSource::CloneSource(Source *origin, uint64_t id) : Source(id), origin_(origin) -{ - name_ = origin->name(); - // set symbol - symbol_ = new Symbol(Symbol::CLONE, glm::vec3(0.75f, 0.75f, 0.01f)); - symbol_->scale_.y = 1.5f; -} - -CloneSource::~CloneSource() -{ - if (origin_) - origin_->clones_.remove(this); -} - -CloneSource *CloneSource::clone(uint64_t id) -{ - // do not clone a clone : clone the original instead - if (origin_) - return origin_->clone(id); - else - return nullptr; -} - -void CloneSource::init() -{ - if (origin_ && origin_->mode_ > Source::UNINITIALIZED) { - - // get the texture index from framebuffer of view, apply it to the surface - texturesurface_->setTextureIndex( origin_->texture() ); - - // create Frame buffer matching size of session - FrameBuffer *renderbuffer = new FrameBuffer( origin_->frame()->resolution(), true); - - // set the renderbuffer of the source and attach rendering nodes - attach(renderbuffer); - - // deep update to reorder - ++View::need_deep_update_; - - // done init - Log::Info("Source %s cloning source %s.", name().c_str(), origin_->name().c_str() ); - } -} - -void CloneSource::setActive (bool on) -{ - active_ = on; - - groups_[View::RENDERING]->visible_ = active_; - groups_[View::GEOMETRY]->visible_ = active_; - groups_[View::LAYER]->visible_ = active_; - - if (origin_) { - if ( mode_ > Source::UNINITIALIZED) - origin_->touch(); - - // change visibility of active surface (show preview of origin when inactive) - if (activesurface_) { - if (active_) - activesurface_->setTextureIndex(Resource::getTextureTransparent()); - else - activesurface_->setTextureIndex(origin_->texture()); - } - } -} - -uint CloneSource::texture() const -{ - if (origin_ != nullptr) - return origin_->texture(); - else - return Resource::getTextureBlack(); -} - -void CloneSource::accept(Visitor& v) -{ - Source::accept(v); - if (!failed()) - v.visit(*this); -} - -glm::ivec2 CloneSource::icon() const -{ - return glm::ivec2(ICON_SOURCE_CLONE); -} - -std::string CloneSource::info() const -{ - return std::string("clone of '") + origin_->name() + "'"; -} diff --git a/Source.h b/Source.h index b226f02..863c645 100644 --- a/Source.h +++ b/Source.h @@ -328,37 +328,6 @@ protected: }; -class CloneSource : public Source -{ - friend class Source; - -public: - ~CloneSource(); - - // implementation of source API - void setActive (bool on) override; - bool playing () const override { return true; } - void play (bool) override {} - bool playable () const override { return false; } - void replay () override {} - uint texture() const override; - bool failed() const override { return origin_ == nullptr; } - void accept (Visitor& v) override; - - CloneSource *clone(uint64_t id = 0) override; - inline void detach() { origin_ = nullptr; } - inline Source *origin() const { return origin_; } - - glm::ivec2 icon() const override; - std::string info() const override; - -protected: - // only Source class can create new CloneSource via clone(); - CloneSource(Source *origin, uint64_t id = 0); - - void init() override; - Source *origin_; -}; #endif // SOURCE_H diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index eabea6b..f22eb45 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -76,6 +76,7 @@ using namespace std; #include "Selection.h" #include "FrameBuffer.h" #include "MediaPlayer.h" +#include "CloneSource.h" #include "MediaSource.h" #include "SessionSource.h" #include "PatternSource.h"