From a87463a84058a834ff7729c6ba9064bb5db2556a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Philipp=20Sch=C3=A4fer?=
 <pschaefer@ITA.AKUSTIK.RWTH-AACHEN.DE>
Date: Mon, 5 Dec 2022 15:14:10 +0100
Subject: [PATCH] VA Sound Source: Added setting to create renderer explicit
 sources

---
 .../Private/ImageSourceModel/VAImageSourceModel.cpp   |  7 ++++---
 .../Private/ImageSourceModel/VAImageSourceModel.h     |  2 +-
 .../Private/SoundSource/VAAbstractSourceComponent.cpp |  4 +++-
 Source/VAPlugin/Private/SoundSource/VASoundSource.cpp | 11 +++++++++--
 Source/VAPlugin/Private/SoundSource/VASoundSource.h   |  4 +++-
 Source/VAPlugin/Private/VAPlugin.cpp                  |  8 ++++++--
 Source/VAPlugin/Private/VAPlugin.h                    |  2 +-
 .../Public/SoundSource/VAAbstractSourceComponent.h    |  8 ++++++++
 8 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/Source/VAPlugin/Private/ImageSourceModel/VAImageSourceModel.cpp b/Source/VAPlugin/Private/ImageSourceModel/VAImageSourceModel.cpp
index 2d5802d..9751244 100644
--- a/Source/VAPlugin/Private/ImageSourceModel/VAImageSourceModel.cpp
+++ b/Source/VAPlugin/Private/ImageSourceModel/VAImageSourceModel.cpp
@@ -29,7 +29,7 @@ FVAImageSourceModel::FVAImageSourceModel(UWorld* World, TSharedRef<FVASoundSourc
 
 		const float R = Wall->GetReflectionValueR();
 		const float PowerR = ParentSource->GetPower() * R * R;
-		ImageSources.Add( MakeShared<FVAImageSource>(Wall, World, ParentSource->GetPosition(), ParentSource->GetRotation(), PowerR, ISName, ParentSource->GetDirectivity()) );
+		ImageSources.Add( MakeShared<FVAImageSource>(Wall, World, ParentSource->GetPosition(), ParentSource->GetRotation(), PowerR, ISName, ParentSource->GetExplicitRendererID(), ParentSource->GetDirectivity()) );
 	}
 }
 
