You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
- Hide superfluous type info & non-preferred literal data - Allow user to rename nodes with display name, which is independent from node string name (and supports localization) - Add better membership checks to editor detail customizations to ensure document member renames/data org doesn't break editor #rb ethan.geller #rnx #jira UEAU-546 [CL 13981474 by Rob Gay in ue5-main branch]
151 lines
4.4 KiB
C++
151 lines
4.4 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "MetasoundSource.h"
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "Internationalization/Text.h"
|
|
#include "AssetRegistryModule.h"
|
|
|
|
#include "MetasoundAssetBase.h"
|
|
#include "MetasoundGenerator.h"
|
|
#include "MetasoundAudioFormats.h"
|
|
#include "MetasoundPrimitives.h"
|
|
#include "MetasoundDataReferenceTypes.h"
|
|
|
|
#include "MetasoundArchetypeRegistration.h"
|
|
|
|
#if WITH_EDITORONLY_DATA
|
|
#include "EdGraph/EdGraph.h"
|
|
#endif // WITH_EDITORONLY_DATA
|
|
|
|
#define LOCTEXT_NAMESPACE "MetasoundSource"
|
|
|
|
static FName MetasoundSourceArchetypeName = FName(TEXT("Metasound Source"));
|
|
|
|
UMetasoundSource::UMetasoundSource(const FObjectInitializer& ObjectInitializer)
|
|
: Super(ObjectInitializer)
|
|
, FMetasoundAssetBase(RootMetasoundDocument)
|
|
{
|
|
// TODO:
|
|
NumChannels = 1;
|
|
Duration = INDEFINITELY_LOOPING_DURATION;
|
|
bLooping = true;
|
|
|
|
// todo: ensure that we have a method so that the audio engine can be authoritative over the sample rate the UMetasoundSource runs at.
|
|
SampleRate = 48000.0f;
|
|
|
|
}
|
|
|
|
void UMetasoundSource::SetMetadata(FMetasoundClassMetadata& InMetadata)
|
|
{
|
|
RootMetasoundDocument.RootClass.Metadata = InMetadata;
|
|
}
|
|
|
|
bool UMetasoundSource::IsPlayable() const
|
|
{
|
|
// todo: cache off whether this metasound is buildable to an operator.
|
|
return true;
|
|
}
|
|
|
|
bool UMetasoundSource::SupportsSubtitles() const
|
|
{
|
|
return Super::SupportsSubtitles();
|
|
}
|
|
|
|
float UMetasoundSource::GetDuration()
|
|
{
|
|
// eh? this is kind of a weird field anyways.
|
|
return Super::GetDuration();
|
|
}
|
|
|
|
ISoundGeneratorPtr UMetasoundSource::CreateSoundGenerator(const FSoundGeneratorInitParams& InParams)
|
|
{
|
|
NumChannels = 1;
|
|
Duration = INDEFINITELY_LOOPING_DURATION;
|
|
bLooping = true;
|
|
SampleRate = InParams.SampleRate;
|
|
|
|
Metasound::FOperatorSettings InSettings(InParams.SampleRate, InParams.NumFramesPerCallback);
|
|
|
|
TArray<Metasound::IOperatorBuilder::FBuildErrorPtr> BuildErrors;
|
|
|
|
Metasound::Frontend::FGraphHandle RootGraph = GetRootGraphHandle();
|
|
ensureAlways(RootGraph.IsValid());
|
|
|
|
TUniquePtr<Metasound::IOperator> Operator = RootGraph.BuildOperator(InSettings, BuildErrors);
|
|
if (ensureAlways(Operator.IsValid()))
|
|
{
|
|
Metasound::FDataReferenceCollection Outputs = Operator->GetOutputs();
|
|
|
|
Metasound::FMetasoundGeneratorInitParams InitParams =
|
|
{
|
|
MoveTemp(Operator),
|
|
Outputs.GetDataReadReferenceOrConstruct<Metasound::FAudioBuffer>(GetAudioOutputName(), InParams.NumFramesPerCallback),
|
|
Outputs.GetDataReadReferenceOrConstruct<Metasound::FBop>(GetIsFinishedOutputName(), false)
|
|
};
|
|
|
|
return ISoundGeneratorPtr(new Metasound::FMetasoundGenerator(MoveTemp(InitParams)));
|
|
}
|
|
else
|
|
{
|
|
return ISoundGeneratorPtr(nullptr);
|
|
}
|
|
}
|
|
|
|
void UMetasoundSource::PostLoad()
|
|
{
|
|
Super::PostLoad();
|
|
|
|
ConformDocumentToArchetype();
|
|
}
|
|
|
|
const FString& UMetasoundSource::GetOnPlayInputName()
|
|
{
|
|
static FString BopInputName = FString(TEXT("On Play"));
|
|
return BopInputName;
|
|
}
|
|
|
|
const FString& UMetasoundSource::GetAudioOutputName()
|
|
{
|
|
static FString AudioOutputName = FString(TEXT("Generated Audio"));
|
|
return AudioOutputName;
|
|
}
|
|
|
|
const FString& UMetasoundSource::GetIsFinishedOutputName()
|
|
{
|
|
static FString OnFinishedOutputName = FString(TEXT("On Finished"));
|
|
return OnFinishedOutputName;
|
|
}
|
|
|
|
FMetasoundArchetype UMetasoundSource::GetArchetype() const
|
|
{
|
|
FMetasoundArchetype Archetype;
|
|
Archetype.ArchetypeName = MetasoundSourceArchetypeName;
|
|
|
|
FMetasoundInputDescription OnPlayBop;
|
|
OnPlayBop.Name = GetOnPlayInputName();
|
|
OnPlayBop.DisplayName = FText::FromString(OnPlayBop.Name);
|
|
OnPlayBop.TypeName = Metasound::Frontend::GetDataTypeName<Metasound::FBop>();
|
|
OnPlayBop.ToolTip = LOCTEXT("OnPlayBopToolTip", "Bop executed when this source is first played.");
|
|
|
|
Archetype.RequiredInputs.Add(OnPlayBop);
|
|
|
|
FMetasoundOutputDescription GeneratedAudio;
|
|
GeneratedAudio.Name = GetAudioOutputName();
|
|
GeneratedAudio.DisplayName = FText::FromString(GeneratedAudio.Name);
|
|
GeneratedAudio.TypeName = Metasound::Frontend::GetDataTypeName<Metasound::FAudioBuffer>();
|
|
GeneratedAudio.ToolTip = LOCTEXT("GeneratedAudioToolTip", "The resulting output audio from this source.");
|
|
Archetype.RequiredOutputs.Add(GeneratedAudio);
|
|
|
|
FMetasoundOutputDescription OnFinished;
|
|
OnFinished.Name = GetIsFinishedOutputName();
|
|
OnFinished.DisplayName = FText::FromString(OnFinished.Name);
|
|
OnFinished.TypeName = Metasound::Frontend::GetDataTypeName<Metasound::FBop>();
|
|
OnFinished.ToolTip = LOCTEXT("OnFinishedToolTip", "Bop executed to initiate stopping the source.");
|
|
Archetype.RequiredOutputs.Add(OnFinished);
|
|
|
|
return Archetype;
|
|
}
|
|
|
|
#undef LOCTEXT_NAMESPACE
|