2023-03-20 17:13:25 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
2023-03-21 10:01:25 -04:00
|
|
|
#include "MetasoundOutputWatcher.h"
|
|
|
|
|
#include "MetasoundTrace.h"
|
2023-03-20 17:13:25 -04:00
|
|
|
|
|
|
|
|
namespace Metasound::Private
|
|
|
|
|
{
|
2023-03-21 10:01:25 -04:00
|
|
|
TMap<FName, TUniquePtr<FMetasoundOutputWatcher::IOutputTypeOperations>> FMetasoundOutputWatcher::OutputTypeOperationMap{};
|
2023-03-20 17:13:25 -04:00
|
|
|
|
2023-03-21 10:01:25 -04:00
|
|
|
FMetasoundOutputWatcher::FMetasoundOutputWatcher(
|
2023-03-20 17:13:25 -04:00
|
|
|
Frontend::FAnalyzerAddress&& Address,
|
|
|
|
|
const FOperatorSettings& OperatorSettings)
|
|
|
|
|
: Name(Address.OutputName)
|
|
|
|
|
, View(MoveTemp(Address))
|
|
|
|
|
{
|
|
|
|
|
View.BindToAllOutputs(OperatorSettings);
|
|
|
|
|
|
|
|
|
|
TArray<Frontend::FMetasoundAnalyzerView::FBoundOutputDescription> OutputDescriptions = View.GetBoundOutputDescriptions();
|
|
|
|
|
for (Frontend::FMetasoundAnalyzerView::FBoundOutputDescription& OutputDescription : OutputDescriptions)
|
|
|
|
|
{
|
|
|
|
|
if (!ensure(OutputTypeOperationMap.Contains(OutputDescription.TypeName)))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 10:01:25 -04:00
|
|
|
FMetaSoundOutput Output;
|
2023-03-20 17:13:25 -04:00
|
|
|
Output.Name = OutputDescription.Name;
|
|
|
|
|
OutputTypeOperationMap[OutputDescription.TypeName]->Init(Output);
|
|
|
|
|
Outputs.Emplace(MoveTemp(Output));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 10:01:25 -04:00
|
|
|
void FMetasoundOutputWatcher::Update(const TFunctionRef<void(FName, const FMetaSoundOutput&)> OnOutputChanged)
|
2023-03-20 17:13:25 -04:00
|
|
|
{
|
2023-03-21 10:01:25 -04:00
|
|
|
METASOUND_TRACE_CPUPROFILER_EVENT_SCOPE(FMetasoundOutputWatcher::Update);
|
|
|
|
|
|
|
|
|
|
for (FMetaSoundOutput& Output : Outputs)
|
2023-03-20 17:13:25 -04:00
|
|
|
{
|
|
|
|
|
const FName TypeName = Output.GetTypeName();
|
|
|
|
|
check(!TypeName.IsNone());
|
|
|
|
|
|
|
|
|
|
if (ensure(OutputTypeOperationMap.Contains(TypeName)))
|
|
|
|
|
{
|
|
|
|
|
if (OutputTypeOperationMap[TypeName]->Update(*this, Output))
|
|
|
|
|
{
|
|
|
|
|
OnOutputChanged(Name, Output);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 10:01:25 -04:00
|
|
|
void FMetasoundOutputWatcher::RegisterOutputTypeOperations(FName TypeName,
|
2023-03-20 17:13:25 -04:00
|
|
|
TUniquePtr<IOutputTypeOperations>&& OutputTypeOperations)
|
|
|
|
|
{
|
|
|
|
|
check(!OutputTypeOperationMap.Contains(TypeName));
|
|
|
|
|
check(OutputTypeOperations.IsValid());
|
|
|
|
|
OutputTypeOperationMap.Emplace(TypeName, MoveTemp(OutputTypeOperations));
|
|
|
|
|
}
|
|
|
|
|
}
|