2020-07-17 16:43:42 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2020-12-14 15:48:27 -04:00
|
|
|
#include "MetasoundAccessPtr.h"
|
2021-11-07 23:43:01 -05:00
|
|
|
#include "MetasoundAssetManager.h"
|
2020-07-17 16:43:42 -04:00
|
|
|
#include "MetasoundFrontend.h"
|
2021-01-13 10:48:59 -04:00
|
|
|
#include "MetasoundFrontendController.h"
|
2021-07-27 15:36:03 -04:00
|
|
|
#include "MetasoundFrontendDocument.h"
|
2021-05-10 19:52:56 -04:00
|
|
|
#include "MetasoundFrontendDocumentAccessPtr.h"
|
2020-07-17 16:43:42 -04:00
|
|
|
#include "MetasoundGraph.h"
|
2021-01-22 03:05:22 -04:00
|
|
|
#include "MetasoundLog.h"
|
2021-08-30 14:08:45 -04:00
|
|
|
#include "MetasoundParameterTransmitter.h"
|
2021-09-13 14:14:37 -04:00
|
|
|
#include "MetasoundVertex.h"
|
2021-07-27 15:36:03 -04:00
|
|
|
#include "UObject/SoftObjectPath.h"
|
2020-07-17 16:43:42 -04:00
|
|
|
#include "UObject/WeakObjectPtrTemplates.h"
|
|
|
|
|
|
2021-07-27 15:36:03 -04:00
|
|
|
// Forward Declarations
|
|
|
|
|
class FMetasoundAssetBase;
|
2020-07-23 20:32:26 -04:00
|
|
|
class UEdGraph;
|
2020-07-17 16:43:42 -04:00
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
namespace Metasound
|
|
|
|
|
{
|
|
|
|
|
namespace Frontend {
|
|
|
|
|
class IInterfaceRegistryEntry;
|
|
|
|
|
} // namespace Frontend
|
|
|
|
|
} // namespace Metasound
|
|
|
|
|
|
2021-07-27 15:36:03 -04:00
|
|
|
|
2020-12-14 15:48:27 -04:00
|
|
|
/** FMetasoundAssetBase is intended to be a mix-in subclass for UObjects which utilize
|
2021-01-13 10:48:59 -04:00
|
|
|
* Metasound assets. It provides consistent access to FMetasoundFrontendDocuments, control
|
2021-11-22 15:55:50 -05:00
|
|
|
* over the FMetasoundFrontendClassInterface of the FMetasoundFrontendDocument. It also enables the UObject
|
2021-07-27 15:36:03 -04:00
|
|
|
* to be utilized by a host of other engine tools built to support MetaSounds.
|
2020-12-14 15:48:27 -04:00
|
|
|
*/
|
2020-07-17 16:43:42 -04:00
|
|
|
class METASOUNDFRONTEND_API FMetasoundAssetBase
|
|
|
|
|
{
|
|
|
|
|
public:
|
2020-07-23 16:39:56 -04:00
|
|
|
static const FString FileExtension;
|
|
|
|
|
|
2021-06-08 10:52:31 -04:00
|
|
|
FMetasoundAssetBase() = default;
|
2020-07-17 16:43:42 -04:00
|
|
|
virtual ~FMetasoundAssetBase() = default;
|
|
|
|
|
|
2020-07-23 20:32:26 -04:00
|
|
|
#if WITH_EDITORONLY_DATA
|
2021-06-08 10:52:31 -04:00
|
|
|
virtual FText GetDisplayName() const = 0;
|
2020-07-23 20:32:26 -04:00
|
|
|
|
|
|
|
|
// 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;
|
2021-06-08 10:52:31 -04:00
|
|
|
|
2021-06-16 11:21:13 -04:00
|
|
|
// 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;
|
2020-07-23 20:32:26 -04:00
|
|
|
#endif // WITH_EDITORONLY_DATA
|
|
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
// Called when the interface is changed, presenting the opportunity for
|
|
|
|
|
// any reflected object data to be updated based on the new interface.
|
2021-08-18 15:16:57 -04:00
|
|
|
// Returns whether or not any edits were made.
|
2021-11-22 15:55:50 -05:00
|
|
|
virtual bool ConformObjectDataToInterfaces() = 0;
|
2021-08-18 15:16:57 -04:00
|
|
|
|
2021-06-08 10:52:31 -04:00
|
|
|
// Registers the root graph of the given asset with the MetaSound Frontend.
|
2021-11-07 23:43:01 -05:00
|
|
|
void RegisterGraphWithFrontend(Metasound::Frontend::FMetaSoundAssetRegistrationOptions InRegistrationOptions = Metasound::Frontend::FMetaSoundAssetRegistrationOptions());
|
2021-06-08 10:52:31 -04:00
|
|
|
|
2021-07-27 15:36:03 -04:00
|
|
|
// Unregisters the root graph of the given asset with the MetaSound Frontend.
|
|
|
|
|
void UnregisterGraphWithFrontend();
|
|
|
|
|
|
2020-07-17 16:43:42 -04:00
|
|
|
// Sets/overwrites the root class metadata
|
2021-01-13 10:48:59 -04:00
|
|
|
virtual void SetMetadata(FMetasoundFrontendClassMetadata& InMetadata);
|
2020-07-17 16:43:42 -04:00
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
// Returns a default interface required when a given asset is created.
|
2020-12-14 15:48:27 -04:00
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
// Returns the interface entries declared by the given asset's document from the InterfaceRegistry.
|
|
|
|
|
bool GetDeclaredInterfaces(TArray<const Metasound::Frontend::IInterfaceRegistryEntry*>& OutInterfaces) const;
|
2021-06-08 10:52:31 -04:00
|
|
|
|
2021-12-01 15:59:03 -05:00
|
|
|
// Returns whether an interface with the given version is declared by the given asset's document.
|
|
|
|
|
bool IsInterfaceDeclared(const FMetasoundFrontendVersion& InVersion) const;
|
2021-06-08 10:52:31 -04:00
|
|
|
|
2021-06-16 11:21:13 -04:00
|
|
|
// Gets the asset class info.
|
|
|
|
|
virtual Metasound::Frontend::FNodeClassInfo GetAssetClassInfo() const = 0;
|
|
|
|
|
|
2021-08-18 15:16:57 -04:00
|
|
|
// Returns all the class keys of this asset's referenced assets
|
|
|
|
|
virtual const TSet<FString>& GetReferencedAssetClassKeys() const = 0;
|
2021-07-27 15:36:03 -04:00
|
|
|
|
2021-11-07 23:43:01 -05:00
|
|
|
// Returns set of cached class references set on last registration
|
|
|
|
|
// prior to serialize. Used at runtime to hint where to load referenced
|
2021-11-18 14:37:34 -05:00
|
|
|
// class if sound loads before AssetManager scan is completed. When registered
|
|
|
|
|
// hint paths to classes here can be superseded by another asset class if it shares
|
|
|
|
|
// the same key and has already been registered in the MetaSoundAssetManager.
|
2021-11-07 23:43:01 -05:00
|
|
|
virtual TSet<FSoftObjectPath>& GetReferencedAssetClassCache() = 0;
|
|
|
|
|
virtual const TSet<FSoftObjectPath>& GetReferencedAssetClassCache() const = 0;
|
2021-07-27 15:36:03 -04:00
|
|
|
|
2021-08-18 15:16:57 -04:00
|
|
|
bool AddingReferenceCausesLoop(const FSoftObjectPath& InReferencePath) const;
|
2021-11-18 14:37:34 -05:00
|
|
|
bool IsReferencedAsset(const FMetasoundAssetBase& InAssetToCheck) const;
|
2021-06-16 11:21:13 -04:00
|
|
|
void ConvertFromPreset();
|
2021-08-18 15:16:57 -04:00
|
|
|
bool IsRegistered() const;
|
2021-07-27 15:36:03 -04:00
|
|
|
|
2020-08-05 12:47:19 -04:00
|
|
|
// Imports data from a JSON string directly
|
|
|
|
|
bool ImportFromJSON(const FString& InJSON);
|
2020-07-23 16:39:56 -04:00
|
|
|
|
2020-08-05 12:47:19 -04:00
|
|
|
// Imports the asset from a JSON file at provided path
|
|
|
|
|
bool ImportFromJSONAsset(const FString& InAbsolutePath);
|
2020-07-17 16:43:42 -04:00
|
|
|
|
2021-01-13 10:48:59 -04:00
|
|
|
// Returns handle for the root metasound graph of this asset.
|
|
|
|
|
Metasound::Frontend::FDocumentHandle GetDocumentHandle();
|
2021-01-13 19:18:22 -04:00
|
|
|
Metasound::Frontend::FConstDocumentHandle GetDocumentHandle() const;
|
2021-01-13 10:48:59 -04:00
|
|
|
|
2020-07-17 16:43:42 -04:00
|
|
|
// Returns handle for the root metasound graph of this asset.
|
2020-12-14 15:48:27 -04:00
|
|
|
Metasound::Frontend::FGraphHandle GetRootGraphHandle();
|
2021-01-13 19:18:22 -04:00
|
|
|
Metasound::Frontend::FConstGraphHandle GetRootGraphHandle() const;
|
2020-07-17 16:43:42 -04:00
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
// Overwrites the existing document. If the document's interface is not supported,
|
|
|
|
|
// the FMetasoundAssetBase be while queried for a new one using `GetPreferredInterface`.
|
2021-06-08 10:52:31 -04:00
|
|
|
void SetDocument(const FMetasoundFrontendDocument& InDocument);
|
2020-12-14 15:48:27 -04:00
|
|
|
|
2021-01-13 10:48:59 -04:00
|
|
|
FMetasoundFrontendDocument& GetDocumentChecked();
|
|
|
|
|
const FMetasoundFrontendDocument& GetDocumentChecked() const;
|
2020-07-23 20:32:26 -04:00
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
void AddDefaultInterfaces();
|
2021-08-18 15:16:57 -04:00
|
|
|
bool AutoUpdate(bool bInMarkDirty = false);
|
|
|
|
|
bool VersionAsset();
|
2021-07-27 15:36:03 -04:00
|
|
|
|
2021-11-18 14:37:34 -05:00
|
|
|
#if WITH_EDITORONLY_DATA
|
|
|
|
|
bool GetSynchronizationPending() const;
|
|
|
|
|
bool GetSynchronizationClearUpdateNotes() const;
|
2021-11-22 15:55:50 -05:00
|
|
|
bool GetSynchronizationInterfacesUpdated() const;
|
2021-11-18 14:37:34 -05:00
|
|
|
void ResetSynchronizationState();
|
|
|
|
|
void SetClearNodeNotesOnSynchronization();
|
2021-11-22 15:55:50 -05:00
|
|
|
void SetInterfacesUpdatedOnSynchronization();
|
2021-11-18 14:37:34 -05:00
|
|
|
void SetSynchronizationRequired();
|
|
|
|
|
#endif // WITH_EDITORONLY_DATA
|
|
|
|
|
|
2021-07-27 15:36:03 -04:00
|
|
|
// Calls the outermost package and marks it dirty.
|
2021-02-01 15:59:27 -04:00
|
|
|
bool MarkMetasoundDocumentDirty() const;
|
|
|
|
|
|
2021-06-08 10:52:31 -04:00
|
|
|
struct FSendInfoAndVertexName
|
|
|
|
|
{
|
2021-08-30 14:08:45 -04:00
|
|
|
Metasound::FMetaSoundParameterTransmitter::FSendInfo SendInfo;
|
2021-09-13 14:14:37 -04:00
|
|
|
Metasound::FVertexName VertexName;
|
2021-06-08 10:52:31 -04:00
|
|
|
};
|
|
|
|
|
|
2021-11-07 23:43:01 -05:00
|
|
|
// 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;
|
|
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
FString GetOwningAssetName() const;
|
|
|
|
|
|
2021-07-28 17:12:57 -04:00
|
|
|
protected:
|
2021-08-18 15:16:57 -04:00
|
|
|
virtual void SetReferencedAssetClassKeys(TSet<Metasound::Frontend::FNodeRegistryKey>&& InKeys) = 0;
|
2021-07-28 17:12:57 -04:00
|
|
|
|
2021-09-16 14:46:43 -04:00
|
|
|
// Get information for communicating asynchronously with MetaSound running instance.
|
2021-06-08 10:52:31 -04:00
|
|
|
TArray<FSendInfoAndVertexName> GetSendInfos(uint64 InInstanceID) const;
|
|
|
|
|
|
|
|
|
|
#if WITH_EDITORONLY_DATA
|
|
|
|
|
FText GetDisplayName(FString&& InTypeName) const;
|
|
|
|
|
#endif // WITH_EDITORONLY_DATA
|
|
|
|
|
|
2020-12-14 15:48:27 -04:00
|
|
|
// Returns an access pointer to the document.
|
2021-05-10 19:52:56 -04:00
|
|
|
virtual Metasound::Frontend::FDocumentAccessPtr GetDocument() = 0;
|
2020-07-17 16:43:42 -04:00
|
|
|
|
2020-12-14 15:48:27 -04:00
|
|
|
// Returns an access pointer to the document.
|
2021-05-10 19:52:56 -04:00
|
|
|
virtual Metasound::Frontend::FConstDocumentAccessPtr GetDocument() const = 0;
|
2020-07-23 16:39:56 -04:00
|
|
|
|
2021-09-16 14:46:43 -04:00
|
|
|
// Returns a shared instance of the core metasound graph.
|
|
|
|
|
TSharedPtr<const Metasound::IGraph, ESPMode::ThreadSafe> GetMetasoundCoreGraph() const;
|
2021-07-28 17:12:57 -04:00
|
|
|
|
2021-11-18 14:37:34 -05:00
|
|
|
#if WITH_EDITORONLY_DATA
|
|
|
|
|
bool bSynchronizationRequired = true;
|
|
|
|
|
bool bSynchronizationClearUpdateNotes = false;
|
2021-11-22 15:55:50 -05:00
|
|
|
bool bSynchronizationInterfacesUpdated = false;
|
2021-11-18 14:37:34 -05:00
|
|
|
#endif // WITH_EDITORONLY_DATA
|
|
|
|
|
|
2021-06-08 10:52:31 -04:00
|
|
|
private:
|
2021-07-27 15:36:03 -04:00
|
|
|
Metasound::Frontend::FNodeRegistryKey RegistryKey;
|
2021-06-16 11:21:13 -04:00
|
|
|
|
2021-09-16 14:46:43 -04:00
|
|
|
// Container for runtime data of MetaSound graph.
|
|
|
|
|
struct FRuntimeData
|
|
|
|
|
{
|
|
|
|
|
// Current ID of graph.
|
|
|
|
|
FGuid ChangeID;
|
|
|
|
|
|
|
|
|
|
// Array of inputs which can be transmitted to.
|
|
|
|
|
TArray<FMetasoundFrontendClassInput> TransmittableInputs;
|
|
|
|
|
|
|
|
|
|
// Core graph.
|
|
|
|
|
TSharedPtr<Metasound::IGraph, ESPMode::ThreadSafe> Graph;
|
|
|
|
|
};
|
|
|
|
|
// Cache ID is used to determine whether CachedRuntimeData is out-of-date.
|
|
|
|
|
mutable FGuid CurrentCachedRuntimeDataChangeID;
|
|
|
|
|
mutable FRuntimeData CachedRuntimeData;
|
|
|
|
|
|
|
|
|
|
// Returns the current runtime data. If the cached data is out-of-date, it will
|
|
|
|
|
// be updated in this call.
|
|
|
|
|
const FRuntimeData& GetRuntimeData() const;
|
|
|
|
|
|
|
|
|
|
TSharedPtr<Metasound::IGraph, ESPMode::ThreadSafe> BuildMetasoundDocument() const;
|
2021-11-22 15:55:50 -05:00
|
|
|
TArray<const FMetasoundFrontendClassInput*> GetTransmittableClassInputs() const;
|
2021-09-13 14:14:37 -04:00
|
|
|
Metasound::FSendAddress CreateSendAddress(uint64 InInstanceID, const Metasound::FVertexName& InVertexName, const FName& InDataTypeName) const;
|
2021-08-30 14:08:45 -04:00
|
|
|
Metasound::Frontend::FNodeHandle AddInputPinForSendAddress(const Metasound::FMetaSoundParameterTransmitter::FSendInfo& InSendInfo, Metasound::Frontend::FGraphHandle InGraph) const;
|
2020-07-17 16:43:42 -04:00
|
|
|
};
|