// Copyright Epic Games, Inc. All Rights Reserved. #include "Metasound.h" #include "MetasoundAssetSubsystem.h" #include "MetasoundAudioBus.h" #include "MetasoundBuilderSubsystem.h" #include "MetasoundDataReference.h" #include "MetasoundDataTypeRegistrationMacro.h" #include "MetasoundDocumentBuilderRegistry.h" #include "MetasoundDocumentInterface.h" #include "MetasoundFrontendDocumentBuilder.h" #include "MetasoundLog.h" #include "MetasoundOutputSubsystem.h" #include "MetasoundSource.h" #include "MetasoundTrace.h" #include "MetasoundUObjectRegistry.h" #include "MetasoundWave.h" #include "MetasoundWaveTable.h" #include "Analysis/MetasoundFrontendAnalyzerRegistry.h" #include "Analysis/MetasoundFrontendVertexAnalyzerAudioBuffer.h" #include "Analysis/MetasoundFrontendVertexAnalyzerEnvelopeFollower.h" #include "Analysis/MetasoundFrontendVertexAnalyzerForwardValue.h" #include "Analysis/MetasoundFrontendVertexAnalyzerTriggerDensity.h" #include "Analysis/MetasoundFrontendVertexAnalyzerTriggerToTime.h" #include "Analysis/MetasoundVertexAnalyzerAudioBusWriter.h" #include "Interfaces/MetasoundDeprecatedInterfaces.h" #include "Interfaces/MetasoundInterface.h" #include "Interfaces/MetasoundInterfaceBindingsPrivate.h" #include "Modules/ModuleManager.h" #include "Sound/AudioSettings.h" namespace Metasound { // Enable send/receive node registration for data types which existed before // send/receive were deprecated in order to support old UMetaSound assets. template<> struct TEnableTransmissionNodeRegistration { static constexpr bool Value = true; }; } REGISTER_METASOUND_DATATYPE(Metasound::FAudioBusAsset, "AudioBusAsset", Metasound::ELiteralType::UObjectProxy, UAudioBus); REGISTER_METASOUND_DATATYPE(Metasound::FWaveAsset, "WaveAsset", Metasound::ELiteralType::UObjectProxy, USoundWave); REGISTER_METASOUND_DATATYPE(WaveTable::FWaveTable, "WaveTable", Metasound::ELiteralType::FloatArray) REGISTER_METASOUND_DATATYPE(Metasound::FWaveTableBankAsset, "WaveTableBankAsset", Metasound::ELiteralType::UObjectProxy, UWaveTableBank); namespace Metasound::Engine { class FModule : public IModuleInterface { // Supplies GC referencing in the MetaSound Frontend node registry for doing // async work on UObjets class FObjectReferencer : public FMetasoundFrontendRegistryContainer::IObjectReferencer , public FGCObject { public: virtual void AddObject(UObject* InObject) override { FScopeLock LockObjectArray(&ObjectArrayCriticalSection); ObjectArray.Add(InObject); } virtual void RemoveObject(UObject* InObject) override { FScopeLock LockObjectArray(&ObjectArrayCriticalSection); ObjectArray.Remove(InObject); } virtual void AddReferencedObjects(FReferenceCollector& Collector) override { FScopeLock LockObjectArray(&ObjectArrayCriticalSection); Collector.AddReferencedObjects(ObjectArray); } virtual FString GetReferencerName() const override { return TEXT("FMetasoundEngineModule::FObjectReferencer"); } private: mutable FCriticalSection ObjectArrayCriticalSection; TArray> ObjectArray; }; public: virtual void StartupModule() override { using namespace Frontend; METASOUND_LLM_SCOPE; FModuleManager::Get().LoadModuleChecked("MetasoundGraphCore"); FModuleManager::Get().LoadModuleChecked("MetasoundFrontend"); FModuleManager::Get().LoadModuleChecked("MetasoundStandardNodes"); FModuleManager::Get().LoadModuleChecked("MetasoundGenerator"); FModuleManager::Get().LoadModuleChecked("WaveTable"); InitializeAssetManager(); IDocumentBuilderRegistry::Initialize(MakeUnique()); // Set GCObject referencer for metasound frontend node registry. The MetaSound // frontend does not have access to Engine GC tools and must have them // supplied externally. FMetasoundFrontendRegistryContainer::Get()->SetObjectReferencer(MakeUnique()); // Register engine-level parameter interfaces if not done already. // (Potentially not already called if plugin is loaded while cooking.) UAudioSettings* AudioSettings = GetMutableDefault(); check(AudioSettings); AudioSettings->RegisterParameterInterfaces(); IMetasoundUObjectRegistry::Get().RegisterUClass(MakeUnique>()); IMetasoundUObjectRegistry::Get().RegisterUClass(MakeUnique>()); IMetasoundUObjectRegistry::Get().RegisterUClass(MakeUnique>()); RegisterDeprecatedInterfaces(); RegisterInterfaces(); RegisterInternalInterfaceBindings(); // Flush node registration queue FMetasoundFrontendRegistryContainer::Get()->RegisterPendingNodes(); // Register Analyzers // TODO: Determine if we can move this registration to Frontend where it likely belongs METASOUND_REGISTER_VERTEX_ANALYZER_FACTORY(Frontend::FVertexAnalyzerAudioBuffer) METASOUND_REGISTER_VERTEX_ANALYZER_FACTORY(Frontend::FVertexAnalyzerEnvelopeFollower) METASOUND_REGISTER_VERTEX_ANALYZER_FACTORY(Frontend::FVertexAnalyzerForwardBool) METASOUND_REGISTER_VERTEX_ANALYZER_FACTORY(Frontend::FVertexAnalyzerForwardFloat) METASOUND_REGISTER_VERTEX_ANALYZER_FACTORY(Frontend::FVertexAnalyzerForwardInt) METASOUND_REGISTER_VERTEX_ANALYZER_FACTORY(Frontend::FVertexAnalyzerForwardTime) METASOUND_REGISTER_VERTEX_ANALYZER_FACTORY(Frontend::FVertexAnalyzerForwardString) METASOUND_REGISTER_VERTEX_ANALYZER_FACTORY(Frontend::FVertexAnalyzerTriggerDensity) METASOUND_REGISTER_VERTEX_ANALYZER_FACTORY(Frontend::FVertexAnalyzerTriggerToTime) METASOUND_REGISTER_VERTEX_ANALYZER_FACTORY(Engine::FVertexAnalyzerAudioBusWriter) // Register passthrough output analyzers UMetasoundGeneratorHandle::RegisterPassthroughAnalyzerForType( GetMetasoundDataTypeName(), Frontend::FVertexAnalyzerForwardFloat::GetAnalyzerName(), Frontend::FVertexAnalyzerForwardFloat::FOutputs::GetValue().Name); UMetasoundGeneratorHandle::RegisterPassthroughAnalyzerForType( GetMetasoundDataTypeName(), Frontend::FVertexAnalyzerForwardInt::GetAnalyzerName(), Frontend::FVertexAnalyzerForwardInt::FOutputs::GetValue().Name); UMetasoundGeneratorHandle::RegisterPassthroughAnalyzerForType( GetMetasoundDataTypeName(), Frontend::FVertexAnalyzerForwardBool::GetAnalyzerName(), Frontend::FVertexAnalyzerForwardBool::FOutputs::GetValue().Name); UMetasoundGeneratorHandle::RegisterPassthroughAnalyzerForType( GetMetasoundDataTypeName(), Frontend::FVertexAnalyzerForwardString::GetAnalyzerName(), Frontend::FVertexAnalyzerForwardString::FOutputs::GetValue().Name); UMetasoundGeneratorHandle::RegisterPassthroughAnalyzerForType( GetMetasoundDataTypeName(), Frontend::FVertexAnalyzerForwardTime::GetAnalyzerName(), Frontend::FVertexAnalyzerForwardTime::FOutputs::GetValue().Name); UMetasoundGeneratorHandle::RegisterPassthroughAnalyzerForType( GetMetasoundDataTypeName(), Frontend::FVertexAnalyzerTriggerToTime::GetAnalyzerName(), Frontend::FVertexAnalyzerTriggerToTime::FOutputs::GetValue().Name); UE_LOG(LogMetaSound, Log, TEXT("MetaSound Engine Initialized")); } virtual void ShutdownModule() override { DeinitializeAssetManager(); Frontend::IDocumentBuilderRegistry::Deinitialize(); } }; } // namespace Metasound::Engine IMPLEMENT_MODULE(Metasound::Engine::FModule, MetasoundEngine);