2021-01-13 10:48:59 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "MetasoundFrontendTransform.h"
|
|
|
|
|
|
|
|
|
|
namespace Metasound
|
|
|
|
|
{
|
|
|
|
|
namespace Frontend
|
|
|
|
|
{
|
|
|
|
|
bool FMatchRootGraphToArchetype::Transform(FDocumentHandle InDocument) const
|
|
|
|
|
{
|
|
|
|
|
if (!InDocument->IsValid())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool bDidEdit = false;
|
|
|
|
|
FGraphHandle Graph = InDocument->GetRootGraph();
|
|
|
|
|
|
2021-02-24 02:02:03 -04:00
|
|
|
TArray<FMetasoundFrontendClassInput> RequiredInputs = InDocument->GetRequiredInputs();
|
|
|
|
|
TArray<FMetasoundFrontendClassOutput> RequiredOutputs = InDocument->GetRequiredOutputs();
|
2021-01-13 10:48:59 -04:00
|
|
|
|
|
|
|
|
// Go through each input and add or swap if something is missing.
|
2021-02-24 02:02:03 -04:00
|
|
|
for (const FMetasoundFrontendClassInput& RequiredInput : RequiredInputs)
|
2021-01-13 10:48:59 -04:00
|
|
|
{
|
|
|
|
|
const FMetasoundFrontendClassInput* ClassInput = Graph->FindClassInputWithName(RequiredInput.Name).Get();
|
|
|
|
|
|
|
|
|
|
bool bIsMatching = false;
|
|
|
|
|
if (nullptr != ClassInput)
|
|
|
|
|
{
|
|
|
|
|
bIsMatching = FMetasoundFrontendClassVertex::IsFunctionalEquivalent(RequiredInput, *ClassInput);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bIsMatching)
|
|
|
|
|
{
|
|
|
|
|
bDidEdit = true;
|
|
|
|
|
if (nullptr != ClassInput)
|
|
|
|
|
{
|
|
|
|
|
Graph->RemoveInputVertex(RequiredInput.Name);
|
|
|
|
|
}
|
|
|
|
|
Graph->AddInputVertex(RequiredInput);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Go through each output and add or swap if something is missing.
|
2021-02-24 02:02:03 -04:00
|
|
|
for (const FMetasoundFrontendClassOutput& RequiredOutput : RequiredOutputs)
|
2021-01-13 10:48:59 -04:00
|
|
|
{
|
|
|
|
|
const FMetasoundFrontendClassOutput* ClassOutput = Graph->FindClassOutputWithName(RequiredOutput.Name).Get();
|
|
|
|
|
|
|
|
|
|
bool bIsMatching = false;
|
|
|
|
|
if (nullptr != ClassOutput)
|
|
|
|
|
{
|
|
|
|
|
bIsMatching = FMetasoundFrontendClassVertex::IsFunctionalEquivalent(RequiredOutput, *ClassOutput);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bIsMatching)
|
|
|
|
|
{
|
|
|
|
|
bDidEdit = true;
|
|
|
|
|
if (nullptr != ClassOutput)
|
|
|
|
|
{
|
|
|
|
|
Graph->RemoveOutputVertex(RequiredOutput.Name);
|
|
|
|
|
}
|
|
|
|
|
Graph->AddOutputVertex(RequiredOutput);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bDidEdit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|