Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image ID Map in Skin Engine improved #2846

Merged
merged 1 commit into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scripts/misc/addSVG.pl
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@
close( IN );
close( OUT );
system( "mv hacktmp4.h src/windows/scalableresource.h" );

system( "cat src/common/resource.h | perl scripts/misc/idmap.pl > src/common/gui/SkimImageMaps.h" );
12 changes: 9 additions & 3 deletions scripts/misc/idmap.pl
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#!/usr/bin/perl

print "// see scripts/misc/idmap.pl if you want to regen this\n";
print "std::map<std::string, iant> createIdNameMap() {\n";
print " std::map<std::string, int> res;\n";
print "// cat src/common/resource.h | perl scripts/misc/idmap.pl > src/common/gui/SkinImageMaps.h if you want to regen this\n";
print "inline std::unordered_map<std::string, int> createIdNameMap() {\n";
print " std::unordered_map<std::string, int> res;\n";

$all = "";
while( <> )
{
if( m/define IDB_(\S+) (\d+)/ )
{
$all .= " allowed.insert( $2 );\n";
print " res[\"" . $1 . "\"] = " . $2 . ";\n";
}
}

print " return res;\n}\n";

print "\ninline std::unordered_set<int> allowedImageIds() {\n std::unordered_set<int> allowed;\n";
print "$all\n";
print " return allowed;\n}\n";
4 changes: 3 additions & 1 deletion src/common/gui/CScalableBitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,9 @@ void CScalableBitmap::draw (CDrawContext* context, const CRect& rect, const CPoi
VSTGUI::CDrawContext::Transform t2(*offscreen, ztf);

ztf.inverse().transform( newRect );
pngZooms[zoomScan]->draw(offscreen, newRect, offset, 1.0);
auto offs = offset;
ztf.inverse().transform( offs );
pngZooms[zoomScan]->draw(offscreen, newRect, offs, 1.0);
}
offscreen->endDraw();
CBitmap* tmp = offscreen->getBitmap();
Expand Down
137 changes: 137 additions & 0 deletions src/common/gui/SkinImageMaps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// cat src/common/resource.h | perl scripts/misc/idmap.pl > src/common/gui/SkinImageMaps.h if you want to regen this
inline std::unordered_map<std::string, int> createIdNameMap() {
std::unordered_map<std::string, int> res;
res["BG"] = 102;
res["FADERV_BG"] = 105;
res["FILTERBUTTONS"] = 108;
res["OSCSWITCH"] = 110;
res["FBCONFIG"] = 112;
res["SCENESWITCH"] = 113;
res["SCENEMODE"] = 114;
res["OCTAVES_OSC"] = 117;
res["OCTAVES"] = 118;
res["OSCMENU"] = 119;
res["WAVESHAPER"] = 120;
res["RELATIVE_TOGGLE"] = 121;
res["OSCSELECT"] = 122;
res["POLYMODE"] = 123;
res["MODSRC_BG"] = 124;
res["SWITCH_KTRK"] = 125;
res["SWITCH_RETRIGGER"] = 126;
res["NUMBERS"] = 127;
res["MODSRC_SYMBOL"] = 128;
res["FADERH_LABELS"] = 131;
res["SWITCH_SOLO"] = 132;
res["SWITCH_FM"] = 133;
res["SWITCH_MUTE"] = 134;
res["CONF"] = 135;
res["FXCONF_SYMBOLS"] = 136;
res["FXCONF"] = 137;
res["SWITCH_TEMPOSYNC"] = 140;
res["SWITCH_LINK"] = 140;
res["VFADER_MINI_BG_BLACK"] = 141;
res["OSCROUTE"] = 143;
res["FXBYPASS"] = 144;
res["ENVSHAPE"] = 145;
res["LFOTRIGGER"] = 146;
res["BUTTON_STORE"] = 148;
res["BUTTON_MINUSPLUS"] = 149;
res["BUTTON_CHECK"] = 150;
res["FMCONFIG"] = 151;
res["UNIPOLAR"] = 152;
res["FADERH_HANDLE"] = 153;
res["FADERH_BG"] = 154;
res["FADERV_HANDLE"] = 157;
res["ABOUT"] = 158;
res["BUTTON_ABOUT"] = 159;
res["FILTERSUBTYPE"] = 160;
res["CHARACTER"] = 161;
res["ENVMODE"] = 162;
res["STOREPATCH"] = 163;
res["BUTTON_MENU"] = 164;
res["LFOTYPE"] = 166;
res["MENU_IN_SLIDER_BG"] = 167;
res["MENU_IN_FILTER_BG"] = 168;
res["FILTER_GLYPHS"] = 169;
res["MSEG_SEGMENT_HANDLES"] = 301;
res["MSEG_MOVEMENT"] = 302;
res["MINIEDIT_ICON"] = 170;
res["MSEG_VERTICAL_SNAP"] = 303;
res["MSEG_HORIZONTAL_SNAP"] = 304;
res["MPE_BUTTON"] = 171;
res["ZOOM_BUTTON"] = 172;
res["TUNE_BUTTON"] = 173;
res["POLYSPLIT_NUM_BG"] = 174;
res["PITCHBEND_NUM_BG"] = 175;
res["KEYTRACKROOT_BG"] = 176;
return res;
}

