Skip to content

Commit

Permalink
fix: add read/write lock to property load/save
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Sep 28, 2023
1 parent 39392e0 commit 19b2b21
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Source/State/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ namespace zlstate {
}

void Property::loadAPVTS(juce::AudioProcessorValueTreeState &apvts) {
const juce::ScopedReadLock myScopedLock (readWriteLock);
auto file = uiFile->getFile();
if (auto xml = juce::XmlDocument::parse (file)) {
apvts.replaceState(juce::ValueTree::fromXml(*xml));
}
}

void Property::saveAPVTS(juce::AudioProcessorValueTreeState &apvts) {
const juce::ScopedWriteLock myScopedLock (readWriteLock);
auto file = uiFile->getFile();
if (auto xml = apvts.copyState().createXml()) {
xml->writeTo(file);
Expand Down
1 change: 1 addition & 0 deletions Source/State/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace zlstate {

private:
std::unique_ptr<juce::PropertiesFile> uiFile;
juce::ReadWriteLock readWriteLock;

inline auto static const path = juce::File::getSpecialLocation(juce::File::userApplicationDataDirectory).getFullPathName();
inline auto static const uiPath = path + "/Audio/Presets/" + JucePlugin_Manufacturer + "/" + JucePlugin_Name + "/ui.xml";
Expand Down

0 comments on commit 19b2b21

Please sign in to comment.