// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "CoreMinimal.h" #include "MetasoundAccessPtr.h" #include "MetasoundFrontend.h" #include "MetasoundFrontendController.h" #include "MetasoundFrontendDocumentAccessPtr.h" #include "MetasoundGraph.h" #include "MetasoundInstanceTransmitter.h" #include "MetasoundLog.h" #include "UObject/WeakObjectPtrTemplates.h" class UEdGraph; namespace Metasound { namespace AssetTags { extern const FString METASOUNDFRONTEND_API ArrayDelim; extern const FName METASOUNDFRONTEND_API AssetClassID; extern const FName METASOUNDFRONTEND_API RegistryVersionMajor; extern const FName METASOUNDFRONTEND_API RegistryVersionMinor; #if WITH_EDITORONLY_DATA extern const FName METASOUNDFRONTEND_API RegistryInputTypes; extern const FName METASOUNDFRONTEND_API RegistryOutputTypes; #endif // WITH_EDITORONLY_DATA } // namespace AssetTags } // namespace Metasound /** FMetasoundAssetBase is intended to be a mix-in subclass for UObjects which utilize * Metasound assets. It provides consistent access to FMetasoundFrontendDocuments, control * over the FMetasoundFrontendArchetype of the FMetasoundFrontendDocument. It also enables the UObject * to be utilized by a host of other engine tools built to support Metasounds. */ class METASOUNDFRONTEND_API FMetasoundAssetBase { public: static const FString FileExtension; FMetasoundAssetBase() = default; virtual ~FMetasoundAssetBase() = default; #if WITH_EDITORONLY_DATA virtual FText GetDisplayName() const = 0; // Returns the graph associated with this Metasound. Graph is required to be referenced on // Metasound UObject for editor serialization purposes. // @return Editor graph associated with this metasound uobject. virtual UEdGraph* GetGraph() = 0; virtual const UEdGraph* GetGraph() const = 0; virtual UEdGraph& GetGraphChecked() = 0; virtual const UEdGraph& GetGraphChecked() const = 0; // Sets the graph associated with this Metasound. Graph is required to be referenced on // Metasound UObject for editor serialization purposes. // @param Editor graph associated with this metasound object. virtual void SetGraph(UEdGraph* InGraph) = 0; // Only required for editor builds. Adds metadata to properties available when the object is // not loaded for use by the Asset Registry. virtual void SetRegistryAssetClassInfo(const Metasound::Frontend::FNodeClassInfo& InClassInfo) = 0; #endif // WITH_EDITORONLY_DATA // Registers the root graph of the given asset with the MetaSound Frontend. void RegisterGraphWithFrontend(); bool CopyDocumentAndInjectReceiveNodes(uint64 InInstanceID, const FMetasoundFrontendDocument& InSourceDoc, FMetasoundFrontendDocument& OutDestDoc) const; // Sets/overwrites the root class metadata virtual void SetMetadata(FMetasoundFrontendClassMetadata& InMetadata); // Returns a description of the required inputs and outputs for this metasound UClass. virtual const FMetasoundFrontendVersion& GetDefaultArchetypeVersion() const = 0; // Returns true if the archetype is supported by this object. virtual bool IsArchetypeSupported(const FMetasoundFrontendVersion& InArchetypeVersion) const; // Returns an array of archetypes preferred for this class. virtual const TArray& GetSupportedArchetypeVersions() const = 0; // Returns the preferred archetype for the given document. virtual FMetasoundFrontendVersion GetPreferredArchetypeVersion(const FMetasoundFrontendDocument& InDocument) const; // TODO: //virtual void OnMetaSoundDependencyAdded(const FMetasoundFrontendClassMetadata& InMetadata) = 0; //virtual void OnMetaSoundDependencyRemoved(const FMetasoundFrontendClassMetadata& InMetadata) = 0; // Gets the asset class info. virtual Metasound::Frontend::FNodeClassInfo GetAssetClassInfo() const = 0; void ConvertFromPreset(); // Imports data from a JSON string directly bool ImportFromJSON(const FString& InJSON); // Imports the asset from a JSON file at provided path bool ImportFromJSONAsset(const FString& InAbsolutePath); // Returns handle for the root metasound graph of this asset. Metasound::Frontend::FDocumentHandle GetDocumentHandle(); Metasound::Frontend::FConstDocumentHandle GetDocumentHandle() const; // Returns handle for the root metasound graph of this asset. Metasound::Frontend::FGraphHandle GetRootGraphHandle(); Metasound::Frontend::FConstGraphHandle GetRootGraphHandle() const; // Overwrites the existing document. If the document's archetype is not supported, // the FMetasoundAssetBase be while queried for a new one using `GetPreferredArchetype`. If `bForceUpdateArchetype` // is true, `GetPreferredArchetype` will be used whether or not the provided document's archetype // is supported. void SetDocument(const FMetasoundFrontendDocument& InDocument); FMetasoundFrontendDocument& GetDocumentChecked(); const FMetasoundFrontendDocument& GetDocumentChecked() const; // This must be called on UObject::PostLoad, as well as in this asset's UFactory, to fix up the root document based on the most recent version of the archetype. void ConformDocumentToArchetype(); bool VersionAsset(bool bInMarkDirty = true); // Calls the outermost package and marks it dirty. bool MarkMetasoundDocumentDirty() const; protected: struct FSendInfoAndVertexName { Metasound::FMetasoundInstanceTransmitter::FSendInfo SendInfo; FString VertexName; }; TArray GetSendInfos(uint64 InInstanceID) const; #if WITH_EDITORONLY_DATA FText GetDisplayName(FString&& InTypeName) const; #endif // WITH_EDITORONLY_DATA // Returns an access pointer to the document. virtual Metasound::Frontend::FDocumentAccessPtr GetDocument() = 0; // Returns an access pointer to the document. virtual Metasound::Frontend::FConstDocumentAccessPtr GetDocument() const = 0; // Returns the owning asset responsible for transactions applied to metasound virtual UObject* GetOwningAsset() = 0; // Returns the owning asset responsible for transactions applied to metasound virtual const UObject* GetOwningAsset() const = 0; private: bool bHasRegistered = false; bool GetReceiveNodeMetadataForDataType(const FName& InTypeName, FMetasoundFrontendClassMetadata& OutMetadata) const; TArray GetTransmittableInputVertexNames() const; Metasound::FSendAddress CreateSendAddress(uint64 InInstanceID, const FString& InVertexName, const FName& InDataTypeName) const; Metasound::Frontend::FNodeHandle AddInputPinForSendAddress(const Metasound::FMetasoundInstanceTransmitter::FSendInfo& InSendInfo, Metasound::Frontend::FGraphHandle InGraph) const; };