commit fff6f5d849fdef87b69f1e5d1896f5d828d2f251
parent 77f894468b59b37c62c7b071d44170c82de6e07d
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Fri, 3 May 2024 00:28:42 +0200
fix possible issue of patch modifications losing modifications because of dirty cache
Diffstat:
4 files changed, 24 insertions(+), 25 deletions(-)
diff --git a/source/jucePluginLib/patchdb/datasource.cpp b/source/jucePluginLib/patchdb/datasource.cpp
@@ -4,6 +4,7 @@
#include <sstream>
#include <memory>
+#include "db.h"
#include "patch.h"
#include "patchmodifications.h"
@@ -191,11 +192,8 @@ namespace pluginLib::patchDB
if(!patch->read(in))
return false;
- if(patch->modifications)
- {
- patch->modifications->patch = patch;
- patch->modifications->updateCache();
- }
+ DB::assign(patch, patch->modifications);
+
patches.insert(patch);
}
diff --git a/source/jucePluginLib/patchdb/db.cpp b/source/jucePluginLib/patchdb/db.cpp
@@ -81,6 +81,16 @@ namespace pluginLib::patchDB
return true;
}
+ void DB::assign(const PatchPtr& _patch, const PatchModificationsPtr& _mods)
+ {
+ if(!_patch || !_mods)
+ return;
+
+ _patch->modifications = _mods;
+ _mods->patch = _patch;
+ _mods->updateCache();
+ }
+
DataSourceNodePtr DB::addDataSource(const DataSource& _ds, const bool _save)
{
const auto needsSave = _save && _ds.origin == DataSourceOrigin::Manual && _ds.type != SourceType::Rom;
@@ -582,8 +592,7 @@ namespace pluginLib::patchDB
if(!mods)
{
mods = std::make_shared<PatchModifications>();
- mods->patch = patch;
- patch->modifications = mods;
+ assign(patch, mods);
}
if (!mods->modifyTags(_tags))
@@ -624,14 +633,11 @@ namespace pluginLib::patchDB
if(!mods)
{
mods = std::make_shared<PatchModifications>();
- mods->patch = _patch;
- _patch->modifications = mods;
+ assign(_patch, mods);
}
mods->name = _name;
- mods->updateCache();
-
updateSearches({_patch});
}
@@ -914,12 +920,10 @@ namespace pluginLib::patchDB
const auto itMod = m_patchModifications.find(key);
if (itMod != m_patchModifications.end())
{
- patch->modifications = itMod->second;
+ auto mods = itMod->second;
+ assign(patch, mods);
m_patchModifications.erase(itMod);
-
- patch->modifications->patch = patch;
- patch->modifications->updateCache();
}
// add to all known categories, tags, etc
@@ -960,6 +964,7 @@ namespace pluginLib::patchDB
if(mods && !mods->empty())
{
mods->patch.reset();
+ mods->updateCache();
m_patchModifications.insert({PatchKey(*_patch), mods});
}
@@ -1361,10 +1366,7 @@ namespace pluginLib::patchDB
const auto it = patchModifications.find(key);
if(it != patchModifications.end())
{
- patch->modifications = it->second;
- patch->modifications->patch = patch;
- patch->modifications->updateCache();
-
+ assign(patch, it->second);
patchModifications.erase(it);
if(patchModifications.empty())
@@ -1848,8 +1850,7 @@ namespace pluginLib::patchDB
if(*patch != key)
continue;
- patch->modifications = mods;
- mods->patch = patch;
+ assign(patch, mods);
}
}
}
diff --git a/source/jucePluginLib/patchdb/db.h b/source/jucePluginLib/patchdb/db.h
@@ -77,6 +77,8 @@ namespace pluginLib::patchDB
bool writePatchesToFile(const juce::File& _file, const std::vector<PatchPtr>& _patches);
+ static void assign(const PatchPtr& _patch, const PatchModificationsPtr& _mods);
+
protected:
DataSourceNodePtr addDataSource(const DataSource& _ds, bool _save);
diff --git a/source/jucePluginLib/patchdb/patch.cpp b/source/jucePluginLib/patchdb/patch.cpp
@@ -3,6 +3,7 @@
#include <cassert>
#include <sstream>
+#include "db.h"
#include "patchmodifications.h"
#include "serialization.h"
@@ -29,10 +30,7 @@ namespace pluginLib::patchDB
newMods = std::make_shared<PatchModifications>(*mods);
if(newMods)
- {
- p->modifications = newMods;
- newMods->patch = p;
- }
+ DB::assign(p, newMods);
return { p, newMods };
}