Files
UnrealEngineUWP/Engine/Plugins/Runtime/Metasound/Source/MetasoundEditor/Private/SMetasoundSpectrumAnalyzerGraphNode.cpp
rob gay 01bcc9e365 Round 2: Backout of backout(s?):
- Uniform color fix-ups for MetaSound analyzers
- Move live MetaSound stats/audition settings to top left of graph
- Fix ordering of playback widget in input details panel to follow same order as page details panel

#rnx
[FYI] helen.yang, jon.huller, sondra.moyls, aaron.mcleran
#rb Brian.Chrisman
#jira UE-224143

[CL 36453576 by rob gay in 5.5 branch]
2024-09-19 17:46:22 -04:00

87 lines
2.9 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "SMetasoundSpectrumAnalyzerGraphNode.h"
#include "AudioSpectrumAnalyzer.h"
#include "Editor.h"
#include "MetasoundEditorGraphBuilder.h"
#include "MetasoundEditorGraphNode.h"
#include "MetasoundEditorModule.h"
#include "Widgets/Layout/SBox.h"
namespace Metasound::Editor
{
SMetaSoundSpectrumAnalyzerGraphNode::~SMetaSoundSpectrumAnalyzerGraphNode()
{
if (AnalyzerInstanceID.IsValid())
{
if (TSharedPtr<FEditor> Editor = FGraphBuilder::GetEditorForNode(GetMetaSoundNode()))
{
Editor->GetConnectionManager().RemoveAudioBusWriter(AnalyzerInstanceID);
}
AnalyzerInstanceID.Invalidate();
}
}
void SMetaSoundSpectrumAnalyzerGraphNode::Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime)
{
SMetaSoundGraphNode::Tick(AllottedGeometry, InCurrentTime, InDeltaTime);
const UMetasoundEditorGraphNode& MetaSoundNode = GetMetaSoundNode();
if (SpectrumAnalyzer.IsValid() && ensure(MetaSoundNode.Pins.Num() == 1))
{
const UEdGraphPin* Pin = MetaSoundNode.Pins.Last();
if (!Pin->LinkedTo.IsEmpty() && ensure(Pin->PinType.PinCategory == FGraphBuilder::PinCategoryAudio && Pin->Direction == EGPD_Input))
{
// Find connected output for the input (only ever one):
UEdGraphPin* SourcePin = Pin->LinkedTo.Last();
ensure(SourcePin->Direction == EGPD_Output);
TSharedPtr<FEditor> Editor = FGraphBuilder::GetEditorForNode(MetaSoundNode);
if (Editor.IsValid() && ensure(GEditor))
{
// Analyze audio with AudioBusWriter, if not already doing so:
FGraphConnectionManager& ConnectionManager = Editor->GetConnectionManager();
if (!AnalyzerInstanceID.IsValid() || !ConnectionManager.HasAudioBusWriter(AnalyzerInstanceID))
{
const Frontend::FConstOutputHandle OutputHandle = FGraphBuilder::FindReroutedOutputHandleFromPin(SourcePin);
const FGuid NodeID = OutputHandle->GetOwningNodeID();
const FName OutputName = OutputHandle->GetName();
const Audio::FDeviceId DeviceId = GEditor->GetMainAudioDeviceID();
AnalyzerInstanceID = ConnectionManager.AddAudioBusWriter(NodeID, OutputName, DeviceId, SpectrumAnalyzer->GetAudioBus());
}
}
}
}
}
void SMetaSoundSpectrumAnalyzerGraphNode::CreateBelowPinControls(TSharedPtr<SVerticalBox> MainBox)
{
using namespace AudioWidgets;
if (ensure(GEditor))
{
if (!SpectrumAnalyzer.IsValid())
{
FAudioSpectrumAnalyzerParams Params;
Params.NumChannels = 1;
Params.AudioDeviceId = GEditor->GetMainAudioDeviceID();
Params.PlotStyle = &Style::GetSpectrumPlotStyle();
SpectrumAnalyzer = MakeShared<FAudioSpectrumAnalyzer>(Params);
}
MainBox->AddSlot()
.AutoHeight()
.Padding(1.0f, 0.0f)
[
SNew(SBox)
.MinDesiredWidth(250.0f)
.MinDesiredHeight(250.0f)
[
SpectrumAnalyzer->GetWidget()
]
];
}
}
}