| @@ -14,9 +14,8 @@ namespace engine { | |||||
| /** Manages Modules and Cables and steps them in time. | /** Manages Modules and Cables and steps them in time. | ||||
| All methods are thread-safe and can safely be called from anywhere. | All methods are thread-safe and can safely be called from anywhere. | ||||
| The methods clear, addModule, removeModule, moduleToJson, moduleFromJson, addCable, removeCable, addParamHandle, removeParamHandle, toJson, and fromJson cannot be run simultaneously with any other Engine method. | |||||
| Calling these methods inside any Engine method will result in a deadlock. | |||||
| However, the following methods obtain a write-lock, so they cannot be called with the engine thread (e.g. inside Module::process()): | |||||
| clear, stepBlock, setPrimaryModule, setSampleRate, addModule, removeModule, resetModule, randomizeModule, bypassModule, moduleFromJson, addCable, removeCable, addParamHandle, removeParamHandle, and fromJson | |||||
| */ | */ | ||||
| struct Engine { | struct Engine { | ||||
| struct Internal; | struct Internal; | ||||
| @@ -31,7 +30,10 @@ struct Engine { | |||||
| Only call this method from the primary module. | Only call this method from the primary module. | ||||
| */ | */ | ||||
| void stepBlock(int frames); | void stepBlock(int frames); | ||||
| /** */ | |||||
| /** Module does not need to belong to the Engine. | |||||
| However, Engine will unset the primary module when it is removed from the Engine. | |||||
| NULL will unset the primary module. | |||||
| */ | |||||
| void setPrimaryModule(Module* module); | void setPrimaryModule(Module* module); | ||||
| Module* getPrimaryModule(); | Module* getPrimaryModule(); | ||||
| @@ -196,10 +196,9 @@ struct AudioInterface : Module, audio::Port { | |||||
| if (audioJ) | if (audioJ) | ||||
| audio::Port::fromJson(audioJ); | audio::Port::fromJson(audioJ); | ||||
| // TODO | |||||
| // json_t* primaryJ = json_object_get(rootJ, "primary"); | |||||
| // if (primaryJ) | |||||
| // setPrimary(); | |||||
| json_t* primaryJ = json_object_get(rootJ, "primary"); | |||||
| if (primaryJ) | |||||
| setPrimary(); | |||||
| } | } | ||||
| /** Must be called when the Engine mutex is unlocked. | /** Must be called when the Engine mutex is unlocked. | ||||
| @@ -215,9 +214,6 @@ struct AudioInterface : Module, audio::Port { | |||||
| // audio::Port | // audio::Port | ||||
| void processInput(const float* input, int inputStride, int frames) override { | void processInput(const float* input, int inputStride, int frames) override { | ||||
| if (!APP->engine->hasModule(this)) | |||||
| return; | |||||
| // Claim primary module if there is none | // Claim primary module if there is none | ||||
| if (!APP->engine->getPrimaryModule()) { | if (!APP->engine->getPrimaryModule()) { | ||||
| setPrimary(); | setPrimary(); | ||||
| @@ -7,7 +7,6 @@ | |||||
| #include <tuple> | #include <tuple> | ||||
| #include <pmmintrin.h> | #include <pmmintrin.h> | ||||
| #include <pthread.h> | #include <pthread.h> | ||||
| #include <unistd.h> | |||||
| #include <engine/Engine.hpp> | #include <engine/Engine.hpp> | ||||
| #include <settings.hpp> | #include <settings.hpp> | ||||
| @@ -566,13 +565,6 @@ void Engine::stepBlock(int frames) { | |||||
| void Engine::setPrimaryModule(Module* module) { | void Engine::setPrimaryModule(Module* module) { | ||||
| WriteLock lock(internal->mutex); | WriteLock lock(internal->mutex); | ||||
| // Don't allow module to be set if not added to the Engine. | |||||
| // NULL will unset the primary module. | |||||
| if (module) { | |||||
| auto it = std::find(internal->modules.begin(), internal->modules.end(), module); | |||||
| if (it == internal->modules.end()) | |||||
| throw Exception("Module being set as primary does not belong to Engine"); | |||||
| } | |||||
| internal->primaryModule = module; | internal->primaryModule = module; | ||||
| } | } | ||||
| @@ -752,8 +744,9 @@ void Engine::removeModule(Module* module) { | |||||
| Module::RemoveEvent eRemove; | Module::RemoveEvent eRemove; | ||||
| module->onRemove(eRemove); | module->onRemove(eRemove); | ||||
| // Unset primary module | // Unset primary module | ||||
| if (internal->primaryModule == module) | |||||
| if (internal->primaryModule == module) { | |||||
| internal->primaryModule = NULL; | internal->primaryModule = NULL; | ||||
| } | |||||
| // Remove module | // Remove module | ||||
| internal->modulesCache.erase(module->id); | internal->modulesCache.erase(module->id); | ||||
| internal->modules.erase(it); | internal->modules.erase(it); | ||||
| @@ -1115,8 +1108,6 @@ void Engine::fromJson(json_t* rootJ) { | |||||
| module->id = moduleIndex; | module->id = moduleIndex; | ||||
| } | } | ||||
| sleep(1); | |||||
| // This write-locks | // This write-locks | ||||
| addModule(module); | addModule(module); | ||||
| } | } | ||||