2020-12-14 15:48:27 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "CoreMinimal.h"
|
2021-07-12 15:44:53 -04:00
|
|
|
|
|
|
|
|
#include "Engine/Engine.h"
|
2020-12-14 15:48:27 -04:00
|
|
|
#include "MetasoundAssetBase.h"
|
2021-06-16 14:11:49 -04:00
|
|
|
#include "Subsystems/EngineSubsystem.h"
|
2020-12-14 15:48:27 -04:00
|
|
|
#include "UObject/Object.h"
|
2021-12-01 15:59:03 -05:00
|
|
|
#include "Templates/Function.h"
|
2021-06-16 14:11:49 -04:00
|
|
|
|
2021-06-16 11:21:13 -04:00
|
|
|
|
2021-08-09 15:13:40 -04:00
|
|
|
// Forward Declarations
|
|
|
|
|
class UAssetManager;
|
|
|
|
|
|
2021-06-16 11:21:13 -04:00
|
|
|
|
2020-12-14 15:48:27 -04:00
|
|
|
namespace Metasound
|
|
|
|
|
{
|
|
|
|
|
/** Interface for an entry into the Metasound-UObject Registry.
|
|
|
|
|
*
|
2021-11-22 15:55:50 -05:00
|
|
|
* An entry provides information linking a FMetasoundFrontendClassInterface to a UClass.
|
2020-12-14 15:48:27 -04:00
|
|
|
* It also provides methods for accessing the FMetasoundAssetBase from a UObject.
|
|
|
|
|
*/
|
|
|
|
|
class IMetasoundUObjectRegistryEntry
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual ~IMetasoundUObjectRegistryEntry() = default;
|
|
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
/** Interface version associated with this entry. */
|
|
|
|
|
virtual const FMetasoundFrontendVersion& GetInterfaceVersion() const = 0;
|
2020-12-14 15:48:27 -04:00
|
|
|
|
|
|
|
|
/** UClass associated with this entry. */
|
|
|
|
|
virtual UClass* GetUClass() const = 0;
|
|
|
|
|
|
|
|
|
|
/** Returns true if the UObject is of a Class which is a child of this UClass associated with this entry. */
|
|
|
|
|
virtual bool IsChildClass(const UObject* InObject) const = 0;
|
|
|
|
|
|
|
|
|
|
/** Returns true if the UClass is a child of this UClass associated with this entry. */
|
|
|
|
|
virtual bool IsChildClass(const UClass* InClass) const = 0;
|
|
|
|
|
|
|
|
|
|
/** Attempts to cast the UObject to an FMetasoundAssetBase */
|
|
|
|
|
virtual FMetasoundAssetBase* Cast(UObject* InObject) const = 0;
|
|
|
|
|
|
|
|
|
|
/** Attempts to cast the UObject to an FMetasoundAssetBase */
|
|
|
|
|
virtual const FMetasoundAssetBase* Cast(const UObject* InObject) const = 0;
|
|
|
|
|
|
|
|
|
|
/** Creates a new object of the UClass type. */
|
|
|
|
|
virtual UObject* NewObject(UPackage* InPackage, const FName& InName) const = 0;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
IMetasoundUObjectRegistryEntry() = default;
|
|
|
|
|
|
|
|
|
|
/** Only the TMetasoundUObjectRegistryEntry can construct this class. */
|
|
|
|
|
template<typename UClassType>
|
|
|
|
|
friend class TMetasoundUObjectRegistryEntry;
|
|
|
|
|
};
|
|
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
/** An entry into the Metasound-UObject registry.
|
2020-12-14 15:48:27 -04:00
|
|
|
*
|
|
|
|
|
* @Tparam UClassType A class which derives from UObject and FMetasoundAssetBase.
|
|
|
|
|
*/
|
|
|
|
|
template<typename UClassType>
|
|
|
|
|
class TMetasoundUObjectRegistryEntry : public IMetasoundUObjectRegistryEntry
|
|
|
|
|
{
|
|
|
|
|
// Ensure that this is a subclass of FMetasoundAssetBase and UObject.
|
|
|
|
|
static_assert(std::is_base_of<FMetasoundAssetBase, UClassType>::value, "UClass must be derived from FMetasoundAssetBase");
|
|
|
|
|
static_assert(std::is_base_of<UObject, UClassType>::value, "UClass must be derived from UObject");
|
|
|
|
|
|
|
|
|
|
public:
|
2021-11-22 15:55:50 -05:00
|
|
|
TMetasoundUObjectRegistryEntry(const FMetasoundFrontendVersion& InInterfaceVersion)
|
|
|
|
|
: InterfaceVersion(InInterfaceVersion)
|
2020-12-14 15:48:27 -04:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual ~TMetasoundUObjectRegistryEntry() = default;
|
|
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
virtual const FMetasoundFrontendVersion& GetInterfaceVersion() const override
|
2020-12-14 15:48:27 -04:00
|
|
|
{
|
2021-11-22 15:55:50 -05:00
|
|
|
return InterfaceVersion;
|
2020-12-14 15:48:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UClass* GetUClass() const override
|
|
|
|
|
{
|
|
|
|
|
return UClassType::StaticClass();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IsChildClass(const UObject* InObject) const override
|
|
|
|
|
{
|
|
|
|
|
if (nullptr != InObject)
|
|
|
|
|
{
|
|
|
|
|
return InObject->IsA(UClassType::StaticClass());
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IsChildClass(const UClass* InClass) const override
|
|
|
|
|
{
|
|
|
|
|
if (nullptr != InClass)
|
|
|
|
|
{
|
|
|
|
|
return InClass->IsChildOf(UClassType::StaticClass());
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FMetasoundAssetBase* Cast(UObject* InObject) const override
|
|
|
|
|
{
|
|
|
|
|
if (nullptr == InObject)
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
return static_cast<FMetasoundAssetBase*>(CastChecked<UClassType>(InObject));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FMetasoundAssetBase* Cast(const UObject* InObject) const override
|
|
|
|
|
{
|
|
|
|
|
if (nullptr == InObject)
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
return static_cast<const FMetasoundAssetBase*>(CastChecked<const UClassType>(InObject));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UObject* NewObject(UPackage* InPackage, const FName& InName) const override
|
|
|
|
|
{
|
|
|
|
|
return ::NewObject<UClassType>(InPackage, InName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
FMetasoundFrontendVersion InterfaceVersion;
|
2020-12-14 15:48:27 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
/** IMetasoundUObjectRegistry contains IMetasoundUObjectRegistryEntries.
|
2020-12-14 15:48:27 -04:00
|
|
|
*
|
|
|
|
|
* Registered UObject classes can utilize the Metasound Editor. It also enables
|
2021-01-13 10:48:59 -04:00
|
|
|
* the creation of a UObject directly from a FMetasoundFrontendDocument.
|
2020-12-14 15:48:27 -04:00
|
|
|
*/
|
|
|
|
|
class METASOUNDENGINE_API IMetasoundUObjectRegistry
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual ~IMetasoundUObjectRegistry() = default;
|
|
|
|
|
|
|
|
|
|
/** Return static singleton instance of the registry. */
|
|
|
|
|
static IMetasoundUObjectRegistry& Get();
|
|
|
|
|
|
|
|
|
|
/** Adds an entry to the registry. */
|
2021-11-22 15:55:50 -05:00
|
|
|
virtual void RegisterUClassInterface(TUniquePtr<IMetasoundUObjectRegistryEntry>&& InEntry) = 0;
|
2020-12-14 15:48:27 -04:00
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
/** Returns all RegistryEntries with the given name */
|
|
|
|
|
virtual TArray<const IMetasoundUObjectRegistryEntry*> FindInterfaceEntriesByName(FName InName) const = 0;
|
2020-12-14 15:48:27 -04:00
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
/** Returns all UClasses registered to the interface version. */
|
|
|
|
|
virtual TArray<UClass*> FindSupportedInterfaceClasses(const FMetasoundFrontendVersion& InInterfaceVersion) const = 0;
|
|
|
|
|
|
|
|
|
|
/** Creates a new object from a MetaSound document.
|
2020-12-14 15:48:27 -04:00
|
|
|
*
|
|
|
|
|
* @param InClass - A registered UClass to create.
|
2021-06-08 10:52:31 -04:00
|
|
|
* @param InDocument - The FMetasoundFrontendDocument to use when creating the class.
|
2021-11-22 15:55:50 -05:00
|
|
|
* @param InInterfaceVersion - The version of the FMetasoundFrontendClassInterface to use when creating the class.
|
2020-12-14 15:48:27 -04:00
|
|
|
* @param InPath - If in editor, the created asset will be stored at this content path.
|
|
|
|
|
*
|
|
|
|
|
* @return A new object. A nullptr on error.
|
|
|
|
|
*/
|
2021-06-23 20:08:21 -04:00
|
|
|
virtual UObject* NewObject(UClass* InClass, const FMetasoundFrontendDocument& InDocument, const FString& InPath) const = 0;
|
2020-12-14 15:48:27 -04:00
|
|
|
|
2021-12-01 15:59:03 -05:00
|
|
|
/** Iterate all registered UClasses that serve as MetaSound assets.*/
|
|
|
|
|
virtual void IterateRegisteredUClasses(TFunctionRef<void(UClass&)> InFunc) const = 0;
|
|
|
|
|
|
2020-12-14 15:48:27 -04:00
|
|
|
/** Returns true if the InObject is of a class or child class which is registered. */
|
|
|
|
|
virtual bool IsRegisteredClass(UObject* InObject) const = 0;
|
|
|
|
|
|
|
|
|
|
/** Returns casts the UObject to a FMetasoundAssetBase if the UObject is of a registered type.
|
|
|
|
|
* If the UObject's UClass is not registered, then a nullptr is returned.
|
|
|
|
|
*/
|
|
|
|
|
virtual FMetasoundAssetBase* GetObjectAsAssetBase(UObject* InObject) const = 0;
|
|
|
|
|
|
|
|
|
|
/** Returns casts the UObject to a FMetasoundAssetBase if the UObject is of a registered type.
|
|
|
|
|
* If the UObject's UClass is not registered, then a nullptr is returned.
|
|
|
|
|
*/
|
|
|
|
|
virtual const FMetasoundAssetBase* GetObjectAsAssetBase(const UObject* InObject) const = 0;
|
|
|
|
|
};
|
2021-06-16 11:21:13 -04:00
|
|
|
} // namespace Metasound
|