diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index e5c912025..94bc2fb1b 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -149,6 +149,57 @@ bool FurnaceGUI::decodeNote(const char* what, short& note, short& octave) { return false; } +String FurnaceGUI::encodeKeyMap(std::map& map) { + String ret; + for (std::map::value_type& i: map) { + ret+=fmt::printf("%d:%d;",i.first,i.second); + } + return ret; +} + +void FurnaceGUI::decodeKeyMap(std::map& map, String source) { + map.clear(); + bool inValue=false; + bool negateKey=false; + bool negateValue=false; + int key=0; + int val=0; + for (char& i: source) { + switch (i) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + if (inValue) { + val*=10; + val+=i-'0'; + } else { + key*=10; + key+=i-'0'; + } + break; + case '-': + if (inValue) { + negateValue=true; + } else { + negateKey=true; + } + break; + case ':': + inValue=true; + break; + case ';': + if (inValue) { + map[negateKey?-key:key]=negateValue?-val:val; + } + key=0; + val=0; + inValue=false; + negateKey=false; + negateValue=false; + break; + } + } +} + void FurnaceGUI::encodeMMLStr(String& target, unsigned char* macro, unsigned char macroLen, signed char macroLoop, signed char macroRel) { target=""; char buf[32]; diff --git a/src/gui/gui.h b/src/gui/gui.h index 907667433..5ab473103 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -552,7 +552,9 @@ class FurnaceGUI { SDL_Scancode samplePreviewKey; int samplePreviewNote; + // SDL_Scancode,int std::map noteKeys; + // SDL_Keycode,int std::map valueKeys; int arpMacroScroll; @@ -687,6 +689,9 @@ class FurnaceGUI { void decodeMMLStr(String& source, int* macro, unsigned char& macroLen, signed char& macroLoop, int macroMin, int macroMax, signed char& macroRel); void decodeMMLStrW(String& source, int* macro, int& macroLen, int macroMax); + String encodeKeyMap(std::map& map); + void decodeKeyMap(std::map& map, String source); + const char* getSystemName(DivSystem which); public: