2020-07-15 00:16:40 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
#include "Metasound.h"
|
|
|
|
|
|
2021-06-08 10:52:31 -04:00
|
|
|
#include "AssetRegistryModule.h"
|
2020-07-15 00:16:40 -04:00
|
|
|
#include "CoreMinimal.h"
|
2021-06-08 10:52:31 -04:00
|
|
|
#include "Internationalization/Text.h"
|
|
|
|
|
#include "MetasoundAssetBase.h"
|
|
|
|
|
#include "MetasoundAudioFormats.h"
|
|
|
|
|
#include "MetasoundEngineEnvironment.h"
|
|
|
|
|
#include "MetasoundFrontendController.h"
|
|
|
|
|
#include "MetasoundFrontendQuery.h"
|
|
|
|
|
#include "MetasoundFrontendQuerySteps.h"
|
|
|
|
|
#include "MetasoundFrontendSearchEngine.h"
|
|
|
|
|
#include "MetasoundGenerator.h"
|
|
|
|
|
#include "MetasoundInstanceTransmitter.h"
|
|
|
|
|
#include "MetasoundLog.h"
|
|
|
|
|
#include "MetasoundOperatorSettings.h"
|
|
|
|
|
#include "MetasoundPrimitives.h"
|
|
|
|
|
#include "MetasoundReceiveNode.h"
|
|
|
|
|
#include "MetasoundTrigger.h"
|
|
|
|
|
#include "MetasoundEnvironment.h"
|
|
|
|
|
#include "UObject/ObjectSaveContext.h"
|
2020-07-23 16:39:56 -04:00
|
|
|
|
2021-06-08 10:52:31 -04:00
|
|
|
#if WITH_EDITORONLY_DATA
|
|
|
|
|
#include "EdGraph/EdGraph.h"
|
|
|
|
|
#endif // WITH_EDITORONLY_DATA
|
|
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "MetaSound"
|
2021-04-02 02:09:50 -04:00
|
|
|
UMetaSound::UMetaSound(const FObjectInitializer& ObjectInitializer)
|
2020-07-15 00:16:40 -04:00
|
|
|
: Super(ObjectInitializer)
|
2021-06-08 10:52:31 -04:00
|
|
|
, FMetasoundAssetBase()
|
2020-07-15 00:16:40 -04:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-08 10:52:31 -04:00
|
|
|
#if WITH_EDITOR
|
|
|
|
|
void UMetaSound::PreSave(FObjectPreSaveContext SaveContext)
|
|
|
|
|
{
|
|
|
|
|
Super::PreSave(SaveContext);
|
|
|
|
|
UpdateAssetTags(AssetTags);
|
|
|
|
|
RegisterGraphWithFrontend();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UMetaSound::PostEditUndo()
|
|
|
|
|
{
|
|
|
|
|
Super::PostEditUndo();
|
|
|
|
|
|
|
|
|
|
if (Graph)
|
|
|
|
|
{
|
|
|
|
|
Graph->Synchronize();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UMetaSound::PostEditChangeProperty(FPropertyChangedEvent& InEvent)
|
|
|
|
|
{
|
|
|
|
|
Super::PostEditChangeProperty(InEvent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // WITHEDITOR
|
|
|
|
|
|
2020-07-15 12:59:38 -04:00
|
|
|
#if WITH_EDITORONLY_DATA
|
2021-04-02 02:09:50 -04:00
|
|
|
UEdGraph* UMetaSound::GetGraph()
|
2020-07-15 12:59:38 -04:00
|
|
|
{
|
|
|
|
|
return Graph;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-02 02:09:50 -04:00
|
|
|
const UEdGraph* UMetaSound::GetGraph() const
|
2020-07-17 16:43:42 -04:00
|
|
|
{
|
|
|
|
|
return Graph;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-02 02:09:50 -04:00
|
|
|
UEdGraph& UMetaSound::GetGraphChecked()
|
2020-07-15 12:59:38 -04:00
|
|
|
{
|
|
|
|
|
check(Graph);
|
|
|
|
|
return *Graph;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-02 02:09:50 -04:00
|
|
|
const UEdGraph& UMetaSound::GetGraphChecked() const
|
2020-07-17 16:43:42 -04:00
|
|
|
{
|
|
|
|
|
check(Graph);
|
|
|
|
|
return *Graph;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-08 10:52:31 -04:00
|
|
|
FText UMetaSound::GetDisplayName() const
|
2020-07-15 12:59:38 -04:00
|
|
|
{
|
2021-06-08 10:52:31 -04:00
|
|
|
FString TypeName = UMetaSound::StaticClass()->GetName();
|
|
|
|
|
return FMetasoundAssetBase::GetDisplayName(MoveTemp(TypeName));
|
2020-07-15 12:59:38 -04:00
|
|
|
}
|
|
|
|
|
#endif // WITH_EDITORONLY_DATA
|
|
|
|
|
|
2021-06-08 10:52:31 -04:00
|
|
|
void UMetaSound::ConvertFromPreset()
|
2020-12-14 15:48:27 -04:00
|
|
|
{
|
2021-05-10 19:52:56 -04:00
|
|
|
using namespace Metasound::Frontend;
|
2021-06-08 10:52:31 -04:00
|
|
|
FGraphHandle GraphHandle = GetRootGraphHandle();
|
|
|
|
|
FMetasoundFrontendGraphStyle Style = GraphHandle->GetGraphStyle();
|
|
|
|
|
Style.bIsGraphEditable = true;
|
|
|
|
|
GraphHandle->SetGraphStyle(Style);
|
2020-12-14 15:48:27 -04:00
|
|
|
}
|
|
|
|
|
|
2021-06-08 10:52:31 -04:00
|
|
|
const FMetasoundFrontendArchetype& UMetaSound::GetArchetype() const
|
2020-12-14 15:48:27 -04:00
|
|
|
{
|
2021-06-08 10:52:31 -04:00
|
|
|
return GetBaseArchetype();
|
2020-12-14 15:48:27 -04:00
|
|
|
}
|
|
|
|
|
|
2021-06-08 10:52:31 -04:00
|
|
|
Metasound::FOperatorSettings UMetaSound::GetOperatorSettings(Metasound::FSampleRate InSampleRate) const
|
2020-12-14 15:48:27 -04:00
|
|
|
{
|
2021-06-08 10:52:31 -04:00
|
|
|
const float BlockRate = FMath::Clamp(Metasound::ConsoleVariables::BlockRate, 1.0f, 1000.0f);
|
|
|
|
|
return Metasound::FOperatorSettings(InSampleRate, BlockRate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Metasound::FSendAddress UMetaSound::CreateSendAddress(uint64 InInstanceID, const FString& InVertexName, const FName& InDataTypeName) const
|
|
|
|
|
{
|
|
|
|
|
using namespace Metasound;
|
|
|
|
|
|
|
|
|
|
FSendAddress Address;
|
|
|
|
|
|
|
|
|
|
Address.Subsystem = GetSubsystemNameForSendScope(ETransmissionScope::Global);
|
|
|
|
|
Address.ChannelName = FName(FString::Printf(TEXT("%d:%s:%s"), InInstanceID, *InVertexName, *InDataTypeName.ToString()));
|
|
|
|
|
|
|
|
|
|
return Address;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TArray<FMetasoundFrontendArchetype>& UMetaSound::GetPreferredArchetypes() const
|
|
|
|
|
{
|
|
|
|
|
static const TArray<FMetasoundFrontendArchetype> Preferred
|
|
|
|
|
{
|
|
|
|
|
GetBaseArchetype()
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-14 15:48:27 -04:00
|
|
|
return Preferred;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-08 10:52:31 -04:00
|
|
|
const FString& UMetaSound::GetAudioDeviceHandleVariableName()
|
2020-12-14 15:48:27 -04:00
|
|
|
{
|
2021-06-08 10:52:31 -04:00
|
|
|
static const FString AudioDeviceHandleVarName = TEXT("AudioDeviceHandle");
|
|
|
|
|
return AudioDeviceHandleVarName;
|
2020-12-14 15:48:27 -04:00
|
|
|
}
|
|
|
|
|
|
2021-06-08 10:52:31 -04:00
|
|
|
const FMetasoundFrontendArchetype& UMetaSound::GetBaseArchetype()
|
2020-12-14 15:48:27 -04:00
|
|
|
{
|
2021-06-08 10:52:31 -04:00
|
|
|
auto CreateBaseArchetype = []() -> FMetasoundFrontendArchetype
|
|
|
|
|
{
|
|
|
|
|
FMetasoundFrontendArchetype Archetype;
|
|
|
|
|
|
|
|
|
|
FMetasoundFrontendEnvironmentVariable AudioDeviceHandle;
|
|
|
|
|
AudioDeviceHandle.Name = GetAudioDeviceHandleVariableName();
|
|
|
|
|
AudioDeviceHandle.Metadata.DisplayName = FText::FromString(AudioDeviceHandle.Name);
|
|
|
|
|
AudioDeviceHandle.Metadata.Description = LOCTEXT("AudioDeviceHandleToolTip", "Audio device handle");
|
2020-12-14 15:48:27 -04:00
|
|
|
|
2021-06-08 10:52:31 -04:00
|
|
|
Archetype.Interface.Environment.Add(AudioDeviceHandle);
|
|
|
|
|
|
|
|
|
|
return Archetype;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const FMetasoundFrontendArchetype BaseArchetype = CreateBaseArchetype();
|
|
|
|
|
|
|
|
|
|
return BaseArchetype;
|
|
|
|
|
}
|
|
|
|
|
#undef LOCTEXT_NAMESPACE // MetaSound
|