From b5e9b24821ef06ba00fdf9a9e666ec5a462d8476 Mon Sep 17 00:00:00 2001
From: jehret <ehret@vr.rwth-aachen.de>
Date: Fri, 30 Jun 2023 21:58:08 +0200
Subject: [PATCH] improve getplayaction documentation and API and remove debug
 logging

---
 .../SignalSources/VAAudiofileSignalSource.cpp    | 16 +++++++---------
 .../SignalSources/VAAudiofileSignalSource.h      | 16 ++++++++++------
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/Source/VAPlugin/Private/SignalSources/VAAudiofileSignalSource.cpp b/Source/VAPlugin/Private/SignalSources/VAAudiofileSignalSource.cpp
index 1fe8e09..a137569 100644
--- a/Source/VAPlugin/Private/SignalSources/VAAudiofileSignalSource.cpp
+++ b/Source/VAPlugin/Private/SignalSources/VAAudiofileSignalSource.cpp
@@ -146,8 +146,6 @@ bool UVAAudiofileSignalSource::SetPlayAction(const int Action)
 	InterallyStoredPlayAction = Action;
 	StorePlayStateInternallyEvent.Send(Action); //also send this to all slaves, so potentially still pending send numbers from GetPlayAction are overwritten
 
-	FVAUtils::LogStuff("set play action to " + FString::FromInt(InterallyStoredPlayAction) + "   (and stored internally)");
-
 	if (!UVirtualRealityUtilities::IsMaster())
 	{
 		return false;
@@ -172,12 +170,12 @@ bool UVAAudiofileSignalSource::GetLoop() const
 	return bLoop;
 }
 
-EPlayAction::Type UVAAudiofileSignalSource::GetPlayActionEnum()
+EPlayAction::Type UVAAudiofileSignalSource::GetPlayActionEnum(bool bDirectOnMaster /*= false*/)
 {
-	return EPlayAction::Type(GetPlayAction());
+	return EPlayAction::Type(GetPlayAction(bDirectOnMaster));
 }
 
-int UVAAudiofileSignalSource::GetPlayAction()
+int UVAAudiofileSignalSource::GetPlayAction(bool bDirectOnMaster /*= false*/)
 {
 	//we return the internally stored action in case this is in cluster and not the master
 	//but also update the internally stored data by the one which the master can get from the VAServer
@@ -188,11 +186,12 @@ int UVAAudiofileSignalSource::GetPlayAction()
 		// otherwise (in cluster mode) this emits acluster event, so the internal data will be updated before next Tick
 		int VAServerPlayAction = FVAPlugin::GetSignalSourceBufferPlayAction(ID);
 		StorePlayStateInternallyEvent.Send(VAServerPlayAction);
-		FVAUtils::LogStuff("send " + FString::FromInt(VAServerPlayAction)+ "   as cluster event");
+		if(bDirectOnMaster)
+		{
+			return VAServerPlayAction;
+		}
 	}
 
-	FVAUtils::LogStuff("returned stored play action " + FString::FromInt(InterallyStoredPlayAction));
-
 	return InterallyStoredPlayAction;
 }
 
@@ -222,6 +221,5 @@ bool UVAAudiofileSignalSource::CopySignalSourceSettings(const std::string& Other
 
 void UVAAudiofileSignalSource::StorePlayStateInternally(int PlayAction)
 {
-	FVAUtils::LogStuff("set " + FString::FromInt(PlayAction) + "   from cluster event");
 	InterallyStoredPlayAction = PlayAction;
 }
diff --git a/Source/VAPlugin/Public/SignalSources/VAAudiofileSignalSource.h b/Source/VAPlugin/Public/SignalSources/VAAudiofileSignalSource.h
index ecc8179..38761bd 100644
--- a/Source/VAPlugin/Public/SignalSources/VAAudiofileSignalSource.h
+++ b/Source/VAPlugin/Public/SignalSources/VAAudiofileSignalSource.h
@@ -62,8 +62,6 @@ public:
 	bool SetLoop(bool bLoopN);
 	UFUNCTION(BlueprintCallable)
 	bool SetPlayBackPosition(float Time);
-	UFUNCTION(BlueprintCallable)
-	bool SetPlayAction(int Action);
 
 
 	// *** Getter *** //
@@ -73,12 +71,15 @@ public:
 	UFUNCTION(BlueprintCallable)
 	bool GetLoop() const;
 
-	//GetPlayActionEnum() might be one tick behind in cluster mode, since the current play action is only synced between master and slaves after this is called
-	//so make sue to, e.g., call this every frame or at least multiple times (if you, e.g., want to observe a change from play to pause)
+	//CAUTION when used in cluster mode (e.g., CAVE):
+	// GetPlayActionEnum() might be one tick behind in cluster mode, since the current play action is only synced between master and slaves after this is called
+	// so make sure to, e.g., call this every frame or at least multiple times (if you, e.g., want to observe a change from play to pause)
+	// Alternatively, you can also set the bDirectOnMaster flag to get the status directly from the master, in that case you should make sure
+	// that everything is synced to the slaves, e.g., using sync components, as data will be delayed on the slaves!!!
 	UFUNCTION(BlueprintCallable) 
-	EPlayAction::Type GetPlayActionEnum();
+	EPlayAction::Type GetPlayActionEnum(bool bDirectOnMaster = false);
 
-	int GetPlayAction();
+	
 
 	// *** Events/Delegates *** //
 
@@ -111,6 +112,9 @@ protected:
 
 private:
 
+	bool SetPlayAction(int Action);
+	int GetPlayAction(bool bDirectOnMaster=false);
+
 	void StorePlayStateInternally(int PlayAction);
 	DECLARE_DISPLAY_CLUSTER_EVENT(UVAAudiofileSignalSource, StorePlayStateInternally);
 	int InterallyStoredPlayAction = -1;
-- 
GitLab