Skip to content
Snippets Groups Projects
Commit bcf09f90 authored by Philipp Schäfer's avatar Philipp Schäfer
Browse files

SoundSourceComponent

- now initializes SignalSource component and sets ID if changing SignalSource on runtime
parent dc74880e
Branches
No related tags found
No related merge requests found
...@@ -87,7 +87,11 @@ bool UVAAudiofileSignalSource::SetAudiofile(FString AudioFilename) ...@@ -87,7 +87,11 @@ bool UVAAudiofileSignalSource::SetAudiofile(FString AudioFilename)
Filename = AudioFilename; Filename = AudioFilename;
ID = NewID; ID = NewID;
if (bInitialized) //Broadcast is only required after initialization (after BeginPlay())
{
AudiofileChangedEvent.Broadcast(ID); AudiofileChangedEvent.Broadcast(ID);
}
return true; return true;
} }
......
...@@ -158,11 +158,6 @@ void UVASourceComponent::Initialize() ...@@ -158,11 +158,6 @@ void UVASourceComponent::Initialize()
SpawnRotation = GetOwner()->GetTransform().GetRotation().Rotator(); SpawnRotation = GetOwner()->GetTransform().GetRotation().Rotator();
if (SignalSource)
{
SignalSource->Initialize();
}
TArray<AVAReflectionWall*> WallArray = CurrentReceiverActor->GetReflectionWalls(); TArray<AVAReflectionWall*> WallArray = CurrentReceiverActor->GetReflectionWalls();
SoundSource = MakeShared<FVASoundSource>(this, WallArray); SoundSource = MakeShared<FVASoundSource>(this, WallArray);
if (FVAPlugin::GetIsMaster()) if (FVAPlugin::GetIsMaster())
...@@ -188,6 +183,12 @@ void UVASourceComponent::Initialize() ...@@ -188,6 +183,12 @@ void UVASourceComponent::Initialize()
} }
} }
if (SignalSource)
{
SignalSource->Initialize();
SetSignalSourceID(SignalSource->GetID());
}
FVAUtils::LogStuff("[UVASourceComponent::Initialize()]: SoundSourceComponent initialized successfully", false); FVAUtils::LogStuff("[UVASourceComponent::Initialize()]: SoundSourceComponent initialized successfully", false);
bInitialized = true; bInitialized = true;
...@@ -222,9 +223,14 @@ bool UVASourceComponent::ForceUpdateSignalSourceType(TSubclassOf<UVAAbstractSign ...@@ -222,9 +223,14 @@ bool UVASourceComponent::ForceUpdateSignalSourceType(TSubclassOf<UVAAbstractSign
return true; return true;
} }
void UVASourceComponent::SetSignalSourceID(const std::string& ID) bool UVASourceComponent::SetSignalSourceID(const std::string& ID)
{
return FVAPlugin::SetNewBufferForSoundSource(SoundSource->GetSoundSourceID(), ID);
}
void UVASourceComponent::OnSignalSourceIDChanged(const std::string& ID)
{ {
//TODO: Implement FVAPlugin::SetNewBufferForSoundSource(SoundSource->GetSoundSourceID(), ID);
} }
void UVASourceComponent::BindSignalSourceEvents() void UVASourceComponent::BindSignalSourceEvents()
...@@ -232,7 +238,7 @@ void UVASourceComponent::BindSignalSourceEvents() ...@@ -232,7 +238,7 @@ void UVASourceComponent::BindSignalSourceEvents()
UVAAudiofileSignalSource* AudioSignalSource = Cast<UVAAudiofileSignalSource>(SignalSource); UVAAudiofileSignalSource* AudioSignalSource = Cast<UVAAudiofileSignalSource>(SignalSource);
if (AudioSignalSource && !AudioSignalSource->OnAudiofileChanged().IsBoundToObject(this)) if (AudioSignalSource && !AudioSignalSource->OnAudiofileChanged().IsBoundToObject(this))
{ {
SignalSourceChangedDelegate = AudioSignalSource->OnAudiofileChanged().AddUObject(this, &UVASourceComponent::SetSignalSourceID); SignalSourceChangedDelegate = AudioSignalSource->OnAudiofileChanged().AddUObject(this, &UVASourceComponent::OnSignalSourceIDChanged);
} }
} }
...@@ -314,7 +320,15 @@ bool UVASourceComponent::SetSignalSourceType(TSubclassOf<UVAAbstractSignalSource ...@@ -314,7 +320,15 @@ bool UVASourceComponent::SetSignalSourceType(TSubclassOf<UVAAbstractSignalSource
if(SignalSourceType == SignalSourceTypeN) if(SignalSourceType == SignalSourceTypeN)
return true; return true;
return ForceUpdateSignalSourceType(SignalSourceTypeN); if (!ForceUpdateSignalSourceType(SignalSourceTypeN))
return false;
if (SignalSource)
{
SignalSource->Initialize();
return SetSignalSourceID(SignalSource->GetID());
}
return true;
} }
...@@ -706,14 +720,17 @@ float UVASourceComponent::GetSoundTimeOffset() const ...@@ -706,14 +720,17 @@ float UVASourceComponent::GetSoundTimeOffset() const
void UVASourceComponent::PreEditChange(UProperty* PropertyWhatWillChange) void UVASourceComponent::PreEditChange(UProperty* PropertyWhatWillChange)
{ {
//If user directly changes the signal source component to "None" Super::PreEditChange(PropertyWhatWillChange);
// TODO:
// This is true if user directly changes the signal source component to "None"
// However, it is also true if user changes a sub-property of SignalSource
if (PropertyWhatWillChange->GetFName() == GET_MEMBER_NAME_CHECKED(UVASourceComponent, SignalSource)) if (PropertyWhatWillChange->GetFName() == GET_MEMBER_NAME_CHECKED(UVASourceComponent, SignalSource))
{ {
UnbindSignalSourceEvents(); UnbindSignalSourceEvents(); //Unbind works for now, since we bind in BeginPlay() again.
SignalSourceType = nullptr; //SignalSourceType = nullptr;
} }
Super::PreEditChange(PropertyWhatWillChange);
} }
void UVASourceComponent::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) void UVASourceComponent::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
......
...@@ -259,7 +259,8 @@ protected: ...@@ -259,7 +259,8 @@ protected:
bool ForceUpdateSignalSourceType(TSubclassOf<UVAAbstractSignalSource> SignalSourceTypeN); bool ForceUpdateSignalSourceType(TSubclassOf<UVAAbstractSignalSource> SignalSourceTypeN);
void SetSignalSourceID(const std::string& ID); bool SetSignalSourceID(const std::string& ID);
void OnSignalSourceIDChanged(const std::string& ID);
// *** Event/Delegates *** // // *** Event/Delegates *** //
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment