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"
2022-08-10 14:18:10 -04:00
# include "Templates/SharedPointer.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
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
{
2022-05-10 16:51:39 -04:00
namespace Frontend
{
// Forward Declarations
2021-11-22 15:55:50 -05:00
class IInterfaceRegistryEntry ;
2022-05-10 16:51:39 -04:00
METASOUNDFRONTEND_API float GetDefaultBlockRate ( ) ;
2021-11-22 15:55:50 -05:00
} // 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
2023-03-07 17:01:52 -05:00
UE_DEPRECATED ( 5.3 , " Directly setting graph class Metadata is no longer be supported. Use the FMetaSoundFrontendDocumentBuilder to modify class data. " )
2021-01-13 10:48:59 -04:00
virtual void SetMetadata ( FMetasoundFrontendClassMetadata & InMetadata ) ;
2020-07-17 16:43:42 -04:00
2022-10-13 17:38:11 -04:00
# if WITH_EDITOR
// Rebuild dependent asset classes
void RebuildReferencedAssetClasses ( ) ;
# endif // WITH_EDITOR
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.
2023-03-07 17:01:52 -05:00
UE_DEPRECATED ( 5.3 , " Use static FMetaSoundFrontendDocumentBuilder 'FindDeclaredInterfaces instead. " )
2021-11-22 15:55:50 -05:00
bool GetDeclaredInterfaces ( TArray < const Metasound : : Frontend : : IInterfaceRegistryEntry * > & OutInterfaces ) const ;
2021-06-08 10:52:31 -04:00
2021-12-10 20:37:31 -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
2022-10-13 17:38:11 -04:00
// Returns set of class references set call to serialize in the editor
// Used at runtime load register referenced classes.
virtual TArray < FMetasoundAssetBase * > GetReferencedAssets ( ) = 0 ;
// Return all dependent asset paths to load asynchronously
virtual const TSet < FSoftObjectPath > & GetAsyncReferencedAssetClassPaths ( ) const = 0 ;
// Called when async assets have finished loading.
virtual void OnAsyncReferencedAssetsLoaded ( const TArray < FMetasoundAssetBase * > & InAsyncReferences ) = 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 ;
2023-03-07 17:01:52 -05:00
UE_DEPRECATED ( 5.3 , " ConvertFromPreset moved to FMetaSoundFrontendDocumentBuilder. " )
2021-06-16 11:21:13 -04:00
void ConvertFromPreset ( ) ;
2023-03-07 17:01:52 -05:00
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 ) ;
2023-03-07 17:01:52 -05:00
void SetDocument ( 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
2023-03-23 14:04:36 -04:00
const Metasound : : Frontend : : FNodeRegistryKey & GetRegistryKey ( ) const ;
2023-03-07 17:01:52 -05:00
UE_DEPRECATED ( 5.3 , " AddDefaultInterfaces is included in now applied via FMetaSoundFrontendDocumentBuilder::InitDocument and no longer directly supported via this function. " )
2021-11-22 15:55:50 -05:00
void AddDefaultInterfaces ( ) ;
2022-01-21 13:34:39 -05:00
2021-08-18 15:16:57 -04:00
bool VersionAsset ( ) ;
2021-07-27 15:36:03 -04:00
2022-02-10 18:36:26 -05:00
# if WITH_EDITOR
2022-01-26 18:11:52 -05:00
/*
* Caches transient metadata ( class & vertex ) found in the registry
* that is not necessary for serialization or core graph generation .
*
* @ return - Whether class was found in the registry & data was cached successfully .
*/
void CacheRegistryMetadata ( ) ;
2022-09-22 15:02:24 -04:00
FMetasoundFrontendDocumentModifyContext & GetModifyContext ( ) ;
const FMetasoundFrontendDocumentModifyContext & GetModifyContext ( ) const ;
2022-02-10 18:36:26 -05:00
# endif // WITH_EDITOR
2021-11-18 14:37:34 -05:00
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 :
2022-10-13 17:38:11 -04:00
# if WITH_EDITOR
virtual void SetReferencedAssetClasses ( TSet < Metasound : : Frontend : : IMetaSoundAssetManager : : FAssetInfo > & & InAssetClasses ) = 0 ;
# endif
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.
2023-04-05 17:38:47 -04:00
UE_DEPRECATED ( 5.3 , " MetaSounds no longer communicate using FSendInfo. " )
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.
2023-03-07 17:01:52 -05:00
virtual Metasound : : Frontend : : FDocumentAccessPtr GetDocumentAccessPtr ( ) = 0 ;
2020-07-17 16:43:42 -04:00
2020-12-14 15:48:27 -04:00
// Returns an access pointer to the document.
2023-03-07 17:01:52 -05:00
virtual Metasound : : Frontend : : FConstDocumentAccessPtr GetDocumentConstAccessPtr ( ) const = 0 ;
2020-07-23 16:39:56 -04:00
2022-02-15 11:30:22 -05:00
protected :
2021-09-16 14:46:43 -04:00
// Container for runtime data of MetaSound graph.
struct FRuntimeData
{
// Current ID of graph.
FGuid ChangeID ;
2022-08-18 13:55:13 -04:00
// Array of inputs which can be set for construction.
TArray < FMetasoundFrontendClassInput > PublicInputs ;
2021-09-16 14:46:43 -04:00
// Array of inputs which can be transmitted to.
TArray < FMetasoundFrontendClassInput > TransmittableInputs ;
// Core graph.
TSharedPtr < Metasound : : IGraph , ESPMode : : ThreadSafe > Graph ;
} ;
2022-03-10 22:07:08 -05:00
// Returns the cached runtime data.
2021-09-16 14:46:43 -04:00
const FRuntimeData & GetRuntimeData ( ) const ;
2022-08-18 13:55:13 -04:00
// Returns all public class inputs. This is a potentially expensive.
// Prefer accessing public class inputs using CacheRuntimeData.
TArray < FMetasoundFrontendClassInput > GetPublicClassInputs ( ) const ;
2022-10-13 17:38:11 -04:00
bool AutoUpdate ( bool bInLogWarningsOnDroppedConnection ) ;
void RegisterAssetDependencies ( const Metasound : : Frontend : : FMetaSoundAssetRegistrationOptions & InRegistrationOptions ) ;
TSharedPtr < FMetasoundFrontendDocument > PreprocessDocument ( ) ;
2022-03-10 22:07:08 -05:00
private :
2022-10-13 17:38:11 -04:00
# if WITH_EDITORONLY_DATA
void UpdateAssetRegistry ( ) ;
# endif
2022-10-10 15:44:28 -04:00
// Returns the cached runtime data. Call updates cached data if out-of-date.
const FRuntimeData & CacheRuntimeData ( const FMetasoundFrontendDocument & InPreprocessedDoc ) ;
2022-08-18 13:55:13 -04:00
2022-03-10 22:07:08 -05:00
Metasound : : Frontend : : FNodeRegistryKey RegistryKey ;
// Cache ID is used to determine whether CachedRuntimeData is out-of-date.
FGuid CurrentCachedRuntimeDataChangeID ;
FRuntimeData CachedRuntimeData ;
2022-10-10 15:44:28 -04:00
TSharedPtr < Metasound : : IGraph , ESPMode : : ThreadSafe > BuildMetasoundDocument ( const FMetasoundFrontendDocument & InPreprocessDoc , const TSet < FName > & InTransmittableInputNames ) const ;
2020-07-17 16:43:42 -04:00
} ;