Files
helen yang 803e3e44b4 Use loc text for MetaSound node vertex names (Part 2)
- pass on MetaSound nodes to use METASOUND_PARAM() and related macros for information about node vertices that should be localized
- fix typos, loc key collisions, and update audio unit test call sites

#jira UE-144518
#jira UE-145530
#rb aaron.mcleran
#preflight 62335f6ce12e0da4a52e74ba
#robomerge FNNC

[CL 19423048 by helen yang in ue5-main branch]
2022-03-17 13:14:50 -04:00

132 lines
2.7 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "MetasoundArrayShuffleNode.h"
#include "MetasoundDataTypeRegistrationMacro.h"
#define LOCTEXT_NAMESPACE "MetasoundFrontend"
namespace Metasound
{
/**
* FArrayIndexShuffler
*/
FArrayIndexShuffler::FArrayIndexShuffler(int32 InSeed, int32 InMaxIndices)
{
Init(InSeed, InMaxIndices);
}
void FArrayIndexShuffler::Init(int32 InSeed, int32 InMaxIndices)
{
SetSeed(InSeed);
if (InMaxIndices > 0)
{
ShuffleIndices.AddUninitialized(InMaxIndices);
for (int32 i = 0; i < ShuffleIndices.Num(); ++i)
{
ShuffleIndices[i] = i;
}
ShuffleArray();
}
}
void FArrayIndexShuffler::SetSeed(int32 InSeed)
{
if (InSeed == INDEX_NONE)
{
RandomStream.Initialize(FPlatformTime::Cycles());
}
else
{
RandomStream.Initialize(InSeed);
}
ResetSeed();
}
void FArrayIndexShuffler::ResetSeed()
{
RandomStream.Reset();
}
bool FArrayIndexShuffler::NextValue(bool bAutoShuffle, int32& OutIndex)
{
bool bShuffled = false;
if (CurrentIndex == ShuffleIndices.Num())
{
if (bAutoShuffle)
{
ShuffleArray();
bShuffled = true;
}
else
{
CurrentIndex = 0;
}
}
check(CurrentIndex < ShuffleIndices.Num());
PrevValue = ShuffleIndices[CurrentIndex];
OutIndex = PrevValue;
++CurrentIndex;
return bShuffled;
}
// Shuffle the array with the given max indices
void FArrayIndexShuffler::ShuffleArray()
{
// Randomize the shuffled array by randomly swapping indicies
for (int32 i = 0; i < ShuffleIndices.Num(); ++i)
{
RandomSwap(i, 0, ShuffleIndices.Num() - 1);
}
// Reset the current index back to 0
CurrentIndex = 0;
// Fix up the new current index if the value is our previous value and we have an array larger than 1
if (ShuffleIndices.Num() > 1 && ShuffleIndices[CurrentIndex] == PrevValue)
{
RandomSwap(0, 1, ShuffleIndices.Num() - 1);
}
}
void FArrayIndexShuffler::RandomSwap(int32 InCurrentIndex, int32 InStartIndex, int32 InEndIndex)
{
int32 ShuffleIndex = RandomStream.RandRange(InStartIndex, InEndIndex);
int32 Temp = ShuffleIndices[ShuffleIndex];
ShuffleIndices[ShuffleIndex] = ShuffleIndices[InCurrentIndex];
ShuffleIndices[InCurrentIndex] = Temp;
}
namespace ArrayNodeGetGlobalArrayKeyVertexNames
{
const FVertexName& GetInputNamespaceName()
{
static const FVertexName Name = TEXT("Namespace");
return Name;
}
const FVertexName& GetInputArraySizeName()
{
static const FVertexName Name = TEXT("Array Size");
return Name;
}
const FVertexName& GetInputSeedName()
{
static const FVertexName Name = TEXT("Seed");
return Name;
}
const FVertexName& GetOutputArrayKeyName()
{
static const FVertexName Name = TEXT("Global Array Key");
return Name;
}
}
}
#undef LOCTEXT_NAMESPACE