2020-09-08 14:13:51 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "CoreMinimal.h"
|
|
|
|
|
#include "MetasoundBuilderInterface.h"
|
2020-11-24 15:24:29 -04:00
|
|
|
#include "MetasoundNode.h"
|
2020-09-08 14:13:51 -04:00
|
|
|
#include "MetasoundNodeInterface.h"
|
|
|
|
|
#include "MetasoundOperatorInterface.h"
|
|
|
|
|
#include "MetasoundDataReference.h"
|
|
|
|
|
#include "MetasoundExecutableOperator.h"
|
|
|
|
|
#include "MetasoundRouter.h"
|
|
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
2020-11-24 15:24:29 -04:00
|
|
|
#define LOCTEXT_NAMESPACE "MetasoundFrontend"
|
2020-09-08 14:13:51 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Metasound
|
|
|
|
|
{
|
|
|
|
|
template<typename TDataType>
|
2020-11-24 15:24:29 -04:00
|
|
|
class TSendNode : public FNode
|
2020-09-08 14:13:51 -04:00
|
|
|
{
|
|
|
|
|
public:
|
2020-11-04 14:26:37 -04:00
|
|
|
static const FString& GetAddressInputName()
|
2020-09-08 14:13:51 -04:00
|
|
|
{
|
2021-01-23 12:59:01 -04:00
|
|
|
static const FString InputName = TEXT("Address");
|
2020-09-08 14:13:51 -04:00
|
|
|
return InputName;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-04 14:26:37 -04:00
|
|
|
static const FString& GetSendInputName()
|
2020-09-08 14:13:51 -04:00
|
|
|
{
|
2021-01-23 12:59:01 -04:00
|
|
|
static const FString& SendInput = GetMetasoundDataTypeString<TDataType>();
|
2020-09-08 14:13:51 -04:00
|
|
|
return SendInput;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-24 15:24:29 -04:00
|
|
|
static FVertexInterface DeclareVertexInterface()
|
|
|
|
|
{
|
|
|
|
|
return FVertexInterface(
|
|
|
|
|
FInputVertexInterface(
|
|
|
|
|
TInputDataVertexModel<FSendAddress>(GetAddressInputName(), FText::GetEmpty()),
|
|
|
|
|
TInputDataVertexModel<TDataType>(GetSendInputName(), FText::GetEmpty())
|
|
|
|
|
),
|
|
|
|
|
FOutputVertexInterface(
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-28 19:02:51 -04:00
|
|
|
static const FNodeClassMetadata& GetNodeInfo()
|
2020-11-24 15:24:29 -04:00
|
|
|
{
|
2021-01-28 19:02:51 -04:00
|
|
|
auto InitNodeInfo = []() -> FNodeClassMetadata
|
2020-11-24 15:24:29 -04:00
|
|
|
{
|
2021-01-23 12:59:01 -04:00
|
|
|
const FString& InputName = GetSendInputName();
|
2021-01-28 19:02:51 -04:00
|
|
|
FNodeClassMetadata Info;
|
2020-11-24 15:24:29 -04:00
|
|
|
|
2021-01-28 19:02:51 -04:00
|
|
|
Info.ClassName = {TEXT("Send"), GetMetasoundDataTypeName<TDataType>(), TEXT("")};
|
2020-11-24 15:24:29 -04:00
|
|
|
Info.MajorVersion = 1;
|
|
|
|
|
Info.MinorVersion = 0;
|
2021-01-28 19:02:51 -04:00
|
|
|
Info.DisplayName = FText::Format(LOCTEXT("Metasound_SendNodeDisplayNameFormat", "Send {0}"), FText::FromName(GetMetasoundDataTypeName<TDataType>()));
|
2020-11-24 15:24:29 -04:00
|
|
|
Info.Description = LOCTEXT("Metasound_SendNodeDescription", "Sends data from a send node with the same name.");
|
|
|
|
|
Info.Author = PluginAuthor;
|
|
|
|
|
Info.PromptIfMissing = PluginNodeMissingPrompt;
|
|
|
|
|
Info.DefaultInterface = DeclareVertexInterface();
|
2021-01-20 00:42:47 -04:00
|
|
|
Info.CategoryHierarchy = { LOCTEXT("Metasound_TransmissionNodeCategory", "Transmission") };
|
2021-01-23 12:59:01 -04:00
|
|
|
Info.Keywords = { "Send", GetMetasoundDataTypeName<TDataType>()};
|
2020-11-24 15:24:29 -04:00
|
|
|
|
|
|
|
|
return Info;
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-28 19:02:51 -04:00
|
|
|
static const FNodeClassMetadata Info = InitNodeInfo();
|
2020-11-24 15:24:29 -04:00
|
|
|
|
|
|
|
|
return Info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-09-08 14:13:51 -04:00
|
|
|
private:
|
|
|
|
|
class TSendOperator : public TExecutableOperator<TSendOperator>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
TSendOperator(TDataReadReference<TDataType> InInputData, TDataReadReference<FSendAddress> InSendAddress, const FOperatorSettings& InOperatorSettings)
|
|
|
|
|
: InputData(InInputData)
|
|
|
|
|
, SendAddress(InSendAddress)
|
|
|
|
|
, CachedSendAddress(*InSendAddress)
|
|
|
|
|
, CachedSenderParams({InOperatorSettings, 0.0f})
|
|
|
|
|
, Sender(FDataTransmissionCenter::Get().RegisterNewSend<TDataType>(CachedSendAddress, CachedSenderParams))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual ~TSendOperator() {}
|
|
|
|
|
|
2020-12-08 19:34:18 -04:00
|
|
|
virtual FDataReferenceCollection GetInputs() const override
|
2020-09-08 14:13:51 -04:00
|
|
|
{
|
2020-12-08 19:34:18 -04:00
|
|
|
FDataReferenceCollection Inputs;
|
|
|
|
|
Inputs.AddDataReadReference<FSendAddress>(GetAddressInputName(), SendAddress);
|
|
|
|
|
Inputs.AddDataReadReference<TDataType>(GetSendInputName(), TDataReadReference<TDataType>(InputData));
|
2020-09-08 14:13:51 -04:00
|
|
|
return Inputs;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-08 19:34:18 -04:00
|
|
|
virtual FDataReferenceCollection GetOutputs() const override
|
2020-09-08 14:13:51 -04:00
|
|
|
{
|
2020-12-08 19:34:18 -04:00
|
|
|
return {};
|
2020-09-08 14:13:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Execute()
|
|
|
|
|
{
|
|
|
|
|
if (SendAddress->ChannelName != CachedSendAddress.ChannelName)
|
|
|
|
|
{
|
|
|
|
|
CachedSendAddress = *SendAddress;
|
|
|
|
|
Sender = FDataTransmissionCenter::Get().RegisterNewSend<TDataType>(CachedSendAddress, CachedSenderParams);
|
|
|
|
|
check(Sender.IsValid());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Sender->Push(*InputData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
TDataReadReference<TDataType> InputData;
|
|
|
|
|
TDataReadReference<FSendAddress> SendAddress;
|
|
|
|
|
FSendAddress CachedSendAddress;
|
|
|
|
|
FSenderInitParams CachedSenderParams;
|
|
|
|
|
|
|
|
|
|
TSenderPtr<TDataType> Sender;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class FSendOperatorFactory : public IOperatorFactory
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FSendOperatorFactory() = default;
|
|
|
|
|
|
|
|
|
|
virtual TUniquePtr<IOperator> CreateOperator(const FCreateOperatorParams& InParams, FBuildErrorArray& OutErrors) override
|
|
|
|
|
{
|
|
|
|
|
return MakeUnique<TSendOperator>(InParams.InputDataReferences.GetDataReadReference<TDataType>(GetSendInputName()),
|
|
|
|
|
InParams.InputDataReferences.GetDataReadReference<FSendAddress>(GetAddressInputName()),
|
|
|
|
|
InParams.OperatorSettings
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
TSendNode(const FNodeInitData& InInitData)
|
2021-01-28 19:02:51 -04:00
|
|
|
: FNode(InInitData.InstanceName, InInitData.InstanceID, GetNodeInfo())
|
2020-09-08 14:13:51 -04:00
|
|
|
, Interface(DeclareVertexInterface())
|
|
|
|
|
, Factory(MakeOperatorFactoryRef<FSendOperatorFactory>())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual ~TSendNode() = default;
|
|
|
|
|
|
|
|
|
|
virtual const FVertexInterface& GetVertexInterface() const override
|
|
|
|
|
{
|
|
|
|
|
return Interface;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual bool SetVertexInterface(const FVertexInterface& InInterface) override
|
|
|
|
|
{
|
|
|
|
|
return Interface == InInterface;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual bool IsVertexInterfaceSupported(const FVertexInterface& InInterface) const override
|
|
|
|
|
{
|
|
|
|
|
return Interface == InInterface;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual FOperatorFactorySharedRef GetDefaultOperatorFactory() const override
|
|
|
|
|
{
|
|
|
|
|
return Factory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
FVertexInterface Interface;
|
|
|
|
|
FOperatorFactorySharedRef Factory;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
#undef LOCTEXT_NAMESPACE
|