From b82cfdc285461df5d74d3a6810bf03e208442b6f Mon Sep 17 00:00:00 2001
From: Marius Schmeling <schmeling@vr.rwth-aachen.de>
Date: Thu, 28 Nov 2019 13:46:15 +0100
Subject: [PATCH] DirManager Logging, config now in Study folder

---
 Source/VAPlugin/Private/VADirectivity.cpp     |  3 +
 .../VAPlugin/Private/VADirectivityManager.cpp | 22 ++++++-
 Source/VAPlugin/Private/VAPlugin.cpp          |  6 +-
 Source/VAPlugin/Private/VAReceiverActor.cpp   | 31 +++++-----
 .../Private/VASoundSourceRepresentation.cpp   | 27 ---------
 Source/VAPlugin/Private/VAUtils.cpp           | 57 -------------------
 Source/VAPlugin/Public/VAReceiverActor.h      | 18 +++---
 config/directivities/default.ini              | 24 --------
 8 files changed, 52 insertions(+), 136 deletions(-)
 delete mode 100644 config/directivities/default.ini

diff --git a/Source/VAPlugin/Private/VADirectivity.cpp b/Source/VAPlugin/Private/VADirectivity.cpp
index 37e7805..d3e3cd6 100644
--- a/Source/VAPlugin/Private/VADirectivity.cpp
+++ b/Source/VAPlugin/Private/VADirectivity.cpp
@@ -30,6 +30,9 @@ VADirectivity::VADirectivity(FString fileName, TArray<FString> phonemes_)
 		UE_LOG(LogTemp, Warning, TEXT("   Directivity file %s cannot be found!"), *fileName);
 		return;
 	}
+	
+	VAUtils::logStuff("created new VADirectivity");
+	
 }
 
 
diff --git a/Source/VAPlugin/Private/VADirectivityManager.cpp b/Source/VAPlugin/Private/VADirectivityManager.cpp
index ed91e8b..2665aed 100644
--- a/Source/VAPlugin/Private/VADirectivityManager.cpp
+++ b/Source/VAPlugin/Private/VADirectivityManager.cpp
@@ -1,4 +1,7 @@
 #include "VADirectivityManager.h"
+
+#include "VAUtils.h"
+
 #include "Core.h"
 #include "Interfaces/IPluginManager.h"
 
@@ -22,8 +25,12 @@ void VADirectivityManager::readConfigFile(FString configFileName_) {
 	configFileName = configFileName_;
 
 	// Read config File
-	FString BaseDir = IPluginManager::Get().FindPlugin("VAPlugin")->GetBaseDir();
-	FString dir = FPaths::Combine(*BaseDir, TEXT("config/directivities/"));
+	// FString BaseDir = IPluginManager::Get().FindPlugin("VAPlugin")->GetBaseDir();
+	// FString dir = FPaths::Combine(*BaseDir, TEXT("config/directivities/"));
+
+	FString RelativePath = FPaths::ProjectContentDir();
+	FString dir = IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*RelativePath) + "Study/";
+
 	FString config_file_name = dir + configFileName;
 
 	GConfig->UnloadFile(config_file_name);
