Home

2024

Worklog

LETSGO Game

Janky ass notes-to-sound mapping

Date
August 21, 2024
Hours
1
Tags
UnrealCodeC++LETSGO

I’ve decided to build this data structure out as naively as possible, the theory being “Get absolute dogshit technically working, then iterate the shittiness out.”

As such:

/**
 * This is some jank. Not pleased at all with this.
 * I'm going to continue on with this until it's end-to-end working though
 * I've decided to go with the most naive possible approach then iterate a better solution
 */ 
TArray<FCheeseKeyData> FCheeseKeyData::GenerateKeys(TArray<UMetaSoundSource*> Sounds)
{
	TArray<ELetsGoMusicNotes> AssumedNoteOrder = {
		C,
		CSharp,
		D,
		EFlat,
		E,
		F,
		FSharp,
		G,
		AFlat,
		A,
		BFlat,
		B,
	};
	
	TArray<FCheeseKeyData> KeyData = TArray<FCheeseKeyData>();
	int CurrentOctave = 1;
	
	for (int i = 0; i <= Sounds.Num(); i++)
	{
		if (i % 12 == 0)
		{
			CurrentOctave++;
		}

		const ELetsGoMusicNotes Note = AssumedNoteOrder[i % 12];

		FCheeseKeyData Key = FCheeseKeyData(CurrentOctave, Note, Sounds[i]);
		KeyData.Emplace(Key);
	}

	return KeyData;
}

The idea is to take an array of 48 sound cues manually connected through a Mapping Blueprint like this:

	UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
	UMetaSoundSource* C1_Music_Note;
	
	UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
	UMetaSoundSource* CSharp1_Music_Note;
	
	UPROPERTY(BlueprintReadWrite, EditDefaultsOnly)
	UMetaSoundSource* D1_Music_Note;
	
	//... For four octaves multiplied by 12 notes

And turn each one into a data structure like this:

USTRUCT()
struct FCheeseKeyData {
	GENERATED_BODY()

	UPROPERTY()
	int Octave; 
	
	UPROPERTY()
	TEnumAsByte<ELetsGoMusicNotes> Note;

	UPROPERTY()
	UMetaSoundSource* Sound;

	FCheeseKeyData();
}

It’s janky, I need a better solution. But I figure it’s going to be easier to refactor this jank than it is to try and pontificates Gods own true data structure.

Time will tell if this is true.