Skip to content

Commit

Permalink
Internal datastructures for Positions (#1677)
Browse files Browse the repository at this point in the history
Modify the XML, the XML generator, and the internal data structures
to allow per-control class and position controls along with a simple
inheritance hierarchy. At this point, do nothing with those data structures
other than run over a commented out cout in SurgeGUIEditor.

Along the road to #1625
  • Loading branch information
baconpaul authored Mar 30, 2020
1 parent 82cb81a commit a2c43bb
Show file tree
Hide file tree
Showing 6 changed files with 347 additions and 1,270 deletions.
652 changes: 169 additions & 483 deletions resources/data/skins/dark-mode.surge-skin/skin.xml

Large diffs are not rendered by default.

285 changes: 0 additions & 285 deletions resources/data/skins/default.surge-skin/SVG/background.svg

This file was deleted.

487 changes: 3 additions & 484 deletions resources/data/skins/default.surge-skin/skin.xml

Large diffs are not rendered by default.

67 changes: 64 additions & 3 deletions src/common/gui/SkinSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,24 @@ void Skin::reloadSkin(std::shared_ptr<SurgeBitmaps> bitmapStore)
displayName = name;
author = "";
authorURL = "";
if (a = surgeskin->Attribute("name"))
if ( (a = surgeskin->Attribute("name") ) )
displayName = a;
if (a = surgeskin->Attribute("author"))
if ( (a = surgeskin->Attribute("author") ) )
author = a;
if (a = surgeskin->Attribute("authorURL"))
if ( ( a = surgeskin->Attribute("authorURL") ) )
authorURL = a;

auto globalsxml = TINYXML_SAFE_TO_ELEMENT(surgeskin->FirstChild("globals"));
auto componentclassesxml = TINYXML_SAFE_TO_ELEMENT(surgeskin->FirstChild("component-classes"));
auto controlsxml = TINYXML_SAFE_TO_ELEMENT(surgeskin->FirstChild("controls"));
if (!globalsxml)
{
FIXMEERROR << "surge-skin contains no globals element" << std::endl;
}
if(!componentclassesxml)
{
FIXMEERROR << "surge-skin contains no component-classes element" << std::endl;
}
if (!controlsxml)
{
FIXMEERROR << "surge-skin contains no controls element" << std::endl;
Expand Down Expand Up @@ -297,6 +302,13 @@ void Skin::reloadSkin(std::shared_ptr<SurgeBitmaps> bitmapStore)
return std::atoi(av);
};

auto attrstr = [](TiXmlElement *e, const char* a ) {
const char* av = e->Attribute(a);
if( !av )
return std::string();
return std::string( av );
};

for (auto gchild = controlsxml->FirstChild(); gchild; gchild = gchild->NextSibling())
{
auto lkid = TINYXML_SAFE_TO_ELEMENT(gchild);
Expand All @@ -318,9 +330,58 @@ void Skin::reloadSkin(std::shared_ptr<SurgeBitmaps> bitmapStore)
c.posy = attrint(lkid, "posy");
c.posy_offset = attrint(lkid, "posy_offset");

c.classname = attrstr(lkid, "class" );
if( lkid->Attribute( "tag_value" ) )
{
c.type = Control::Type::ENUM;
c.enum_id = attrint( lkid, "tag_value" );
c.enum_name = attrstr( lkid, "tag_name" );
}
else
{
c.type = Control::Type::UIID;
c.ui_id = attrstr( lkid, "ui_identifier" );
}

for (auto a = lkid->FirstAttribute(); a; a = a->Next())
c.allprops[a->Name()] = a->Value();

controls.push_back(c);
}

// TODO: add component-classes section
for (auto gchild = componentclassesxml->FirstChild(); gchild; gchild = gchild->NextSibling())
{
auto lkid = TINYXML_SAFE_TO_ELEMENT(gchild);
if (!lkid)
continue;

if (std::string(lkid->Value()) != "class")
{
FIXMEERROR << "INVALID CLASS" << std::endl;
continue;
}

Skin::ComponentClass c;

c.name = attrstr( lkid, "name" );
if( c.name == "" )
{
FIXMEERROR << "INVALUD NAME" << std::endl;
}

if( componentClasses.find( c.name ) != componentClasses.end() )
{
FIXMEERROR << "Double Definition" << std::endl;
}

for (auto a = lkid->FirstAttribute(); a; a = a->Next())
c.allprops[a->Name()] = a->Value();

componentClasses[c.name] = c;

};

// process the images
for (auto g : globals)
{
Expand Down
27 changes: 25 additions & 2 deletions src/common/gui/SkinSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <unordered_set>
#include <memory>
#include <atomic>
#include <iostream>

#include "vstgui/lib/ccolor.h"

Expand Down Expand Up @@ -63,24 +64,45 @@ class Skin
std::string displayName;
std::string author;
std::string authorURL;

struct ComponentClass
{
std::string name;
props_t allprops;
};

struct Control
{
int x, y, w, h, posx, posy, posy_offset;

int enum_id;
std::string ui_id;
std::string ui_id, enum_name;
typedef enum {
ENUM,
UIID
} Type;
Type type;
props_t instance_info;
std::string classname;
props_t allprops;
};

bool hasColor( std::string id );
VSTGUI::CColor getColor( std::string id, const VSTGUI::CColor &def, std::unordered_set<std::string> noLoops = std::unordered_set<std::string>() );
std::unordered_set<std::string> getQueriedColors() { return queried_colors; }

bool controlForUIID( std::string ui_id, Skin::Control &c ) {
// FIXME don't be stupid like this of course
for( auto ic : controls )
{
if( ic.type == Control::Type::UIID && ic.ui_id == ui_id )
{
c = ic;
return true;
}
}

return false;
}

private:
static std::atomic<int> instances;
Expand All @@ -104,6 +126,7 @@ class Skin
std::unordered_set<std::string> queried_colors;
std::unordered_map<std::string, int> imageIds;
std::vector<Control> controls;
std::unordered_map<std::string, ComponentClass> componentClasses;
};

class SkinDB
Expand Down
99 changes: 86 additions & 13 deletions src/common/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,59 @@ enum special_tags
start_paramtags,
};