@@ -179,8 +179,9 @@ FRotator FVAImageSourceModel::ComputeReflectedRot(const AVAReflectionWall* Wall,
 // ******* Image Source Class *************************************** //
 // ****************************************************************** //
 
-FVAImageSourceModel::FVAImageSource::FVAImageSource(AVAReflectionWall* Wall, UWorld* World, const FVector& Position, const FRotator& Rotation, float Power, const std::string& Name, TSharedPtr<FVADirectivity>  Directivity /* = nullptr */)
-	: FVASoundSource(World, Position, Rotation, Power, Name, Directivity)
+FVAImageSourceModel::FVAImageSource::FVAImageSource(AVAReflectionWall* Wall, UWorld* World, const FVector& Position, const FRotator& Rotation, float Power,
+	const std::string& Name, const std::string& RendererID /* = "" */, TSharedPtr<FVADirectivity>  Directivity /* = nullptr */)
+	: FVASoundSource(World, Position, Rotation, Power, Name, RendererID, Directivity)
 	, Wall(Wall)
 {
 	if (Wall == nullptr)
diff --git a/Source/VAPlugin/Private/ImageSourceModel/VAImageSourceModel.h b/Source/VAPlugin/Private/ImageSourceModel/VAImageSourceModel.h
index ac62ea1..c8c7c9b 100644
--- a/Source/VAPlugin/Private/ImageSourceModel/VAImageSourceModel.h
+++ b/Source/VAPlugin/Private/ImageSourceModel/VAImageSourceModel.h
@@ -56,7 +56,7 @@ private:
 	class FVAImageSource : public FVASoundSource
 	{
 	public:
-		FVAImageSource(AVAReflectionWall* Wall, UWorld* World, const FVector& PosN, const FRotator& RotN, float PowerN, const std::string& NameN, TSharedPtr<FVADirectivity> Directivity = nullptr);
+		FVAImageSource(AVAReflectionWall* Wall, UWorld* World, const FVector& PosN, const FRotator& RotN, float PowerN, const std::string& NameN, const std::string& RendererID = "", TSharedPtr<FVADirectivity> Directivity = nullptr);
 		AVAReflectionWall* GetWall();
 	private:
 		AVAReflectionWall* Wall;
diff --git a/Source/VAPlugin/Private/SoundSource/VAAbstractSourceComponent.cpp b/Source/VAPlugin/Private/SoundSource/VAAbstractSourceComponent.cpp
index 0639a3e..a85a86d 100644
--- a/Source/VAPlugin/Private/SoundSource/VAAbstractSourceComponent.cpp
+++ b/Source/VAPlugin/Private/SoundSource/VAAbstractSourceComponent.cpp
@@ -150,8 +150,10 @@ void UVAAbstractSourceComponent::Initialize()
 	SpawnPosition = GetOwner()->GetTransform().GetLocation();
 	SpawnRotation = GetOwner()->GetTransform().GetRotation().Rotator();
 
+
+	const std::string ExplicitRendererID = bRendererExplicit ? std::string( TCHAR_TO_UTF8(*RendererID) ): ""; // Empty ID => general source
 	const std::string SoundSourceName = std::string( TCHAR_TO_UTF8(*GetName()) );
-	SoundSource = MakeShared<FVASoundSource>(GetWorld(), GetPosition(), GetRotation(), SoundPower, SoundSourceName);
+	SoundSource = MakeShared<FVASoundSource>(GetWorld(), GetPosition(), GetRotation(), SoundPower, SoundSourceName, ExplicitRendererID);
 
 	if (UVirtualRealityUtilities::IsMaster())
 	{
diff --git a/Source/VAPlugin/Private/SoundSource/VASoundSource.cpp b/Source/VAPlugin/Private/SoundSource/VASoundSource.cpp
index 28f7979..4398f16 100644
--- a/Source/VAPlugin/Private/SoundSource/VASoundSource.cpp
+++ b/Source/VAPlugin/Private/SoundSource/VASoundSource.cpp
@@ -14,9 +14,11 @@
 // ******* Initialization ******************************************* //
 // ****************************************************************** //
 
-FVASoundSource::FVASoundSource(UWorld* World, const FVector& Position, const FRotator& Rotation, float Power, const std::string& Name /* = "" */, TSharedPtr<FVADirectivity> Directivity /* = nullptr */)
+FVASoundSource::FVASoundSource(UWorld* World, const FVector& Position, const FRotator& Rotation, float Power, const std::string& Name,
+	const std::string& RendererID /* = "" */, TSharedPtr<FVADirectivity> Directivity /* = nullptr */)
 	: SoundSourceID(VA_INVALID_ID)
 	, Name(Name)
+	, RendererID(RendererID)
 	, Position(Position)
 	, Rotation(Rotation)
 	, bShowCones(false)
@@ -26,7 +28,7 @@ FVASoundSource::FVASoundSource(UWorld* World, const FVector& Position, const FRo
 {
 	bShowCones = FVAPlugin::GetDebugMode();
 
-	SoundSourceID = FVAPlugin::CreateNewSoundSource(Name, Position, Rotation, Power);
+	SoundSourceID = FVAPlugin::CreateNewSoundSource(Name, Position, Rotation, Power, RendererID);
 	if (SoundSourceID == VA_INVALID_ID)
 	{
 		FVAUtils::LogStuff("[FVASoundSource::FVASoundSource()]: Error initializing VA sound source", true);
@@ -182,6 +184,11 @@ const std::string& FVASoundSource::GetSoundSourceName() const
 	return Name;
 }
 
+const std::string& FVASoundSource::GetExplicitRendererID() const
+{
+	return RendererID;
+}
+
 FVector FVASoundSource::GetPosition() const
 {
 	return Position;
diff --git a/Source/VAPlugin/Private/SoundSource/VASoundSource.h b/Source/VAPlugin/Private/SoundSource/VASoundSource.h
index a007878..a5f7210 100644
--- a/Source/VAPlugin/Private/SoundSource/VASoundSource.h
+++ b/Source/VAPlugin/Private/SoundSource/VASoundSource.h
@@ -17,7 +17,7 @@ class FVASoundSource
 public:
 
 	// Initialization
-	FVASoundSource(UWorld* World, const FVector& PosN, const FRotator& RotN, float PowerN, const std::string& NameN = "", TSharedPtr<FVADirectivity> DirectivityID = nullptr);
+	FVASoundSource(UWorld* World, const FVector& PosN, const FRotator& RotN, float PowerN, const std::string& NameN, const std::string& RendererID = "", TSharedPtr<FVADirectivity> DirectivityID = nullptr);
 	virtual ~FVASoundSource();
 
 	// Setter
@@ -39,6 +39,7 @@ public:
 	// Getter
 	int GetSoundSourceID() const;
 	const std::string& GetSoundSourceName() const;
+	const std::string& GetExplicitRendererID() const;
 
 	FVector GetPosition() const;
 	FRotator GetRotation() const;
@@ -54,6 +55,7 @@ private:
 
 	int SoundSourceID;
 	std::string Name;
+	std::string RendererID;
 
 	FVector Position;
 	FRotator Rotation;
diff --git a/Source/VAPlugin/Private/VAPlugin.cpp b/Source/VAPlugin/Private/VAPlugin.cpp
index d0f3ba5..87eeda9 100644
--- a/Source/VAPlugin/Private/VAPlugin.cpp
+++ b/Source/VAPlugin/Private/VAPlugin.cpp
@@ -635,7 +635,7 @@ bool FVAPlugin::SetJetEngineRMP(const std::string& SignalSourceID, float fRPM)
 // ******* Sound Sources ******************************************** //
 // ****************************************************************** //
 
-int FVAPlugin::CreateNewSoundSource(const std::string& Name, FVector Pos, FRotator Rot, const float Power, const std::string& SignalSourceID)
+int FVAPlugin::CreateNewSoundSource(const std::string& Name, FVector Pos, FRotator Rot, const float Power, const std::string& RendererID, const std::string& SignalSourceID)
 {
 	if (!ShouldInteractWithServer())
 	{
@@ -660,7 +660,11 @@ int FVAPlugin::CreateNewSoundSource(const std::string& Name, FVector Pos, FRotat
 
 	try
 	{
-		const int SoundSourceID = VAServer->CreateSoundSource(Name);
+		int SoundSourceID;
+		if ( RendererID.empty() )
+			SoundSourceID = VAServer->CreateSoundSource(Name);
+		else
+			SoundSourceID = VAServer->CreateSoundSourceExplicitRenderer(RendererID, Name);
 
 		VAServer->SetSoundSourcePose(SoundSourceID, *TmpVAVec3, *TmpVAQuat);
 
diff --git a/Source/VAPlugin/Private/VAPlugin.h b/Source/VAPlugin/Private/VAPlugin.h
index 48cb7ea..9fa2bcf 100644
--- a/Source/VAPlugin/Private/VAPlugin.h
+++ b/Source/VAPlugin/Private/VAPlugin.h
@@ -86,7 +86,7 @@ public:
 	// ******* Sound Sources ******* //
 
 	static int CreateNewSoundSource(const std::string& Name, FVector Pos = FVector(0, 0, 0),
-		FRotator Rot = FRotator(0, 0, 0), float Power = -1.0f, const std::string& SignalSourceID = "");
+		FRotator Rot = FRotator(0, 0, 0), float Power = -1.0f, const std::string& RendererID = "", const std::string & SignalSourceID = "");
 	// Deletes a sound source with given ID. Use with great care!
 	static bool DeleteSoundSource(int SoundSourceID);
 	static bool SetSoundSourcePosition(int SoundSourceID, FVector Pos);
diff --git a/Source/VAPlugin/Public/SoundSource/VAAbstractSourceComponent.h b/Source/VAPlugin/Public/SoundSource/VAAbstractSourceComponent.h
index 0a9176f..fdc43f4 100644
--- a/Source/VAPlugin/Public/SoundSource/VAAbstractSourceComponent.h
+++ b/Source/VAPlugin/Public/SoundSource/VAAbstractSourceComponent.h
@@ -35,6 +35,14 @@ protected:
 		ClampMin = "0.0", ClampMax = "100.0", UIMin = "0.0", UIMax = "100.0"))
 	float SoundPower = 0.0316227749f;
 
+	// Enable to make this sound source only available to a specific VA renderer
+	UPROPERTY(EditAnywhere, meta = (DisplayName = "Renderer explicit", Category = "General Settings") )
+	bool bRendererExplicit;
+
+	// VA Renderer ID for using specific renderer. An empty string refers to a general source.
+	UPROPERTY(EditAnywhere, meta = (DisplayName = "Renderer ID", Category = "General Settings", EditCondition = "bRendererExplicit") )
+	FString RendererID = "";
+
 	// Decide whether to use manual Transform (below) or use Transform / Movement of Actor
 	UPROPERTY(EditAnywhere, meta = (DisplayName = "Position Settings", Category = "Position",
 		CustomStructureParam = "Move With the Object, At Object Spawn Point (unmovable, also reflections), Attatch to a Bone"))
-- 
GitLab