2021-01-13 10:48:59 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2021-09-17 14:41:22 -04:00
|
|
|
#include "Internationalization/Text.h"
|
2021-07-27 15:36:03 -04:00
|
|
|
#include "MetasoundAssetBase.h"
|
2021-06-23 20:08:21 -04:00
|
|
|
#include "MetasoundFrontendArchetypeRegistry.h"
|
2021-01-13 10:48:59 -04:00
|
|
|
#include "MetasoundFrontendController.h"
|
2021-06-08 10:52:31 -04:00
|
|
|
#include "MetasoundFrontendDocument.h"
|
2021-09-13 14:14:37 -04:00
|
|
|
#include "MetasoundVertex.h"
|
2021-12-01 15:59:03 -05:00
|
|
|
#include "Templates/Function.h"
|
2021-06-08 10:52:31 -04:00
|
|
|
|
2021-01-13 10:48:59 -04:00
|
|
|
namespace Metasound
|
|
|
|
|
{
|
|
|
|
|
namespace Frontend
|
|
|
|
|
{
|
|
|
|
|
/** Interface for transforms applied to documents. */
|
|
|
|
|
class IDocumentTransform
|
|
|
|
|
{
|
2021-06-23 20:08:21 -04:00
|
|
|
public:
|
|
|
|
|
virtual ~IDocumentTransform() = default;
|
|
|
|
|
/** Return true if InDocument was modified, false otherwise. */
|
|
|
|
|
virtual bool Transform(FDocumentHandle InDocument) const = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** Interface for transforms applied to a graph. */
|
|
|
|
|
class IGraphTransform
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual ~IGraphTransform() = default;
|
|
|
|
|
/** Return true if InGraph was modified, false otherwise. */
|
|
|
|
|
virtual bool Transform(FGraphHandle InGraph) const = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
/** Adds or swaps document members (inputs, outputs) and removing any document members where necessary and adding those missing. */
|
|
|
|
|
class METASOUNDFRONTEND_API FModifyRootGraphInterfaces : public IDocumentTransform
|
2021-06-23 20:08:21 -04:00
|
|
|
{
|
|
|
|
|
public:
|
2021-11-22 15:55:50 -05:00
|
|
|
FModifyRootGraphInterfaces(const TArray<FMetasoundFrontendInterface>& InInterfacesToRemove, const TArray<FMetasoundFrontendInterface>& InInterfacesToAdd);
|
|
|
|
|
FModifyRootGraphInterfaces(const TArray<FMetasoundFrontendVersion>& InInterfaceVersionsToRemove, const TArray<FMetasoundFrontendVersion>& InInterfaceVersionsToAdd);
|
2021-06-23 20:08:21 -04:00
|
|
|
|
2021-12-01 15:59:03 -05:00
|
|
|
// Whether or not to propagate node locations to new members. Setting to false
|
|
|
|
|
// results in members not having a default physical location in the editor graph.
|
2021-11-22 15:55:50 -05:00
|
|
|
void SetDefaultNodeLocations(bool bInSetDefaultNodeLocations);
|
2021-12-01 15:59:03 -05:00
|
|
|
|
|
|
|
|
// Override function used to match removed members with added members, allowing
|
|
|
|
|
// transform to preserve connections made between removed interface members & new interface members
|
|
|
|
|
// that may be related but not be named the same.
|
|
|
|
|
void SetNamePairingFunction(const TFunction<bool(FName, FName)>& InNamePairingFunction);
|
|
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
bool Transform(FDocumentHandle InDocument) const override;
|
2021-06-23 20:08:21 -04:00
|
|
|
|
|
|
|
|
private:
|
2021-12-01 15:59:03 -05:00
|
|
|
void Init(const TFunction<bool(FName, FName)>* InNamePairingFunction = nullptr);
|
2021-11-22 15:55:50 -05:00
|
|
|
|
|
|
|
|
bool bSetDefaultNodeLocations = true;
|
|
|
|
|
|
|
|
|
|
TArray<FMetasoundFrontendInterface> InterfacesToRemove;
|
|
|
|
|
TArray<FMetasoundFrontendInterface> InterfacesToAdd;
|
|
|
|
|
|
2021-06-23 20:08:21 -04:00
|
|
|
using FVertexPair = TTuple<FMetasoundFrontendClassVertex, FMetasoundFrontendClassVertex>;
|
|
|
|
|
TArray<FVertexPair> PairedInputs;
|
|
|
|
|
TArray<FVertexPair> PairedOutputs;
|
2021-11-22 15:55:50 -05:00
|
|
|
|
|
|
|
|
TArray<FMetasoundFrontendClassInput> InputsToAdd;
|
|
|
|
|
TArray<FMetasoundFrontendClassInput> InputsToRemove;
|
|
|
|
|
TArray<FMetasoundFrontendClassOutput> OutputsToAdd;
|
|
|
|
|
TArray<FMetasoundFrontendClassOutput> OutputsToRemove;
|
2021-06-23 20:08:21 -04:00
|
|
|
|
2021-01-13 10:48:59 -04:00
|
|
|
};
|
|
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
/** Updates document's given interface to the most recent version. */
|
|
|
|
|
class METASOUNDFRONTEND_API FUpdateRootGraphInterface : public IDocumentTransform
|
2021-01-13 10:48:59 -04:00
|
|
|
{
|
2021-06-23 20:08:21 -04:00
|
|
|
public:
|
2021-11-22 15:55:50 -05:00
|
|
|
FUpdateRootGraphInterface(const FMetasoundFrontendVersion& InInterfaceVersion)
|
|
|
|
|
: InterfaceVersion(InInterfaceVersion)
|
2021-06-23 20:08:21 -04:00
|
|
|
{
|
|
|
|
|
}
|
2021-06-08 10:52:31 -04:00
|
|
|
|
2021-06-23 20:08:21 -04:00
|
|
|
bool Transform(FDocumentHandle InDocument) const override;
|
2021-06-08 10:52:31 -04:00
|
|
|
|
2021-06-23 20:08:21 -04:00
|
|
|
private:
|
2021-11-22 15:55:50 -05:00
|
|
|
void GetUpdatePathForDocument(const FMetasoundFrontendVersion& InCurrentVersion, const FMetasoundFrontendVersion& InTargetVersion, TArray<const IInterfaceRegistryEntry*>& OutUpgradePath) const;
|
|
|
|
|
bool UpdateDocumentInterface(const TArray<const IInterfaceRegistryEntry*>& InUpgradePath, FDocumentHandle InDocument) const;
|
2021-06-23 20:08:21 -04:00
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
FMetasoundFrontendVersion InterfaceVersion;
|
2021-01-13 10:48:59 -04:00
|
|
|
};
|
2021-05-28 14:09:45 -04:00
|
|
|
|
2021-10-12 21:21:22 -04:00
|
|
|
/** Completely rebuilds the graph connecting a preset's inputs to the reference
|
|
|
|
|
* document's root graph. It maintains previously set input values entered upon
|
|
|
|
|
* the presets wrapping graph. */
|
2021-07-27 15:36:03 -04:00
|
|
|
class METASOUNDFRONTEND_API FRebuildPresetRootGraph : public IDocumentTransform
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-10-12 21:21:22 -04:00
|
|
|
/** Create transform.
|
|
|
|
|
* @param InReferenceDocument - The document containing the wrapped MetaSound graph.
|
|
|
|
|
*/
|
2021-07-27 15:36:03 -04:00
|
|
|
FRebuildPresetRootGraph(FConstDocumentHandle InReferencedDocument)
|
|
|
|
|
: ReferencedDocument(InReferencedDocument)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Transform(FDocumentHandle InDocument) const override;
|
|
|
|
|
|
|
|
|
|
private:
|
2021-10-12 21:21:22 -04:00
|
|
|
|
|
|
|
|
// Get the class inputs needed for this preset. Input literals set on
|
|
|
|
|
// the parent graph will be used if they exist.
|
|
|
|
|
TArray<FMetasoundFrontendClassInput> GenerateRequiredClassInputs(const FConstGraphHandle& InParentGraph) const;
|
|
|
|
|
|
|
|
|
|
// Get the class Outputs needed for this preset.
|
|
|
|
|
TArray<FMetasoundFrontendClassOutput> GenerateRequiredClassOutputs(const FConstGraphHandle& InParentGraph) const;
|
|
|
|
|
|
|
|
|
|
// Add inputs to parent graph and connect to wrapped graph node.
|
|
|
|
|
void AddAndConnectInputs(const TArray<FMetasoundFrontendClassInput>& InClassInputs, FGraphHandle& InParentGraphHandle, FNodeHandle& InReferencedNode) const;
|
|
|
|
|
|
|
|
|
|
// Add outputs to parent graph and connect to wrapped graph node.
|
|
|
|
|
void AddAndConnectOutputs(const TArray<FMetasoundFrontendClassOutput>& InClassOutputs, FGraphHandle& InParentGraphHandle, FNodeHandle& InReferencedNode) const;
|
|
|
|
|
|
2021-07-27 15:36:03 -04:00
|
|
|
FConstDocumentHandle ReferencedDocument;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class METASOUNDFRONTEND_API FAutoUpdateRootGraph : public IDocumentTransform
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-08-18 15:16:57 -04:00
|
|
|
FAutoUpdateRootGraph() = default;
|
2021-07-27 15:36:03 -04:00
|
|
|
|
|
|
|
|
bool Transform(FDocumentHandle InDocument) const override;
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-27 20:30:14 -04:00
|
|
|
/** Synchronizes the document's root graph's display name with that of the asset. */
|
|
|
|
|
class METASOUNDFRONTEND_API FSynchronizeAssetClassDisplayName : public IDocumentTransform
|
2021-07-27 15:36:03 -04:00
|
|
|
{
|
|
|
|
|
public:
|
2021-07-27 20:30:14 -04:00
|
|
|
FSynchronizeAssetClassDisplayName(FName InAssetName)
|
2021-07-27 15:36:03 -04:00
|
|
|
: AssetName(InAssetName)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Transform(FDocumentHandle InDocument) const override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
FName AssetName;
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-27 20:30:14 -04:00
|
|
|
/** Regenerates the class' name, effectively causing the class to get registered as
|
|
|
|
|
* a new class (useful for when an asset is duplicated). */
|
|
|
|
|
class METASOUNDFRONTEND_API FRegenerateAssetClassName : public IDocumentTransform
|
|
|
|
|
{
|
2021-09-17 14:41:22 -04:00
|
|
|
|
2021-07-27 20:30:14 -04:00
|
|
|
public:
|
|
|
|
|
FRegenerateAssetClassName() = default;
|
|
|
|
|
|
|
|
|
|
bool Transform(FDocumentHandle InDocument) const override;
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-28 14:09:45 -04:00
|
|
|
/** Base class for versioning a document. */
|
|
|
|
|
class METASOUNDFRONTEND_API FVersionDocument : public IDocumentTransform
|
|
|
|
|
{
|
2021-06-08 10:52:31 -04:00
|
|
|
const FName Name;
|
|
|
|
|
const FString& Path;
|
|
|
|
|
|
2021-06-23 20:08:21 -04:00
|
|
|
public:
|
|
|
|
|
static FMetasoundFrontendVersionNumber GetMaxVersion()
|
|
|
|
|
{
|
2021-09-13 14:14:37 -04:00
|
|
|
return FMetasoundFrontendVersionNumber { 1, 7 };
|
2021-06-23 20:08:21 -04:00
|
|
|
}
|
2021-06-08 10:52:31 -04:00
|
|
|
|
2021-06-23 20:08:21 -04:00
|
|
|
FVersionDocument(FName InName, const FString& InPath);
|
2021-06-08 10:52:31 -04:00
|
|
|
|
2021-06-23 20:08:21 -04:00
|
|
|
bool Transform(FDocumentHandle InDocument) const override;
|
2021-05-28 14:09:45 -04:00
|
|
|
};
|
2021-01-13 10:48:59 -04:00
|
|
|
}
|
|
|
|
|
}
|