std::string specialTagToString( special_tags t )
{
if( t >= tag_mod_source0 && t <= tag_mod_source_end )
{
modsources modsource = (modsources)(t - tag_mod_source0);
std::string s = std::string( "tag_modsource" ) + modsource_abberations_short[modsource];
return s;
}

switch( t ) {
case tag_scene_select:
return "tag_scene_select";
case tag_osc_select:
return "tag_osc_select";
case tag_osc_menu:
return "tag_osc_menu";
case tag_fx_select:
return "tag_fx_select";
case tag_fx_menu:
return "tag_fx_menu";
case tag_patchname:
return "tag_patchname";
case tag_statuspanel:
return "tag_statuspanel";
case tag_mp_category:
return "tag_mp_category";
case tag_mp_patch:
return "tag_mp_patch";
case tag_store:
return "tag_store";
case tag_store_cancel:
return "tag_store_cancel";
case tag_store_ok:
return "tag_store_ok";
case tag_store_name:
return "tag_store_name";
case tag_store_category:
return "tag_store_category";
case tag_store_creator:
return "tag_store_creator";
case tag_store_comments:
return "tag_store_comments";
case tag_store_tuning:
return "tag_store_tuning";
case tag_settingsmenu:
return "tag_store_settingsmenu";
default:
return "ERROR";
}
return "ERROR";

}

