2023-03-21 10:01:25 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "MetasoundOutputSubsystem.h"
|
|
|
|
|
|
|
|
|
|
#include "MetasoundGenerator.h"
|
2023-04-05 17:42:36 -04:00
|
|
|
#include "MetasoundGeneratorHandle.h"
|
2023-03-21 10:01:25 -04:00
|
|
|
#include "MetasoundSource.h"
|
|
|
|
|
#include "MetasoundTrace.h"
|
|
|
|
|
#include "Components/AudioComponent.h"
|
|
|
|
|
#include "ProfilingDebugging/CpuProfilerTrace.h"
|
|
|
|
|
|
|
|
|
|
bool UMetaSoundOutputSubsystem::WatchOutput(
|
|
|
|
|
UAudioComponent* AudioComponent,
|
|
|
|
|
const FName OutputName,
|
|
|
|
|
const FOnMetasoundOutputValueChanged& OnOutputValueChanged,
|
2023-04-05 17:42:36 -04:00
|
|
|
const FName AnalyzerName,
|
|
|
|
|
const FName AnalyzerOutputName)
|
2023-03-21 10:01:25 -04:00
|
|
|
{
|
|
|
|
|
METASOUND_TRACE_CPUPROFILER_EVENT_SCOPE(UMetasoundOutputSubsystem::WatchOutput);
|
|
|
|
|
|
2023-04-05 17:42:36 -04:00
|
|
|
if (nullptr == AudioComponent)
|
2023-03-21 10:01:25 -04:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 17:42:36 -04:00
|
|
|
UMetasoundGeneratorHandle* Handle = nullptr;
|
2023-03-21 10:01:25 -04:00
|
|
|
|
2023-04-05 17:42:36 -04:00
|
|
|
// Try to find an existing handle
|
|
|
|
|
const uint64 AudioComponentId = AudioComponent->GetAudioComponentID();
|
|
|
|
|
if (const TObjectPtr<UMetasoundGeneratorHandle>* FoundHandle = TrackedGenerators.FindByPredicate(
|
|
|
|
|
[AudioComponentId](const TObjectPtr<UMetasoundGeneratorHandle> ExistingHandle)
|
2023-03-21 10:01:25 -04:00
|
|
|
{
|
2023-04-05 17:42:36 -04:00
|
|
|
return ExistingHandle->IsValid() && ExistingHandle->GetAudioComponentId() == AudioComponentId;
|
|
|
|
|
}))
|
2023-03-21 10:01:25 -04:00
|
|
|
{
|
2023-04-05 17:42:36 -04:00
|
|
|
Handle = *FoundHandle;
|
2023-03-21 10:01:25 -04:00
|
|
|
}
|
2023-04-05 17:42:36 -04:00
|
|
|
// Create a new one
|
2023-03-21 10:01:25 -04:00
|
|
|
else
|
|
|
|
|
{
|
2023-04-05 17:42:36 -04:00
|
|
|
Handle = UMetasoundGeneratorHandle::CreateMetaSoundGeneratorHandle(AudioComponent);
|
|
|
|
|
TrackedGenerators.Add(Handle);
|
2023-03-21 10:01:25 -04:00
|
|
|
}
|
|
|
|
|
|
2023-04-05 17:42:36 -04:00
|
|
|
if (nullptr == Handle)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Handle->WatchOutput(OutputName, OnOutputValueChanged, AnalyzerName, AnalyzerOutputName);
|
2023-03-21 10:01:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool UMetaSoundOutputSubsystem::IsTickable() const
|
|
|
|
|
{
|
|
|
|
|
return TrackedGenerators.Num() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UMetaSoundOutputSubsystem::Tick(float DeltaTime)
|
|
|
|
|
{
|
|
|
|
|
METASOUND_TRACE_CPUPROFILER_EVENT_SCOPE(UMetasoundOutputSubsystem::Tick);
|
2023-04-05 17:42:36 -04:00
|
|
|
|
|
|
|
|
for (auto It = TrackedGenerators.CreateIterator(); It; ++It)
|
2023-03-21 10:01:25 -04:00
|
|
|
{
|
2023-04-05 17:42:36 -04:00
|
|
|
if (!(*It)->IsValid())
|
2023-03-21 10:01:25 -04:00
|
|
|
{
|
2023-04-05 17:42:36 -04:00
|
|
|
It.RemoveCurrent();
|
2023-03-21 10:01:25 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-04-05 17:42:36 -04:00
|
|
|
(*It)->UpdateWatchers();
|
2023-03-21 10:01:25 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TStatId UMetaSoundOutputSubsystem::GetStatId() const
|
|
|
|
|
{
|
|
|
|
|
RETURN_QUICK_DECLARE_CYCLE_STAT(UMetasoundGeneratorAccessSubsystem, STATGROUP_Tickables);
|
|
|
|
|
}
|