2023-06-20 13:12:39 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
#include "MetasoundFrontendDocument.h"
|
|
|
|
|
#include "HAL/IConsoleManager.h"
|
|
|
|
|
#include "Misc/Guid.h"
|
|
|
|
|
|
|
|
|
|
namespace Metasound
|
|
|
|
|
{
|
|
|
|
|
namespace Frontend
|
|
|
|
|
{
|
2023-08-21 12:25:01 -04:00
|
|
|
extern METASOUNDFRONTEND_API int32 MetaSoundEnableCookDeterministicIDGeneration;
|
2023-06-20 13:12:39 -04:00
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
* For generating IDs using a given document.
|
|
|
|
|
* USAGE:
|
|
|
|
|
*
|
|
|
|
|
* If you want everything within the calling scope to be deterministic, use
|
|
|
|
|
* the scope determinism lock like you would a `FScopeLock`
|
|
|
|
|
*
|
|
|
|
|
* {
|
|
|
|
|
* constexpr bool bIsDeterministic = true;
|
|
|
|
|
* FDocumentIDGenerator::FScopeDeterminism DeterminismScope(bIsDeterministic);
|
|
|
|
|
*
|
|
|
|
|
* // Anything called in this scope will use a deterministic ID generator.
|
|
|
|
|
* // Once the `DeterminismScope` variable is destroyed, it will return to
|
|
|
|
|
* // whatever the prior behavior was
|
|
|
|
|
* MetaSoundAsset->UpdateOrWhatever();
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* void FMetaSoundAsset::UpdateOrWhatever()
|
|
|
|
|
* {
|
|
|
|
|
* // Anytime you call IDGen::Create*ID(..), it will obey whatever the outside scope set it to be.
|
|
|
|
|
* AddNewNodeOrWhatever(...)
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* void FMetaSoundAsset::AddNodeOrWhatever(...)
|
|
|
|
|
* {
|
|
|
|
|
* FDocumentIDGenerator& IDGen = FDocumentIDGenerator::Get();
|
|
|
|
|
*
|
|
|
|
|
* FGuid NewNodeID = IDGen::CreateNewNodeID();
|
|
|
|
|
* ...
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
*/
|
2023-09-05 17:54:02 -04:00
|
|
|
class METASOUNDFRONTEND_API FDocumentIDGenerator
|
2023-06-20 13:12:39 -04:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
class METASOUNDFRONTEND_API FScopeDeterminism final
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FScopeDeterminism(bool bInIsDeterministic);
|
|
|
|
|
bool GetDeterminism() const;
|
|
|
|
|
~FScopeDeterminism();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool bOriginalValue = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static FDocumentIDGenerator& Get();
|
|
|
|
|
|
|
|
|
|
FGuid CreateNodeID(const FMetasoundFrontendDocument& InDocument) const;
|
|
|
|
|
FGuid CreateVertexID(const FMetasoundFrontendDocument& InDocument) const;
|
|
|
|
|
FGuid CreateClassID(const FMetasoundFrontendDocument& InDocument) const;
|
|
|
|
|
|
|
|
|
|
FGuid CreateIDFromDocument(const FMetasoundFrontendDocument& InDocument) const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
FDocumentIDGenerator() = default;
|
|
|
|
|
|
|
|
|
|
friend class FScopeDeterminism;
|
|
|
|
|
void SetDeterminism(bool bInIsDeterministic);
|
|
|
|
|
bool GetDeterminism() const;
|
|
|
|
|
|
|
|
|
|
bool bIsDeterministic = false;
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-27 17:32:15 -04:00
|
|
|
// For generating IDs that are derived from a given class vertex. Unlike
|
|
|
|
|
// document ID generation, the class ID generator's results are not unique
|
2024-06-27 18:32:11 -04:00
|
|
|
// upon each request and therefore can deterministically generate the same
|
2024-06-27 17:32:15 -04:00
|
|
|
// ID for the same provided vertex.
|
2023-06-20 13:12:39 -04:00
|
|
|
class FClassIDGenerator
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static FClassIDGenerator& Get();
|
|
|
|
|
|
|
|
|
|
FGuid CreateInputID(const FMetasoundFrontendClassInput& Input) const;
|
|
|
|
|
FGuid CreateInputID(const Audio::FParameterInterface::FInput& Input) const;
|
|
|
|
|
FGuid CreateOutputID(const FMetasoundFrontendClassOutput& Output) const;
|
|
|
|
|
FGuid CreateOutputID(const Audio::FParameterInterface::FOutput& Output) const;
|
|
|
|
|
|
2024-06-14 13:05:35 -04:00
|
|
|
FGuid CreateNamespacedIDFromString(const FGuid& NamespaceGuid, const FString& StringToHash) const;
|
2023-06-20 13:12:39 -04:00
|
|
|
};
|
2023-10-16 18:42:49 -04:00
|
|
|
|
|
|
|
|
METASOUNDFRONTEND_API FGuid CreateLocallyUniqueId();
|
2023-06-20 13:12:39 -04:00
|
|
|
}
|
|
|
|
|
}
|