From fc4e40fba30b38a7b871dfe119bb88a1b5a8a3dc Mon Sep 17 00:00:00 2001 From: Bruno Date: Mon, 2 Aug 2021 22:27:06 +0200 Subject: [PATCH] Display mixing source original texture when inactive Re-using activesurface_ for manipulation and display of the source's input texture in the Mixer icon when inactive. --- MediaPlayer.cpp | 5 ++--- SessionSource.cpp | 12 ++++++++++-- Source.cpp | 27 +++++++++++++++++++-------- Source.h | 4 ++++ StreamSource.cpp | 15 ++++++++++++--- UserInterfaceManager.cpp | 11 ++++++++++- 6 files changed, 57 insertions(+), 17 deletions(-) diff --git a/MediaPlayer.cpp b/MediaPlayer.cpp index ee08bfe..467f9dc 100644 --- a/MediaPlayer.cpp +++ b/MediaPlayer.cpp @@ -519,7 +519,7 @@ void MediaPlayer::enable(bool on) if ( enabled_ != on ) { // option to automatically rewind each time the player is disabled - if (!on && rewind_on_disable_ ) + if (!on && rewind_on_disable_ && desired_state_ == GST_STATE_PLAYING) rewind(true); // apply change @@ -529,9 +529,8 @@ void MediaPlayer::enable(bool on) GstState requested_state = GST_STATE_PAUSED; // unpause only if enabled - if (enabled_) { + if (enabled_) requested_state = desired_state_; - } // apply state change GstStateChangeReturn ret = gst_element_set_state (pipeline_, requested_state); diff --git a/SessionSource.cpp b/SessionSource.cpp index 103ceaf..444eae0 100644 --- a/SessionSource.cpp +++ b/SessionSource.cpp @@ -66,8 +66,17 @@ void SessionSource::setActive (bool on) Source::setActive(on); // change status of session (recursive change of internal sources) - if (session_) + if (session_) { session_->setActive(active_); + + // change visibility of active surface (show preview of session when inactive) + if (activesurface_) { + if (active_) + activesurface_->setTextureIndex(Resource::getTextureTransparent()); + else + activesurface_->setTextureIndex(session_->frame()->texture()); + } + } } void SessionSource::update(float dt) @@ -101,7 +110,6 @@ void SessionSource::replay () } } - SessionFileSource::SessionFileSource(uint64_t id) : SessionSource(id), path_(""), initialized_(false), wait_for_sources_(false) { // specific node for transition view diff --git a/Source.cpp b/Source.cpp index 0e44e36..23a03da 100644 --- a/Source.cpp +++ b/Source.cpp @@ -268,7 +268,7 @@ Source::Source(uint64_t id) : SourceCore(), id_(id), ready_(false), symbol_(null // for drawing in mixing view mixingshader_ = new ImageShader; - mixingshader_->stipple = 1.0; + mixingshader_->stipple = 1.0f; mixinggroup_ = nullptr; // create media surface: @@ -281,6 +281,7 @@ Source::Source(uint64_t id) : SourceCore(), id_(id), ready_(false), symbol_(null renderbuffer_ = nullptr; rendersurface_ = nullptr; mixingsurface_ = nullptr; + activesurface_ = nullptr; maskbuffer_ = nullptr; maskimage_ = nullptr; mask_need_update_ = false; @@ -454,11 +455,11 @@ void Source::attach(FrameBuffer *renderbuffer) groups_[View::LAYER]->attach(mixingsurface_); // for views showing a scaled mixing surface, a dedicated transparent surface allows grabbing - Surface *surfacetmp = new Surface(); - surfacetmp->setTextureIndex(Resource::getTextureTransparent()); - groups_[View::TEXTURE]->attach(surfacetmp); - groups_[View::MIXING]->attach(surfacetmp); - groups_[View::LAYER]->attach(surfacetmp); + activesurface_ = new Surface(); + activesurface_->setTextureIndex(Resource::getTextureTransparent()); + groups_[View::TEXTURE]->attach(activesurface_); + groups_[View::MIXING]->attach(activesurface_); + groups_[View::LAYER]->attach(activesurface_); // Transition group node is optionnal if (groups_[View::TRANSITION]->numChildren() > 0) @@ -866,8 +867,18 @@ void CloneSource::setActive (bool on) groups_[View::GEOMETRY]->visible_ = active_; groups_[View::LAYER]->visible_ = active_; - if ( mode_ > Source::UNINITIALIZED && origin_ != nullptr) - origin_->touch(); + 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 diff --git a/Source.h b/Source.h index 99f1c4c..db0bfd5 100644 --- a/Source.h +++ b/Source.h @@ -250,7 +250,11 @@ protected: // the rendersurface draws the renderbuffer in the scene // It is associated to the rendershader for mixing effects FrameBufferSurface *rendersurface_; + + // for the mixer, we have a surface with stippling to show + // the rendering, and a preview of the original texture FrameBufferSurface *mixingsurface_; + Surface *activesurface_; // blendingshader provides mixing controls ImageShader *blendingshader_; diff --git a/StreamSource.cpp b/StreamSource.cpp index 470cc76..99547e9 100644 --- a/StreamSource.cpp +++ b/StreamSource.cpp @@ -105,10 +105,19 @@ void StreamSource::setActive (bool on) // try to activate (may fail if source is cloned) Source::setActive(on); - // change status of stream (only if status changed) - if ( stream_ && active_ != was_active ) - stream_->enable(active_); + if (stream_) { + // change status of stream (only if status changed) + if (active_ != was_active) + stream_->enable(active_); + // change visibility of active surface (show preview of stream when inactive) + if (activesurface_) { + if (active_) + activesurface_->setTextureIndex(Resource::getTextureTransparent()); + else + activesurface_->setTextureIndex(stream_->texture()); + } + } } diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index c4b800d..8899d0e 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -72,7 +72,7 @@ TextEditor editor; #define PLOT_ARRAY_SIZE 180 #define LABEL_AUTO_MEDIA_PLAYER ICON_FA_CARET_SQUARE_RIGHT " Dynamic selection" #define LABEL_STORE_SELECTION " Store selection" -#define LABEL_EDIT_FADING ICON_FA_RANDOM " Edit Fading" +#define LABEL_EDIT_FADING ICON_FA_RANDOM " Edit timeline fading" // utility functions void ShowAboutGStreamer(bool* p_open); @@ -2867,6 +2867,15 @@ void SourceController::RenderSingleSource(Source *s) ImGui::Text("%s %s", SourcePlayIcon(s), GstToolkit::time_to_string(s->playtime()).c_str() ); ImGui::PopFont(); +// if ( ms != nullptr ) { +// // ok, get the media player of the media source +// MediaPlayer *mp = ms->mediaplayer(); +// const double width_ratio = static_cast(rendersize.x) / static_cast(mp->timeline()->sectionsDuration()); + +// DrawTimeline("##timeline_mediaplayers", mp->timeline(), mp->position(), width_ratio, 60); + +// } + /// /// Play button bar ///