@@ -32,9 +39,11 @@ void VADirectivityManager::readConfigFile(FString configFileName_) {
 	FConfigFile* config = GConfig->FindConfigFile(config_file_name);
 
 	if (config == nullptr) {
-		VAUtils::logStuff(FString("[VADirectivityManager::readConfigFile()] - Unable to load directivity config file") + config_file_name);
+		VAUtils::logStuff(FString("[VADirectivityManager::readConfigFile()] - Unable to load directivity config file: ") + config_file_name);
 		return;
 	}
+	VAUtils::logStuff(FString("[VADirectivityManager::readConfigFile()] - Config file loaded: ") + config_file_name);
+
 
 	FString listSymbol, mapToSymbol;
 	config->GetString(TEXT("DirectivityMapping"), TEXT("listSymbol"), listSymbol);
@@ -83,6 +92,13 @@ void VADirectivityManager::readConfigFile(FString configFileName_) {
 		// 	continue;
 		// }
 
+		FString output = "Mapping from: ";
+		for (auto p : tmp_phonemes) {
+			output.Append(p + ",");
+		}
+		output.Append(" --> " + tmp_fileName);
+		VAUtils::logStuff(output);
+
 		VADirectivity* tmpDir = new VADirectivity(tmp_fileName, tmp_phonemes);
 		directivities.Add(tmpDir);
 
diff --git a/Source/VAPlugin/Private/VAPlugin.cpp b/Source/VAPlugin/Private/VAPlugin.cpp
index e3a568e..97f4485 100644
--- a/Source/VAPlugin/Private/VAPlugin.cpp
+++ b/Source/VAPlugin/Private/VAPlugin.cpp
@@ -174,11 +174,11 @@ void FVAPluginModule::askForSettings(FString host, int port, bool askForDebugMod
 	isMaster = IDisplayCluster::Get().GetClusterMgr() != nullptr && IDisplayCluster::Get().GetClusterMgr()->IsMaster();
 
 	EAppReturnType::Type ret = FMessageDialog::Open(EAppMsgType::YesNo, FText::FromString("Use VA Server (" + host + ":" + FString::FromInt(port) + ")? If yes, make sure to have it switched on."));
-	if (ret == EAppReturnType::Type::No) {
-		useVA = false;
+	if (ret == EAppReturnType::Type::Yes) {
+		useVA = true;
 	}
 	else {
-		useVA = true;
+		useVA = false;
 		debugMode = false;
 		initialized = true;
 		return;
diff --git a/Source/VAPlugin/Private/VAReceiverActor.cpp b/Source/VAPlugin/Private/VAReceiverActor.cpp
index cfb9d06..a648906 100644
--- a/Source/VAPlugin/Private/VAReceiverActor.cpp
+++ b/Source/VAPlugin/Private/VAReceiverActor.cpp
@@ -168,9 +168,14 @@ void AVAReceiverActor::Tick(float DeltaTime)
 		timeSinceUpdate = 0.0f;
 	}
 
-	if (totalTime > 8.0f) {
-		runOnAllNodes("debugMode = false");
-		timeSinceUpdate = -100000.0f;
+	if (totalTime > 2.0f) {
+		if (FVAPluginModule::getDebugMode()) {
+			runOnAllNodes("debugMode = false");
+		}
+		else {
+			runOnAllNodes("debugMode = true");
+		}
+		totalTime = 0.0f;
 	}
 }
 
@@ -183,20 +188,18 @@ bool AVAReceiverActor::updateVirtualWorldPosition()
 {
 	controller->GetPlayerViewPoint(tmpPosF, tmpRotF);
 
-	FString text = "Position of Receiver (id: " + FString::FromInt(receiverID) + ") is: ";
-	text.Append(FString::FromInt(tmpPosF.X)).Append("/").Append(FString::FromInt(tmpPosF.Y)).Append("/").Append(FString::FromInt(tmpPosF.Z));
-	VAUtils::logStuff(text);
-
-	text = "Rotation of Receiver (id: " + FString::FromInt(receiverID) + ") is: ";
-	text.Append(FString::FromInt(tmpRotF.Roll)).Append("/").Append(FString::FromInt(tmpRotF.Pitch)).Append("/").Append(FString::FromInt(tmpRotF.Yaw));
-	
-	VAUtils::logStuff(text);
+	// FString text = "Position of Receiver (id: " + FString::FromInt(receiverID) + ") is: ";
+	// text.Append(FString::FromInt(tmpPosF.X)).Append("/").Append(FString::FromInt(tmpPosF.Y)).Append("/").Append(FString::FromInt(tmpPosF.Z));
+	// VAUtils::logStuff(text);
+	// 
+	// text = "Rotation of Receiver (id: " + FString::FromInt(receiverID) + ") is: ";
+	// text.Append(FString::FromInt(tmpRotF.Roll)).Append("/").Append(FString::FromInt(tmpRotF.Pitch)).Append("/").Append(FString::FromInt(tmpRotF.Yaw));
+	// 
+	// VAUtils::logStuff(text);
 
 	FVAPluginModule::setSoundReceiverPosition(receiverID, tmpPosF);
 	FVAPluginModule::setSoundReceiverRotation(receiverID, tmpRotF);
 
-	// FVAPluginModule::updateReceiverPos(tmpPosF, tmpRotF);
-
 	return false;
 }
 
@@ -395,6 +398,8 @@ void AVAReceiverActor::HandleClusterEvent(const FDisplayClusterClusterEvent & Ev
 
 void AVAReceiverActor::handleClusterCommand(FString command)
 {
+	VAUtils::logStuff("Cluster Command " + command + " received");
+
 	if (command == "useVA = false") {
 		FVAPluginModule::setUseVA(false);
 	}
diff --git a/Source/VAPlugin/Private/VASoundSourceRepresentation.cpp b/Source/VAPlugin/Private/VASoundSourceRepresentation.cpp
index 7324578..641f05d 100644
--- a/Source/VAPlugin/Private/VASoundSourceRepresentation.cpp
+++ b/Source/VAPlugin/Private/VASoundSourceRepresentation.cpp
@@ -14,33 +14,6 @@ AVASoundSourceRepresentation::AVASoundSourceRepresentation()
  	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
 	PrimaryActorTick.bCanEverTick = true;
 
-	// reflection Sphere
-	// sphereComp2 = CreateDefaultSubobject<USphereComponent>(FName("ShapeComponent"));
-	// sphereComp2->bHiddenInGame = false;
-	// sphereComp2->Mobility = EComponentMobility::Movable;
-	// RootComponent = sphereComp2;
-	// 
-	// sphereMesh2 = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VisualRepresentation"));
-	// sphereMesh2->AttachTo(RootComponent);
-	// 
-	// // static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereMeshAsset(TEXT("/VAPlugin/Shape_Cone.Shape_Cone"));
-	// 
-	// static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereMeshAsset(TEXT("/Game/StarterContent/Shapes/Shape_Cone.Shape_Cone"));
-	// 
-	// // FString BaseDir = IPluginManager::Get().FindPlugin("VAPlugin")->GetBaseDir();
-	// // FString pathFile = FPaths::Combine(*BaseDir, TEXT("Content/Shape_Cone.Shape_Cone"));
-	// // BaseDir.Append("/Content/Shape_Cone.Shape_Cone");
-	// // static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereMeshAsset(*BaseDir);
-	// 
-	// if (SphereMeshAsset.Succeeded()) {
-	// 	sphereMesh2->SetStaticMesh(SphereMeshAsset.Object);
-	// 	sphereMesh2->SetRelativeLocation(FVector(80.0f, 0.0f, 0.0f));
-	// 	sphereMesh2->SetRelativeRotation(FRotator(90.0f, 0.0f, 0.0f));
-	// 	sphereMesh2->SetWorldScale3D(FVector(0.8f));
-	// }
-	// 
-	// setVisibility(FVAPluginModule::isInDebugMode());
-
 	sphereComp = CreateDefaultSubobject<USphereComponent>(FName("SphereComp"));
 	sphereComp->bHiddenInGame = true;
 	sphereComp->Mobility = EComponentMobility::Movable;
diff --git a/Source/VAPlugin/Private/VAUtils.cpp b/Source/VAPlugin/Private/VAUtils.cpp
index f748dd5..9db5d87 100644
--- a/Source/VAPlugin/Private/VAUtils.cpp
+++ b/Source/VAPlugin/Private/VAUtils.cpp
@@ -230,61 +230,4 @@ int VAUtils::EPlayActionToVAAction(EPlayAction action)
 }
 
 
-/*
-bool VAUtils::getViewingPos(FVector* vec, FQuat* quat)
-{
-	if (vec == NULL || quat == NULL)
-		return false;
-
-	FRotator* rot = new FRotator();
-
-	//UHeadMountedDisplayFunctionLibrary::GetOrientationAndPosition(*rot, *vec);
-	*quat = rot->Quaternion();
-	delete rot;
-
-	return true;
-}
-
-bool VAUtils::getViewingPos(VAVec3* vec, VAQuat* quat)
-{
-	if (vec == NULL || quat == NULL)
-		return false;
-
-	FVector* vecF = new FVector();
-	FQuat* quatF = new FQuat();
-	FRotator* rot = new FRotator();
-
-	if(FVAPluginModule::isViewModeHMD())
-	{
-		//UHeadMountedDisplayFunctionLibrary::GetOrientationAndPosition(*rot, *vecF);
-	}
-
-	*quatF = rot->Quaternion();
-
-	fQuatToVAQuat(quatF, quat);
-	fVecToVAVec3(vecF, vec);
-
-	delete vecF, quatF, rot;
-	return true;
-}
-
-bool VAUtils::getViewingPosVA(VAVec3* vec, VAQuat* quat)
-{
-	if (vec == NULL || quat == NULL)
-		return false;
-
-	FVector* vecF = new FVector();
-	FQuat* quatF = new FQuat();
-	FRotator* rot = new FRotator();
-
-	//UHeadMountedDisplayFunctionLibrary::GetOrientationAndPosition(*rot, *vecF);
-	*quatF = rot->Quaternion();
-
-	fQuatToVAQuatRot(quatF, quat);
-	fVecToVAVec3Rot(vecF, vec);
-
-	delete vecF, quatF, rot;
-	return true;
-}
-*/
 
diff --git a/Source/VAPlugin/Public/VAReceiverActor.h b/Source/VAPlugin/Public/VAReceiverActor.h
index 0e77ff0..0b1efc6 100644
--- a/Source/VAPlugin/Public/VAReceiverActor.h
+++ b/Source/VAPlugin/Public/VAReceiverActor.h
@@ -5,8 +5,8 @@
 #include "VAPlugin.h"
 
 #include "VADirectivityManager.h"
-
-#include "Cluster/IDisplayClusterClusterManager.h"		// For Events
+
+#include "Cluster/IDisplayClusterClusterManager.h"		// For Events
 #include "Cluster/DisplayClusterClusterEvent.h"			// For Events
 
 #include "CoreMinimal.h"								// For Events
@@ -80,7 +80,7 @@ public:
 
 	// Factor for global output Gain
 	UPROPERTY(EditAnywhere, meta = (DisplayName = "Name of ini file for directivities",		Category = "Directivity Manager"))
-		FString dirName = "default.ini";
+		FString dirName = "VADir_default.ini";
 
 
 
@@ -156,12 +156,12 @@ protected:
 
 
 	// Event Listener Delegate
-	FOnClusterEventListener ClusterEventListenerDelegate;
-
-	// Called on cluster Event emission
-	void HandleClusterEvent(const FDisplayClusterClusterEvent& Event);
-
-	// "Compiler"
+	FOnClusterEventListener ClusterEventListenerDelegate;
+
+	// Called on cluster Event emission
+	void HandleClusterEvent(const FDisplayClusterClusterEvent& Event);
+
+	// "Compiler"
 	void handleClusterCommand(FString command);
 
 
diff --git a/config/directivities/default.ini b/config/directivities/default.ini
deleted file mode 100644
index 7d98601..0000000
--- a/config/directivities/default.ini
+++ /dev/null
@@ -1,24 +0,0 @@
-[DirectivityMapping]
-
-# Symbol the list is devided (default: ",")
-listSymbol=,
-
-# Symbol the mapping is done (default ":")
-mapToSymbol=:
-
-# Mapping in form: 
-# mapping=phoneme1,phoeneme2,phoneme3:file1
-# mapping=default,phoneme4:file2
-mapping=a,b,c:$(HumanDir)
-
-
-
-# old data, please ignore:
-dirFolder=
-default=defaultDir
-dividingSymbol=,
-pair=a,ab
-pair=b,bb
-pair=c,cb
-
-
-- 
GitLab