2021-01-13 10:48:59 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "MetasoundFrontendDocument.h"
|
|
|
|
|
|
2022-01-20 19:19:55 -05:00
|
|
|
#include "Algo/ForEach.h"
|
2021-07-27 15:36:03 -04:00
|
|
|
#include "Algo/Transform.h"
|
2021-12-10 20:37:31 -05:00
|
|
|
#include "IAudioParameterInterfaceRegistry.h"
|
2022-01-20 19:19:55 -05:00
|
|
|
#include "Logging/LogMacros.h"
|
2021-01-13 10:48:59 -04:00
|
|
|
#include "MetasoundFrontend.h"
|
|
|
|
|
#include "MetasoundFrontendRegistries.h"
|
2021-02-10 21:43:31 -04:00
|
|
|
#include "MetasoundLog.h"
|
2021-01-13 10:48:59 -04:00
|
|
|
|
2021-01-28 19:02:51 -04:00
|
|
|
namespace Metasound
|
|
|
|
|
{
|
|
|
|
|
const FGuid FrontendInvalidID = FGuid();
|
2021-07-27 15:36:03 -04:00
|
|
|
|
|
|
|
|
namespace Frontend
|
|
|
|
|
{
|
|
|
|
|
namespace DisplayStyle
|
|
|
|
|
{
|
|
|
|
|
namespace NodeLayout
|
|
|
|
|
{
|
|
|
|
|
const FVector2D DefaultOffsetX { 300.0f, 0.0f };
|
|
|
|
|
const FVector2D DefaultOffsetY { 0.0f, 80.0f };
|
|
|
|
|
} // namespace NodeLayout
|
|
|
|
|
} // namespace DisplayStyle
|
|
|
|
|
} // namespace Frontend
|
2022-01-19 18:24:30 -05:00
|
|
|
|
|
|
|
|
namespace DocumentPrivate
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* Sets an array to a given array and updates the change ID if the array changed.
|
|
|
|
|
* @returns true if value changed, false if not.
|
|
|
|
|
*/
|
|
|
|
|
template <typename TElementType>
|
|
|
|
|
bool SetWithChangeID(const TElementType& InNewValue, TElementType& OutValue, FGuid& OutChangeID)
|
|
|
|
|
{
|
|
|
|
|
if (OutValue != InNewValue)
|
|
|
|
|
{
|
|
|
|
|
OutValue = InNewValue;
|
|
|
|
|
OutChangeID = FGuid::NewGuid();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Array Text specialization as FText does not implement == nor does it support IsBytewiseComparable */
|
|
|
|
|
template <>
|
|
|
|
|
bool SetWithChangeID<TArray<FText>>(const TArray<FText>& InNewArray, TArray<FText>& OutArray, FGuid& OutChangeID)
|
|
|
|
|
{
|
|
|
|
|
bool bIsEqual = OutArray.Num() == InNewArray.Num();
|
|
|
|
|
if (bIsEqual)
|
|
|
|
|
{
|
|
|
|
|
for (int32 i = 0; i < InNewArray.Num(); ++i)
|
|
|
|
|
{
|
|
|
|
|
bIsEqual &= InNewArray[i].IdenticalTo(OutArray[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bIsEqual)
|
|
|
|
|
{
|
|
|
|
|
OutArray = InNewArray;
|
|
|
|
|
OutChangeID = FGuid::NewGuid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return !bIsEqual;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Text specialization as FText does not implement == nor does it support IsBytewiseComparable */
|
|
|
|
|
template <>
|
|
|
|
|
bool SetWithChangeID<FText>(const FText& InNewText, FText& OutText, FGuid& OutChangeID)
|
|
|
|
|
{
|
|
|
|
|
if (!InNewText.IdenticalTo(OutText))
|
|
|
|
|
{
|
|
|
|
|
OutText = InNewText;
|
|
|
|
|
OutChangeID = FGuid::NewGuid();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} // namespace Metasound
|
2021-01-28 19:02:51 -04:00
|
|
|
|
2021-01-13 10:48:59 -04:00
|
|
|
FMetasoundFrontendNodeInterface::FMetasoundFrontendNodeInterface(const FMetasoundFrontendClassInterface& InClassInterface)
|
|
|
|
|
{
|
|
|
|
|
for (const FMetasoundFrontendClassInput& Input : InClassInterface.Inputs)
|
|
|
|
|
{
|
|
|
|
|
Inputs.Add(Input);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const FMetasoundFrontendClassOutput& Output : InClassInterface.Outputs)
|
|
|
|
|
{
|
|
|
|
|
Outputs.Add(Output);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const FMetasoundFrontendClassEnvironmentVariable& EnvVar : InClassInterface.Environment)
|
|
|
|
|
{
|
|
|
|
|
FMetasoundFrontendVertex EnvVertex;
|
|
|
|
|
EnvVertex.Name = EnvVar.Name;
|
|
|
|
|
EnvVertex.TypeName = EnvVar.TypeName;
|
|
|
|
|
|
|
|
|
|
Environment.Add(MoveTemp(EnvVertex));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FMetasoundFrontendNode::FMetasoundFrontendNode(const FMetasoundFrontendClass& InClass)
|
|
|
|
|
: ClassID(InClass.ID)
|
2021-07-27 15:36:03 -04:00
|
|
|
, Name(InClass.Metadata.GetClassName().Name.ToString())
|
2021-01-13 10:48:59 -04:00
|
|
|
, Interface(InClass.Interface)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-23 20:08:21 -04:00
|
|
|
FString FMetasoundFrontendVersion::ToString() const
|
|
|
|
|
{
|
|
|
|
|
return FString::Format(TEXT("{0} {1}"), { Name.ToString(), Number.ToString() });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FMetasoundFrontendVersion::IsValid() const
|
|
|
|
|
{
|
2021-11-22 15:55:50 -05:00
|
|
|
return Number != GetInvalid().Number && Name != GetInvalid().Name;
|
2021-06-23 20:08:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FMetasoundFrontendVersion& FMetasoundFrontendVersion::GetInvalid()
|
|
|
|
|
{
|
|
|
|
|
static const FMetasoundFrontendVersion InvalidVersion { FName(), FMetasoundFrontendVersionNumber::GetInvalid() };
|
|
|
|
|
return InvalidVersion;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-13 10:48:59 -04:00
|
|
|
bool FMetasoundFrontendVertex::IsFunctionalEquivalent(const FMetasoundFrontendVertex& InLHS, const FMetasoundFrontendVertex& InRHS)
|
|
|
|
|
{
|
2021-02-24 18:37:19 -04:00
|
|
|
return (InLHS.Name == InRHS.Name) && (InLHS.TypeName == InRHS.TypeName);
|
2021-01-13 10:48:59 -04:00
|
|
|
}
|
|
|
|
|
|
2021-12-10 20:37:31 -05:00
|
|
|
void FMetasoundFrontendClassVertex::SplitName(FName& OutNamespace, FName& OutParameterName) const
|
|
|
|
|
{
|
|
|
|
|
Audio::FParameterPath::SplitName(Name, OutNamespace, OutParameterName);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-27 15:36:03 -04:00
|
|
|
bool FMetasoundFrontendClassVertex::IsFunctionalEquivalent(const FMetasoundFrontendClassVertex& InLHS, const FMetasoundFrontendClassVertex& InRHS)
|
2021-01-13 10:48:59 -04:00
|
|
|
{
|
2021-02-24 18:37:19 -04:00
|
|
|
return FMetasoundFrontendVertex::IsFunctionalEquivalent(InLHS, InRHS);
|
2021-01-13 10:48:59 -04:00
|
|
|
}
|
|
|
|
|
|
2021-01-28 19:02:51 -04:00
|
|
|
FMetasoundFrontendClassName::FMetasoundFrontendClassName(const FName& InNamespace, const FName& InName, const FName& InVariant)
|
|
|
|
|
: Namespace(InNamespace)
|
|
|
|
|
, Name(InName)
|
|
|
|
|
, Variant(InVariant)
|
2021-01-13 10:48:59 -04:00
|
|
|
{
|
2021-01-28 19:02:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FMetasoundFrontendClassName::FMetasoundFrontendClassName(const Metasound::FNodeClassName& InName)
|
|
|
|
|
: FMetasoundFrontendClassName(InName.GetNamespace(), InName.GetName(), InName.GetVariant())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FName FMetasoundFrontendClassName::GetScopedName() const
|
|
|
|
|
{
|
|
|
|
|
return Metasound::FNodeClassName::FormatScopedName(Namespace, Name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FName FMetasoundFrontendClassName::GetFullName() const
|
|
|
|
|
{
|
|
|
|
|
return Metasound::FNodeClassName::FormatFullName(Namespace, Name, Variant);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FString FMetasoundFrontendClassName::ToString() const
|
|
|
|
|
{
|
|
|
|
|
return GetFullName().ToString();
|
2021-01-13 10:48:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator==(const FMetasoundFrontendClassName& InLHS, const FMetasoundFrontendClassName& InRHS)
|
|
|
|
|
{
|
|
|
|
|
return (InLHS.Namespace == InRHS.Namespace) && (InLHS.Name == InRHS.Name) && (InLHS.Variant == InRHS.Variant);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-27 15:36:03 -04:00
|
|
|
bool operator!=(const FMetasoundFrontendClassName& InLHS, const FMetasoundFrontendClassName& InRHS)
|
|
|
|
|
{
|
|
|
|
|
return !(InLHS == InRHS);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-19 18:24:30 -05:00
|
|
|
void FMetasoundFrontendClassMetadata::SetAuthor(const FText& InAuthor)
|
2021-01-28 19:02:51 -04:00
|
|
|
{
|
2022-01-19 18:24:30 -05:00
|
|
|
using namespace Metasound::DocumentPrivate;
|
|
|
|
|
SetWithChangeID(InAuthor, Author, ChangeID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FMetasoundFrontendClassMetadata::SetAutoUpdateManagesInterface(bool bInAutoUpdateManagesInterface)
|
|
|
|
|
{
|
|
|
|
|
using namespace Metasound::DocumentPrivate;
|
|
|
|
|
SetWithChangeID(bInAutoUpdateManagesInterface, bAutoUpdateManagesInterface, ChangeID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FMetasoundFrontendClassMetadata::SetCategoryHierarchy(const TArray<FText>& InCategoryHierarchy)
|
|
|
|
|
{
|
|
|
|
|
using namespace Metasound::DocumentPrivate;
|
|
|
|
|
SetWithChangeID(InCategoryHierarchy, CategoryHierarchy, ChangeID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FMetasoundFrontendClassMetadata::SetKeywords(const TArray<FText>& InKeywords)
|
|
|
|
|
{
|
|
|
|
|
using namespace Metasound::DocumentPrivate;
|
|
|
|
|
SetWithChangeID(InKeywords, Keywords, ChangeID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FMetasoundFrontendClassMetadata::SetClassName(const FMetasoundFrontendClassName& InClassName)
|
|
|
|
|
{
|
|
|
|
|
using namespace Metasound::DocumentPrivate;
|
|
|
|
|
SetWithChangeID(InClassName, ClassName, ChangeID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FMetasoundFrontendClassMetadata::SetDescription(const FText& InDescription)
|
|
|
|
|
{
|
|
|
|
|
using namespace Metasound::DocumentPrivate;
|
|
|
|
|
SetWithChangeID(InDescription, Description, ChangeID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FMetasoundFrontendClassMetadata::SetDisplayName(const FText& InDisplayName)
|
|
|
|
|
{
|
|
|
|
|
using namespace Metasound::DocumentPrivate;
|
|
|
|
|
SetWithChangeID(InDisplayName, DisplayName, ChangeID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FMetasoundFrontendClassMetadata::SetIsDeprecated(bool bInIsDeprecated)
|
|
|
|
|
{
|
|
|
|
|
using namespace Metasound::DocumentPrivate;
|
|
|
|
|
SetWithChangeID(bInIsDeprecated, bIsDeprecated, ChangeID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FMetasoundFrontendClassMetadata::SetPromptIfMissing(const FText& InPromptIfMissing)
|
|
|
|
|
{
|
|
|
|
|
using namespace Metasound::DocumentPrivate;
|
|
|
|
|
SetWithChangeID(InPromptIfMissing, PromptIfMissing, ChangeID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FMetasoundFrontendClassMetadata::SetVersion(const FMetasoundFrontendVersionNumber& InVersion)
|
|
|
|
|
{
|
|
|
|
|
using namespace Metasound::DocumentPrivate;
|
|
|
|
|
SetWithChangeID(InVersion, Version, ChangeID);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-21 00:53:01 -05:00
|
|
|
bool FMetasoundFrontendClass::CacheRegistryData()
|
2022-01-20 19:19:55 -05:00
|
|
|
{
|
|
|
|
|
using namespace Metasound::Frontend;
|
|
|
|
|
|
|
|
|
|
const FNodeRegistryKey Key = NodeRegistryKey::CreateKey(Metadata);
|
|
|
|
|
FMetasoundFrontendClass Class;
|
|
|
|
|
|
|
|
|
|
FMetasoundFrontendRegistryContainer* Registry = FMetasoundFrontendRegistryContainer::Get();
|
|
|
|
|
if (ensure(Registry))
|
|
|
|
|
{
|
|
|
|
|
if (Registry->FindFrontendClassFromRegistered(Key, Class))
|
|
|
|
|
{
|
|
|
|
|
Metadata = Class.Metadata;
|
|
|
|
|
|
|
|
|
|
using FNameTypeKey = TPair<FName, FName>;
|
|
|
|
|
TMap<FNameTypeKey, const FMetasoundFrontendVertexMetadata*> InterfaceMembers;
|
|
|
|
|
|
|
|
|
|
auto MakePairFromVertex = [](const FMetasoundFrontendClassVertex& InVertex)
|
|
|
|
|
{
|
|
|
|
|
const FNameTypeKey Key(InVertex.Name, InVertex.TypeName);
|
|
|
|
|
return TPair<FNameTypeKey, const FMetasoundFrontendVertexMetadata*> { Key, &InVertex.Metadata };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto CacheRegistryVertexMetadata = [&](FMetasoundFrontendClassVertex& OutVertex)
|
|
|
|
|
{
|
|
|
|
|
const FNameTypeKey Key(OutVertex.Name, OutVertex.TypeName);
|
|
|
|
|
if (const FMetasoundFrontendVertexMetadata* RegVertex = InterfaceMembers.FindRef(Key))
|
|
|
|
|
{
|
|
|
|
|
OutVertex.Metadata = *RegVertex;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Algo::Transform(Class.Interface.Inputs, InterfaceMembers, [&](const FMetasoundFrontendClassInput& Input) { return MakePairFromVertex(Input); });
|
|
|
|
|
Algo::ForEach(Interface.Inputs, [&](FMetasoundFrontendClassInput& Input) { CacheRegistryVertexMetadata(Input); });
|
|
|
|
|
|
|
|
|
|
InterfaceMembers.Reset();
|
|
|
|
|
|
|
|
|
|
Algo::Transform(Class.Interface.Outputs, InterfaceMembers, [&](const FMetasoundFrontendClassOutput& Output) { return MakePairFromVertex(Output); });
|
|
|
|
|
Algo::ForEach(Interface.Outputs, [&](FMetasoundFrontendClassOutput& Output) { CacheRegistryVertexMetadata(Output); });
|
|
|
|
|
|
2022-01-21 00:53:01 -05:00
|
|
|
Interface.InputStyle = Class.Interface.InputStyle;
|
|
|
|
|
Interface.OutputStyle = Class.Interface.OutputStyle;
|
|
|
|
|
Style = Class.Style;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-01-20 19:19:55 -05:00
|
|
|
}
|
2022-01-21 00:53:01 -05:00
|
|
|
|
|
|
|
|
return false;
|
2022-01-20 19:19:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FMetasoundFrontendClass::ClearRegistryData()
|
|
|
|
|
{
|
|
|
|
|
Metadata.DisplayName = { };
|
|
|
|
|
Metadata.Description = { };
|
|
|
|
|
Metadata.PromptIfMissing = { };
|
|
|
|
|
Metadata.Author = { };
|
|
|
|
|
Metadata.Keywords.Reset();
|
|
|
|
|
Metadata.CategoryHierarchy.Reset();
|
|
|
|
|
|
|
|
|
|
Algo::ForEach(Interface.Inputs, [](FMetasoundFrontendClassInput& Input) { Input.Metadata = { }; });
|
|
|
|
|
Algo::ForEach(Interface.Outputs, [](FMetasoundFrontendClassOutput& Output) { Output.Metadata = { }; });
|
|
|
|
|
|
|
|
|
|
Interface.InputStyle = { };
|
|
|
|
|
Interface.OutputStyle = { };
|
|
|
|
|
Style = { };
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-19 18:24:30 -05:00
|
|
|
FMetasoundFrontendClassMetadata FMetasoundFrontendClassMetadata::GenerateClassDescription(const Metasound::FNodeClassMetadata& InNodeClassMetadata, EMetasoundFrontendClassType InType)
|
|
|
|
|
{
|
|
|
|
|
FMetasoundFrontendClassMetadata NewMetadata;
|
|
|
|
|
NewMetadata.Type = InType;
|
|
|
|
|
|
|
|
|
|
// TODO: This flag is only used by the graph class' metadata.
|
|
|
|
|
// Should probably be moved elsewhere (AssetBase?) as to not
|
|
|
|
|
// get confused with behavior encapsulated on registry class
|
|
|
|
|
// descriptions/individual node class dependencies.
|
|
|
|
|
NewMetadata.bAutoUpdateManagesInterface = false;
|
|
|
|
|
|
|
|
|
|
NewMetadata.ClassName = InNodeClassMetadata.ClassName;
|
|
|
|
|
NewMetadata.Version = { InNodeClassMetadata.MajorVersion, InNodeClassMetadata.MinorVersion };
|
|
|
|
|
NewMetadata.DisplayName = InNodeClassMetadata.DisplayName;
|
|
|
|
|
NewMetadata.Description = InNodeClassMetadata.Description;
|
|
|
|
|
NewMetadata.PromptIfMissing = InNodeClassMetadata.PromptIfMissing;
|
|
|
|
|
NewMetadata.Author = InNodeClassMetadata.Author;
|
|
|
|
|
NewMetadata.Keywords = InNodeClassMetadata.Keywords;
|
|
|
|
|
NewMetadata.CategoryHierarchy = InNodeClassMetadata.CategoryHierarchy;
|
|
|
|
|
NewMetadata.bIsDeprecated = InNodeClassMetadata.bDeprecated;
|
|
|
|
|
|
|
|
|
|
return NewMetadata;
|
2021-01-28 19:02:51 -04:00
|
|
|
}
|
|
|
|
|
|
2021-01-13 10:48:59 -04:00
|
|
|
FMetasoundFrontendClassInput::FMetasoundFrontendClassInput(const FMetasoundFrontendClassVertex& InOther)
|
|
|
|
|
: FMetasoundFrontendClassVertex(InOther)
|
|
|
|
|
{
|
2021-08-19 09:59:27 -04:00
|
|
|
using namespace Metasound::Frontend;
|
|
|
|
|
|
|
|
|
|
EMetasoundFrontendLiteralType DefaultType = GetMetasoundFrontendLiteralType(IDataTypeRegistry::Get().GetDesiredLiteralType(InOther.TypeName));
|
2021-01-13 10:48:59 -04:00
|
|
|
|
2021-02-24 18:37:19 -04:00
|
|
|
DefaultLiteral.SetType(DefaultType);
|
2021-01-13 10:48:59 -04:00
|
|
|
}
|
|
|
|
|
|
2021-05-28 14:09:45 -04:00
|
|
|
FMetasoundFrontendClassVariable::FMetasoundFrontendClassVariable(const FMetasoundFrontendClassVertex& InOther)
|
|
|
|
|
: FMetasoundFrontendClassVertex(InOther)
|
|
|
|
|
{
|
2021-08-19 09:59:27 -04:00
|
|
|
using namespace Metasound::Frontend;
|
|
|
|
|
|
|
|
|
|
EMetasoundFrontendLiteralType DefaultType = GetMetasoundFrontendLiteralType(IDataTypeRegistry::Get().GetDesiredLiteralType(InOther.TypeName));
|
2021-05-28 14:09:45 -04:00
|
|
|
|
|
|
|
|
DefaultLiteral.SetType(DefaultType);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-13 10:48:59 -04:00
|
|
|
FMetasoundFrontendGraphClass::FMetasoundFrontendGraphClass()
|
|
|
|
|
{
|
2021-07-27 15:36:03 -04:00
|
|
|
Metadata.SetType(EMetasoundFrontendClassType::Graph);
|
2021-01-13 10:48:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FMetasoundFrontendDocument::FMetasoundFrontendDocument()
|
|
|
|
|
{
|
2021-01-20 17:26:40 -04:00
|
|
|
RootGraph.ID = FGuid::NewGuid();
|
2021-07-27 15:36:03 -04:00
|
|
|
RootGraph.Metadata.SetType(EMetasoundFrontendClassType::Graph);
|
2021-06-23 20:08:21 -04:00
|
|
|
ArchetypeVersion = FMetasoundFrontendVersion::GetInvalid();
|
2021-01-13 10:48:59 -04:00
|
|
|
}
|