From d7aa204bc70f6296014a7cc6b4d253f7de6ea4a2 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 22 Nov 2021 00:12:43 -0500 Subject: [PATCH] Copy patch storage dir when cloning individual module. --- include/engine/Engine.hpp | 6 +++++- src/app/ModuleWidget.cpp | 8 ++++++++ src/engine/Engine.cpp | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/engine/Engine.hpp b/include/engine/Engine.hpp index 6ea5e4a0..cac81d5f 100644 --- a/include/engine/Engine.hpp +++ b/include/engine/Engine.hpp @@ -146,7 +146,11 @@ struct Engine { Write-locks. */ void moduleFromJson(Module* module, json_t* rootJ); - /** Dispatches Save event to all modules + /** Dispatches Save event to a module. + Read-locks. + */ + void prepareSaveModule(Module* module); + /** Dispatches Save event to all modules. Read-locks. */ void prepareSave(); diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 819b3f59..26a3b117 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -773,6 +773,9 @@ void ModuleWidget::cloneAction(bool cloneCables) { history::ComplexAction* h = new history::ComplexAction; h->name = "duplicate module"; + // Save patch store in this module so we can copy it below + APP->engine->prepareSaveModule(module); + // JSON serialization is the obvious way to do this json_t* moduleJ = toJson(); DEFER({ @@ -782,6 +785,11 @@ void ModuleWidget::cloneAction(bool cloneCables) { // Clone Module engine::Module* clonedModule = model->createModule(); + + // Set ID here so we can copy module storage dir + clonedModule->id = random::u64() % (1ull << 53); + system::copy(module->getPatchStorageDirectory(), clonedModule->getPatchStorageDirectory()); + // This doesn't need a lock (via Engine::moduleFromJson()) because the Module is not added to the Engine yet. try { clonedModule->fromJson(moduleJ); diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index 35693fef..d473fd61 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -947,6 +947,13 @@ void Engine::moduleFromJson(Module* module, json_t* rootJ) { } +void Engine::prepareSaveModule(Module* module) { + ReadLock lock(internal->mutex); + Module::SaveEvent e; + module->onSave(e); +} + + void Engine::prepareSave() { ReadLock lock(internal->mutex); for (Module* module : internal->modules) {