2021-01-13 10:48:59 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
#include "MetasoundFrontendTransform.h"
|
|
|
|
|
|
2021-03-31 00:23:34 -04:00
|
|
|
#include "MetasoundFrontendDocument.h"
|
|
|
|
|
|
|
|
|
|
|
2021-01-13 10:48:59 -04:00
|
|
|
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 18:37:19 -04:00
|
|
|
TArray<FMetasoundFrontendClassVertex> RequiredInputs = InDocument->GetRequiredInputs();
|
|
|
|
|
TArray<FMetasoundFrontendClassVertex> 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 18:37:19 -04:00
|
|
|
for (const FMetasoundFrontendClassVertex& RequiredInput : RequiredInputs)
|
2021-01-13 10:48:59 -04:00
|
|
|
{
|
2021-03-31 00:23:34 -04:00
|
|
|
if (const FMetasoundFrontendClassInput* ClassInput = Graph->FindClassInputWithName(RequiredInput.Name).Get())
|
2021-01-13 10:48:59 -04:00
|
|
|
{
|
2021-03-31 00:23:34 -04:00
|
|
|
if (!FMetasoundFrontendClassVertex::IsFunctionalEquivalent(RequiredInput, *ClassInput))
|
|
|
|
|
{
|
|
|
|
|
bDidEdit = true;
|
2021-01-13 10:48:59 -04:00
|
|
|
|
2021-03-31 00:23:34 -04:00
|
|
|
// Cache off node locations to push to new node
|
|
|
|
|
FNodeHandle InputNode = Graph->GetInputNodeWithName(ClassInput->Name);
|
|
|
|
|
const TMap<FGuid, FVector2D> Locations = InputNode->GetNodeStyle().Display.Locations;
|
|
|
|
|
|
|
|
|
|
Graph->RemoveInputVertex(RequiredInput.Name);
|
|
|
|
|
InputNode = Graph->AddInputVertex(RequiredInput);
|
|
|
|
|
|
|
|
|
|
FMetasoundFrontendNodeStyle Style = InputNode->GetNodeStyle();
|
|
|
|
|
Style.Display.Locations = Locations;
|
|
|
|
|
InputNode->SetNodeStyle(Style);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2021-01-13 10:48:59 -04:00
|
|
|
{
|
|
|
|
|
bDidEdit = true;
|
|
|
|
|
Graph->AddInputVertex(RequiredInput);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Go through each output and add or swap if something is missing.
|
2021-02-24 18:37:19 -04:00
|
|
|
for (const FMetasoundFrontendClassVertex& RequiredOutput : RequiredOutputs)
|
2021-01-13 10:48:59 -04:00
|
|
|
{
|
2021-03-31 00:23:34 -04:00
|
|
|
if (const FMetasoundFrontendClassOutput* ClassOutput = Graph->FindClassOutputWithName(RequiredOutput.Name).Get())
|
2021-01-13 10:48:59 -04:00
|
|
|
{
|
2021-03-31 00:23:34 -04:00
|
|
|
if (!FMetasoundFrontendClassVertex::IsFunctionalEquivalent(RequiredOutput, *ClassOutput))
|
|
|
|
|
{
|
|
|
|
|
bDidEdit = true;
|
2021-01-13 10:48:59 -04:00
|
|
|
|
2021-03-31 00:23:34 -04:00
|
|
|
// Cache off node locations to push to new node
|
|
|
|
|
FNodeHandle OutputNode = Graph->GetOutputNodeWithName(ClassOutput->Name);
|
|
|
|
|
const TMap<FGuid, FVector2D> Locations = OutputNode->GetNodeStyle().Display.Locations;
|
|
|
|
|
|
|
|
|
|
Graph->RemoveOutputVertex(RequiredOutput.Name);
|
|
|
|
|
OutputNode = Graph->AddOutputVertex(RequiredOutput);
|
|
|
|
|
|
|
|
|
|
FMetasoundFrontendNodeStyle Style = OutputNode->GetNodeStyle();
|
|
|
|
|
Style.Display.Locations = Locations;
|
|
|
|
|
OutputNode->SetNodeStyle(Style);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2021-01-13 10:48:59 -04:00
|
|
|
{
|
|
|
|
|
bDidEdit = true;
|
|
|
|
|
Graph->AddOutputVertex(RequiredOutput);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bDidEdit;
|
|
|
|
|
}
|
2021-03-31 00:23:34 -04:00
|
|
|
} // namespace Frontend
|
|
|
|
|
} // namespace Metasound
|