gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

commit 1f17a918aaed43cd9e285336aa0a0bfd3ab1be32
parent ca6a44e536fed9f185d475c031993234d61e4d33
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Sat,  2 Nov 2024 21:47:18 +0100

migrate patch manager DB to new data folder

Diffstat:
Msource/jucePluginEditorLib/patchmanager/patchmanager.cpp | 23+++++++++++++++--------
Msource/jucePluginEditorLib/patchmanager/patchmanager.h | 2++
Msource/jucePluginLib/patchdb/db.cpp | 50++++++++++++++++++++++++++++++++++++++++++++++----
Msource/jucePluginLib/patchdb/db.h | 2+-
Msource/jucePluginLib/processor.cpp | 5+++++
Msource/jucePluginLib/processor.h | 1+
6 files changed, 70 insertions(+), 13 deletions(-)

diff --git a/source/jucePluginEditorLib/patchmanager/patchmanager.cpp b/source/jucePluginEditorLib/patchmanager/patchmanager.cpp @@ -28,14 +28,10 @@ namespace jucePluginEditorLib::patchManager constexpr auto g_searchBarHeight = 32; constexpr int g_padding = 4; - juce::File initRootDirectory(const Editor& _editor) - { - const auto configOptions = _editor.getProcessor().getConfigOptions(); - const auto dir = configOptions.getDefaultFile().getParentDirectory(); - return dir; - } - - PatchManager::PatchManager(Editor& _editor, Component* _root, const std::initializer_list<GroupType>& _groupTypes) : DB(initRootDirectory(_editor)), m_editor(_editor), m_state(*this) + PatchManager::PatchManager(Editor& _editor, Component* _root, const std::initializer_list<GroupType>& _groupTypes) + : DB(juce::File(_editor.getProcessor().getPatchManagerDataFolder(false))) + , m_editor(_editor) + , m_state(*this) { setTagTypeName(pluginLib::patchDB::TagType::Category, "Category"); setTagTypeName(pluginLib::patchDB::TagType::Tag, "Tag"); @@ -886,6 +882,17 @@ namespace jucePluginEditorLib::patchManager return m_grid; } + void PatchManager::startLoaderThread(const juce::File& _migrateFromDir/* = {}*/) + { + if(_migrateFromDir.getFullPathName().isEmpty()) + { + const auto& configOptions = m_editor.getProcessor().getConfigOptions(); + DB::startLoaderThread(configOptions.getDefaultFile().getParentDirectory()); + return; + } + DB::startLoaderThread(_migrateFromDir); + } + pluginLib::patchDB::SearchHandle PatchManager::getSearchHandle(const pluginLib::patchDB::DataSource& _ds, bool _selectTreeItem) { if(auto* item = m_treeDS->getItem(_ds)) diff --git a/source/jucePluginEditorLib/patchmanager/patchmanager.h b/source/jucePluginEditorLib/patchmanager/patchmanager.h @@ -142,6 +142,8 @@ namespace jucePluginEditorLib::patchManager ListModel* getListModel() const; + void startLoaderThread(const juce::File& _migrateFromDir = {}) override; + private: pluginLib::patchDB::SearchHandle getSearchHandle(const pluginLib::patchDB::DataSource& _ds, bool _selectTreeItem); void onSelectedItemsChanged(); diff --git a/source/jucePluginLib/patchdb/db.cpp b/source/jucePluginLib/patchdb/db.cpp @@ -812,14 +812,49 @@ namespace pluginLib::patchDB return synthLib::MidiToSysex::extractSysexFromData(_results, _data); } - void DB::startLoaderThread() + void DB::startLoaderThread(const juce::File& _migrateFromDir/* = {}*/) { m_loader.start(); - runOnLoaderThread([this] + runOnLoaderThread([this, _migrateFromDir] { if(!g_cacheEnabled || !loadCache()) - loadJson(); + { + if(!loadJson()) + { + if(_migrateFromDir.isDirectory()) + { + m_settingsDir.createDirectory(); + + std::vector<std::string> files; + synthLib::getDirectoryEntries(files, _migrateFromDir.getFullPathName().toStdString()); + + std::vector<juce::File> toBeDeleted; + + for (const auto& file : files) + { + if( !synthLib::hasExtension(file, ".json") && + !synthLib::hasExtension(file, ".syx") && + !synthLib::hasExtension(file, ".cache")) + continue; + + juce::File fileFrom(file); + juce::File fileTo(m_settingsDir.getChildFile(fileFrom.getFileName())); + + if(!fileFrom.copyFileTo(fileTo)) + return; + + toBeDeleted.push_back(fileFrom); + } + + if(loadJson()) + { + for (auto& f : toBeDeleted) + f.deleteFile(); + } + } + } + } }); } @@ -1295,7 +1330,12 @@ namespace pluginLib::patchDB { bool success = true; - const auto json = juce::JSON::parse(getJsonFile()); + const auto jsonFile = getJsonFile(); + + if(!jsonFile.existsAsFile()) + return false; + + const auto json = juce::JSON::parse(jsonFile); const auto* datasources = json["datasources"].getArray(); if(datasources) @@ -1479,6 +1519,8 @@ namespace pluginLib::patchDB const auto cacheFile = getCacheFile(); const auto jsonFile = getJsonFile(); + jsonFile.createDirectory(); + cacheFile.deleteFile(); if (!jsonFile.hasWriteAccess()) diff --git a/source/jucePluginLib/patchdb/db.h b/source/jucePluginLib/patchdb/db.h @@ -107,7 +107,7 @@ namespace pluginLib::patchDB protected: virtual void onLoadFinished() {} - void startLoaderThread(); + virtual void startLoaderThread(const juce::File& _migrateFromDir = {}); void stopLoaderThread(); void runOnLoaderThread(std::function<void()>&& _func); diff --git a/source/jucePluginLib/processor.cpp b/source/jucePluginLib/processor.cpp @@ -353,6 +353,11 @@ namespace pluginLib return synthLib::validatePath(getDataFolder(_useFxFolder) + "config/"); } + std::string Processor::getPatchManagerDataFolder(bool _useFxFolder) const + { + return synthLib::validatePath(getDataFolder(_useFxFolder) + "patchmanagerDb/"); + } + std::string Processor::getConfigFile(const bool _useFxFolder) const { return getConfigFolder(_useFxFolder) + getProductName(_useFxFolder) + ".xml"; diff --git a/source/jucePluginLib/processor.h b/source/jucePluginLib/processor.h @@ -125,6 +125,7 @@ namespace pluginLib std::string getDataFolder(bool _useFxFolder = false) const; std::string getPublicRomFolder() const; std::string getConfigFolder(bool _useFxFolder = false) const; + std::string getPatchManagerDataFolder(bool _useFxFolder = false) const; std::string getConfigFile(bool _useFxFolder = false) const; std::string getProductName(bool _useFxName = false) const;