2024-04-24 01:17:15 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "AudioDevice.h"
|
|
|
|
|
#include "AudioDeviceManager.h"
|
|
|
|
|
#include "Audio/AudioDebug.h"
|
|
|
|
|
#include "MetasoundSource.h"
|
|
|
|
|
|
2024-04-24 02:36:37 -04:00
|
|
|
#if ENABLE_AUDIO_DEBUG
|
|
|
|
|
|
2024-04-24 01:17:15 -04:00
|
|
|
namespace Metasound
|
|
|
|
|
{
|
|
|
|
|
namespace Console
|
|
|
|
|
{
|
2024-05-08 02:21:36 -04:00
|
|
|
static void HandleSoloMetaSound(const TArray<FString>& InArgs, UWorld* World)
|
2024-04-24 01:17:15 -04:00
|
|
|
{
|
|
|
|
|
check(GEngine);
|
|
|
|
|
FAudioDeviceManager* DeviceManager = GEngine->GetAudioDeviceManager();
|
|
|
|
|
if (!DeviceManager)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FAudioDeviceHandle AudioDevice = DeviceManager->GetActiveAudioDevice();
|
|
|
|
|
if (!AudioDevice)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TArray<FString> MetaSoundWaves;
|
|
|
|
|
|
|
|
|
|
const int32 WorldID = World->GetUniqueID();
|
|
|
|
|
const TArray<FActiveSound*>& ActiveSounds = AudioDevice->GetActiveSounds();
|
|
|
|
|
for (const FActiveSound* const& ActiveSound : ActiveSounds)
|
|
|
|
|
{
|
|
|
|
|
if (WorldID == ActiveSound->GetWorldID())
|
|
|
|
|
{
|
|
|
|
|
// Make sure that sound asset is MetaSound based
|
|
|
|
|
if (Cast<UMetaSoundSource>(ActiveSound->GetSound()))
|
|
|
|
|
{
|
|
|
|
|
for (const TPair<UPTRINT, FWaveInstance*>& WaveInstancePair : ActiveSound->GetWaveInstances())
|
|
|
|
|
{
|
|
|
|
|
const FWaveInstance* WaveInstance = WaveInstancePair.Value;
|
|
|
|
|
MetaSoundWaves.Add(WaveInstance->GetName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (InArgs.Num() == 1)
|
|
|
|
|
{
|
|
|
|
|
for (const FString& Wave : MetaSoundWaves)
|
|
|
|
|
{
|
|
|
|
|
// we can't use FAudioDebugger::SetSoloSoundWave(...) because we don't want to mute non MetaSounds
|
2024-05-08 02:21:36 -04:00
|
|
|
const bool bMute = !Wave.Contains(InArgs[0], ESearchCase::IgnoreCase);
|
2024-04-24 01:17:15 -04:00
|
|
|
DeviceManager->GetDebugger().SetMuteSoundWave(*Wave, bMute);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-05-08 02:21:36 -04:00
|
|
|
UE_LOG(LogMetaSound, Error, TEXT("You can solo ONLY ONE MetaSound!"));
|
2024-04-24 01:17:15 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-08 02:21:36 -04:00
|
|
|
static void HandleMuteMetaSound(const TArray<FString>& InArgs, UWorld* World)
|
2024-04-24 01:17:15 -04:00
|
|
|
{
|
|
|
|
|
check(GEngine);
|
|
|
|
|
FAudioDeviceManager* DeviceManager = GEngine->GetAudioDeviceManager();
|
|
|
|
|
if (!DeviceManager)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FAudioDeviceHandle AudioDevice = DeviceManager->GetActiveAudioDevice();
|
|
|
|
|
if (!AudioDevice)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TArray<FString> MetaSoundWaves;
|
|
|
|
|
|
|
|
|
|
const int32 WorldID = World->GetUniqueID();
|
|
|
|
|
const TArray<FActiveSound*>& ActiveSounds = AudioDevice->GetActiveSounds();
|
|
|
|
|
for (const FActiveSound* const& ActiveSound : ActiveSounds)
|
|
|
|
|
{
|
|
|
|
|
if (WorldID == ActiveSound->GetWorldID())
|
|
|
|
|
{
|
|
|
|
|
// Make sure that sound asset is MetaSound based
|
|
|
|
|
if (Cast<UMetaSoundSource>(ActiveSound->GetSound()))
|
|
|
|
|
{
|
|
|
|
|
for (const TPair<UPTRINT, FWaveInstance*>& WaveInstancePair : ActiveSound->GetWaveInstances())
|
|
|
|
|
{
|
|
|
|
|
const FWaveInstance* WaveInstance = WaveInstancePair.Value;
|
|
|
|
|
MetaSoundWaves.Add(WaveInstance->GetName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const FString& Arg : InArgs)
|
|
|
|
|
{
|
|
|
|
|
for (const FString& Wave : MetaSoundWaves)
|
|
|
|
|
{
|
2024-05-08 02:21:36 -04:00
|
|
|
if (Wave.Contains(Arg, ESearchCase::IgnoreCase))
|
2024-04-24 01:17:15 -04:00
|
|
|
{
|
|
|
|
|
DeviceManager->GetDebugger().SetMuteSoundWave(*Wave, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} // namespace Console
|
|
|
|
|
} // namespace Metasound
|
|
|
|
|
|
2024-05-08 02:21:36 -04:00
|
|
|
static FAutoConsoleCommandWithWorldAndArgs SoloMetaSound
|
2024-04-24 01:17:15 -04:00
|
|
|
(
|
|
|
|
|
TEXT("au.MetaSound.SoloMetaSound"),
|
2024-05-08 02:21:36 -04:00
|
|
|
TEXT("Mutes all other MetaSounds. Only the first argument is accepted."),
|
|
|
|
|
FConsoleCommandWithWorldAndArgsDelegate::CreateStatic(&Metasound::Console::HandleSoloMetaSound)
|
2024-04-24 01:17:15 -04:00
|
|
|
);
|
|
|
|
|
|
2024-05-08 02:21:36 -04:00
|
|
|
static FAutoConsoleCommandWithWorldAndArgs MuteMetaSound
|
2024-04-24 01:17:15 -04:00
|
|
|
(
|
2024-05-08 02:21:36 -04:00
|
|
|
TEXT("au.MetaSound.MuteMetaSound"),
|
|
|
|
|
TEXT("Mutes all given MetaSounds."),
|
|
|
|
|
FConsoleCommandWithWorldAndArgsDelegate::CreateStatic(&Metasound::Console::HandleMuteMetaSound)
|
2024-04-24 01:17:15 -04:00
|
|
|
);
|
2024-04-24 02:36:37 -04:00
|
|
|
|
|
|
|
|
#endif // ENABLE_AUDIO_DEBUG
|