Files
UnrealEngineUWP/Engine/Plugins/Runtime/Metasound/Source/MetasoundEngine/Private/Metasound.cpp
rob gay 7fe604fb2e UX Scaffolding for MetaSound Composition/Presets Part 2
- Leverage AssetRegistry/Manager to only load data on MetaSounds required to register (disabled until frontend registry supports this)
- Drag-And-Drop assets on MetaSound Graph
- Move ConvertToPreset to toolbar (WIP, still need to properly hide when clicked instead of closing editor blindly, has issue with refresh)

#rb phil.popp
#preflight 60c9a0a83e1b3c0001335ee7

#ROBOMERGE-SOURCE: CL 16689213 via CL 16689237
#ROBOMERGE-BOT: STARSHIP (Main -> Release-Engine-Test) (v835-16672529)

[CL 16689251 by rob gay in ue5-release-engine-test branch]
2021-06-16 11:21:13 -04:00

164 lines
4.1 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "Metasound.h"
#include "AssetRegistryModule.h"
#include "CoreMinimal.h"
#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"
#if WITH_EDITORONLY_DATA
#include "EdGraph/EdGraph.h"
#endif // WITH_EDITORONLY_DATA
#define LOCTEXT_NAMESPACE "MetaSound"
UMetaSound::UMetaSound(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
, FMetasoundAssetBase()
{
}
#if WITH_EDITOR
void UMetaSound::PreSave(FObjectPreSaveContext SaveContext)
{
Super::PreSave(SaveContext);
// TODO: Enable Composition
// RegisterGraphWithFrontend();
}
void UMetaSound::PostEditUndo()
{
Super::PostEditUndo();
if (Graph)
{
Graph->Synchronize();
}
}
void UMetaSound::PostEditChangeProperty(FPropertyChangedEvent& InEvent)
{
Super::PostEditChangeProperty(InEvent);
Metasound::PostEditChangeProperty(*this, InEvent);
}
#endif // WITHEDITOR
#if WITH_EDITORONLY_DATA
UEdGraph* UMetaSound::GetGraph()
{
return Graph;
}
const UEdGraph* UMetaSound::GetGraph() const
{
return Graph;
}
UEdGraph& UMetaSound::GetGraphChecked()
{
check(Graph);
return *Graph;
}
const UEdGraph& UMetaSound::GetGraphChecked() const
{
check(Graph);
return *Graph;
}
FText UMetaSound::GetDisplayName() const
{
FString TypeName = UMetaSound::StaticClass()->GetName();
return FMetasoundAssetBase::GetDisplayName(MoveTemp(TypeName));
}
void UMetaSound::SetRegistryAssetClassInfo(const Metasound::Frontend::FNodeClassInfo& InNodeInfo)
{
Metasound::SetMetaSoundRegistryAssetClassInfo(*this, InNodeInfo);
}
#endif // WITH_EDITORONLY_DATA
Metasound::Frontend::FNodeClassInfo UMetaSound::GetAssetClassInfo() const
{
return { GetDocumentChecked().RootGraph, *GetPathName() };
}
const FMetasoundFrontendArchetype& UMetaSound::GetArchetype() const
{
return GetBaseArchetype();
}
Metasound::FOperatorSettings UMetaSound::GetOperatorSettings(Metasound::FSampleRate InSampleRate) const
{
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()
};
return Preferred;
}
const FString& UMetaSound::GetAudioDeviceHandleVariableName()
{
static const FString AudioDeviceHandleVarName = TEXT("AudioDeviceHandle");
return AudioDeviceHandleVarName;
}
const FMetasoundFrontendArchetype& UMetaSound::GetBaseArchetype()
{
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");
Archetype.Interface.Environment.Add(AudioDeviceHandle);
return Archetype;
};
static const FMetasoundFrontendArchetype BaseArchetype = CreateBaseArchetype();
return BaseArchetype;
}
#undef LOCTEXT_NAMESPACE // MetaSound