mapping phrases to colors for patterns

This commit is contained in:
PS 2021-03-27 14:46:17 -07:00
parent 76b86c9ba0
commit 874925a5fe
7 changed files with 129 additions and 8 deletions

View File

@ -42,6 +42,7 @@ typedef struct panel panel;
#include "engine/animation/foldhaus_animation_renderer.cpp"
#include "engine/user_space.h"
#include "ss_blumen_lumen/phrase_hue_map.h"
#include "ss_blumen_lumen/blumen_lumen.h"
struct app_state

View File

@ -27,6 +27,7 @@ Handle_IsValid(handle Handle)
}
#include "..\gs_libs\gs_string.h"
#include "..\gs_libs\gs_csv.h"
#include "foldhaus_debug.h"
global debug_services* GlobalDebugServices;

View File

@ -1193,8 +1193,7 @@ Pattern_WavyPatchy(led_buffer* Leds, led_buffer_range Range, assembly Assembly,
r32 LightHueMin = (ModR32(Time, 10) / 10) * 360;
r32 LightHueMax = ModR32((LightHueMin + 45), 360) ;
#else
v4 CenterColor = BLState->AssemblyColors[Assembly.AssemblyIndex % 3];
r32 CenterHue = RGBToHSV(CenterColor).x;
r32 CenterHue = BLState->AssemblyColors[Assembly.AssemblyIndex % 3].Hue0;
r32 LightHueMin = ModR32(CenterHue + 30, 360);;
r32 LightHueMax = ModR32(CenterHue - 30, 360) ;
#endif

View File

@ -524,7 +524,6 @@ SetWorkingDirectory(HINSTANCE HInstance, gs_thread_context ThreadContext)
}
#include "../../gs_libs/gs_path.h"
#include "../../gs_libs/gs_csv.h"
internal void
Win32_SendOutputData(gs_thread_context ThreadContext, addressed_data_buffer_list OutputData)
@ -575,6 +574,27 @@ WinMain (
if (!SetWorkingDirectory(HInstance, ThreadContext)) return 1;
gs_file TestFile = ReadEntireFile(ThreadContext.FileHandler, ConstString("data/flower_codes.tsv"));
gs_const_string TestFileStr = {};
TestFileStr.Str = (char*)TestFile.Memory;
TestFileStr.Length = TestFile.Size;
gscsv_sheet Sheet = CSV_Parse(TestFileStr, { '\t' }, ThreadContext.Transient);
gs_string Out = PushString(ThreadContext.Transient, TestFile.Size * 2);
for (u64 y = 0; y < Sheet.RowCount; y++)
{
for (u64 x = 0; x < Sheet.ColumnCount; x++)
{
gs_const_string Cell = CSVSheet_GetCell(Sheet, x, y);
AppendPrintF(&Out, "%S\t", Cell);
}
AppendPrintF(&Out, "\n");
}
NullTerminate(&Out);
OutputDebugStringA(Out.Str);
MainWindow = Win32CreateWindow (HInstance, "Foldhaus", 1440, 768, HandleWindowEvents);
Win32UpdateWindowDimension(&MainWindow);

View File

@ -281,6 +281,15 @@ BlumenLumen_CustomInit(app_state* State, context Context)
BLState->AssemblyNameToClearCore_Names[2] = HashDJB2ToU32(StringExpand(Flower2->Name));
#endif
{
gs_file ColorPhraseCSVFile = ReadEntireFile(Context.ThreadContext.FileHandler, ConstString("data/flower_codes.tsv"));
gs_const_string ColorPhraseMapStr = ConstString((char*)ColorPhraseCSVFile.Memory,
ColorPhraseCSVFile.Size);
gscsv_sheet ColorPhraseSheet = CSV_Parse(ColorPhraseMapStr, { '\t' }, State->Transient);
BLState->PhraseHueMap = PhraseHueMap_GenFromCSV(ColorPhraseSheet, &State->Permanent);
}
#if 1
{ // Animation PLAYGROUND
animation_desc Desc = {};
@ -323,10 +332,6 @@ BlumenLumen_CustomInit(app_state* State, context Context)
#endif
State->AnimationSystem.TimelineShouldAdvance = true;
BLState->AssemblyColors[0] = RedV4;
BLState->AssemblyColors[1] = GreenV4;
BLState->AssemblyColors[2] = BlueV4;
return Result;
}
@ -360,8 +365,16 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
case PacketType_PatternCommand:
{
microphone_packet Mic = Packet.MicPacket;
u64 NameHash = HashDJB2ToU32(Mic.AnimationFileName);
u32 NameLen = CStringLength(Mic.AnimationFileName);
phrase_hue NewHue = PhraseHueMap_Get(BLState->PhraseHueMap, NameHash);
if (NewHue.PhraseHash != 0)
{
u32 AssemblyIdx = BLState->LastAssemblyColorSet;
BLState->AssemblyColors[AssemblyIdx] = NewHue;
}
#if 0
for (u32 i = 0; i < PhraseToAnimMapCount; i++)
{
gs_const_string PhraseStr = ConstString(PhraseToAnimMap[i].Phrase);
@ -379,6 +392,7 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
OutputDebugStringA(T.Str);
}
}
#endif
}break;
case PacketType_MotorState:

