Browse Source

No longer require that a primary Module belongs to the Engine.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
2f5ce16ce8
3 changed files with 11 additions and 22 deletions
  1. +6
    -4
      include/engine/Engine.hpp
  2. +3
    -7
      src/core/AudioInterface.cpp
  3. +2
    -11
      src/engine/Engine.cpp

+ 6
- 4
include/engine/Engine.hpp View File

@@ -14,9 +14,8 @@ namespace engine {
/** Manages Modules and Cables and steps them in time.

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 Internal;
@@ -31,7 +30,10 @@ struct Engine {
Only call this method from the primary module.
*/
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);
Module* getPrimaryModule();



+ 3
- 7
src/core/AudioInterface.cpp View File

@@ -196,10 +196,9 @@ struct AudioInterface : Module, audio::Port {
if (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.
@@ -215,9 +214,6 @@ struct AudioInterface : Module, audio::Port {
// audio::Port

void processInput(const float* input, int inputStride, int frames) override {
if (!APP->engine->hasModule(this))
return;

// Claim primary module if there is none
if (!APP->engine->getPrimaryModule()) {
setPrimary();


+ 2
- 11
src/engine/Engine.cpp View File

@@ -7,7 +7,6 @@
#include <tuple>
#include <pmmintrin.h>
#include <pthread.h>
#include <unistd.h>

#include <engine/Engine.hpp>
#include <settings.hpp>
@@ -566,13 +565,6 @@ void Engine::stepBlock(int frames) {

void Engine::setPrimaryModule(Module* module) {
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;
}

@@ -752,8 +744,9 @@ void Engine::removeModule(Module* module) {
Module::RemoveEvent eRemove;
module->onRemove(eRemove);
// Unset primary module
if (internal->primaryModule == module)
if (internal->primaryModule == module) {
internal->primaryModule = NULL;
}
// Remove module
internal->modulesCache.erase(module->id);
internal->modules.erase(it);
@@ -1115,8 +1108,6 @@ void Engine::fromJson(json_t* rootJ) {
module->id = moduleIndex;
}

sleep(1);

// This write-locks
addModule(module);
}


Loading…
Cancel
Save