2021-12-10 20:37:31 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
# include "MetasoundSourceInterface.h"
# include "MetasoundDataReference.h"
# include "MetasoundPrimitives.h"
# include "MetasoundTrigger.h"
# include "UObject/Class.h"
# include "Templates/SharedPointer.h"
2021-12-15 23:11:10 -05:00
# include "AudioParameter.h"
2021-12-10 20:37:31 -05:00
# define LOCTEXT_NAMESPACE "Metasound"
2021-12-15 23:11:10 -05:00
2021-12-10 20:37:31 -05:00
namespace Metasound
{
namespace Frontend
{
2021-12-15 23:11:10 -05:00
# define AUDIO_PARAMETER_INTERFACE_NAMESPACE "UE.Source.OneShot"
namespace SourceOneShotInterface
{
const FMetasoundFrontendVersion & GetVersion ( )
{
static const FMetasoundFrontendVersion Version = { AUDIO_PARAMETER_INTERFACE_NAMESPACE , { 1 , 0 } } ;
return Version ;
}
namespace Outputs
{
const FName OnFinished = AUDIO_PARAMETER_INTERFACE_MEMBER_DEFINE ( " OnFinished " ) ;
}
Audio : : FParameterInterfacePtr CreateInterface ( const UClass & InUClass )
{
struct FInterface : public Audio : : FParameterInterface
{
FInterface ( const UClass & InAssetClass )
: FParameterInterface ( SourceOneShotInterface : : GetVersion ( ) . Name , SourceOneShotInterface : : GetVersion ( ) . Number . ToInterfaceVersion ( ) , InAssetClass )
{
Outputs =
{
{
LOCTEXT ( " OnFinished " , " On Finished " ) ,
LOCTEXT ( " OnFinishedDescription " , " Trigger executed to initiate stopping the source. " ) ,
GetMetasoundDataTypeName < FTrigger > ( ) ,
2022-02-25 09:45:49 -05:00
Outputs : : OnFinished ,
LOCTEXT ( " OnFinishedWarning " , " \" On Finished \" should be connected for OneShot MetaSound sources. For sources with undefined duration (e.g. looping), remove the OneShot interface and use an audio component to avoid leaking the source. " ) ,
2021-12-15 23:11:10 -05:00
}
} ;
}
} ;
return MakeShared < FInterface > ( InUClass ) ;
}
} // namespace SourceOneShotInterface
# undef AUDIO_PARAMETER_INTERFACE_NAMESPACE
# define AUDIO_PARAMETER_INTERFACE_NAMESPACE "UE.Source"
namespace SourceInterfaceV1_0
2021-12-10 20:37:31 -05:00
{
const FMetasoundFrontendVersion & GetVersion ( )
{
static const FMetasoundFrontendVersion Version = { AUDIO_PARAMETER_INTERFACE_NAMESPACE , { 1 , 0 } } ;
return Version ;
}
namespace Inputs
{
const FName OnPlay = AUDIO_PARAMETER_INTERFACE_MEMBER_DEFINE ( " OnPlay " ) ;
}
namespace Outputs
{
const FName OnFinished = AUDIO_PARAMETER_INTERFACE_MEMBER_DEFINE ( " OnFinished " ) ;
}
namespace Environment
{
const FName DeviceID = AUDIO_PARAMETER_INTERFACE_MEMBER_DEFINE ( " AudioDeviceID " ) ;
const FName GraphName = AUDIO_PARAMETER_INTERFACE_MEMBER_DEFINE ( " GraphName " ) ;
const FName IsPreview = AUDIO_PARAMETER_INTERFACE_MEMBER_DEFINE ( " IsPreviewSound " ) ;
const FName SoundUniqueID = AUDIO_PARAMETER_INTERFACE_MEMBER_DEFINE ( " SoundUniqueID " ) ;
const FName TransmitterID = AUDIO_PARAMETER_INTERFACE_MEMBER_DEFINE ( " TransmitterID " ) ;
}
Audio : : FParameterInterfacePtr CreateInterface ( const UClass & InUClass )
{
struct FInterface : public Audio : : FParameterInterface
{
FInterface ( const UClass & InAssetClass )
2021-12-15 23:11:10 -05:00
: FParameterInterface ( SourceInterfaceV1_0 : : GetVersion ( ) . Name , SourceInterfaceV1_0 : : GetVersion ( ) . Number . ToInterfaceVersion ( ) , InAssetClass )
2021-12-10 20:37:31 -05:00
{
Inputs =
{
{
LOCTEXT ( " OnPlay " , " On Play " ) ,
LOCTEXT ( " OnPlayDescription " , " Trigger executed when the source is played. " ) ,
GetMetasoundDataTypeName < FTrigger > ( ) ,
{ Inputs : : OnPlay , false }
}
} ;
Outputs =
{
{
LOCTEXT ( " OnFinished " , " On Finished " ) ,
LOCTEXT ( " OnFinishedDescription " , " Trigger executed to initiate stopping the source. " ) ,
GetMetasoundDataTypeName < FTrigger > ( ) ,
Outputs : : OnFinished
}
} ;
Environment =
{
{
LOCTEXT ( " AudioDeviceIDDisplayName " , " Audio Device ID " ) ,
LOCTEXT ( " AudioDeviceIDDescription " , " ID of AudioDevice source is played from. " ) ,
FName ( ) , // TODO: Align environment data types with environment (ex. this is actually set/get as a uint32)
Environment : : DeviceID
} ,
{
LOCTEXT ( " GraphNameDisplayName " , " Graph Name " ) ,
2022-02-04 14:18:45 -05:00
LOCTEXT ( " GraphNameDescription " , " Name of source graph (for debugging/logging). " ) ,
2021-12-10 20:37:31 -05:00
GetMetasoundDataTypeName < FString > ( ) ,
Environment : : GraphName
} ,
{
LOCTEXT ( " IsPreviewSoundDisplayName " , " Is Preview Sound " ) ,
LOCTEXT ( " IsPreviewSoundDescription " , " Whether source is being played as a previewed sound. " ) ,
GetMetasoundDataTypeName < bool > ( ) ,
Environment : : IsPreview
} ,
{
LOCTEXT ( " TransmitterIDDisplayName " , " Transmitter ID " ) ,
LOCTEXT ( " TransmitterIDDescription " , " ID used by Transmission System to generate a unique send address for each source instance. " ) ,
FName ( ) , // TODO: Align environment data types with environment (ex. this is actually set/get as a uint64)
Environment : : TransmitterID
} ,
{
2022-02-04 14:18:45 -05:00
LOCTEXT ( " SoundUniqueIdDisplayName " , " Sound Unique ID " ) ,
LOCTEXT ( " SoundUniqueIdDescription " , " ID of unique source instance. " ) ,
2021-12-10 20:37:31 -05:00
FName ( ) , // TODO: Align environment data types with environment (ex. this is actually set/get as a uint32)
Environment : : SoundUniqueID
}
} ;
}
} ;
return MakeShared < FInterface > ( InUClass ) ;
}
2021-12-15 23:11:10 -05:00
} // namespace SourceInterfaceV1_0
namespace SourceInterface
{
const FMetasoundFrontendVersion & GetVersion ( )
{
static const FMetasoundFrontendVersion Version = { AUDIO_PARAMETER_INTERFACE_NAMESPACE , { 1 , 1 } } ;
return Version ;
}
namespace Inputs
{
const FName OnPlay = AUDIO_PARAMETER_INTERFACE_MEMBER_DEFINE ( " OnPlay " ) ;
}
namespace Environment
{
const FName DeviceID = AUDIO_PARAMETER_INTERFACE_MEMBER_DEFINE ( " AudioDeviceID " ) ;
const FName GraphName = AUDIO_PARAMETER_INTERFACE_MEMBER_DEFINE ( " GraphName " ) ;
const FName IsPreview = AUDIO_PARAMETER_INTERFACE_MEMBER_DEFINE ( " IsPreviewSound " ) ;
const FName SoundUniqueID = AUDIO_PARAMETER_INTERFACE_MEMBER_DEFINE ( " SoundUniqueID " ) ;
const FName TransmitterID = AUDIO_PARAMETER_INTERFACE_MEMBER_DEFINE ( " TransmitterID " ) ;
}
Audio : : FParameterInterfacePtr CreateInterface ( const UClass & InUClass )
{
struct FInterface : public Audio : : FParameterInterface
{
FInterface ( const UClass & InAssetClass )
: FParameterInterface ( SourceInterface : : GetVersion ( ) . Name , SourceInterface : : GetVersion ( ) . Number . ToInterfaceVersion ( ) , InAssetClass )
{
Inputs =
{
{
LOCTEXT ( " OnPlay " , " On Play " ) ,
LOCTEXT ( " OnPlayDescription " , " Trigger executed when the source is played. " ) ,
GetMetasoundDataTypeName < FTrigger > ( ) ,
{ Inputs : : OnPlay , false }
}
} ;
Environment =
{
{
2022-02-04 14:18:45 -05:00
LOCTEXT ( " AudioDeviceIDDisplayName1 " , " Audio Device ID " ) ,
2022-03-01 14:57:03 -05:00
LOCTEXT ( " AudioDeviceIDDescription2 " , " ID of AudioDevice source is played from. " ) ,
2021-12-15 23:11:10 -05:00
FName ( ) , // TODO: Align environment data types with environment (ex. this is actually set/get as a uint32)
Environment : : DeviceID
} ,
{
LOCTEXT ( " GraphNameDisplayName " , " Graph Name " ) ,
2022-03-01 14:57:03 -05:00
LOCTEXT ( " AudioDeviceIDDescription3 " , " Name of source graph (for debugging/logging). " ) ,
2021-12-15 23:11:10 -05:00
GetMetasoundDataTypeName < FString > ( ) ,
Environment : : GraphName
} ,
{
LOCTEXT ( " IsPreviewSoundDisplayName " , " Is Preview Sound " ) ,
2022-03-01 14:57:03 -05:00
LOCTEXT ( " IsPreviewSoundDescription4 " , " Whether source is being played as a previewed sound. " ) ,
2021-12-15 23:11:10 -05:00
GetMetasoundDataTypeName < bool > ( ) ,
Environment : : IsPreview
} ,
{
LOCTEXT ( " TransmitterIDDisplayName " , " Transmitter ID " ) ,
LOCTEXT ( " TransmitterIDDescription " , " ID used by Transmission System to generate a unique send address for each source instance. " ) ,
FName ( ) , // TODO: Align environment data types with environment (ex. this is actually set/get as a uint64)
Environment : : TransmitterID
} ,
{
2022-02-04 14:18:45 -05:00
LOCTEXT ( " SoundUniqueDisplayName " , " Sound Unique ID " ) ,
2022-03-04 16:10:23 -05:00
LOCTEXT ( " SoundUniqueDescription " , " ID of unique source instance. " ) ,
2021-12-15 23:11:10 -05:00
FName ( ) , // TODO: Align environment data types with environment (ex. this is actually set/get as a uint32)
Environment : : SoundUniqueID
}
} ;
}
} ;
return MakeShared < FInterface > ( InUClass ) ;
}
bool FUpdateInterface : : Transform ( Frontend : : FDocumentHandle InDocument ) const
{
using namespace Frontend ;
// When upgrading, we only want to add the one-shot interface if the MetaSound actually has the OnFinished trigger connected.
bool bIsOnFinishedConnected = false ;
InDocument - > GetRootGraph ( ) - > IterateConstNodes ( [ & ] ( FConstNodeHandle NodeHandle )
{
NodeHandle - > IterateConstInputs ( [ & ] ( FConstInputHandle InputHandle )
{
if ( InputHandle - > GetName ( ) = = SourceInterfaceV1_0 : : Outputs : : OnFinished )
{
bIsOnFinishedConnected = InputHandle - > IsConnected ( ) ;
}
} ) ;
} , EMetasoundFrontendClassType : : Output ) ;
const TArray < FMetasoundFrontendVersion > InterfacesToRemove
{
SourceInterfaceV1_0 : : GetVersion ( )
} ;
TArray < FMetasoundFrontendVersion > InterfacesToAdd
{
SourceInterface : : GetVersion ( )
} ;
if ( bIsOnFinishedConnected )
{
InterfacesToAdd . Add ( SourceOneShotInterface : : GetVersion ( ) ) ;
}
FModifyRootGraphInterfaces InterfaceTransform ( InterfacesToRemove , InterfacesToAdd ) ;
return InterfaceTransform . Transform ( InDocument ) ;
}
} // namespace SourceInterface
# undef AUDIO_PARAMETER_INTERFACE_NAMESPACE
2021-12-10 20:37:31 -05:00
} // namespace Frontend
} // namespace Metasound
2021-12-15 23:11:10 -05:00
2022-02-24 23:16:52 -05:00
# undef LOCTEXT_NAMESPACE