From dd92f2dccbffd751feddcd95cd3fc9444822f308 Mon Sep 17 00:00:00 2001 From: Bruno Herbelin Date: Wed, 17 Aug 2022 19:11:21 +0200 Subject: [PATCH] Improved OSC sync Accept OSC request to sync source by name or id. Changed OSC seek request to be by percent target --- ControlManager.cpp | 5 +++++ SourceCallback.cpp | 10 ++++++---- SourceCallback.h | 6 +++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ControlManager.cpp b/ControlManager.cpp index 0961adf..06d88d1 100644 --- a/ControlManager.cpp +++ b/ControlManager.cpp @@ -680,6 +680,11 @@ bool Control::receiveSourceAttribute(Source *target, const std::string &attribut arguments >> t >> osc::EndMessage; target->call( new Seek( t ), true ); } + /// e.g. '/vimix/name/sync' + else if ( attribute.compare(OSC_SYNC) == 0) { + // this will require to send feedback status about source + send_feedback = true; + } #ifdef CONTROL_DEBUG else { Log::Info(CONTROL_OSC_MSG "Ignoring attribute '%s' for target %s.", attribute.c_str(), target->name().c_str()); diff --git a/SourceCallback.cpp b/SourceCallback.cpp index 4bb4135..2a53987 100644 --- a/SourceCallback.cpp +++ b/SourceCallback.cpp @@ -460,7 +460,7 @@ SourceCallback *RePlay::clone() const } -Seek::Seek(float time) : SourceCallback(), target_time_(time) +Seek::Seek(float time) : SourceCallback(), target_(time) { } @@ -473,8 +473,10 @@ void Seek::update(Source *s, float dt) // access media player if target source is a media source MediaSource *ms = dynamic_cast(s); - if (ms != nullptr) - ms->mediaplayer()->seek( GST_SECOND * target_time_ ); + if (ms != nullptr) { + GstClockTime duration = ms->mediaplayer()->timeline()->duration(); + ms->mediaplayer()->seek( target_ * duration ); + } status_ = FINISHED; } @@ -482,7 +484,7 @@ void Seek::update(Source *s, float dt) SourceCallback *Seek::clone() const { - return new Seek(target_time_); + return new Seek(target_); } void Seek::accept(Visitor& v) diff --git a/SourceCallback.h b/SourceCallback.h index 66ff688..3b8d9f0 100644 --- a/SourceCallback.h +++ b/SourceCallback.h @@ -180,13 +180,13 @@ public: class Seek : public SourceCallback { - float target_time_; + float target_; public: Seek (float time = 0.f); - float value () const { return target_time_;} - void setValue (float t) { target_time_ = t; } + float value () const { return target_;} + void setValue (float t) { target_ = t; } void update (Source *s, float dt) override; SourceCallback *clone() const override;