2020-07-15 00:16:40 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "CoreMinimal.h"
|
2021-06-16 11:21:13 -04:00
|
|
|
|
2021-06-08 10:52:31 -04:00
|
|
|
#include "EdGraph/EdGraph.h"
|
2021-05-10 19:52:56 -04:00
|
|
|
#include "MetasoundAssetBase.h"
|
2020-07-15 00:16:40 -04:00
|
|
|
#include "MetasoundFrontend.h"
|
2021-01-13 10:48:59 -04:00
|
|
|
#include "MetasoundFrontendDocument.h"
|
2021-07-28 16:21:39 -04:00
|
|
|
#include "MetasoundFrontendTransform.h"
|
2021-06-08 10:52:31 -04:00
|
|
|
#include "MetasoundOperatorSettings.h"
|
|
|
|
|
#include "MetasoundRouter.h"
|
2021-07-27 15:36:03 -04:00
|
|
|
#include "MetasoundUObjectRegistry.h"
|
|
|
|
|
#include "Serialization/Archive.h"
|
2021-08-31 16:07:45 -04:00
|
|
|
#include "UObject/ObjectSaveContext.h"
|
2020-07-15 12:59:38 -04:00
|
|
|
|
2021-06-16 14:11:49 -04:00
|
|
|
#if WITH_EDITORONLY_DATA
|
|
|
|
|
#include "Algo/Transform.h"
|
|
|
|
|
#endif // WITH_EDITORONLY_DATA
|
|
|
|
|
|
2020-07-15 00:16:40 -04:00
|
|
|
#include "Metasound.generated.h"
|
|
|
|
|
|
2020-07-22 14:52:03 -04:00
|
|
|
|
2021-11-18 14:37:34 -05:00
|
|
|
UCLASS(Abstract)
|
2021-07-27 15:36:03 -04:00
|
|
|
class METASOUNDENGINE_API UMetasoundEditorGraphBase : public UEdGraph
|
|
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
virtual bool IsEditorOnly() const override { return true; }
|
|
|
|
|
virtual bool NeedsLoadForEditorGame() const override { return false; }
|
|
|
|
|
|
2021-11-18 14:37:34 -05:00
|
|
|
virtual void SetSynchronizationRequired(bool bInClearUpdateNotes = false) PURE_VIRTUAL(UMetasoundEditorGraphBase::Synchronize, )
|
|
|
|
|
virtual void RegisterGraphWithFrontend() PURE_VIRTUAL(UMetasoundEditorGraphBase::RegisterGraphWithFrontend(), )
|
2021-07-27 15:36:03 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2021-06-16 11:21:13 -04:00
|
|
|
namespace Metasound
|
|
|
|
|
{
|
|
|
|
|
namespace ConsoleVariables
|
|
|
|
|
{
|
|
|
|
|
static float BlockRate = 100.f;
|
|
|
|
|
} // namespace ConsoleVariables
|
|
|
|
|
|
2021-07-27 15:36:03 -04:00
|
|
|
#if WITH_EDITOR
|
2021-06-16 11:21:13 -04:00
|
|
|
template <typename TMetaSoundObject>
|
|
|
|
|
void PostEditChangeProperty(TMetaSoundObject& InMetaSound, FPropertyChangedEvent& InEvent)
|
|
|
|
|
{
|
2021-07-27 15:36:03 -04:00
|
|
|
}
|
|
|
|
|
#endif // WITH_EDITOR
|
|
|
|
|
|
|
|
|
|
template <typename TMetaSoundObject>
|
2021-08-31 16:07:45 -04:00
|
|
|
void PreSaveAsset(TMetaSoundObject& InMetaSound, FObjectPreSaveContext InSaveContext)
|
2021-07-27 15:36:03 -04:00
|
|
|
{
|
2021-11-07 23:43:01 -05:00
|
|
|
using namespace Metasound::Frontend;
|
|
|
|
|
|
2021-08-31 16:07:45 -04:00
|
|
|
// If not editor and cooking, no need to force re-registering as if its already registered,
|
|
|
|
|
// no edits have been made between last registration and this one if a parent asset has requested
|
|
|
|
|
// it to register.
|
|
|
|
|
FMetaSoundAssetRegistrationOptions NonEditorCookRegistrationOptions;
|
|
|
|
|
NonEditorCookRegistrationOptions.bForceReregister = false;
|
|
|
|
|
NonEditorCookRegistrationOptions.bRegisterDependencies = true;
|
|
|
|
|
|
2021-07-27 15:36:03 -04:00
|
|
|
#if WITH_EDITORONLY_DATA
|
|
|
|
|
if (UMetasoundEditorGraphBase* MetaSoundGraph = Cast<UMetasoundEditorGraphBase>(InMetaSound.GetGraph()))
|
|
|
|
|
{
|
2021-08-31 16:07:45 -04:00
|
|
|
if (InSaveContext.IsCooking())
|
2021-07-27 15:36:03 -04:00
|
|
|
{
|
2021-08-31 16:07:45 -04:00
|
|
|
// Non-editor builds use explicit options above as opposed to using
|
|
|
|
|
// editor variant via the MetaSoundEdGraph.
|
|
|
|
|
if (GIsEditor)
|
|
|
|
|
{
|
|
|
|
|
MetaSoundGraph->RegisterGraphWithFrontend();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
InMetaSound.RegisterGraphWithFrontend(NonEditorCookRegistrationOptions);
|
|
|
|
|
}
|
2021-11-18 14:37:34 -05:00
|
|
|
MetaSoundGraph->SetSynchronizationRequired(false /* bInClearUpdateNotes */);
|
2021-08-31 16:07:45 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-11-18 14:37:34 -05:00
|
|
|
MetaSoundGraph->RegisterGraphWithFrontend();
|
|
|
|
|
MetaSoundGraph->SetSynchronizationRequired(true /* bInClearUpdateNotes */);
|
2021-07-27 15:36:03 -04:00
|
|
|
}
|
|
|
|
|
}
|
2021-08-31 16:07:45 -04:00
|
|
|
#else
|
|
|
|
|
InMetaSound.RegisterGraphWithFrontend(NonEditorCookRegistrationOptions);
|
2021-07-27 15:36:03 -04:00
|
|
|
#endif // WITH_EDITORONLY_DATA
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename TMetaSoundObject>
|
|
|
|
|
void SerializeToArchive(TMetaSoundObject& InMetaSound, FArchive& InArchive)
|
|
|
|
|
{
|
|
|
|
|
if (InArchive.IsLoading())
|
|
|
|
|
{
|
2021-08-18 15:16:57 -04:00
|
|
|
InMetaSound.VersionAsset();
|
2021-07-27 15:36:03 -04:00
|
|
|
}
|
2021-06-16 11:21:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if WITH_EDITORONLY_DATA
|
|
|
|
|
template <typename TMetaSoundObject>
|
|
|
|
|
void SetMetaSoundRegistryAssetClassInfo(TMetaSoundObject& InMetaSound, const Metasound::Frontend::FNodeClassInfo& InClassInfo)
|
|
|
|
|
{
|
|
|
|
|
using namespace Metasound;
|
2021-11-07 23:43:01 -05:00
|
|
|
using namespace Metasound::Frontend;
|
2021-06-16 11:21:13 -04:00
|
|
|
|
|
|
|
|
check(AssetTags::AssetClassID == GET_MEMBER_NAME_CHECKED(TMetaSoundObject, AssetClassID));
|
|
|
|
|
check(AssetTags::RegistryInputTypes == GET_MEMBER_NAME_CHECKED(TMetaSoundObject, RegistryInputTypes));
|
|
|
|
|
check(AssetTags::RegistryOutputTypes == GET_MEMBER_NAME_CHECKED(TMetaSoundObject, RegistryOutputTypes));
|
|
|
|
|
check(AssetTags::RegistryVersionMajor == GET_MEMBER_NAME_CHECKED(TMetaSoundObject, RegistryVersionMajor));
|
|
|
|
|
check(AssetTags::RegistryVersionMinor == GET_MEMBER_NAME_CHECKED(TMetaSoundObject, RegistryVersionMinor));
|
|
|
|
|
|
|
|
|
|
bool bMarkDirty = InMetaSound.AssetClassID != InClassInfo.AssetClassID;
|
|
|
|
|
bMarkDirty |= InMetaSound.RegistryVersionMajor != InClassInfo.Version.Major;
|
|
|
|
|
bMarkDirty |= InMetaSound.RegistryVersionMinor != InClassInfo.Version.Minor;
|
|
|
|
|
|
|
|
|
|
InMetaSound.AssetClassID = InClassInfo.AssetClassID;
|
|
|
|
|
InMetaSound.RegistryVersionMajor = InClassInfo.Version.Major;
|
|
|
|
|
InMetaSound.RegistryVersionMinor = InClassInfo.Version.Minor;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
TArray<FString> InputTypes;
|
|
|
|
|
Algo::Transform(InClassInfo.InputTypes, InputTypes, [](const FName& Name) { return Name.ToString(); });
|
|
|
|
|
|
|
|
|
|
const FString TypeString = FString::Join(InputTypes, *AssetTags::ArrayDelim);
|
|
|
|
|
bMarkDirty |= InMetaSound.RegistryInputTypes != TypeString;
|
|
|
|
|
InMetaSound.RegistryInputTypes = TypeString;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
TArray<FString> OutputTypes;
|
|
|
|
|
Algo::Transform(InClassInfo.OutputTypes, OutputTypes, [](const FName& Name) { return Name.ToString(); });
|
|
|
|
|
|
|
|
|
|
const FString TypeString = FString::Join(OutputTypes, *AssetTags::ArrayDelim);
|
|
|
|
|
bMarkDirty |= InMetaSound.RegistryOutputTypes != TypeString;
|
|
|
|
|
InMetaSound.RegistryOutputTypes = TypeString;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif // WITH_EDITORONLY_DATA
|
|
|
|
|
} // namespace Metasound
|
|
|
|
|
|
|
|
|
|
|
2020-07-15 00:16:40 -04:00
|
|
|
/**
|
|
|
|
|
* This asset type is used for Metasound assets that can only be used as nodes in other Metasound graphs.
|
2021-06-08 10:52:31 -04:00
|
|
|
* Because of this, they contain no required inputs or outputs.
|
2020-07-15 00:16:40 -04:00
|
|
|
*/
|
2020-07-15 12:59:38 -04:00
|
|
|
UCLASS(hidecategories = object, BlueprintType)
|
2021-04-02 02:09:50 -04:00
|
|
|
class METASOUNDENGINE_API UMetaSound : public UObject, public FMetasoundAssetBase
|
2020-07-15 00:16:40 -04:00
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
|
|
protected:
|
2020-08-05 12:47:19 -04:00
|
|
|
UPROPERTY(EditAnywhere, Category = CustomView)
|
2021-06-08 10:52:31 -04:00
|
|
|
FMetasoundFrontendDocument RootMetaSoundDocument;
|
2020-07-15 00:16:40 -04:00
|
|
|
|
2020-07-15 12:59:38 -04:00
|
|
|
#if WITH_EDITORONLY_DATA
|
|
|
|
|
UPROPERTY()
|
2021-06-08 10:52:31 -04:00
|
|
|
UMetasoundEditorGraphBase* Graph;
|
2020-07-15 12:59:38 -04:00
|
|
|
#endif // WITH_EDITORONLY_DATA
|
|
|
|
|
|
2020-07-15 00:16:40 -04:00
|
|
|
public:
|
2021-04-02 02:09:50 -04:00
|
|
|
UMetaSound(const FObjectInitializer& ObjectInitializer);
|
2020-07-15 00:16:40 -04:00
|
|
|
|
2021-07-27 15:36:03 -04:00
|
|
|
UPROPERTY()
|
2021-08-18 15:16:57 -04:00
|
|
|
TSet<FString> ReferencedAssetClassKeys;
|
|
|
|
|
|
2021-11-07 23:43:01 -05:00
|
|
|
UPROPERTY()
|
|
|
|
|
TSet<FSoftObjectPath> ReferenceAssetClassCache;
|
2021-07-27 15:36:03 -04:00
|
|
|
|
2021-06-16 11:21:13 -04:00
|
|
|
UPROPERTY(AssetRegistrySearchable)
|
|
|
|
|
FGuid AssetClassID;
|
|
|
|
|
|
2020-07-15 12:59:38 -04:00
|
|
|
#if WITH_EDITORONLY_DATA
|
2021-06-16 11:21:13 -04:00
|
|
|
UPROPERTY(AssetRegistrySearchable)
|
|
|
|
|
FString RegistryInputTypes;
|
|
|
|
|
|
|
|
|
|
UPROPERTY(AssetRegistrySearchable)
|
|
|
|
|
FString RegistryOutputTypes;
|
|
|
|
|
|
|
|
|
|
UPROPERTY(AssetRegistrySearchable)
|
|
|
|
|
int32 RegistryVersionMajor = 0;
|
|
|
|
|
|
|
|
|
|
UPROPERTY(AssetRegistrySearchable)
|
|
|
|
|
int32 RegistryVersionMinor = 0;
|
|
|
|
|
|
|
|
|
|
// Sets Asset Registry Metadata associated with this MetaSound
|
|
|
|
|
virtual void SetRegistryAssetClassInfo(const Metasound::Frontend::FNodeClassInfo& InClassInfo) override;
|
|
|
|
|
|
2020-07-30 16:57:04 -04:00
|
|
|
// Returns document name (for editor purposes, and avoids making document public for edit
|
|
|
|
|
// while allowing editor to reference directly)
|
|
|
|
|
static FName GetDocumentPropertyName()
|
|
|
|
|
{
|
2021-06-08 10:52:31 -04:00
|
|
|
return GET_MEMBER_NAME_CHECKED(UMetaSound, RootMetaSoundDocument);
|
2020-07-30 16:57:04 -04:00
|
|
|
}
|
2020-07-15 12:59:38 -04:00
|
|
|
|
2021-06-08 10:52:31 -04:00
|
|
|
// Name to display in editors
|
|
|
|
|
virtual FText GetDisplayName() const override;
|
|
|
|
|
|
2020-07-15 12:59:38 -04:00
|
|
|
// Returns the graph associated with this Metasound. Graph is required to be referenced on
|
|
|
|
|
// Metasound UObject for editor serialization purposes.
|
2021-06-08 10:52:31 -04:00
|
|
|
// @return Editor graph associated with UMetaSoundSource.
|
2020-07-23 20:32:26 -04:00
|
|
|
virtual UEdGraph* GetGraph() override;
|
|
|
|
|
virtual const UEdGraph* GetGraph() const override;
|
|
|
|
|
virtual UEdGraph& GetGraphChecked() override;
|
|
|
|
|
virtual const UEdGraph& GetGraphChecked() const override;
|
2020-07-15 12:59:38 -04:00
|
|
|
|
|
|
|
|
// Sets the graph associated with this Metasound. Graph is required to be referenced on
|
|
|
|
|
// Metasound UObject for editor serialization purposes.
|
2021-06-08 10:52:31 -04:00
|
|
|
// @param Editor graph associated with UMetaSoundSource.
|
|
|
|
|
virtual void SetGraph(UEdGraph* InGraph) override
|
|
|
|
|
{
|
|
|
|
|
Graph = CastChecked<UMetasoundEditorGraphBase>(InGraph);
|
|
|
|
|
}
|
|
|
|
|
#endif // #if WITH_EDITORONLY_DATA
|
|
|
|
|
|
|
|
|
|
#if WITH_EDITOR
|
2021-07-28 16:21:39 -04:00
|
|
|
virtual void PostDuplicate(EDuplicateMode::Type DuplicateMode) override;
|
2021-06-08 10:52:31 -04:00
|
|
|
virtual void PostEditUndo() override;
|
|
|
|
|
virtual void PostEditChangeProperty(FPropertyChangedEvent& InEvent) override;
|
|
|
|
|
#endif // WITH_EDITOR
|
|
|
|
|
|
2021-07-27 15:36:03 -04:00
|
|
|
virtual void BeginDestroy() override;
|
|
|
|
|
virtual void PreSave(FObjectPreSaveContext InSaveContext) override;
|
|
|
|
|
virtual void Serialize(FArchive& InArchive) override;
|
|
|
|
|
|
2021-11-07 23:43:01 -05:00
|
|
|
virtual TSet<FSoftObjectPath>& GetReferencedAssetClassCache() override;
|
|
|
|
|
virtual const TSet<FSoftObjectPath>& GetReferencedAssetClassCache() const override;
|
2021-07-27 15:36:03 -04:00
|
|
|
|
2021-06-16 11:21:13 -04:00
|
|
|
// Returns Asset Metadata associated with this MetaSound
|
|
|
|
|
virtual Metasound::Frontend::FNodeClassInfo GetAssetClassInfo() const override;
|
2021-06-08 10:52:31 -04:00
|
|
|
|
2020-07-15 12:59:38 -04:00
|
|
|
|
2021-11-22 15:55:50 -05:00
|
|
|
virtual bool ConformObjectDataToInterfaces() override { return false; }
|
2021-08-18 15:16:57 -04:00
|
|
|
|
|
|
|
|
virtual const TSet<FString>& GetReferencedAssetClassKeys() const override
|
|
|
|
|
{
|
|
|
|
|
return ReferencedAssetClassKeys;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-01 15:59:27 -04:00
|
|
|
UObject* GetOwningAsset() override
|
2020-07-23 16:39:56 -04:00
|
|
|
{
|
2021-02-01 15:59:27 -04:00
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const UObject* GetOwningAsset() const override
|
|
|
|
|
{
|
|
|
|
|
return this;
|
2020-07-17 16:43:42 -04:00
|
|
|
}
|
2020-07-15 00:16:40 -04:00
|
|
|
|
2021-06-08 10:52:31 -04:00
|
|
|
protected:
|
2021-08-18 15:16:57 -04:00
|
|
|
virtual void SetReferencedAssetClassKeys(TSet<Metasound::Frontend::FNodeRegistryKey>&& InKeys) override;
|
2020-12-14 15:48:27 -04:00
|
|
|
|
2021-06-08 10:52:31 -04:00
|
|
|
Metasound::Frontend::FDocumentAccessPtr GetDocument() override
|
|
|
|
|
{
|
|
|
|
|
using namespace Metasound::Frontend;
|
|
|
|
|
// Return document using FAccessPoint to inform the TAccessPtr when the
|
|
|
|
|
// object is no longer valid.
|
|
|
|
|
return MakeAccessPtr<FDocumentAccessPtr>(RootMetaSoundDocument.AccessPoint, RootMetaSoundDocument);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Metasound::Frontend::FConstDocumentAccessPtr GetDocument() const override
|
|
|
|
|
{
|
|
|
|
|
using namespace Metasound::Frontend;
|
|
|
|
|
// Return document using FAccessPoint to inform the TAccessPtr when the
|
|
|
|
|
// object is no longer valid.
|
|
|
|
|
return MakeAccessPtr<FConstDocumentAccessPtr>(RootMetaSoundDocument.AccessPoint, RootMetaSoundDocument);
|
|
|
|
|
}
|
2020-12-14 15:48:27 -04:00
|
|
|
};
|