2020-12-04 11:19:17 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-06-23 14:53:34 -04:00
|
|
|
#include "Containers/Array.h"
|
|
|
|
|
#include "Containers/Map.h"
|
|
|
|
|
#include "Containers/Set.h"
|
|
|
|
|
#include "Containers/UnrealString.h"
|
|
|
|
|
#include "MetasoundFrontendDocument.h"
|
2024-05-24 14:33:22 -04:00
|
|
|
#include "MetasoundFrontendDocumentIdGenerator.h"
|
2020-12-04 11:19:17 -04:00
|
|
|
#include "MetasoundGraph.h"
|
2023-06-23 14:53:34 -04:00
|
|
|
#include "MetasoundNodeConstructorParams.h"
|
2020-12-04 11:19:17 -04:00
|
|
|
#include "MetasoundNodeInterface.h"
|
2023-06-23 14:53:34 -04:00
|
|
|
#include "MetasoundVertex.h"
|
|
|
|
|
#include "Misc/Guid.h"
|
|
|
|
|
#include "Templates/SharedPointer.h"
|
|
|
|
|
#include "Templates/UniquePtr.h"
|
2020-12-04 11:19:17 -04:00
|
|
|
|
|
|
|
|
namespace Metasound
|
|
|
|
|
{
|
|
|
|
|
/** FFrontendGraph is a utility graph for use in the frontend. It can own nodes
|
|
|
|
|
* that live within the graph and provides query interfaces for finding nodes
|
|
|
|
|
* by dependency ID or input/output index.
|
|
|
|
|
*/
|
2021-07-28 17:12:57 -04:00
|
|
|
class METASOUNDFRONTEND_API FFrontendGraph : public FGraph
|
2020-12-04 11:19:17 -04:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/** FFrontendGraph constructor.
|
|
|
|
|
*
|
|
|
|
|
* @parma InInstanceName - Name of this graph.
|
2021-01-28 19:02:51 -04:00
|
|
|
* @parma InInstanceID - ID of this graph.
|
2020-12-04 11:19:17 -04:00
|
|
|
*/
|
2021-01-28 19:02:51 -04:00
|
|
|
FFrontendGraph(const FString& InInstanceName, const FGuid& InInstanceID);
|
2020-12-04 11:19:17 -04:00
|
|
|
|
|
|
|
|
virtual ~FFrontendGraph() = default;
|
|
|
|
|
|
|
|
|
|
/** Add an input node to this graph.
|
|
|
|
|
*
|
2021-01-13 10:48:59 -04:00
|
|
|
* @param InNodeID - The NodeID related to the parent FMetasoundFrontendClass.
|
2020-12-04 11:19:17 -04:00
|
|
|
* @param InIndex - The positional index for the input.
|
2021-09-13 14:14:37 -04:00
|
|
|
* @param InVertexName - The key for the graph input vertex.
|
2021-05-20 19:33:21 -04:00
|
|
|
* @param InNode - A shared pointer to an input node.
|
2020-12-04 11:19:17 -04:00
|
|
|
*/
|
2021-09-13 14:14:37 -04:00
|
|
|
void AddInputNode(FGuid InNodeID, int32 InIndex, const FVertexName& InVertexName, TSharedPtr<const INode> InNode);
|
2020-12-04 11:19:17 -04:00
|
|
|
|
|
|
|
|
/** Add an output node to this graph.
|
|
|
|
|
*
|
2021-01-13 10:48:59 -04:00
|
|
|
* @param InNodeID - The NodeID related to the parent FMetasoundFrontendClass.
|
2020-12-04 11:19:17 -04:00
|
|
|
* @param InIndex - The positional index for the output.
|
2021-09-13 14:14:37 -04:00
|
|
|
* @param InVertexName - The key for the graph output vertex.
|
2021-05-20 19:33:21 -04:00
|
|
|
* @param InNode - A shared pointer to an output node.
|
2020-12-04 11:19:17 -04:00
|
|
|
*/
|
2021-09-13 14:14:37 -04:00
|
|
|
void AddOutputNode(FGuid InNodeID, int32 InIndex, const FVertexName& InVertexName, TSharedPtr<const INode> InNode);
|
2020-12-04 11:19:17 -04:00
|
|
|
|
|
|
|
|
/** Retrieve node by input index.
|
|
|
|
|
*
|
|
|
|
|
* @param InIndex - The index of the requested input.
|
|
|
|
|
*
|
|
|
|
|
* @return Pointer to the Node if it is stored on this graph. nullptr otherwise.
|
|
|
|
|
*/
|
|
|
|
|
const INode* FindInputNode(int32 InIndex) const;
|
|
|
|
|
|
|
|
|
|
/** Retrieve node by output index.
|
|
|
|
|
*
|
|
|
|
|
* @param InIndex - The index of the requested output.
|
|
|
|
|
*
|
|
|
|
|
* @return Pointer to the Node if it is stored on this graph. nullptr otherwise.
|
|
|
|
|
*/
|
|
|
|
|
const INode* FindOutputNode(int32 InIndex) const;
|
|
|
|
|
|
2023-06-23 14:53:34 -04:00
|
|
|
UE_DEPRECATED(5.3, "This function is no longer analyzes node ownership and will always return true.")
|
2020-12-04 11:19:17 -04:00
|
|
|
bool OwnsAllReferencedNodes() const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
2021-05-20 19:33:21 -04:00
|
|
|
TMap<int32, const INode*> InputNodes;
|
|
|
|
|
TMap<int32, const INode*> OutputNodes;
|
2020-12-04 11:19:17 -04:00
|
|
|
};
|
|
|
|
|
|
2023-03-13 17:23:05 -04:00
|
|
|
/** FFrontendGraphBuilder builds a FFrontendGraph from a FMetasoundDocument
|
2021-01-13 10:48:59 -04:00
|
|
|
* or FMetasoundFrontendClass.
|
2020-12-04 11:19:17 -04:00
|
|
|
*/
|
2021-07-28 17:12:57 -04:00
|
|
|
class METASOUNDFRONTEND_API FFrontendGraphBuilder
|
2020-12-04 11:19:17 -04:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/** Check that all dependencies are C++ class dependencies.
|
|
|
|
|
*
|
|
|
|
|
* @param InDocument - Document containing dependencies.
|
|
|
|
|
*
|
|
|
|
|
* @return True if all dependencies are C++ classes. False otherwise.
|
|
|
|
|
*/
|
2024-05-29 15:33:29 -04:00
|
|
|
UE_DEPRECATED(5.5, "No longer supported (not useful nor maintainable with paged graph support")
|
2021-05-28 14:09:45 -04:00
|
|
|
static bool IsFlat(const FMetasoundFrontendDocument& InDocument);
|
2021-01-13 10:48:59 -04:00
|
|
|
|
2024-05-29 15:33:29 -04:00
|
|
|
UE_DEPRECATED(5.5, "No longer supported (not useful nor maintainable with paged graph support")
|
2021-05-28 14:09:45 -04:00
|
|
|
static bool IsFlat(const FMetasoundFrontendGraphClass& InRoot, const TArray<FMetasoundFrontendClass>& InDependencies);
|
2020-12-04 11:19:17 -04:00
|
|
|
|
2023-09-13 14:21:35 -04:00
|
|
|
/* Create a FFrontendGraph from a FMetasoundFrontendDocument.*/
|
|
|
|
|
UE_DEPRECATED(5.4, "Use the version of CreateGraph(...) which does not include \"TransmittableInputNames\".")
|
2022-10-10 15:44:28 -04:00
|
|
|
static TUniquePtr<FFrontendGraph> CreateGraph(const FMetasoundFrontendDocument& InDocument, const TSet<FName>& TransmittableInputNames, const FString& InDebugAssetName);
|
2021-01-13 10:48:59 -04:00
|
|
|
|
2023-09-13 14:21:35 -04:00
|
|
|
/* Create a FFrontendGraph from a FMetasoundFrontendDocument subobjects.*/
|
|
|
|
|
UE_DEPRECATED(5.4, "Use the version of CreateGraph(...) which does not include \"TransmittableInputNames\".")
|
2022-10-10 15:44:28 -04:00
|
|
|
static TUniquePtr<FFrontendGraph> CreateGraph(const FMetasoundFrontendGraphClass& InGraphClass, const TArray<FMetasoundFrontendGraphClass>& InSubgraphs, const TArray<FMetasoundFrontendClass>& InDependencies, const TSet<FName>& TransmittableInputNames, const FString& InDebugAssetName);
|
2020-12-04 11:19:17 -04:00
|
|
|
|
2023-09-13 14:21:35 -04:00
|
|
|
/* Create a FFrontendGraph from a FMetasoundFrontendDocument.*/
|
|
|
|
|
static TUniquePtr<FFrontendGraph> CreateGraph(const FMetasoundFrontendDocument& InDocument, const FString& InDebugAssetName);
|
|
|
|
|
|
|
|
|
|
/* Create a FFrontendGraph from a FMetasoundFrontendDocument retrieving proxies from a FProxyDataCache.*/
|
2024-05-24 14:33:22 -04:00
|
|
|
static TUniquePtr<FFrontendGraph> CreateGraph(const FMetasoundFrontendDocument& InDocument, const Frontend::FProxyDataCache& InProxies, const FString& InDebugAssetName, const FGuid InGraphId = Frontend::CreateLocallyUniqueId());
|
2023-09-13 14:21:35 -04:00
|
|
|
|
2024-05-24 14:33:22 -04:00
|
|
|
/* Create a FFrontendGraph from a FMetasoundFrontendDocument and subobjects.*/
|
2023-09-13 14:21:35 -04:00
|
|
|
static TUniquePtr<FFrontendGraph> CreateGraph(const FMetasoundFrontendGraphClass& InGraph, const TArray<FMetasoundFrontendGraphClass>& InSubgraphs, const TArray<FMetasoundFrontendClass>& InDependencies, const FString& InDebugAssetName);
|
|
|
|
|
|
2024-05-24 14:33:22 -04:00
|
|
|
/* Create a FFrontendGraph from a FMetasoundFrontendDocument and subobjects, retrieving proxies from a FProxyDataCache.*/
|
|
|
|
|
static TUniquePtr<FFrontendGraph> CreateGraph(const FMetasoundFrontendGraphClass& InGraph, const TArray<FMetasoundFrontendGraphClass>& InSubgraphs, const TArray<FMetasoundFrontendClass>& InDependencies, const Frontend::FProxyDataCache& InProxyDataCache, const FString& InDebugAssetName, const FGuid InGraphId = Frontend::CreateLocallyUniqueId());
|
2023-09-13 14:21:35 -04:00
|
|
|
|
2020-12-04 11:19:17 -04:00
|
|
|
private:
|
2021-09-07 17:07:54 -04:00
|
|
|
struct FDefaultLiteralData
|
2021-05-28 14:09:45 -04:00
|
|
|
{
|
|
|
|
|
FGuid DestinationNodeID;
|
|
|
|
|
FGuid DestinationVertexID;
|
2021-09-13 14:14:37 -04:00
|
|
|
FVertexName DestinationVertexKey;
|
2021-05-28 14:09:45 -04:00
|
|
|
FName TypeName;
|
2021-09-07 17:07:54 -04:00
|
|
|
FLiteralNodeConstructorParams InitParams;
|
2021-05-28 14:09:45 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Map of Input VertexID to variable data required to construct and connect default variable
|
2021-06-02 11:30:20 -04:00
|
|
|
using FNodeIDVertexID = TTuple<FGuid, FGuid>;
|
2021-05-20 19:33:21 -04:00
|
|
|
using FDependencyByIDMap = TMap<FGuid, const FMetasoundFrontendClass*>;
|
|
|
|
|
using FSharedNodeByIDMap = TMap<FGuid, TSharedPtr<const INode>>;
|
2021-09-07 17:07:54 -04:00
|
|
|
using FDefaultInputByIDMap = TMap<FNodeIDVertexID, FDefaultLiteralData>;
|
2021-05-20 19:33:21 -04:00
|
|
|
|
2021-05-28 14:09:45 -04:00
|
|
|
// Context used throughout entire graph build process
|
|
|
|
|
// (for both a root and nested subgraphs)
|
2021-05-20 19:33:21 -04:00
|
|
|
struct FBuildContext
|
|
|
|
|
{
|
2022-03-04 04:25:00 -05:00
|
|
|
FString DebugAssetName;
|
2021-05-20 19:33:21 -04:00
|
|
|
FDependencyByIDMap FrontendClasses;
|
|
|
|
|
FSharedNodeByIDMap Graphs;
|
2023-09-13 14:21:35 -04:00
|
|
|
const Frontend::IDataTypeRegistry& DataTypeRegistry;
|
|
|
|
|
const Frontend::FProxyDataCache& ProxyDataCache;
|
2024-05-24 14:33:22 -04:00
|
|
|
FGuid GraphId;
|
2021-05-20 19:33:21 -04:00
|
|
|
};
|
|
|
|
|
|
2021-05-28 14:09:45 -04:00
|
|
|
// Transient context used for building a specific graph
|
|
|
|
|
struct FBuildGraphContext
|
|
|
|
|
{
|
|
|
|
|
TUniquePtr<FFrontendGraph> Graph;
|
|
|
|
|
const FMetasoundFrontendGraphClass& GraphClass;
|
|
|
|
|
FBuildContext& BuildContext;
|
|
|
|
|
FDefaultInputByIDMap DefaultInputs;
|
|
|
|
|
};
|
2020-12-04 11:19:17 -04:00
|
|
|
|
2023-09-13 14:21:35 -04:00
|
|
|
|
|
|
|
|
static TArray<FDefaultLiteralData> GetInputDefaultLiteralData(const FBuildContext& InContext, const FMetasoundFrontendNode& InNode, const FNodeInitData& InInitData, const TSet<FNodeIDVertexID>& InEdgeDestinations);
|
2020-12-04 11:19:17 -04:00
|
|
|
|
2021-05-28 14:09:45 -04:00
|
|
|
static bool SortSubgraphDependencies(TArray<const FMetasoundFrontendGraphClass*>& Subgraphs);
|
2020-12-04 11:19:17 -04:00
|
|
|
|
2023-09-13 14:21:35 -04:00
|
|
|
static TUniquePtr<FFrontendGraph> CreateGraph(FBuildContext& InContext, const FMetasoundFrontendGraphClass& InSubgraph);
|
2020-12-04 11:19:17 -04:00
|
|
|
|
2021-05-28 14:09:45 -04:00
|
|
|
static const FMetasoundFrontendClassInput* FindClassInputForInputNode(const FMetasoundFrontendGraphClass& InOwningGraph, const FMetasoundFrontendNode& InInputNode, int32& OutClassInputIndex);
|
|
|
|
|
static const FMetasoundFrontendClassOutput* FindClassOutputForOutputNode(const FMetasoundFrontendGraphClass& InOwningGraph, const FMetasoundFrontendNode& InOutputNode, int32& OutClassOutputIndex);
|
|
|
|
|
static const FMetasoundFrontendLiteral* FindInputLiteralForInputNode(const FMetasoundFrontendNode& InInputNode, const FMetasoundFrontendClass& InInputNodeClass, const FMetasoundFrontendClassInput& InOwningGraphClassInput);
|
2021-10-12 21:21:22 -04:00
|
|
|
static const FMetasoundFrontendVariable* FindVariableForVariableNode(const FMetasoundFrontendNode& InVariableNode, const FMetasoundFrontendGraph& InGraph);
|
2020-12-04 11:19:17 -04:00
|
|
|
|
2023-09-13 14:21:35 -04:00
|
|
|
static TUniquePtr<INode> CreateInputNode(const FBuildContext& InContext, const FMetasoundFrontendNode& InNode, const FMetasoundFrontendClass& InClass, const FMetasoundFrontendClassInput& InOwningGraphClassInput);
|
|
|
|
|
static TUniquePtr<INode> CreateOutputNode(const FBuildContext& InContext, const FMetasoundFrontendNode& InNode, const FMetasoundFrontendClass& InClass, FBuildGraphContext& InGraphContext, const TSet<FNodeIDVertexID>& InEdgeDestinations);
|
|
|
|
|
static TUniquePtr<INode> CreateVariableNode(const FBuildContext& InContext, const FMetasoundFrontendNode& InNode, const FMetasoundFrontendGraph& InGraph);
|
|
|
|
|
static TUniquePtr<INode> CreateExternalNode(const FBuildContext& InContext, const FMetasoundFrontendNode& InNode, const FMetasoundFrontendClass& InClass, FBuildGraphContext& InGraphContext, const TSet<FNodeIDVertexID>& InEdgeDestinations);
|
2020-12-04 11:19:17 -04:00
|
|
|
|
2022-03-04 04:25:00 -05:00
|
|
|
// Returns false on error
|
2023-09-13 14:21:35 -04:00
|
|
|
static bool AddNodesToGraph(FBuildGraphContext& InGraphContext);
|
2022-03-04 04:25:00 -05:00
|
|
|
|
|
|
|
|
// Returns false on error
|
|
|
|
|
static bool AddEdgesToGraph(FBuildGraphContext& InGraphContext);
|
|
|
|
|
|
|
|
|
|
// Returns false on error
|
|
|
|
|
static bool AddDefaultInputLiterals(FBuildGraphContext& InGraphContext);
|
2020-12-04 11:19:17 -04:00
|
|
|
};
|
|
|
|
|
}
|