View File

@ -219,7 +219,8 @@ struct blumen_lumen_state
system_time LastSendTime;
v4 AssemblyColors[3];
phrase_hue AssemblyColors[3];
u32 LastAssemblyColorSet;
// The indices of this array are the index the clear core uses to
// represent a motor.
@ -229,6 +230,8 @@ struct blumen_lumen_state
u32 AssemblyNameToClearCoreMapCount;
u64* AssemblyNameToClearCore_Names;
phrase_hue_map PhraseHueMap;
// Debug
motor_packet DEBUG_PendingMotorPacket;
};

View File

@ -0,0 +1,83 @@
/* date = March 27th 2021 1:55 pm */
#ifndef PHRASE_HUE_MAP_H
#define PHRASE_HUE_MAP_H
typedef struct phrase_hue_map
{
u64 Count;
gs_const_string* Phrases;
u64* PhraseHashes;
r32* Hue0;
r32* Hue1;
r32* Hue2;
} phrase_hue_map;
typedef struct phrase_hue
{
gs_const_string Phrase;
u64 PhraseHash;
r32 Hue0;
r32 Hue1;
r32 Hue2;
} phrase_hue;
internal phrase_hue_map
PhraseHueMap_GenFromCSV(gscsv_sheet Sheet, gs_memory_arena* Arena)
{
phrase_hue_map Result = {};
Result.Count = Sheet.RowCount - 1; // we don't include the header row
Result.Phrases = PushArray(Arena, gs_const_string, Result.Count);
Result.PhraseHashes = PushArray(Arena, u64, Result.Count);
Result.Hue0 = PushArray(Arena, r32, Result.Count);
Result.Hue1 = PushArray(Arena, r32, Result.Count);
Result.Hue2 = PushArray(Arena, r32, Result.Count);
for (u32 Row = 1; Row < Sheet.RowCount; Row++)
{
u32 Index = Row - 1;
gs_const_string Phrase = CSVSheet_GetCell(Sheet,
0, Row);
u64 PhraseHash = HashDJB2ToU32(StringExpand(Phrase));
gs_const_string Hue0Str = CSVSheet_GetCell(Sheet,
1, Row);
gs_const_string Hue1Str = CSVSheet_GetCell(Sheet,
2, Row);
gs_const_string Hue2Str = CSVSheet_GetCell(Sheet,
3, Row);
gs_const_string Homonyms = CSVSheet_GetCell(Sheet,
4, Row);
Result.Phrases[Index] = PushStringF(Arena, Phrase.Length, "%S", Phrase).ConstString;
Result.PhraseHashes[Index] = PhraseHash;
Result.Hue0[Index] = (r64)ParseFloat(Hue0Str);
Result.Hue1[Index] = (r64)ParseFloat(Hue1Str);
Result.Hue2[Index] = (r64)ParseFloat(Hue2Str);
}
return Result;
}
internal phrase_hue
PhraseHueMap_Get(phrase_hue_map Map, u64 PhraseHash)
{
phrase_hue Result = {};
for (u32 i = 0; i < Map.Count; i++)
{
if (Map.PhraseHashes[i] == PhraseHash)
{
Result.Phrase = Map.Phrases[i];
Result.PhraseHash = Map.PhraseHashes[i];
Result.Hue0 = Map.Hue0[i];
Result.Hue1 = Map.Hue1[i];
Result.Hue2 = Map.Hue2[i];
break;
}
}
return Result;
}
#endif //PHRASE_HUE_MAP_H