Skip to content

Commit

Permalink
Surge runs without a factory directory (#4833)
Browse files Browse the repository at this point in the history
If the factory directory is set to /Flargl/Blargl surge will
start with an empty skin (no hovers etc...) and have one and
only one wavetable (sin to saw) but will work and be usable.

Closes #4398
  • Loading branch information
baconpaul authored Aug 12, 2021
1 parent 435950c commit 6c7438b
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 31 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ juce_add_binary_data(surge-shared-binary
SOURCES
resources/data/configuration.xml
resources/surge-xt/README_UserArea.txt
resources/surge-xt/memoryWavetable.wt
resources/data/windows.wt
resources/data/paramdocumentation.xml)

Expand Down Expand Up @@ -885,6 +886,7 @@ if( BUILD_SURGE_XT )
resources/fonts/Lato*ttf
resources/fonts/IndieFlower.ttf
resources/fonts/FiraMono-Regular.ttf
resources/surge-xt/memory-skin.xml
)

juce_add_binary_data( surge-xt-binary
Expand Down
8 changes: 8 additions & 0 deletions resources/surge-xt/memory-skin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<surge-skin name="In Memory Fallback Skin" category="Tutorial" author="Surge Synth Team" authorURL="https://surge-synth-team.org/" version="2">
<globals>
</globals>
<component-classes>
</component-classes>
<controls>
</controls>
</surge-skin>
Binary file added resources/surge-xt/memoryWavetable.wt
Binary file not shown.
11 changes: 11 additions & 0 deletions src/common/SurgeStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,10 +976,12 @@ void SurgeStorage::refresh_wtlist()

if (wt_category.size() == 0 || wt_list.size() == 0)
{
/*
std::ostringstream ss;
ss << "Surge was unable to load wavetables from '" << datapath
<< "'. Please reinstall Surge!";
reportError(ss.str(), "Surge Installation Error");
*/
}

firstThirdPartyWTCategory = wt_category.size();
Expand Down Expand Up @@ -1106,6 +1108,15 @@ void SurgeStorage::load_wt(int id, Wavetable *wt, OscillatorStorage *osc)
{
wt->current_id = id;
wt->queue_id = -1;
if (wt_list.empty() && id == 0)
{
load_wt_wt_mem(SurgeCoreBinary::memoryWavetable_wt, SurgeCoreBinary::memoryWavetable_wtSize,
wt);
if (osc)
strncpy(osc->wavetable_display_name, "Sin to Saw", TXT_SIZE);

return;
}
if (id < 0)
return;
if (id >= wt_list.size())
Expand Down
78 changes: 53 additions & 25 deletions src/gui/SkinSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <set>
#include <iostream>
#include <iomanip>
#include "BinaryData.h"

namespace Surge
{
Expand Down Expand Up @@ -61,11 +62,11 @@ std::shared_ptr<Skin> SkinDB::defaultSkin(SurgeStorage *storage)
else
{
auto st = (Entry::RootType)(Surge::Storage::getUserDefaultValue(
storage, Surge::Storage::DefaultSkinRootType, Entry::UNKNOWN));
storage, Surge::Storage::DefaultSkinRootType, UNKNOWN));

for (auto e : availableSkins)
{
if (e.name == uds && (e.rootType == st || st == Entry::UNKNOWN))
if (e.name == uds && (e.rootType == st || st == UNKNOWN))
return getSkin(e);
}
return getSkin(defaultSkinEntry);
Expand All @@ -76,7 +77,14 @@ std::shared_ptr<Skin> SkinDB::getSkin(const Entry &skinEntry)
{
if (skins.find(skinEntry) == skins.end())
{
skins[skinEntry] = std::make_shared<Skin>(skinEntry.root, skinEntry.name);
if (skinEntry.rootType == MEMORY)
{
skins[skinEntry] = std::make_shared<Skin>(true);
}
else
{
skins[skinEntry] = std::make_shared<Skin>(skinEntry.root, skinEntry.name);
}
}
return skins[skinEntry];
}
Expand All @@ -93,11 +101,11 @@ void SkinDB::rescanForSkins(SurgeStorage *storage)

for (auto &source : paths)
{
Entry::RootType rt = Entry::UNKNOWN;
Entry::RootType rt = UNKNOWN;
if (path_to_string(source) == path_to_string(paths[0]))
rt = Entry::FACTORY;
rt = FACTORY;
if (path_to_string(source) == path_to_string(paths[1]))
rt = Entry::USER;
rt = USER;

std::vector<fs::path> alldirs;
std::deque<fs::path> workStack;
Expand Down Expand Up @@ -153,8 +161,8 @@ void SkinDB::rescanForSkins(SurgeStorage *storage)
e.rootType = rt;
e.root = path;
e.name = lo + sep;
if (e.name.find("default.surge-skin") != std::string::npos &&
rt == Entry::FACTORY && defaultSkinEntry.name == "")
if (e.name.find("default.surge-skin") != std::string::npos && rt == FACTORY &&
defaultSkinEntry.name == "")
{
defaultSkinEntry = e;
foundDefaultSkinEntry = true;
Expand All @@ -166,13 +174,14 @@ void SkinDB::rescanForSkins(SurgeStorage *storage)
}
if (!foundDefaultSkinEntry)
{
std::ostringstream oss;
oss << "Surge Classic skin was not located. This usually means Surge is incorrectly "
"installed or uses an incompatible "
<< "set of resources. Surge looked in '" << storage->datapath << "' and '"
<< storage->userDataPath << "'. "
<< "Please reinstall Surge or remove incompatible resources.";
storage->reportError(oss.str(), "Skin Loading Error");
auto memSkin = Entry();
memSkin.rootType = MEMORY;
memSkin.name = "In Memory Default";
memSkin.displayName = "In Memory Default";
memSkin.category = "";
memSkin.root = "";
availableSkins.push_back(memSkin);
defaultSkinEntry = memSkin;
}

// Run over the skins parsing the name
Expand Down Expand Up @@ -235,6 +244,17 @@ Skin::Skin(const std::string &root, const std::string &name) : root(root), name(
imageAllowedIds = allowedImageIds();
}

Skin::Skin(bool inMemory)
{
if (!inMemory)
std::cout << "SOFTWARE ERROR" << std::endl;
instances++;
// std::cout << "Constructing a skin " << _D(root) << _D(name) << _D(instances) << std::endl;
imageStringToId = createIdNameMap();
imageAllowedIds = allowedImageIds();
useInMemorySkin = true;
}

Skin::~Skin()
{
#ifdef INSTRUMENT_UI
Expand All @@ -255,17 +275,25 @@ bool Skin::reloadSkin(std::shared_ptr<SurgeImageStore> bitmapStore)
#endif
// std::cout << "Reloading skin " << _D(name) << std::endl;
TiXmlDocument doc;
// Obviously fix this
doc.SetTabSize(4);

if (!doc.LoadFile(string_to_path(resourceName("skin.xml"))))
if (useInMemorySkin)
{
FIXMEERROR << "Unable to load skin.xml resource '" << resourceName("skin.xml") << "'"
<< std::endl;
FIXMEERROR << "Unable to parse skin.xml\nError is:\n"
<< doc.ErrorDesc() << " at row " << doc.ErrorRow() << ", column "
<< doc.ErrorCol() << std::endl;
return false;
auto memSkin = std::string(BinaryData::memoryskin_xml, BinaryData::memoryskin_xmlSize);
doc.Parse(memSkin.c_str());
}
else
{
// Obviously fix this
doc.SetTabSize(4);

if (!doc.LoadFile(string_to_path(resourceName("skin.xml"))))
{
FIXMEERROR << "Unable to load skin.xml resource '" << resourceName("skin.xml") << "'"
<< std::endl;
FIXMEERROR << "Unable to parse skin.xml\nError is:\n"
<< doc.ErrorDesc() << " at row " << doc.ErrorRow() << ", column "
<< doc.ErrorCol() << std::endl;
return false;
}
}

TiXmlElement *surgeskin = TINYXML_SAFE_TO_ELEMENT(doc.FirstChild("surge-skin"));
Expand Down
19 changes: 13 additions & 6 deletions src/gui/SkinSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ void loadTypefacesFromPath(const fs::path &p,
extern const std::string NoneClassName;
class SkinDB;

enum RootType
{
UNKNOWN,
FACTORY,
USER,
MEMORY
};

class Skin
{
public:
Expand All @@ -95,8 +103,11 @@ class Skin
friend class SkinDB;

Skin(const std::string &root, const std::string &name);
Skin(bool inMemory);
~Skin();

bool useInMemorySkin{false};

bool reloadSkin(std::shared_ptr<SurgeImageStore> bitmapStore);

std::string resourceName(const std::string &relativeName)
Expand Down Expand Up @@ -400,13 +411,9 @@ class SkinDB : public juce::DeletedAtShutdown

struct Entry
{
using RootType = Surge::GUI::RootType;

enum RootType
{
UNKNOWN,
FACTORY,
USER
} rootType = UNKNOWN;
RootType rootType = UNKNOWN;

std::string root;
std::string name;
Expand Down

0 comments on commit 6c7438b

Please sign in to comment.