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"
|
2023-03-13 17:23:05 -04:00
|
|
|
#include "Interfaces/MetasoundFrontendInterfaceRegistry.h"
|
2021-07-27 15:36:03 -04:00
|
|
|
#include "MetasoundAssetBase.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-10 20:37:31 -05:00
|
|
|
#include "Templates/Function.h"
|
2021-06-08 10:52:31 -04:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
|
|
|
|
|
// Forward Declarations
|
|
|
|
|
struct FMetaSoundFrontendDocumentBuilder;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Metasound::Frontend
|
2021-01-13 10:48:59 -04:00
|
|
|
{
|
2023-09-05 17:54:02 -04:00
|
|
|
namespace DocumentTransform
|
2021-01-13 10:48:59 -04:00
|
|
|
{
|
2022-03-16 19:27:27 -04:00
|
|
|
#if WITH_EDITOR
|
2023-09-05 17:54:02 -04:00
|
|
|
using FGetNodeDisplayNameProjection = TFunction<FText(const FNodeHandle&)>;
|
|
|
|
|
using FGetNodeDisplayNameProjectionRef = TFunctionRef<FText(const FNodeHandle&)>;
|
2022-03-16 19:27:27 -04:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
METASOUNDFRONTEND_API void RegisterNodeDisplayNameProjection(FGetNodeDisplayNameProjection&& InNameProjection);
|
|
|
|
|
METASOUNDFRONTEND_API FGetNodeDisplayNameProjectionRef GetNodeDisplayNameProjection();
|
2022-03-16 19:27:27 -04:00
|
|
|
#endif // WITH_EDITOR
|
2023-09-05 17:54:02 -04:00
|
|
|
}
|
2022-03-16 19:27:27 -04:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
/** Interface for transforms applied to documents. */
|
|
|
|
|
class METASOUNDFRONTEND_API IDocumentTransform
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual ~IDocumentTransform() = default;
|
2022-08-16 16:19:43 -04:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
/** Return true if InDocument was modified, false otherwise. */
|
|
|
|
|
virtual bool Transform(FDocumentHandle InDocument) const = 0;
|
2022-08-16 16:19:43 -04:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
/** Return true if InDocument was modified, false otherwise.
|
|
|
|
|
* This function is soft deprecated. It is not pure virtual
|
|
|
|
|
* to grandfather in old transform implementation. Old transforms
|
|
|
|
|
* should be deprecated and rewritten to use the Controller-less
|
|
|
|
|
* API in the interest of better performance and simplicity.
|
|
|
|
|
*/
|
|
|
|
|
virtual bool Transform(FMetasoundFrontendDocument& InOutDocument) const;
|
|
|
|
|
};
|
2021-06-23 20:08:21 -04:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
/** Interface for transforms applied to a graph. */
|
|
|
|
|
class METASOUNDFRONTEND_API IGraphTransform
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual ~IGraphTransform() = default;
|
2022-08-16 16:19:43 -04:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
UE_DEPRECATED(5.3, "Deprecated: unused function which encouraged breaking const behavior of transform state.")
|
|
|
|
|
virtual FMetasoundFrontendDocument& GetOwningDocument() const { static FMetasoundFrontendDocument BaseDoc; return BaseDoc; };
|
2022-08-16 16:19:43 -04:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
/** Return true if the graph was modified, false otherwise. */
|
|
|
|
|
virtual bool Transform(FMetasoundFrontendGraph& InOutGraph) const = 0;
|
|
|
|
|
};
|
2022-08-16 16:19:43 -04:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
/** Interface for transforming a node. */
|
|
|
|
|
class METASOUNDFRONTEND_API INodeTransform
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual ~INodeTransform() = default;
|
2022-08-16 16:19:43 -04:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
/** Return true if the node was modified, false otherwise. */
|
2023-09-06 12:54:02 -04:00
|
|
|
virtual bool Transform(const FGuid& InNodeID, FMetaSoundFrontendDocumentBuilder& OutBuilder) const;
|
2021-06-23 20:08:21 -04:00
|
|
|
|
2024-03-07 17:53:25 -05:00
|
|
|
UE_DEPRECATED(5.4, "Use transform overload with node ID and builder parameters to apply node transform to builder's underlying document")
|
2023-09-05 17:54:02 -04:00
|
|
|
virtual bool Transform(FMetasoundFrontendNode& InOutNode) const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** Adds or swaps document members (inputs, outputs) and removing any document members where necessary and adding those missing. */
|
|
|
|
|
class METASOUNDFRONTEND_API FModifyRootGraphInterfaces : public IDocumentTransform
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
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
|
|
|
|
2022-02-10 15:07:39 -05:00
|
|
|
#if WITH_EDITOR
|
2023-09-05 17:54:02 -04: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.
|
|
|
|
|
void SetDefaultNodeLocations(bool bInSetDefaultNodeLocations);
|
2022-02-10 15:07:39 -05:00
|
|
|
#endif // WITH_EDITOR
|
2021-12-10 20:37:31 -05:00
|
|
|
|
2023-09-05 17:54:02 -04: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-12-10 20:37:31 -05:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
virtual bool Transform(FDocumentHandle InDocument) const override;
|
|
|
|
|
virtual bool Transform(FMetasoundFrontendDocument& InOutDocument) const override;
|
2021-06-23 20:08:21 -04:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
private:
|
|
|
|
|
bool AddMissingVertices(FGraphHandle GraphHandle) const;
|
|
|
|
|
void Init(const TFunction<bool(FName, FName)>* InNamePairingFunction = nullptr);
|
|
|
|
|
bool SwapPairedVertices(FGraphHandle GraphHandle) const;
|
|
|
|
|
bool RemoveUnsupportedVertices(FGraphHandle GraphHandle) const;
|
|
|
|
|
bool UpdateInterfacesInternal(FDocumentHandle DocumentHandle) const;
|
2021-11-22 15:55:50 -05:00
|
|
|
|
2023-05-10 20:28:39 -04:00
|
|
|
#if WITH_EDITORONLY_DATA
|
2023-09-05 17:54:02 -04:00
|
|
|
void UpdateAddedVertexNodePositions(FGraphHandle GraphHandle) const;
|
2023-05-04 18:12:21 -04:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
bool bSetDefaultNodeLocations = true;
|
2023-05-10 20:28:39 -04:00
|
|
|
#endif // WITH_EDITORONLY_DATA
|
2021-11-22 15:55:50 -05:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
TArray<FMetasoundFrontendInterface> InterfacesToRemove;
|
|
|
|
|
TArray<FMetasoundFrontendInterface> InterfacesToAdd;
|
2021-11-22 15:55:50 -05:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
using FVertexPair = TTuple<FMetasoundFrontendClassVertex, FMetasoundFrontendClassVertex>;
|
|
|
|
|
TArray<FVertexPair> PairedInputs;
|
|
|
|
|
TArray<FVertexPair> PairedOutputs;
|
2021-11-22 15:55:50 -05:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
struct FInputData
|
2021-01-13 10:48:59 -04:00
|
|
|
{
|
2023-09-05 17:54:02 -04:00
|
|
|
FMetasoundFrontendClassInput Input;
|
|
|
|
|
const FMetasoundFrontendInterface* InputInterface = nullptr;
|
2021-01-13 10:48:59 -04:00
|
|
|
};
|
2021-05-28 14:09:45 -04:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
struct FOutputData
|
2021-07-27 15:36:03 -04:00
|
|
|
{
|
2023-09-05 17:54:02 -04:00
|
|
|
FMetasoundFrontendClassOutput Output;
|
|
|
|
|
const FMetasoundFrontendInterface* OutputInterface = nullptr;
|
2021-07-27 15:36:03 -04:00
|
|
|
};
|
|
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
TArray<FInputData> InputsToAdd;
|
|
|
|
|
TArray<FMetasoundFrontendClassInput> InputsToRemove;
|
|
|
|
|
TArray<FOutputData> OutputsToAdd;
|
|
|
|
|
TArray<FMetasoundFrontendClassOutput> OutputsToRemove;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class METASOUNDFRONTEND_API FUpdateRootGraphInterface : public IDocumentTransform
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FUpdateRootGraphInterface(const FMetasoundFrontendVersion& InInterfaceVersion, const FString& InOwningAssetName=FString(TEXT("Unknown")))
|
2021-07-27 15:36:03 -04:00
|
|
|
{
|
2023-09-05 17:54:02 -04:00
|
|
|
}
|
2021-07-27 15:36:03 -04:00
|
|
|
|
- Fix for attempting to access EngineSubsystem during MetaSound versioning (serialization), which can assert when apparently certain commands in certain contexts can attempt to preload assets prior to the init phase.
- Minor Fix for LocText duplication
#tests BuildCookRun, -game, version MetaSounds assets in editor, PIE
[FYI] bob.tellez
Original CL Desc
-----------------------------------------------------------------
[Backout] - CL33084850
[FYI] Rob.Gay
Original CL Desc
-----------------------------------------------------------------
Version Metasound Document to include all ed data and make all Metasound EdGraph data transient
- Add input template nodes
- Add comment node data to document
- Keep references to member literal data (i.e. knob/slider ranges) in document metadata to ensure continued serialization and flexibility to add more editor-only fields and literal metadata
- Misc builder API updates, bug fixes and migration of controllers to builder API in anticipation of pages
- Sunset non-deterministic guid cvar
#rb phil.popp, helen.yang
[FYI] sondra.moyls
#tests Standard Automated Audio Tests, EngineTests, Offline QA Smoke pass, CPR, etc., extensive MetaSound Editor use, -game MetaSound qa levels, AudioUnitTests
#jira UE-194159
[CL 33102023 by rob gay in ue5-main branch]
2024-04-19 10:09:04 -04:00
|
|
|
UE_DEPRECATED(5.5, "RootGraph update is now handled privately by internal MetaSound asset management")
|
|
|
|
|
virtual bool Transform(FDocumentHandle InDocument) const override { return false; }
|
2023-09-05 17:54:02 -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. */
|
|
|
|
|
class METASOUNDFRONTEND_API FRebuildPresetRootGraph : public IDocumentTransform
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/** Create transform.
|
|
|
|
|
* @param InReferenceDocument - The document containing the wrapped MetaSound graph.
|
|
|
|
|
*/
|
|
|
|
|
FRebuildPresetRootGraph(FConstDocumentHandle InReferencedDocument)
|
|
|
|
|
: ReferencedDocument(InReferencedDocument)
|
2021-07-27 20:30:14 -04:00
|
|
|
{
|
2023-09-05 17:54:02 -04:00
|
|
|
}
|
2021-09-17 14:41:22 -04:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
FRebuildPresetRootGraph(const FMetasoundFrontendDocument& InReferencedDocument);
|
2022-03-10 21:19:13 -05:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
virtual bool Transform(FDocumentHandle InDocument) const override;
|
|
|
|
|
virtual bool Transform(FMetasoundFrontendDocument& InOutDocument) const override;
|
2023-06-28 17:08:29 -04:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
private:
|
2021-07-27 20:30:14 -04:00
|
|
|
|
2023-09-05 17:54:02 -04:00
|
|
|
// Get the class inputs needed for this preset. Input literals set on
|
|
|
|
|
// the preset graph will be used if they are set and are marked as inheriting
|
|
|
|
|
// the default from the referenced graph.
|
|
|
|
|
TArray<FMetasoundFrontendClassInput> GenerateRequiredClassInputs(FDocumentHandle& InDocumentHandle, const FConstGraphHandle& InParentGraph, TSet<FName>& OutInputsInheritingDefault) const;
|
|
|
|
|
|
|
|
|
|
// Get the class Outputs needed for this preset.
|
|
|
|
|
TArray<FMetasoundFrontendClassOutput> GenerateRequiredClassOutputs(FDocumentHandle& InDocumentHandle, 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;
|
|
|
|
|
|
|
|
|
|
FConstDocumentHandle ReferencedDocument = IDocumentController::GetInvalidHandle();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** Automatically updates all nodes and respective dependencies in graph where
|
|
|
|
|
* newer versions exist in the loaded MetaSound Class Node Registry.
|
|
|
|
|
*/
|
|
|
|
|
class METASOUNDFRONTEND_API FAutoUpdateRootGraph : public IDocumentTransform
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/** Construct an AutoUpdate transform
|
|
|
|
|
*
|
|
|
|
|
* @param InDebugAssetPath - Asset path used for debug logs on warnings and errors.
|
|
|
|
|
* @param bInLogWarningOnDroppedConnections - If true, warnings will be logged if a node update results in a dropped connection.
|
|
|
|
|
*/
|
|
|
|
|
FAutoUpdateRootGraph(FString&& InDebugAssetPath, bool bInLogWarningOnDroppedConnection)
|
|
|
|
|
: DebugAssetPath(MoveTemp(InDebugAssetPath))
|
|
|
|
|
, bLogWarningOnDroppedConnection(bInLogWarningOnDroppedConnection)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Transform(FDocumentHandle InDocument) const override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const FString DebugAssetPath;
|
|
|
|
|
bool bLogWarningOnDroppedConnection;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** Sets the document's graph class, optionally updating the namespace and variant. */
|
|
|
|
|
class METASOUNDFRONTEND_API FRenameRootGraphClass : public IDocumentTransform
|
|
|
|
|
{
|
|
|
|
|
const FMetasoundFrontendClassName NewClassName;
|
|
|
|
|
|
|
|
|
|
public:
|
2024-05-08 14:53:53 -04:00
|
|
|
UE_DEPRECATED(5.5, "Use FMetasoundFrontendDocumentBuilder::GenerateNewClassName instead")
|
2023-09-05 17:54:02 -04:00
|
|
|
static bool Generate(FDocumentHandle InDocument, const FGuid& InGuid, const FName Namespace = { }, const FName Variant = { })
|
|
|
|
|
{
|
2024-05-08 14:53:53 -04:00
|
|
|
return false;
|
2023-09-05 17:54:02 -04:00
|
|
|
}
|
|
|
|
|
|
2024-05-08 14:53:53 -04:00
|
|
|
UE_DEPRECATED(5.5, "Use FMetasoundFrontendDocumentBuilder::GenerateNewClassName instead")
|
2023-09-05 17:54:02 -04:00
|
|
|
static bool Generate(FMetasoundFrontendDocument& InDocument, const FGuid& InGuid, const FName Namespace = { }, const FName Variant = { })
|
|
|
|
|
{
|
2024-05-08 14:53:53 -04:00
|
|
|
return false;
|
2023-09-05 17:54:02 -04:00
|
|
|
}
|
|
|
|
|
|
2024-05-08 14:53:53 -04:00
|
|
|
UE_DEPRECATED(5.5, "Use FMetasoundFrontendDocumentBuilder::GenerateNewClassName instead")
|
2023-09-05 17:54:02 -04:00
|
|
|
FRenameRootGraphClass(const FMetasoundFrontendClassName InClassName)
|
|
|
|
|
: NewClassName(InClassName)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-08 14:53:53 -04:00
|
|
|
UE_DEPRECATED(5.5, "Use FMetasoundFrontendDocumentBuilder::GenerateNewClassName instead")
|
2023-09-05 17:54:02 -04:00
|
|
|
bool Transform(FDocumentHandle InDocument) const override;
|
2024-05-08 14:53:53 -04:00
|
|
|
|
|
|
|
|
UE_DEPRECATED(5.5, "Use FMetasoundFrontendDocumentBuilder::GenerateNewClassName instead")
|
2023-09-05 17:54:02 -04:00
|
|
|
bool Transform(FMetasoundFrontendDocument& InOutDocument) const override;
|
|
|
|
|
};
|
|
|
|
|
} // Metasound::Frontend
|