inline std::unordered_set<int> allowedImageIds() {
std::unordered_set<int> allowed;
allowed.insert( 102 );
allowed.insert( 105 );
allowed.insert( 108 );
allowed.insert( 110 );
allowed.insert( 112 );
allowed.insert( 113 );
allowed.insert( 114 );
allowed.insert( 117 );
allowed.insert( 118 );
allowed.insert( 119 );
allowed.insert( 120 );
allowed.insert( 121 );
allowed.insert( 122 );
allowed.insert( 123 );
allowed.insert( 124 );
allowed.insert( 125 );
allowed.insert( 126 );
allowed.insert( 127 );
allowed.insert( 128 );
allowed.insert( 131 );
allowed.insert( 132 );
allowed.insert( 133 );
allowed.insert( 134 );
allowed.insert( 135 );
allowed.insert( 136 );
allowed.insert( 137 );
allowed.insert( 140 );
allowed.insert( 140 );
allowed.insert( 141 );
allowed.insert( 143 );
allowed.insert( 144 );
allowed.insert( 145 );
allowed.insert( 146 );
allowed.insert( 148 );
allowed.insert( 149 );
allowed.insert( 150 );
allowed.insert( 151 );
allowed.insert( 152 );
allowed.insert( 153 );
allowed.insert( 154 );
allowed.insert( 157 );
allowed.insert( 158 );
allowed.insert( 159 );
allowed.insert( 160 );
allowed.insert( 161 );
allowed.insert( 162 );
allowed.insert( 163 );
allowed.insert( 164 );
allowed.insert( 166 );
allowed.insert( 167 );
allowed.insert( 168 );
allowed.insert( 169 );
allowed.insert( 301 );
allowed.insert( 302 );
allowed.insert( 170 );
allowed.insert( 303 );
allowed.insert( 304 );
allowed.insert( 171 );
allowed.insert( 172 );
allowed.insert( 173 );
allowed.insert( 174 );
allowed.insert( 175 );
allowed.insert( 176 );

return allowed;
}
79 changes: 18 additions & 61 deletions src/common/gui/SkinSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,60 +196,8 @@ void SkinDB::rescanForSkins(SurgeStorage* storage)
} );
}

// see scripts/misc/idmap.pl if you want to regen this
std::unordered_map<std::string, int> createIdNameMap()
{
std::unordered_map<std::string, int> res;
res["BG"] = 102;
res["FADERV_BG"] = 105;
res["FILTERBUTTONS"] = 108;
res["OSCSWITCH"] = 110;
res["FBCONFIG"] = 112;
res["SCENESWITCH"] = 113;
res["SCENEMODE"] = 114;
res["OCTAVES_OSC"] = 117;
res["OCTAVES"] = 118;
res["OSCMENU"] = 119;
res["WAVESHAPER"] = 120;
res["RELATIVE_TOGGLE"] = 121;
res["OSCSELECT"] = 122;
res["POLYMODE"] = 123;
res["MODSRC_BG"] = 124;
res["SWITCH_KTRK"] = 125;
res["SWITCH_RETRIGGER"] = 126;
res["NUMBERS"] = 127;
res["MODSRC_SYMBOL"] = 128;
res["FADERH_LABELS"] = 131;
res["SWITCH_SOLO"] = 132;
res["SWITCH_FM"] = 133;
res["SWITCH_MUTE"] = 134;
res["CONF"] = 135;
res["FXCONF_SYMBOLS"] = 136;
res["FXCONF"] = 137;
res["SWITCH_TEMPOSYNC"] = 140;
res["SWITCH_LINK"] = 140;
res["VFADER_MINI_BG_BLACK"] = 141;
res["OSCROUTE"] = 143;
res["FXBYPASS"] = 144;
res["ENVSHAPE"] = 145;
res["LFOTRIGGER"] = 146;
res["BUTTON_STORE"] = 148;
res["BUTTON_MINUSPLUS"] = 149;
res["BUTTON_CHECK"] = 150;
res["FMCONFIG"] = 151;
res["UNIPOLAR"] = 152;
res["FADERH_HANDLE"] = 153;
res["FADERH_BG"] = 154;
res["FADERV_HANDLE"] = 157;
res["ABOUT"] = 158;
res["BUTTON_ABOUT"] = 159;
res["FILTERSUBTYPE"] = 160;
res["CHARACTER"] = 161;
res["ENVMODE"] = 162;
res["STOREPATCH"] = 163;
res["BUTTON_MENU"] = 164;
return res;
}
// Define the inverse maps
#include "SkinImageMaps.h"

