2020-07-17 16:43:42 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
# pragma once
# include "CoreMinimal.h"
2020-12-14 15:48:27 -04:00
# include "MetasoundAccessPtr.h"
2020-07-17 16:43:42 -04:00
# include "MetasoundFrontend.h"
# include "MetasoundFrontendBaseClasses.h"
2021-01-13 10:48:59 -04:00
# include "MetasoundFrontendController.h"
2020-07-17 16:43:42 -04:00
# include "MetasoundGraph.h"
2021-01-22 03:05:22 -04:00
# include "MetasoundLog.h"
2020-07-17 16:43:42 -04:00
# include "UObject/WeakObjectPtrTemplates.h"
2021-01-22 03:05:22 -04:00
2020-07-23 20:32:26 -04:00
class UEdGraph ;
2020-07-17 16:43:42 -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
* over the FMetasoundFrontendArchetype of the FMetasoundFrontendDocument . It also enables the UObject
2020-12-14 15:48:27 -04:00
* to be utilized by a host of other engine tools built to support Metasounds .
*
* Example Usage :
*
* class UMyMetasoundClass : public UObject , public FMetasoundAssetBase
* {
*
* UPROPERTY ( )
2021-01-13 10:48:59 -04:00
* FMetasoundFrontendDocument MetasoundDocument ;
2020-12-14 15:48:27 -04:00
*
* # if WITH_EDITORONLY_DATA
* UPROPERTY ( )
* UEdGraph * Graph ;
* # endif // WITH_EDITORONLY_DATA
*
* public :
* // FMetasoundAssetBase Interface
* . . .
* // End FMetasoundAssetBase Interface
* } ;
*
*/
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 ;
FMetasoundAssetBase ( ) ;
2020-12-14 15:48:27 -04:00
// Construct an FMetasoundAssetBase with a default Metasound Archetype.
// @param InDefaultArchetype - Default archetype for a Metasound Document in this class.
2021-01-13 10:48:59 -04:00
FMetasoundAssetBase ( const FMetasoundFrontendArchetype & InDefaultArchetype ) ;
2020-07-23 16:39:56 -04:00
2020-07-17 16:43:42 -04:00
virtual ~ FMetasoundAssetBase ( ) = default ;
2020-07-23 20:32:26 -04:00
# if WITH_EDITORONLY_DATA
// 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 ;
# endif // WITH_EDITORONLY_DATA
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
2020-07-23 20:32:26 -04:00
// Returns a description of the required inputs and outputs for this metasound UClass.
2021-01-22 03:05:22 -04:00
const FMetasoundFrontendArchetype & GetMetasoundArchetype ( ) const ;
2020-12-14 15:48:27 -04:00
// Sets/overwrites the document archetype.
// @param InArchetype - The desired archetype .
//
// @return True on success. False if archetype is not supported by this object.
2021-01-22 03:05:22 -04:00
bool SetMetasoundArchetype ( const FMetasoundFrontendArchetype & InArchetype ) ;
2020-12-14 15:48:27 -04:00
// Returns an array of archetypes preferred for this class.
2021-01-22 03:05:22 -04:00
virtual const TArray < FMetasoundFrontendArchetype > & GetPreferredMetasoundArchetypes ( ) const = 0 ;
2020-12-14 15:48:27 -04:00
// Returns true if the archetype is supported by this object.
2021-01-22 03:05:22 -04:00
virtual bool IsMetasoundArchetypeSupported ( const FMetasoundFrontendArchetype & InArchetype ) const ;
2020-12-14 15:48:27 -04:00
// Returns the preferred archetype for the given document.
2021-01-22 03:05:22 -04:00
virtual const FMetasoundFrontendArchetype & GetPreferredMetasoundArchetype ( const FMetasoundFrontendDocument & InDocument ) const ;
2020-07-23 20:32:26 -04:00
2020-07-17 16:43:42 -04:00
// Returns the root class metadata
2021-01-13 10:48:59 -04:00
FMetasoundFrontendClassMetadata GetMetadata ( ) ;
2020-07-17 16:43:42 -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
2020-12-14 15:48:27 -04:00
// 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.
2021-01-13 10:48:59 -04:00
void SetDocument ( const FMetasoundFrontendDocument & InDocument , bool bForceUpdateArchetype = false ) ;
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
// 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.
2021-01-22 03:05:22 -04:00
void ConformDocumentToMetasoundArchetype ( ) ;
2020-07-23 20:32:26 -04:00
2021-02-01 15:59:27 -04:00
// Calls the outermost package and marks it dirty.
bool MarkMetasoundDocumentDirty ( ) const ;
2020-07-17 16:43:42 -04:00
protected :
2020-12-14 15:48:27 -04:00
// Returns an access pointer to the document.
2021-01-13 10:48:59 -04:00
virtual Metasound : : Frontend : : TAccessPtr < FMetasoundFrontendDocument > 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-01-13 10:48:59 -04:00
virtual Metasound : : Frontend : : TAccessPtr < const FMetasoundFrontendDocument > GetDocument ( ) const = 0 ;
2020-07-23 16:39:56 -04:00
2020-07-17 16:43:42 -04:00
// Returns the owning asset responsible for transactions applied to metasound
2021-02-01 15:59:27 -04:00
virtual UObject * GetOwningAsset ( ) = 0 ;
// Returns the owning asset responsible for transactions applied to metasound
virtual const UObject * GetOwningAsset ( ) const = 0 ;
2020-07-17 16:43:42 -04:00
2020-12-14 15:48:27 -04:00
private :
2021-01-13 10:48:59 -04:00
FMetasoundFrontendArchetype Archetype ;
2020-07-17 16:43:42 -04:00
} ;