SurgeGUIEditor::SurgeGUIEditor(void* effect, SurgeSynthesizer* synth, void* userdata) : super(effect)
{
frame = 0;
Expand Down Expand Up @@ -923,6 +976,13 @@ void SurgeGUIEditor::openOrRecreateEditor()
{
Parameter* p = *iter;

std::string uiid = p->ui_identifier;
Surge::UI::Skin::Control c;
if( currentSkin->controlForUIID(uiid, c) )
{
// std::cout << "Was able to get a control for the uiid '" << c.ui_id << "' class is '" << c.classname << "'" << std::endl;
}

if ((p->posx != 0) && ((p->scene == (current_scene + 1)) || (p->scene == 0)) &&
isControlVisible(p->ctrlgroup, p->ctrlgroup_entry) && (p->ctrltype != ct_none))
{
Expand Down Expand Up @@ -3875,22 +3935,23 @@ VSTGUI::COptionMenu *SurgeGUIEditor::makeDevMenu(VSTGUI::CRect &menuRect)
{
oss << "ui_identifier=\"" << p->ui_identifier << "\"";
}
else if( c->getTag() >= tag_scene_select && c->getTag() < start_paramtags )
{
oss << "tag_value=\"" << c->getTag() << "\" tag_name=\"" << specialTagToString( (special_tags)(c->getTag()) ) << "\"";
}
else
{
oss << "enum_value=\"" << c->getTag() << "\"";
oss << "special=\"true\" ";
}
auto vs = c->getViewSize();
oss << " x=\"" << vs.top << "\" y=\"" << vs.left
oss << " x=\"" << vs.left << "\" y=\"" << vs.top
<< "\" w=\"" << vs.getWidth() << "\" h=\"" << vs.getHeight() << "\"";

if( p )
oss << " posx=\"" << p->posx << "\" "
<< " posy=\"" << p->posy << "\" "
<< " posy_offset=\"" << p->posy_offset << "\" ";

oss << ">\n";
oss << " <instance ";

auto dumpBG = [&oss](CControl *a) {
auto bg = a->getBackground();
auto rd = bg->getResourceDescription();
Expand All @@ -3910,15 +3971,20 @@ VSTGUI::COptionMenu *SurgeGUIEditor::makeDevMenu(VSTGUI::CRect &menuRect)
}
else if( auto a = dynamic_cast<CSurgeSlider *>(c) )
{
oss << " class=\"CSurgeSlider\" ";
if( p->ctrlstyle & Surge::ParamConfig::kHorizontal )
oss << " orientation=\"horizontal\" ";
else
oss << " orientation=\"vertical\" ";
if( p->ctrlstyle & kWhite )
oss << " color=\"light\" ";
{
if( p->ctrlstyle & kWhite )
oss << " class=\"light-hslider\"";
else
oss << " class=\"dark-hslider\"";
}
else
oss << " color=\"dark\" ";
{
if( p->ctrlstyle & kWhite )
oss << " class=\"light-vslider\"";
else
oss << " class=\"dark-vslider\"";
}

}
else if( auto a = dynamic_cast<CSwitchControl *>(c) )
Expand Down Expand Up @@ -3964,7 +4030,6 @@ VSTGUI::COptionMenu *SurgeGUIEditor::makeDevMenu(VSTGUI::CRect &menuRect)
oss << "rtti_class=\"" << typeid(*c).name() << "\" tag=\"" << tag << "\" ";
}
oss << "/>\n";
oss << " </control>" << std::endl;
}
else
{
Expand All @@ -3978,6 +4043,14 @@ VSTGUI::COptionMenu *SurgeGUIEditor::makeDevMenu(VSTGUI::CRect &menuRect)
oss << "<surge-layout>\n";
oss << " <globals>\n";
oss << " </globals\n";

oss << " <component-classes>\n";
oss << " <class name=\"dark-vslider\" parent=\"CSurgeSlider\" orientation=\"vertical\" white=\"false\"/>\n";
oss << " <class name=\"light-vslider\" parent=\"CSurgeSlider\" orientation=\"vertical\" white=\"true\"/>\n";
oss << " <class name=\"dark-hslider\" parent=\"CSurgeSlider\" orientation=\"horizontal\" white=\"false\"/>\n";
oss << " <class name=\"light-hslider\" parent=\"CSurgeSlider\" orientation=\"horizontal\" white=\"true\"/>\n";
oss << " </component-classes>\n\n";

oss << " <controls>\n";
while( ! stk.empty() )
{
Expand Down

0 comments on commit a2c43bb

Please sign in to comment.