Browse Source

Copy patch storage dir when cloning individual module.

tags/v2.0.0
Andrew Belt 2 years ago
parent
commit
d7aa204bc7
3 changed files with 20 additions and 1 deletions
  1. +5
    -1
      include/engine/Engine.hpp
  2. +8
    -0
      src/app/ModuleWidget.cpp
  3. +7
    -0
      src/engine/Engine.cpp

+ 5
- 1
include/engine/Engine.hpp View File

@@ -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();


+ 8
- 0
src/app/ModuleWidget.cpp View File

@@ -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);


+ 7
- 0
src/engine/Engine.cpp View File

@@ -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) {


Loading…
Cancel
Save