Browse Source

Add Engine::getNumModules() and getModuleIds() methods.

tags/v2.0.0
Andrew Belt 4 years ago
parent
commit
b8d47b5378
2 changed files with 31 additions and 0 deletions
  1. +3
    -0
      include/engine/Engine.hpp
  2. +28
    -0
      src/engine/Engine.cpp

+ 3
- 0
include/engine/Engine.hpp View File

@@ -58,6 +58,9 @@ struct Engine {
int getStepFrames(); int getStepFrames();


// Modules // Modules
size_t getNumModules();
void getModuleIds(int* moduleIds, int len);
std::vector<int> getModuleIds();
/** Adds a module to the rack engine. /** Adds a module to the rack engine.
The module ID must not be taken by another module. The module ID must not be taken by another module.
If the module ID is -1, an ID is automatically assigned. If the module ID is -1, an ID is automatically assigned.


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

@@ -559,6 +559,34 @@ int Engine::getStepFrames() {
} }




size_t Engine::getNumModules() {
return internal->modules.size();
}


void Engine::getModuleIds(int* moduleIds, int len) {
SharedLock lock(internal->mutex);
int i = 0;
for (Module* m : internal->modules) {
if (i >= len)
break;
moduleIds[i] = m->id;
i++;
}
}


std::vector<int> Engine::getModuleIds() {
SharedLock lock(internal->mutex);
std::vector<int> moduleIds;
moduleIds.reserve(internal->modules.size());
for (Module* m : internal->modules) {
moduleIds.push_back(m->id);
}
return moduleIds;
}


void Engine::addModule(Module* module) { void Engine::addModule(Module* module) {
ExclusiveSharedLock lock(internal->mutex); ExclusiveSharedLock lock(internal->mutex);
assert(module); assert(module);


Loading…
Cancel
Save