2020-07-23 20:32:26 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
# include "MetasoundSource.h"
2020-12-14 15:48:27 -04:00
# include "AssetRegistryModule.h"
2020-07-23 20:32:26 -04:00
# include "CoreMinimal.h"
# include "Internationalization/Text.h"
# include "MetasoundAssetBase.h"
2020-12-14 15:48:27 -04:00
# include "MetasoundAudioFormats.h"
2020-11-17 17:52:08 -04:00
# include "MetasoundEngineEnvironment.h"
2021-01-22 03:05:22 -04:00
# include "MetasoundFrontendController.h"
# include "MetasoundFrontendQuery.h"
# include "MetasoundFrontendQuerySteps.h"
2021-03-30 18:22:10 -04:00
# include "MetasoundFrontendSearchEngine.h"
2020-07-23 20:32:26 -04:00
# include "MetasoundGenerator.h"
2021-01-22 03:05:22 -04:00
# include "MetasoundInstanceTransmitter.h"
2020-12-14 15:48:27 -04:00
# include "MetasoundLog.h"
2021-02-16 01:26:50 -04:00
# include "MetasoundOperatorSettings.h"
2020-07-23 20:32:26 -04:00
# include "MetasoundPrimitives.h"
2021-01-22 03:05:22 -04:00
# include "MetasoundReceiveNode.h"
2021-01-27 15:54:01 -04:00
# include "MetasoundTrigger.h"
2021-03-15 14:00:26 -04:00
# include "MetasoundEnvironment.h"
2020-07-23 20:32:26 -04:00
# if WITH_EDITORONLY_DATA
# include "EdGraph/EdGraph.h"
# endif // WITH_EDITORONLY_DATA
2021-04-02 02:09:50 -04:00
# define LOCTEXT_NAMESPACE "MetasoundSource"
2021-02-25 14:28:35 -04:00
static float MetaSoundBlockRateCVar = 100.f ;
2021-02-19 18:30:53 -04:00
FAutoConsoleVariableRef CVarMetaSoundBlockRate (
TEXT ( " au.MetaSound.BlockRate " ) ,
MetaSoundBlockRateCVar ,
TEXT ( " Sets block rate (blocks per second) of MetaSounds. \n " )
TEXT ( " Default: 100.0f " ) ,
ECVF_Default ) ;
2021-04-02 02:09:50 -04:00
static const FName MetasoundSourceArchetypeName = " Metasound Source " ;
2021-02-19 18:30:53 -04:00
2021-04-02 02:09:50 -04:00
UMetaSoundSource : : UMetaSoundSource ( const FObjectInitializer & ObjectInitializer )
2020-07-23 20:32:26 -04:00
: Super ( ObjectInitializer )
2020-12-14 15:48:27 -04:00
, FMetasoundAssetBase ( GetMonoSourceArchetype ( ) )
2020-07-23 20:32:26 -04:00
{
2021-01-11 14:18:46 -04:00
bRequiresStopFade = true ;
2020-07-23 20:32:26 -04:00
NumChannels = 1 ;
Duration = INDEFINITELY_LOOPING_DURATION ;
bLooping = true ;
2021-04-02 02:09:50 -04:00
// todo: ensure that we have a method so that the audio engine can be authoritative over the sample rate the UMetaSoundSource runs at.
2021-02-16 01:26:50 -04:00
SampleRate = 48000.f ;
2020-07-23 20:32:26 -04:00
}
2020-12-14 15:48:27 -04:00
# if WITH_EDITOR
2021-04-02 02:09:50 -04:00
void UMetaSoundSource : : PostEditUndo ( )
2021-03-02 21:39:09 -04:00
{
Super : : PostEditUndo ( ) ;
if ( Graph )
{
Graph - > Synchronize ( ) ;
}
}
2021-04-02 02:09:50 -04:00
void UMetaSoundSource : : PostEditChangeProperty ( FPropertyChangedEvent & InEvent )
2020-12-14 15:48:27 -04:00
{
Super : : PostEditChangeProperty ( InEvent ) ;
2021-04-02 02:09:50 -04:00
if ( InEvent . GetPropertyName ( ) = = GET_MEMBER_NAME_CHECKED ( UMetaSoundSource , OutputFormat ) )
2020-12-14 15:48:27 -04:00
{
switch ( OutputFormat )
{
case EMetasoundSourceAudioFormat : : Stereo :
NumChannels = 2 ;
2021-01-22 03:05:22 -04:00
ensure ( SetMetasoundArchetype ( GetStereoSourceArchetype ( ) ) ) ;
2020-12-14 15:48:27 -04:00
break ;
case EMetasoundSourceAudioFormat : : Mono :
default :
NumChannels = 1 ;
2021-01-22 03:05:22 -04:00
ensure ( SetMetasoundArchetype ( GetMonoSourceArchetype ( ) ) ) ;
2020-12-14 15:48:27 -04:00
break ;
}
}
}
2021-03-02 21:39:09 -04:00
# endif // WITHEDITOR
2020-12-14 15:48:27 -04:00
2021-04-02 02:09:50 -04:00
bool UMetaSoundSource : : IsPlayable ( ) const
2020-07-23 20:32:26 -04:00
{
// todo: cache off whether this metasound is buildable to an operator.
return true ;
}
2021-04-02 02:09:50 -04:00
bool UMetaSoundSource : : SupportsSubtitles ( ) const
2020-07-23 20:32:26 -04:00
{
return Super : : SupportsSubtitles ( ) ;
}
2021-04-02 02:09:50 -04:00
float UMetaSoundSource : : GetDuration ( )
2020-07-23 20:32:26 -04:00
{
// eh? this is kind of a weird field anyways.
return Super : : GetDuration ( ) ;
}
2021-04-02 02:09:50 -04:00
ISoundGeneratorPtr UMetaSoundSource : : CreateSoundGenerator ( const FSoundGeneratorInitParams & InParams )
2020-07-23 20:32:26 -04:00
{
2020-11-17 17:52:08 -04:00
using namespace Metasound ;
2021-05-10 19:52:56 -04:00
using namespace Metasound : : Frontend ;
2020-11-17 17:52:08 -04:00
2020-07-23 20:32:26 -04:00
Duration = INDEFINITELY_LOOPING_DURATION ;
bLooping = true ;
2021-01-11 14:18:46 -04:00
VirtualizationMode = EVirtualizationMode : : PlayWhenSilent ;
2020-07-23 20:32:26 -04:00
SampleRate = InParams . SampleRate ;
2021-02-16 01:26:50 -04:00
FOperatorSettings InSettings = GetOperatorSettings ( static_cast < FSampleRate > ( SampleRate ) ) ;
2020-11-17 17:52:08 -04:00
FMetasoundEnvironment Environment ;
2020-07-23 20:32:26 -04:00
2020-11-17 17:52:08 -04:00
// Add audio device ID to environment.
FAudioDeviceHandle DeviceHandle ;
if ( UWorld * World = GetWorld ( ) )
{
DeviceHandle = World - > GetAudioDevice ( ) ;
}
if ( ! DeviceHandle . IsValid ( ) )
{
if ( FAudioDeviceManager * DeviceManager = FAudioDeviceManager : : Get ( ) )
{
DeviceHandle = DeviceManager - > GetMainAudioDeviceHandle ( ) ;
}
}
Environment . SetValue < FAudioDeviceHandle > ( GetAudioDeviceHandleVariableName ( ) , DeviceHandle ) ;
2020-07-23 20:32:26 -04:00
2021-03-15 14:00:26 -04:00
// Set the unique object ID as an environment variable
Environment . SetValue < uint32 > ( GetSoundUniqueIdName ( ) , GetUniqueID ( ) ) ;
2021-04-03 18:41:39 -04:00
Environment . SetValue < bool > ( GetIsPreviewSoundName ( ) , InParams . bIsPreviewSound ) ;
2021-03-15 14:00:26 -04:00
2021-01-22 03:05:22 -04:00
const FMetasoundFrontendDocument * OriginalDoc = GetDocument ( ) . Get ( ) ;
if ( nullptr = = OriginalDoc )
{
2021-04-02 03:03:27 -04:00
UE_LOG ( LogMetaSound , Error , TEXT ( " Cannot create sound generator. Null Metasound document in UMetaSoundSource [Name:%s] " ) , * GetName ( ) ) ;
2021-01-22 03:05:22 -04:00
return ISoundGeneratorPtr ( nullptr ) ;
}
// Inject receive nodes for unused transmittable inputs. Perform edits on a copy
// of the document to avoid altering document.
// TODO: Use a light wrapper of the document instead of a copy.
FMetasoundFrontendDocument DocumentWithInjectedReceives ;
ensure ( CopyDocumentAndInjectReceiveNodes ( InParams . InstanceID , * OriginalDoc , DocumentWithInjectedReceives ) ) ;
// Create handles for new root graph
2021-05-10 19:52:56 -04:00
FConstDocumentHandle NewDocumentHandle = IDocumentController : : CreateDocumentHandle ( MakeAccessPtr < FConstDocumentAccessPtr > ( DocumentWithInjectedReceives . AccessPoint , DocumentWithInjectedReceives ) ) ;
2020-11-17 17:52:08 -04:00
2021-03-23 22:43:04 -04:00
FMetasoundGeneratorInitParams InitParams =
2021-02-10 21:43:31 -04:00
{
2021-03-23 22:43:04 -04:00
InSettings ,
MoveTemp ( DocumentWithInjectedReceives ) ,
Environment ,
NumChannels ,
GetName ( ) ,
GetAudioOutputName ( ) ,
GetOnPlayInputName ( ) ,
GetIsFinishedOutputName ( )
} ;
2020-07-23 20:32:26 -04:00
2021-03-23 22:43:04 -04:00
return ISoundGeneratorPtr ( new FMetasoundGenerator ( MoveTemp ( InitParams ) ) ) ;
2020-07-23 20:32:26 -04:00
}
2021-04-02 02:09:50 -04:00
TUniquePtr < IAudioInstanceTransmitter > UMetaSoundSource : : CreateInstanceTransmitter ( const FAudioInstanceTransmitterInitParams & InParams ) const
2021-01-22 03:05:22 -04:00
{
Metasound : : FMetasoundInstanceTransmitter : : FInitParams InitParams ( GetOperatorSettings ( InParams . SampleRate ) , InParams . InstanceID ) ;
for ( const FSendInfoAndVertexName & InfoAndName : GetSendInfos ( InParams . InstanceID ) )
{
InitParams . Infos . Add ( InfoAndName . SendInfo ) ;
}
return MakeUnique < Metasound : : FMetasoundInstanceTransmitter > ( InitParams ) ;
}
2021-04-02 02:09:50 -04:00
bool UMetaSoundSource : : GetReceiveNodeMetadataForDataType ( const FName & InTypeName , FMetasoundFrontendClassMetadata & OutMetadata ) const
2021-01-22 03:05:22 -04:00
{
using namespace Metasound ;
2021-05-03 17:52:04 -04:00
const FNodeClassName ClassName = FReceiveNodeNames : : GetClassNameForDataType ( InTypeName ) ;
TArray < FMetasoundFrontendClass > ReceiverNodeClasses = Frontend : : ISearchEngine : : Get ( ) . FindClassesWithName ( ClassName , true /* bInSortByVersion */ ) ;
2021-01-22 03:05:22 -04:00
2021-05-03 17:52:04 -04:00
if ( ReceiverNodeClasses . IsEmpty ( ) )
2021-01-22 03:05:22 -04:00
{
2021-05-03 17:52:04 -04:00
return false ;
2021-01-22 03:05:22 -04:00
}
2021-05-03 17:52:04 -04:00
OutMetadata = ReceiverNodeClasses [ 0 ] . Metadata ;
return true ;
2021-01-22 03:05:22 -04:00
}
2021-04-02 02:09:50 -04:00
Metasound : : Frontend : : FNodeHandle UMetaSoundSource : : AddInputPinForSendAddress ( const Metasound : : FMetasoundInstanceTransmitter : : FSendInfo & InSendInfo , Metasound : : Frontend : : FGraphHandle InGraph ) const
2021-01-22 03:05:22 -04:00
{
FMetasoundFrontendClassInput Description ;
2021-05-20 19:33:21 -04:00
FGuid VertexID = FGuid : : NewGuid ( ) ;
2021-01-22 03:05:22 -04:00
Description . Name = InSendInfo . Address . ChannelName . ToString ( ) ;
Description . TypeName = Metasound : : GetMetasoundDataTypeName < Metasound : : FSendAddress > ( ) ;
Description . Metadata . Description = FText : : GetEmpty ( ) ;
2021-02-24 18:37:19 -04:00
Description . VertexID = VertexID ;
Description . DefaultLiteral . Set ( InSendInfo . Address . ChannelName . ToString ( ) ) ;
2021-01-22 03:05:22 -04:00
return InGraph - > AddInputVertex ( Description ) ;
}
2021-04-02 02:09:50 -04:00
bool UMetaSoundSource : : CopyDocumentAndInjectReceiveNodes ( uint64 InInstanceID , const FMetasoundFrontendDocument & InSourceDoc , FMetasoundFrontendDocument & OutDestDoc ) const
2021-01-22 03:05:22 -04:00
{
using namespace Metasound ;
2021-05-10 19:52:56 -04:00
using namespace Metasound : : Frontend ;
2021-01-22 03:05:22 -04:00
OutDestDoc = InSourceDoc ;
2021-05-10 19:52:56 -04:00
FDocumentHandle Document = IDocumentController : : CreateDocumentHandle ( MakeAccessPtr < FDocumentAccessPtr > ( OutDestDoc . AccessPoint , OutDestDoc ) ) ;
FGraphHandle RootGraph = Document - > GetRootGraph ( ) ;
2021-01-22 03:05:22 -04:00
TArray < FSendInfoAndVertexName > SendInfoAndVertexes = GetSendInfos ( InInstanceID ) ;
// Inject receive nodes for each transmittable input
for ( const FSendInfoAndVertexName & InfoAndVertexName : SendInfoAndVertexes )
{
// Add receive node to graph
FMetasoundFrontendClassMetadata ReceiveNodeMetadata ;
bool bSuccess = GetReceiveNodeMetadataForDataType ( InfoAndVertexName . SendInfo . TypeName , ReceiveNodeMetadata ) ;
if ( ! bSuccess )
{
// TODO: log warning
continue ;
}
2021-05-10 19:52:56 -04:00
FNodeHandle ReceiveNode = RootGraph - > AddNode ( ReceiveNodeMetadata ) ;
2021-01-22 03:05:22 -04:00
// Add receive node address to graph
2021-05-10 19:52:56 -04:00
FNodeHandle AddressNode = UMetaSoundSource : : AddInputPinForSendAddress ( InfoAndVertexName . SendInfo , RootGraph ) ;
TArray < FOutputHandle > AddressNodeOutputs = AddressNode - > GetOutputs ( ) ;
2021-01-22 03:05:22 -04:00
if ( AddressNodeOutputs . Num ( ) ! = 1 )
{
// TODO: log warning
continue ;
}
2021-05-10 19:52:56 -04:00
FOutputHandle AddressOutput = AddressNodeOutputs [ 0 ] ;
TArray < FInputHandle > ReceiveAddressInput = ReceiveNode - > GetInputsWithVertexName ( Metasound : : FReceiveNodeNames : : GetAddressInputName ( ) ) ;
2021-01-22 03:05:22 -04:00
if ( ReceiveAddressInput . Num ( ) ! = 1 )
{
// TODO: log error
continue ;
}
ensure ( ReceiveAddressInput [ 0 ] - > Connect ( * AddressOutput ) ) ;
// Swap input node connections with receive node connections
2021-05-10 19:52:56 -04:00
FNodeHandle InputNode = RootGraph - > GetInputNodeWithName ( InfoAndVertexName . VertexName ) ;
2021-01-22 03:05:22 -04:00
if ( ! ensure ( InputNode - > GetOutputs ( ) . Num ( ) = = 1 ) )
{
// TODO: handle input node with varying number of outputs or varying output types.
continue ;
}
2021-05-10 19:52:56 -04:00
FOutputHandle InputNodeOutput = InputNode - > GetOutputs ( ) [ 0 ] ;
2021-01-22 03:05:22 -04:00
if ( ensure ( ReceiveNode - > IsValid ( ) ) )
{
2021-05-10 19:52:56 -04:00
TArray < FOutputHandle > ReceiveNodeOutputs = ReceiveNode - > GetOutputs ( ) ;
2021-01-22 03:05:22 -04:00
if ( ! ensure ( ReceiveNodeOutputs . Num ( ) = = 1 ) )
{
// TODO: handle array outputs and receive nodes of varying formats.
continue ;
}
2021-05-10 19:52:56 -04:00
TArray < FInputHandle > ReceiveDefaultInputs = ReceiveNode - > GetInputsWithVertexName ( Metasound : : FReceiveNodeNames : : GetDefaultDataInputName ( ) ) ;
2021-01-22 03:05:22 -04:00
if ( ensure ( ReceiveDefaultInputs . Num ( ) = = 1 ) )
{
2021-05-10 19:52:56 -04:00
FOutputHandle ReceiverNodeOutput = ReceiveNodeOutputs [ 0 ] ;
2021-05-20 19:33:21 -04:00
for ( FInputHandle NodeInput : InputNodeOutput - > GetConnectedInputs ( ) )
2021-01-22 03:05:22 -04:00
{
// Swap connections to receiver node
ensure ( InputNodeOutput - > Disconnect ( * NodeInput ) ) ;
ensure ( ReceiverNodeOutput - > Connect ( * NodeInput ) ) ;
}
ReceiveDefaultInputs [ 0 ] - > Connect ( * InputNodeOutput ) ;
}
}
}
return true ;
}
2021-04-02 02:09:50 -04:00
TArray < FString > UMetaSoundSource : : GetTransmittableInputVertexNames ( ) const
2021-01-22 03:05:22 -04:00
{
using namespace Metasound ;
// Unused inputs are all input vertices that are not in the archetype.
TArray < FString > ArchetypeInputVertexNames ;
for ( const FMetasoundFrontendClassVertex & Vertex : GetMetasoundArchetype ( ) . Interface . Inputs )
{
ArchetypeInputVertexNames . Add ( Vertex . Name ) ;
}
Frontend : : FConstGraphHandle RootGraph = GetRootGraphHandle ( ) ;
TArray < FString > GraphInputVertexNames = RootGraph - > GetInputVertexNames ( ) ;
// Filter graph inputs by archetype inputs.
GraphInputVertexNames = GraphInputVertexNames . FilterByPredicate ( [ & ] ( const FString & InName ) { return ! ArchetypeInputVertexNames . Contains ( InName ) ; } ) ;
auto IsDataTypeTransmittable = [ & ] ( const FString & InVertexName )
{
Frontend : : FConstClassInputAccessPtr ClassInputPtr = RootGraph - > FindClassInputWithName ( InVertexName ) ;
if ( const FMetasoundFrontendClassInput * ClassInput = ClassInputPtr . Get ( ) )
{
FDataTypeRegistryInfo TypeInfo ;
if ( Frontend : : GetTraitsForDataType ( ClassInput - > TypeName , TypeInfo ) )
{
2021-03-30 18:22:10 -04:00
if ( TypeInfo . bIsTransmittable )
{
// TODO: Currently values set directly on node pins are represented
// as input nodes in the graph. They should not be used for transmission
// as the number of input nodes increases quickly as more nodes
// are added to a graph. Connecting these input nodes to the
// transmission system is relatively expensive. These undesirable input nodes are
// filtered out by ignoring input nodes which are not "Visible".
Frontend : : FConstNodeHandle InputNode = RootGraph - > GetNodeWithID ( ClassInput - > NodeID ) ;
if ( InputNode - > IsValid ( ) )
{
2021-05-28 14:09:45 -04:00
return true ;
2021-03-30 18:22:10 -04:00
}
}
2021-01-22 03:05:22 -04:00
}
}
return false ;
} ;
GraphInputVertexNames = GraphInputVertexNames . FilterByPredicate ( IsDataTypeTransmittable ) ;
return GraphInputVertexNames ;
}
2021-04-02 02:09:50 -04:00
Metasound : : FOperatorSettings UMetaSoundSource : : GetOperatorSettings ( Metasound : : FSampleRate InSampleRate ) const
2021-01-22 03:05:22 -04:00
{
2021-02-19 18:30:53 -04:00
// Metasound graph gets evaluated 100 times per second by default.
2021-02-25 14:28:35 -04:00
float BlockRate = FMath : : Clamp ( MetaSoundBlockRateCVar , 1.0f , 1000.0f ) ;
2021-01-22 03:05:22 -04:00
return Metasound : : FOperatorSettings ( InSampleRate , BlockRate ) ;
}
2021-04-02 02:09:50 -04:00
Metasound : : FSendAddress UMetaSoundSource : : CreateSendAddress ( uint64 InInstanceID , const FString & InVertexName , const FName & InDataTypeName ) const
2021-01-22 03:05:22 -04:00
{
using namespace Metasound ;
FSendAddress Address ;
Address . Subsystem = GetSubsystemNameForSendScope ( ETransmissionScope : : Global ) ;
2021-02-19 14:00:43 -04:00
Address . ChannelName = FName ( FString : : Printf ( TEXT ( " %d:%s:%s " ) , InInstanceID , * InVertexName , * InDataTypeName . ToString ( ) ) ) ;
2021-01-22 03:05:22 -04:00
return Address ;
}
2021-04-02 02:09:50 -04:00
TArray < UMetaSoundSource : : FSendInfoAndVertexName > UMetaSoundSource : : GetSendInfos ( uint64 InInstanceID ) const
2021-01-22 03:05:22 -04:00
{
using FSendInfo = Metasound : : FMetasoundInstanceTransmitter : : FSendInfo ;
using namespace Metasound : : Frontend ;
TArray < FSendInfoAndVertexName > SendInfos ;
FConstGraphHandle RootGraph = GetRootGraphHandle ( ) ;
TArray < FString > SendVertices = GetTransmittableInputVertexNames ( ) ;
for ( const FString & VertexName : SendVertices )
{
FConstNodeHandle InputNode = RootGraph - > GetInputNodeWithName ( VertexName ) ;
2021-03-11 21:12:31 -04:00
for ( FConstInputHandle InputHandle : InputNode - > GetConstInputs ( ) )
2021-01-22 03:05:22 -04:00
{
FSendInfoAndVertexName Info ;
2021-02-24 18:37:19 -04:00
// TODO: incorporate VertexID into address. But need to ensure that VertexID
2021-01-22 03:05:22 -04:00
// will be maintained after injecting Receive nodes.
2021-02-19 14:00:43 -04:00
Info . SendInfo . Address = CreateSendAddress ( InInstanceID , InputHandle - > GetName ( ) , InputHandle - > GetDataType ( ) ) ;
2021-03-11 21:12:31 -04:00
Info . SendInfo . ParameterName = FName ( InputHandle - > GetDisplayName ( ) . ToString ( ) ) ; // TODO: display name hack. Need to have naming consistent in editor for inputs
//Info.SendInfo.ParameterName = FName(*InputHandle->GetName()); // TODO: this is the expected parameter name.
2021-01-22 03:05:22 -04:00
Info . SendInfo . TypeName = InputHandle - > GetDataType ( ) ;
Info . VertexName = VertexName ;
SendInfos . Add ( Info ) ;
}
}
return SendInfos ;
}
2021-04-02 02:09:50 -04:00
const TArray < FMetasoundFrontendArchetype > & UMetaSoundSource : : GetPreferredMetasoundArchetypes ( ) const
2020-12-14 15:48:27 -04:00
{
2021-01-13 10:48:59 -04:00
static const TArray < FMetasoundFrontendArchetype > Preferred ( { GetMonoSourceArchetype ( ) , GetStereoSourceArchetype ( ) } ) ;
2020-12-14 15:48:27 -04:00
return Preferred ;
}
2021-04-02 02:09:50 -04:00
const FString & UMetaSoundSource : : GetOnPlayInputName ( )
2020-07-23 20:32:26 -04:00
{
2021-01-11 14:18:46 -04:00
static const FString TriggerInputName = TEXT ( " On Play " ) ;
return TriggerInputName ;
2020-07-23 20:32:26 -04:00
}
2021-04-02 02:09:50 -04:00
const FString & UMetaSoundSource : : GetAudioOutputName ( )
2020-07-23 20:32:26 -04:00
{
2021-01-11 14:18:46 -04:00
static const FString AudioOutputName = TEXT ( " Generated Audio " ) ;
2020-07-23 20:32:26 -04:00
return AudioOutputName ;
}
2021-04-02 02:09:50 -04:00
const FString & UMetaSoundSource : : GetIsFinishedOutputName ( )
2020-07-23 20:32:26 -04:00
{
2021-01-11 14:18:46 -04:00
static const FString OnFinishedOutputName = TEXT ( " On Finished " ) ;
2020-07-23 20:32:26 -04:00
return OnFinishedOutputName ;
}
2021-04-02 02:09:50 -04:00
const FString & UMetaSoundSource : : GetAudioDeviceHandleVariableName ( )
2020-11-17 17:52:08 -04:00
{
2021-01-11 14:18:46 -04:00
static const FString AudioDeviceHandleVarName = TEXT ( " AudioDeviceHandle " ) ;
2020-11-17 17:52:08 -04:00
return AudioDeviceHandleVarName ;
}
2021-04-02 02:09:50 -04:00
const FString & UMetaSoundSource : : GetSoundUniqueIdName ( )
2021-03-15 14:00:26 -04:00
{
static const FString SoundUniqueIdVarName = TEXT ( " SoundUniqueId " ) ;
return SoundUniqueIdVarName ;
}
2021-04-03 18:41:39 -04:00
const FString & UMetaSoundSource : : GetIsPreviewSoundName ( )
{
static const FString SoundIsPreviewSoundName = TEXT ( " IsPreviewSound " ) ;
return SoundIsPreviewSoundName ;
}
2021-03-15 14:00:26 -04:00
2021-04-02 02:09:50 -04:00
const FMetasoundFrontendArchetype & UMetaSoundSource : : GetBaseArchetype ( )
2020-07-23 20:32:26 -04:00
{
2021-01-13 10:48:59 -04:00
auto CreateBaseArchetype = [ ] ( ) - > FMetasoundFrontendArchetype
2020-12-14 15:48:27 -04:00
{
2021-01-13 10:48:59 -04:00
FMetasoundFrontendArchetype Archetype ;
2020-12-14 15:48:27 -04:00
2021-02-24 16:46:24 -04:00
FMetasoundFrontendClassVertex OnPlayTrigger ;
2021-04-02 02:09:50 -04:00
OnPlayTrigger . Name = UMetaSoundSource : : GetOnPlayInputName ( ) ;
2021-05-10 16:56:43 -04:00
2021-01-27 15:54:01 -04:00
OnPlayTrigger . TypeName = Metasound : : Frontend : : GetDataTypeName < Metasound : : FTrigger > ( ) ;
2021-05-10 16:56:43 -04:00
OnPlayTrigger . Metadata . DisplayName = LOCTEXT ( " OnPlay " , " On Play " ) ;
2021-01-13 10:48:59 -04:00
OnPlayTrigger . Metadata . Description = LOCTEXT ( " OnPlayTriggerToolTip " , " Trigger executed when this source is played. " ) ;
2021-02-24 18:37:19 -04:00
OnPlayTrigger . VertexID = FGuid : : NewGuid ( ) ;
2020-07-23 20:32:26 -04:00
2021-01-13 10:48:59 -04:00
Archetype . Interface . Inputs . Add ( OnPlayTrigger ) ;
2020-07-23 20:32:26 -04:00
2021-02-24 16:46:24 -04:00
FMetasoundFrontendClassVertex OnFinished ;
2021-04-02 02:09:50 -04:00
OnFinished . Name = UMetaSoundSource : : GetIsFinishedOutputName ( ) ;
2021-05-10 16:56:43 -04:00
2021-01-27 15:54:01 -04:00
OnFinished . TypeName = Metasound : : Frontend : : GetDataTypeName < Metasound : : FTrigger > ( ) ;
2021-05-10 16:56:43 -04:00
OnFinished . Metadata . DisplayName = LOCTEXT ( " OnFinished " , " On Finished " ) ;
2021-01-27 15:54:01 -04:00
OnFinished . Metadata . Description = LOCTEXT ( " OnFinishedToolTip " , " Trigger executed to initiate stopping the source. " ) ;
2021-02-24 18:37:19 -04:00
OnFinished . VertexID = FGuid : : NewGuid ( ) ;
2020-07-23 20:32:26 -04:00
2021-01-13 10:48:59 -04:00
Archetype . Interface . Outputs . Add ( OnFinished ) ;
2020-07-23 20:32:26 -04:00
2021-01-13 10:48:59 -04:00
FMetasoundFrontendEnvironmentVariable AudioDeviceHandle ;
2021-04-02 02:09:50 -04:00
AudioDeviceHandle . Name = UMetaSoundSource : : GetAudioDeviceHandleVariableName ( ) ;
2021-01-13 10:48:59 -04:00
AudioDeviceHandle . Metadata . DisplayName = FText : : FromString ( AudioDeviceHandle . Name ) ;
AudioDeviceHandle . Metadata . Description = LOCTEXT ( " AudioDeviceHandleToolTip " , " Audio device handle " ) ;
2020-07-23 20:32:26 -04:00
2021-01-13 10:48:59 -04:00
Archetype . Interface . Environment . Add ( AudioDeviceHandle ) ;
2020-11-17 17:52:08 -04:00
2020-12-14 15:48:27 -04:00
return Archetype ;
} ;
2021-01-13 10:48:59 -04:00
static const FMetasoundFrontendArchetype BaseArchetype = CreateBaseArchetype ( ) ;
2020-12-14 15:48:27 -04:00
return BaseArchetype ;
}
2021-04-02 02:09:50 -04:00
const FMetasoundFrontendArchetype & UMetaSoundSource : : GetMonoSourceArchetype ( )
2020-12-14 15:48:27 -04:00
{
2021-01-13 10:48:59 -04:00
auto CreateMonoArchetype = [ ] ( ) - > FMetasoundFrontendArchetype
2020-12-14 15:48:27 -04:00
{
2021-01-13 10:48:59 -04:00
FMetasoundFrontendArchetype Archetype = GetBaseArchetype ( ) ;
2021-02-24 02:02:03 -04:00
Archetype . Name = " MonoSource " ;
2020-12-14 15:48:27 -04:00
2021-01-13 10:48:59 -04:00
FMetasoundFrontendClassVertex GeneratedAudio ;
2021-04-02 02:09:50 -04:00
GeneratedAudio . Name = UMetaSoundSource : : GetAudioOutputName ( ) ;
2020-12-14 15:48:27 -04:00
GeneratedAudio . TypeName = Metasound : : Frontend : : GetDataTypeName < Metasound : : FMonoAudioFormat > ( ) ;
2021-03-03 15:00:53 -04:00
GeneratedAudio . Metadata . DisplayName = LOCTEXT ( " GeneratedMono " , " Audio " ) ;
2021-01-13 10:48:59 -04:00
GeneratedAudio . Metadata . Description = LOCTEXT ( " GeneratedAudioToolTip " , " The resulting output audio from this source. " ) ;
2021-02-24 18:37:19 -04:00
GeneratedAudio . VertexID = FGuid : : NewGuid ( ) ;
2020-12-14 15:48:27 -04:00
2021-01-13 10:48:59 -04:00
Archetype . Interface . Outputs . Add ( GeneratedAudio ) ;
2020-12-14 15:48:27 -04:00
return Archetype ;
} ;
2021-01-13 10:48:59 -04:00
static const FMetasoundFrontendArchetype MonoArchetype = CreateMonoArchetype ( ) ;
2020-12-14 15:48:27 -04:00
return MonoArchetype ;
}
2021-04-02 02:09:50 -04:00
const FMetasoundFrontendArchetype & UMetaSoundSource : : GetStereoSourceArchetype ( )
2020-12-14 15:48:27 -04:00
{
2021-01-13 10:48:59 -04:00
auto CreateStereoArchetype = [ ] ( ) - > FMetasoundFrontendArchetype
2020-12-14 15:48:27 -04:00
{
2021-01-13 10:48:59 -04:00
FMetasoundFrontendArchetype Archetype = GetBaseArchetype ( ) ;
Archetype . Name = FName ( TEXT ( " StereoSource " ) ) ;
2020-12-14 15:48:27 -04:00
2021-01-13 10:48:59 -04:00
FMetasoundFrontendClassVertex GeneratedAudio ;
2021-04-02 02:09:50 -04:00
GeneratedAudio . Name = UMetaSoundSource : : GetAudioOutputName ( ) ;
2020-12-14 15:48:27 -04:00
GeneratedAudio . TypeName = Metasound : : Frontend : : GetDataTypeName < Metasound : : FStereoAudioFormat > ( ) ;
2021-03-03 15:00:53 -04:00
GeneratedAudio . Metadata . DisplayName = LOCTEXT ( " GeneratedStereo " , " Audio " ) ;
2021-01-13 10:48:59 -04:00
GeneratedAudio . Metadata . Description = LOCTEXT ( " GeneratedAudioToolTip " , " The resulting output audio from this source. " ) ;
2021-02-24 18:37:19 -04:00
GeneratedAudio . VertexID = FGuid : : NewGuid ( ) ;
2020-12-14 15:48:27 -04:00
2021-01-13 10:48:59 -04:00
Archetype . Interface . Outputs . Add ( GeneratedAudio ) ;
2020-12-14 15:48:27 -04:00
return Archetype ;
} ;
2021-01-13 10:48:59 -04:00
static const FMetasoundFrontendArchetype StereoArchetype = CreateStereoArchetype ( ) ;
2020-12-14 15:48:27 -04:00
return StereoArchetype ;
2020-07-23 20:32:26 -04:00
}
# undef LOCTEXT_NAMESPACE