You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
- Rename MetasoundArchetype Source file to MetasoundFrontendInterface - Move MetaSound interface files to subdirectory. - Break out document versioning transforms to own impl/header #rb todo #rnx #jira none #preflight 62fed263200ff87e07d77340 [CL 21458865 by Rob Gay in ue5-main branch]
206 lines
6.7 KiB
C++
206 lines
6.7 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "AudioDevice.h"
|
|
#include "Components/AudioComponent.h"
|
|
#include "IAudioParameterInterfaceRegistry.h"
|
|
#include "Interfaces/IPluginManager.h"
|
|
#include "Interfaces/MetasoundFrontendOutputFormatInterfaces.h"
|
|
#include "Interfaces/MetasoundFrontendSourceInterface.h"
|
|
#include "MetasoundFrontendController.h"
|
|
#include "MetasoundFrontendSearchEngine.h"
|
|
#include "MetasoundSource.h"
|
|
#include "Misc/AutomationTest.h"
|
|
#include "Tests/AutomationCommon.h"
|
|
|
|
#if WITH_DEV_AUTOMATION_TESTS
|
|
|
|
namespace EngineTestMetasoundSourcePrivate
|
|
{
|
|
static FString GetPluginContentDirectory()
|
|
{
|
|
TSharedPtr<IPlugin> Plugin = IPluginManager::Get().FindPlugin(TEXT("Metasound"));
|
|
if (ensure(Plugin.IsValid()))
|
|
{
|
|
return Plugin->GetContentDir();
|
|
}
|
|
return FString();
|
|
}
|
|
static FString GetPathToTestFilesDir()
|
|
{
|
|
FString OutPath = FPaths::Combine(GetPluginContentDirectory(), TEXT("Test"));
|
|
|
|
OutPath = FPaths::ConvertRelativePathToFull(OutPath);
|
|
FPaths::NormalizeDirectoryName(OutPath);
|
|
|
|
return OutPath;
|
|
}
|
|
|
|
static FString GetPathToGeneratedFilesDir()
|
|
{
|
|
FString OutPath = FPaths::Combine(FPaths::ProjectSavedDir(), TEXT("Metasounds"));
|
|
|
|
OutPath = FPaths::ConvertRelativePathToFull(OutPath);
|
|
FPaths::NormalizeDirectoryName(OutPath);
|
|
|
|
return OutPath;
|
|
}
|
|
|
|
static FString GetPathToGeneratedAssetsDir()
|
|
{
|
|
FString OutPath = TEXT("/Game/Metasound/Generated/");
|
|
FPaths::NormalizeDirectoryName(OutPath);
|
|
return OutPath;
|
|
}
|
|
|
|
Metasound::Frontend::FNodeHandle AddNode(Metasound::Frontend::IGraphController& InGraph, const Metasound::FNodeClassName& InClassName, int32 InMajorVersion)
|
|
{
|
|
Metasound::Frontend::FNodeHandle Node = Metasound::Frontend::INodeController::GetInvalidHandle();
|
|
FMetasoundFrontendClass NodeClass;
|
|
if (ensure(Metasound::Frontend::ISearchEngine::Get().FindClassWithHighestMinorVersion(InClassName, InMajorVersion, NodeClass)))
|
|
{
|
|
Node = InGraph.AddNode(NodeClass.Metadata);
|
|
check(Node->IsValid());
|
|
}
|
|
return Node;
|
|
}
|
|
|
|
FMetasoundFrontendDocument CreateMetaSoundMonoSourceDocument()
|
|
{
|
|
using namespace Audio;
|
|
using namespace Metasound;
|
|
using namespace Metasound::Frontend;
|
|
|
|
FMetasoundFrontendDocument Document;
|
|
|
|
Document.RootGraph.Metadata.SetClassName(FMetasoundFrontendClassName { "Namespace", "Unit Test Node", *LexToString(FGuid::NewGuid()) });
|
|
Document.RootGraph.Metadata.SetType(EMetasoundFrontendClassType::Graph);
|
|
|
|
FDocumentHandle DocumentHandle = IDocumentController::CreateDocumentHandle(Document);
|
|
FGraphHandle RootGraph = DocumentHandle->GetRootGraph();
|
|
check(RootGraph->IsValid());
|
|
|
|
// Add default source & mono interface members (OnPlay, OnFinished & Mono Out)
|
|
FModifyRootGraphInterfaces InterfaceTransform(
|
|
{ },
|
|
{
|
|
SourceInterface::GetVersion(),
|
|
SourceOneShotInterface::GetVersion(),
|
|
OutputFormatMonoInterface::GetVersion()
|
|
});
|
|
InterfaceTransform.Transform(DocumentHandle);
|
|
|
|
// Input on Play
|
|
FNodeHandle OnPlayOutputNode = RootGraph->GetInputNodeWithName(SourceInterface::Inputs::OnPlay);
|
|
check(OnPlayOutputNode->IsValid());
|
|
|
|
// Input Frequency
|
|
FMetasoundFrontendClassInput FrequencyInput;
|
|
FrequencyInput.Name = "Frequency";
|
|
FrequencyInput.TypeName = GetMetasoundDataTypeName<float>();
|
|
FrequencyInput.VertexID = FGuid::NewGuid();
|
|
FrequencyInput.DefaultLiteral.Set(100.f);
|
|
FNodeHandle FrequencyInputNode = RootGraph->AddInputVertex(FrequencyInput);
|
|
check(FrequencyInputNode->IsValid());
|
|
|
|
// Output On Finished
|
|
FNodeHandle OnFinishedOutputNode = RootGraph->GetOutputNodeWithName(SourceOneShotInterface::Outputs::OnFinished);
|
|
check(OnFinishedOutputNode->IsValid());
|
|
|
|
// Output Audio
|
|
FNodeHandle AudioOutputNode = RootGraph->GetOutputNodeWithName(OutputFormatMonoInterface::Outputs::MonoOut);
|
|
check(AudioOutputNode->IsValid());
|
|
|
|
// osc node
|
|
FNodeHandle OscNode = AddNode(*RootGraph, { "UE", "Sine", "Audio" }, 1);
|
|
|
|
// Make connections:
|
|
|
|
// frequency input "Frequency" -> oscillator "Frequency"
|
|
FOutputHandle OutputToConnect = FrequencyInputNode->GetOutputWithVertexName("Frequency");
|
|
FInputHandle InputToConnect = OscNode->GetInputWithVertexName("Frequency");
|
|
ensure(InputToConnect->Connect(*OutputToConnect));
|
|
|
|
// oscillator to output
|
|
OutputToConnect = OscNode->GetOutputWithVertexName("Audio");
|
|
InputToConnect = AudioOutputNode->GetInputWithVertexName(OutputFormatMonoInterface::Outputs::MonoOut);
|
|
ensure(InputToConnect->Connect(*OutputToConnect));
|
|
|
|
return Document;
|
|
}
|
|
}
|
|
|
|
DEFINE_LATENT_AUTOMATION_COMMAND_ONE_PARAMETER(FAudioComponentPlayLatentCommand, UAudioComponent*, AudioComponent);
|
|
|
|
bool FAudioComponentPlayLatentCommand::Update()
|
|
{
|
|
if (AudioComponent)
|
|
{
|
|
AudioComponent->Play();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
DEFINE_LATENT_AUTOMATION_COMMAND_ONE_PARAMETER(FAudioComponentStopLatentCommand, UAudioComponent*, AudioComponent);
|
|
|
|
bool FAudioComponentStopLatentCommand::Update()
|
|
{
|
|
if (AudioComponent)
|
|
{
|
|
AudioComponent->Stop();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
DEFINE_LATENT_AUTOMATION_COMMAND_ONE_PARAMETER(FAudioComponentRemoveFromRootLatentCommand, UAudioComponent*, AudioComponent);
|
|
|
|
bool FAudioComponentRemoveFromRootLatentCommand::Update()
|
|
{
|
|
if (AudioComponent)
|
|
{
|
|
AudioComponent->RemoveFromRoot();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// This test imports a metasound source from a JSON file, attempts to play it, and exports it as a json.
|
|
IMPLEMENT_SIMPLE_AUTOMATION_TEST(FAudioMetasoundSourceTest, "Audio.Metasound.BuildAndPlayMetasoundSource", EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter)
|
|
bool FAudioMetasoundSourceTest::RunTest(const FString& Parameters)
|
|
{
|
|
UMetaSoundSource* MetaSoundSource = NewObject<UMetaSoundSource>(GetTransientPackage(), FName(*LexToString(FGuid::NewGuid())));;
|
|
if (ensure(nullptr != MetaSoundSource))
|
|
{
|
|
MetaSoundSource->SetDocument(EngineTestMetasoundSourcePrivate::CreateMetaSoundMonoSourceDocument());
|
|
|
|
if (FAudioDevice* AudioDevice = GEngine->GetMainAudioDeviceRaw())
|
|
{
|
|
|
|
UAudioComponent* AudioComponent = FAudioDevice::CreateComponent(MetaSoundSource);
|
|
AddErrorIfFalse(AudioComponent != nullptr, "Couldn't create audio component!");
|
|
|
|
if (AudioComponent)
|
|
{
|
|
AudioComponent->bIsUISound = true;
|
|
AudioComponent->bAllowSpatialization = false;
|
|
AudioComponent->SetVolumeMultiplier(1.0f);
|
|
AudioComponent->AddToRoot();
|
|
|
|
ADD_LATENT_AUTOMATION_COMMAND(FAudioComponentPlayLatentCommand(AudioComponent));
|
|
ADD_LATENT_AUTOMATION_COMMAND(FEngineWaitLatentCommand(2.f));
|
|
ADD_LATENT_AUTOMATION_COMMAND(FAudioComponentStopLatentCommand(AudioComponent));
|
|
ADD_LATENT_AUTOMATION_COMMAND(FEngineWaitLatentCommand(0.5f));
|
|
ADD_LATENT_AUTOMATION_COMMAND(FAudioComponentRemoveFromRootLatentCommand(AudioComponent));
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// TODO: add separate JSON test.
|
|
|
|
|
|
#endif //WITH_DEV_AUTOMATION_TESTS
|