// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "MetasoundFrontendDocumentBuilder.h" #include "MetasoundGeneratorHandle.h" #include "MVVMViewModelBase.h" #include "MetaSoundViewModel.generated.h" #define UE_API TECHAUDIOTOOLSMETASOUND_API TECHAUDIOTOOLSMETASOUND_API DECLARE_LOG_CATEGORY_EXTERN(LogTechAudioToolsMetaSound, Log, All); class UMetaSoundBuilderBase; class UMetaSoundInputViewModel; class UMetaSoundOutputViewModel; /** * The base class for MetaSound viewmodels. Used for binding metadata and member inputs/outputs of a MetaSound to widgets in UMG. * Can be initialized using a MetaSound Builder or a MetaSound asset. Creates member viewmodels for each input and output in the * MetaSound upon initialization. */ UCLASS(MinimalAPI, DisplayName = "MetaSound Viewmodel") class UMetaSoundViewModel : public UMVVMViewModelBase { GENERATED_BODY() private: // True if this MetaSound Viewmodel has been initialized. UPROPERTY(BlueprintReadOnly, FieldNotify, Category = "MetaSound Viewmodel", meta = (AllowPrivateAccess)) bool bIsInitialized = false; // True if the initialized MetaSound is a preset. UPROPERTY(BlueprintReadOnly, FieldNotify, Category = "MetaSound Viewmodel", meta = (AllowPrivateAccess)) bool bIsPreset = false; public: // Returns the object name of the initialized builder as text. UFUNCTION(BlueprintCallable, FieldNotify, Category = "MetaSound Viewmodel") UE_API FText GetBuilderNameAsText() const; // Contains MetaSound Input Viewmodels for each input of the initialized MetaSound. UFUNCTION(BlueprintCallable, FieldNotify, DisplayName = "Get Input Viewmodels", Category = "MetaSound Viewmodel") UE_API virtual TArray GetInputViewModels() const; // Contains MetaSound Output ViewModels for each output of the initialized MetaSound. UFUNCTION(BlueprintCallable, FieldNotify, DisplayName = "Get Output Viewmodels", Category = "MetaSound Viewmodel") UE_API virtual TArray GetOutputViewModels() const; // Initializes the viewmodel using the given MetaSound asset. UFUNCTION(BlueprintCallable, DisplayName = "Initialize MetaSound", Category = "Audio|MetaSound Viewmodel") UE_API virtual void InitializeMetaSound(const TScriptInterface InMetaSound); // Initializes the viewmodel using the given builder. UFUNCTION(BlueprintCallable, DisplayName = "Initialize Builder", Category = "Audio|MetaSound Viewmodel") UE_API virtual void Initialize(UMetaSoundBuilderBase* InBuilder); // Resets this MetaSoundViewModel instance to an uninitialized state. UFUNCTION(BlueprintCallable, Category = "Audio|MetaSound Viewmodel") UE_API virtual void Reset(); // Returns a reference to the initialized MetaSound's Builder. UFUNCTION(BlueprintCallable, Category = "Audio|MetaSound Viewmodel") UMetaSoundBuilderBase* GetBuilder() const { return Builder; } bool IsInitialized() const { return bIsInitialized; } void SetIsInitialized(const bool bInIsInitialized) { UE_MVVM_SET_PROPERTY_VALUE(bIsInitialized, bInIsInitialized); } protected: UE_API virtual void InitializeProperties(const FMetasoundFrontendDocument& FrontendDocument); UE_API virtual void ResetProperties(); // Called upon initialization. Creates viewmodel instances for all inputs and outputs of the initialized MetaSound. UE_API void CreateMemberViewModels(); // Creates a single MetaSoundInputViewModel instance for the given input. UE_API virtual void CreateInputViewModel(const FMetasoundFrontendClassInput& InInput); UE_API virtual UMetaSoundInputViewModel* CreateInputViewModelInstance(); // Creates a single MetaSoundOutputViewModel instance for the given output. UE_API void CreateOutputViewModel(const FMetasoundFrontendClassOutput& InOutput); UE_API virtual UMetaSoundOutputViewModel* CreateOutputViewModelInstance(); UPROPERTY(Transient) TObjectPtr Builder; UPROPERTY(Transient) TMap> InputViewModels; UPROPERTY(Transient) TMap> OutputViewModels; }; /** * Viewmodel class for MetaSound inputs. Allows widgets in UMG to bind to MetaSound literals. Useful for creating knobs, sliders, and other * widgets for setting MetaSound input parameters. */ UCLASS(MinimalAPI, DisplayName = "MetaSound Input Viewmodel") class UMetaSoundInputViewModel : public UMVVMViewModelBase { GENERATED_BODY() protected: // True if this MetaSoundInputViewModel has been initialized. UPROPERTY(BlueprintReadOnly, FieldNotify, Category = "MetaSound Input", meta = (AllowPrivateAccess)) bool bIsInitialized = false; // Sets the name of the initialized MetaSound input. UPROPERTY(BlueprintReadWrite, EditAnywhere, FieldNotify, Setter, Category = "MetaSound Input", meta = (AllowPrivateAccess)) FName InputName; // Returns the data type of the initialized MetaSound input. UPROPERTY(BlueprintReadWrite, FieldNotify, Setter, Category = "MetaSound Input", meta = (AllowPrivateAccess)) FName DataType; // True if the initialized MetaSound input is an array. UPROPERTY(BlueprintReadWrite, FieldNotify, Setter = "SetIsArray", Category = "MetaSound Input", meta = (AllowPrivateAccess)) bool bIsArray; // The MetaSound Literal belonging to the initialized MetaSound input. UPROPERTY(BlueprintReadWrite, FieldNotify, Setter, Category = "MetaSound Input", meta = (AllowPrivateAccess)) FMetasoundFrontendLiteral Literal; // Returns the Literal Type belonging to the initialized MetaSound input. UPROPERTY(BlueprintReadOnly, FieldNotify, Category = "MetaSound Input", meta = (AllowPrivateAccess)) EMetasoundFrontendLiteralType LiteralType; UPROPERTY(Transient) TObjectPtr Builder; public: UE_API virtual void InitializeInput(UMetaSoundBuilderBase* InBuilder, const FMetasoundFrontendClassInput& InInput); UE_API virtual void ResetInput(); FName GetInputName() const { return InputName; } UE_API void SetIsInitialized(const bool bInIsInitialized); UE_API void SetInputName(const FName& InInputName); UE_API void SetDataType(const FName& InDataType); UE_API void SetIsArray(const bool bInIsArray); // Returns the value of this input's MetaSound Literal as a text value. UFUNCTION(BlueprintCallable, FieldNotify, Category = "Audio|MetaSound Input Viewmodel") UE_API FText GetLiteralValueAsText() const; UE_API void SetLiteral(const FMetasoundFrontendLiteral& InLiteral); }; /** * Viewmodel class for MetaSound outputs. Allows widgets in UMG to bind to data from a MetaSound output. Useful for driving visual parameters * using MetaSound outputs. */ UCLASS(MinimalAPI, DisplayName = "MetaSound Output Viewmodel") class UMetaSoundOutputViewModel : public UMVVMViewModelBase { GENERATED_BODY() protected: // True if this MetaSoundOutputViewModel has been initialized. UPROPERTY(BlueprintReadOnly, FieldNotify, Category = "MetaSound Output", meta = (AllowPrivateAccess)) bool bIsInitialized = false; // Sets the name of the initialized MetaSound output. UPROPERTY(BlueprintReadWrite, EditAnywhere, FieldNotify, Setter, Category = "MetaSound Output", meta = (AllowPrivateAccess)) FName OutputName; // Returns the data type of the initialized MetaSound output. UPROPERTY(BlueprintReadWrite, FieldNotify, Setter, Category = "MetaSound Output", meta = (AllowPrivateAccess)) FName DataType; // True if the initialized MetaSound output is an array. UPROPERTY(BlueprintReadWrite, FieldNotify, Setter = "SetIsArray", Category = "MetaSound Output", meta = (AllowPrivateAccess)) bool bIsArray; // The MetaSound Output belonging to the initialized MetaSound output. UPROPERTY(BlueprintReadWrite, FieldNotify, Setter, DisplayName = "MetaSound Output", Category = "MetaSound Output", meta = (AllowPrivateAccess)) FMetaSoundOutput MetaSoundOutput; UPROPERTY(Transient) TObjectPtr Builder; public: UE_API virtual void InitializeOutput(UMetaSoundBuilderBase* InBuilder, const FMetasoundFrontendClassOutput& InOutput); UE_API virtual void ResetOutput(); FName GetOutputName() const { return OutputName; } UE_API void SetIsInitialized(const bool bInIsInitialized); UE_API void SetOutputName(const FName& InOutputName); UE_API void SetDataType(const FName& InDataType); UE_API void SetIsArray(const bool bInIsArray); UE_API void SetMetaSoundOutput(const FMetaSoundOutput& InMetaSoundOutput); UFUNCTION() UE_API void OnOutputValueChanged(FName InOutputName, const FMetaSoundOutput& InOutput); }; #undef UE_API