std::atomic<int> Skin::instances( 0 );

Expand All @@ -260,7 +208,8 @@ Skin::Skin(const std::string &root, const std::string &name) : root(root), name(
#endif
instances++;
// std::cout << "Constructing a skin " << _D(root) << _D(name) << _D(instances) << std::endl;
imageIds = createIdNameMap();
imageStringToId = createIdNameMap();
imageAllowedIds = allowedImageIds();
}

Skin::~Skin()
Expand Down Expand Up @@ -453,11 +402,19 @@ bool Skin::reloadSkin(std::shared_ptr<SurgeBitmaps> bitmapStore)
for (const fs::path& d : fs::directory_iterator(source))
{
const auto pathStr = path_to_string(d);
const auto pos = pathStr.find("bmp00");
const auto pos = pathStr.find("bmp");
if (pos != std::string::npos)
{
auto postbmp = pathStr.substr(pos+3);
int idx = std::atoi(pathStr.c_str() + pos + 3);
bitmapStore->loadBitmapByPathForID(pathStr, idx);
// We epxpect 5 digits and a .svg or .png
auto xtn = pathStr.substr( pos + 8 );

if( ( xtn == ".svg" || xtn == ".png" ) &&
( imageAllowedIds.find(idx) != imageAllowedIds.end()))
{
bitmapStore->loadBitmapByPathForID(pathStr, idx);
}
}
else
{
Expand All @@ -484,8 +441,8 @@ bool Skin::reloadSkin(std::shared_ptr<SurgeBitmaps> bitmapStore)
{
if (id.size() > 0)
{
if( imageIds.find(id) != imageIds.end() )
bitmapStore->loadBitmapByPathForID(resourceName(res), imageIds[id]);
if( imageStringToId.find(id) != imageStringToId.end() )
bitmapStore->loadBitmapByPathForID(resourceName(res), imageStringToId[id]);
else
{
bitmapStore->loadBitmapByPathForStringID(resourceName(res), id );
Expand Down Expand Up @@ -527,8 +484,8 @@ bool Skin::reloadSkin(std::shared_ptr<SurgeBitmaps> bitmapStore)
else if( k.second["zoom-level"] == "100" )
{
auto res = k.second["resource"];
if( imageIds.find(id) != imageIds.end() )
bm = bitmapStore->loadBitmapByPathForID(resourceName(res), imageIds[id]);
if( imageStringToId.find(id) != imageStringToId.end() )
bm = bitmapStore->loadBitmapByPathForID(resourceName(res), imageStringToId[id]);
else
{
bm = bitmapStore->loadBitmapByPathForStringID(resourceName(res), id );
Expand Down
3 changes: 2 additions & 1 deletion src/common/gui/SkinSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ class Skin
ColorStore( std::string a, Type t ) : type( t ), alias( a ) { }
};
std::unordered_map<std::string, ColorStore> colors;
std::unordered_map<std::string, int> imageIds;
std::unordered_map<std::string, int> imageStringToId;
std::unordered_set<int> imageAllowedIds;
ControlGroup::ptr_t rootControl;
std::vector<Control::ptr_t> controls;
std::unordered_map<std::string, ComponentClass::ptr_t> componentClasses;
Expand Down