Files
UnrealEngineUWP/Engine/Plugins/Runtime/Metasound/Source/MetasoundFrontend/Public/MetasoundParameterTransmitter.h
rob gay 1f287a42ac Parameter Update Perf Regression Fix-ups
- Use cached transmissable inputs when initializing/sanitizing parameters
- Update internal API to promote batching & keeping AudioParameters sorted/using faster merge logic where possible
- Swap CitySample vehicle controller to use batched parameter update call
- Clarify When RuntimeData is cached for safety (in InitResources or InitParameters, whichever comes first)
- Alleviate extreme confusion around AudioParameter setters requiring type by adding static conversion functions
#rb helen.yang
#rnx
#jira UE-145211
#preflight 6229424e6e026fc824b24861

#ROBOMERGE-AUTHOR: rob.gay
#ROBOMERGE-SOURCE: CL 19328764 in //UE5/Release-5.0/... via CL 19329587
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v926-19321884)

[CL 19348372 by rob gay in ue5-main branch]
2022-03-10 22:07:08 -05:00

124 lines
4.2 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "AudioParameterControllerInterface.h"
#include "IAudioParameterTransmitter.h"
#include "MetasoundDataReference.h"
#include "MetasoundFrontendLiteral.h"
#include "MetasoundLog.h"
#include "MetasoundOperatorSettings.h"
#include "MetasoundPrimitives.h"
#include "MetasoundRouter.h"
struct FMetasoundFrontendLiteral;
namespace Metasound
{
namespace Frontend
{
METASOUNDFRONTEND_API FLiteral ConvertParameterToLiteral(FAudioParameter&& InValue);
METASOUNDFRONTEND_API FName ConvertParameterToDataType(EAudioParameterType InParameterType);
}
/** FMetaSoundParameterTransmitter provides a communication interface for
* sending values to a MetaSound instance. It relies on the send/receive transmission
* system to ferry data from the transmitter to the MetaSound instance. Data will
* be safely ushered across thread boundaries in scenarios where the instance
* transmitter and metasound instance live on different threads.
*/
class METASOUNDFRONTEND_API FMetaSoundParameterTransmitter : public Audio::IParameterTransmitter
{
FMetaSoundParameterTransmitter(const FMetaSoundParameterTransmitter&) = delete;
FMetaSoundParameterTransmitter& operator=(const FMetaSoundParameterTransmitter&) = delete;
public:
/** FSendInfo describes the MetaSounds input parameters as well as the
* necessary information to route data to the instances inputs.
*/
struct FSendInfo
{
/** Global address of instance input. */
FSendAddress Address;
/** Name of parameter on MetaSound instance. */
FName ParameterName;
/** Type name of parameter on MetaSound instance. */
FName TypeName;
};
/** Initialization parameters for a FMetaSoundParameterTransmitter. */
struct FInitParams
{
/** FOperatorSettings must match the operator settings of the MetaSound
* instance to ensure proper operation. */
FOperatorSettings OperatorSettings;
/** ID of the MetaSound instance. */
uint64 InstanceID;
/** Available input parameters on MetaSound instance. */
TArray<FSendInfo> Infos;
FInitParams(const FOperatorSettings& InSettings, uint64 InInstanceID, const TArray<FSendInfo>& InInfos=TArray<FSendInfo>())
: OperatorSettings(InSettings)
, InstanceID(InInstanceID)
, Infos(InInfos)
{
}
};
/** Creates a unique send address using the given MetaSound environment. */
static FSendAddress CreateSendAddressFromEnvironment(const FMetasoundEnvironment& InEnvironment, const FVertexName& InVertexName, const FName& InTypeName);
/** Creates a unique send address using the given InstanceID. */
static FSendAddress CreateSendAddressFromInstanceID(uint64 InInstanceID, const FVertexName& InVertexName, const FName& InTypeName);
FMetaSoundParameterTransmitter(const FMetaSoundParameterTransmitter::FInitParams& InInitParams);
virtual ~FMetaSoundParameterTransmitter() = default;
bool Reset() override;
/** Returns ID of the MetaSound instance associated with this transmitter. */
uint64 GetInstanceID() const override;
/** Sets parameters using array of AudioParameter structs
*
* @param InParameter - Parameter to set.
*/
virtual bool SetParameters(TArray<FAudioParameter>&& InParameters) override;
/** Set a parameter using a literal.
*
* @param InParameterName - Name of MetaSound instance parameter.
* @param InValue - Literal value used to construct parameter value.
*
* @return true on success, false on failure.
*/
bool SetParameterWithLiteral(FName InParameterName, const FLiteral& InValue);
/** Duplicate this transmitter interface. The transmitters association with
* the MetaSound instance will be maintained. */
TUniquePtr<Audio::IParameterTransmitter> Clone() const override;
private:
// Find FSendInfo by parameter name.
const FSendInfo* FindSendInfo(const FName& InParameterName) const;
// Find ISender by parameter name.
ISender* FindSender(const FName& InParameterName);
// Create and store a new ISender for the given FSendInfo.
ISender* AddSender(const FSendInfo& InInfo);
TArray<FSendInfo> SendInfos;
FOperatorSettings OperatorSettings;
uint64 InstanceID;
TMap<FName, TUniquePtr<ISender>> InputSends;
};
}