VCV Rack API v2
|
Manages Modules and Cables and steps them in time. More...
#include <Engine.hpp>
Public Member Functions | |
PRIVATE | Engine () |
PRIVATE | ~Engine () |
void | clear () |
Removes all modules and cables. | |
PRIVATE void | clear_NoLock () |
void | stepBlock (int frames) |
Advances the engine by frames frames. | |
void | setMasterModule (Module *module) |
Module does not need to belong to the Engine. | |
void | setMasterModule_NoLock (Module *module) |
Module * | getMasterModule () |
float | getSampleRate () |
Returns the sample rate used by the engine for stepping each module. | |
PRIVATE void | setSampleRate (float sampleRate) |
Sets the sample rate to step the modules. | |
void | setSuggestedSampleRate (float suggestedSampleRate) |
Sets the sample rate if the sample rate in the settings is "Auto". | |
float | getSampleTime () |
Returns the inverse of the current sample rate. | |
void | yieldWorkers () |
Causes worker threads to block on a mutex instead of spinlock. | |
int64_t | getFrame () |
Returns the number of sample frames since the Engine was created. | |
int64_t | getBlock () |
Returns the number of stepBlock() calls since the Engine was created. | |
int64_t | getBlockFrame () |
Returns the frame when stepBlock() was last called. | |
double | getBlockTime () |
Returns the time in seconds when stepBlock() was last called. | |
int | getBlockFrames () |
Returns the number of frames requested by the last stepBlock() call. | |
double | getBlockDuration () |
Returns the total time that stepBlock() is advancing, in seconds. | |
double | getMeterAverage () |
Returns the average block processing time divided by block time in the last T seconds. | |
double | getMeterMax () |
size_t | getNumModules () |
size_t | getModuleIds (int64_t *moduleIds, size_t len) |
Fills moduleIds with up to len module IDs in the rack. | |
std::vector< int64_t > | getModuleIds () |
Returns a vector of module IDs in the rack. | |
void | addModule (Module *module) |
Adds a Module to the rack. | |
PRIVATE void | addModule_NoLock (Module *module) |
void | removeModule (Module *module) |
Removes a Module from the rack. | |
PRIVATE void | removeModule_NoLock (Module *module) |
bool | hasModule (Module *module) |
Checks whether a Module is in the rack. | |
Module * | getModule (int64_t moduleId) |
Returns the Module with the given ID in the rack. | |
Module * | getModule_NoLock (int64_t moduleId) |
void | resetModule (Module *module) |
Triggers a ResetEvent for the given Module. | |
void | randomizeModule (Module *module) |
Triggers a RandomizeEvent for the given Module. | |
void | bypassModule (Module *module, bool bypassed) |
Sets the bypassed state and triggers a BypassEvent or UnBypassEvent of the given Module. | |
json_t * | moduleToJson (Module *module) |
Serializes the given Module with locking, ensuring that Module::process() is not called simultaneously. | |
void | moduleFromJson (Module *module, json_t *rootJ) |
Serializes the given Module with locking, ensuring that Module::process() is not called simultaneously. | |
void | prepareSaveModule (Module *module) |
Dispatches Save event to a module. | |
void | prepareSave () |
Dispatches Save event to all modules. | |
size_t | getNumCables () |
size_t | getCableIds (int64_t *cableIds, size_t len) |
Fills cableIds with up to len cable IDs in the rack. | |
std::vector< int64_t > | getCableIds () |
Returns a vector of cable IDs in the rack. | |
void | addCable (Cable *cable) |
Adds a Cable to the rack. | |
PRIVATE void | addCable_NoLock (Cable *cable) |
void | removeCable (Cable *cable) |
Removes a Cable from the rack. | |
PRIVATE void | removeCable_NoLock (Cable *cable) |
bool | hasCable (Cable *cable) |
Checks whether a Cable is in the rack. | |
Cable * | getCable (int64_t cableId) |
Returns the Cable with the given ID in the rack. | |
void | setParamValue (Module *module, int paramId, float value) |
float | getParamValue (Module *module, int paramId) |
void | setParamSmoothValue (Module *module, int paramId, float value) |
Requests the parameter to smoothly change toward value . | |
float | getParamSmoothValue (Module *module, int paramId) |
Returns the target value before smoothing. | |
void | addParamHandle (ParamHandle *paramHandle) |
Adds a ParamHandle to the rack. | |
void | removeParamHandle (ParamHandle *paramHandle) |
Exclusively locks. | |
PRIVATE void | removeParamHandle_NoLock (ParamHandle *paramHandle) |
ParamHandle * | getParamHandle (int64_t moduleId, int paramId) |
Returns the unique ParamHandle for the given paramId Share-locks. | |
ParamHandle * | getParamHandle_NoLock (int64_t moduleId, int paramId) |
DEPRECATED ParamHandle * | getParamHandle (Module *module, int paramId) |
Use getParamHandle(moduleId, paramId) instead. | |
void | updateParamHandle (ParamHandle *paramHandle, int64_t moduleId, int paramId, bool overwrite=true) |
Sets the ParamHandle IDs and module pointer. | |
void | updateParamHandle_NoLock (ParamHandle *paramHandle, int64_t moduleId, int paramId, bool overwrite=true) |
json_t * | toJson () |
Serializes the rack. | |
void | fromJson (json_t *rootJ) |
Deserializes the rack. | |
PRIVATE void | startFallbackThread () |
If no master module is set, the fallback Engine thread will step blocks, using the CPU clock for timing. | |
Public Attributes | |
Internal * | internal |
Manages Modules and Cables and steps them in time.
Engine contains a shared mutex that locks when the Engine state is being read or written (manipulated). Methods that share-lock (stated in their documentation) can be called simultaneously with other share-locking methods. Methods that exclusively lock cannot be called simultaneously or recursively with another share-locking or exclusive-locking method.
PRIVATE rack::engine::Engine::Engine | ( | ) |
PRIVATE rack::engine::Engine::~Engine | ( | ) |
void rack::engine::Engine::clear | ( | ) |
Removes all modules and cables.
Exclusively locks.
PRIVATE void rack::engine::Engine::clear_NoLock | ( | ) |
void rack::engine::Engine::stepBlock | ( | int | frames | ) |
Advances the engine by frames
frames.
Only call this method from the master module. Share-locks. Also locks so only one stepBlock() can be called simultaneously or recursively.
void rack::engine::Engine::setMasterModule | ( | Module * | module | ) |
void rack::engine::Engine::setMasterModule_NoLock | ( | Module * | module | ) |
Module * rack::engine::Engine::getMasterModule | ( | ) |
float rack::engine::Engine::getSampleRate | ( | ) |
Returns the sample rate used by the engine for stepping each module.
PRIVATE void rack::engine::Engine::setSampleRate | ( | float | sampleRate | ) |
Sets the sample rate to step the modules.
Exclusively locks.
void rack::engine::Engine::setSuggestedSampleRate | ( | float | suggestedSampleRate | ) |
Sets the sample rate if the sample rate in the settings is "Auto".
Exclusively locks.
float rack::engine::Engine::getSampleTime | ( | ) |
Returns the inverse of the current sample rate.
void rack::engine::Engine::yieldWorkers | ( | ) |
Causes worker threads to block on a mutex instead of spinlock.
Call this in your Module::stepBlock() method to hint that the operation will take more than ~0.1 ms.
int64_t rack::engine::Engine::getFrame | ( | ) |
Returns the number of sample frames since the Engine was created.
int64_t rack::engine::Engine::getBlock | ( | ) |
Returns the number of stepBlock() calls since the Engine was created.
int64_t rack::engine::Engine::getBlockFrame | ( | ) |
Returns the frame when stepBlock() was last called.
double rack::engine::Engine::getBlockTime | ( | ) |
Returns the time in seconds when stepBlock() was last called.
int rack::engine::Engine::getBlockFrames | ( | ) |
Returns the number of frames requested by the last stepBlock() call.
double rack::engine::Engine::getBlockDuration | ( | ) |
Returns the total time that stepBlock() is advancing, in seconds.
Calculated by blockFrames / sampleRate
.
double rack::engine::Engine::getMeterAverage | ( | ) |
Returns the average block processing time divided by block time in the last T seconds.
double rack::engine::Engine::getMeterMax | ( | ) |
size_t rack::engine::Engine::getNumModules | ( | ) |
size_t rack::engine::Engine::getModuleIds | ( | int64_t * | moduleIds, |
size_t | len ) |
Fills moduleIds
with up to len
module IDs in the rack.
Returns the number of IDs written. This C-like method does no allocations. The vector C++ version below does. Share-locks.
std::vector< int64_t > rack::engine::Engine::getModuleIds | ( | ) |
Returns a vector of module IDs in the rack.
Share-locks.
void rack::engine::Engine::addModule | ( | Module * | module | ) |
void rack::engine::Engine::removeModule | ( | Module * | module | ) |
Removes a Module from the rack.
Exclusively locks.
bool rack::engine::Engine::hasModule | ( | Module * | module | ) |
Checks whether a Module is in the rack.
Share-locks.
Module * rack::engine::Engine::getModule | ( | int64_t | moduleId | ) |
Returns the Module with the given ID in the rack.
Share-locks.
Module * rack::engine::Engine::getModule_NoLock | ( | int64_t | moduleId | ) |
void rack::engine::Engine::resetModule | ( | Module * | module | ) |
Triggers a ResetEvent for the given Module.
Exclusively locks.
void rack::engine::Engine::randomizeModule | ( | Module * | module | ) |
Triggers a RandomizeEvent for the given Module.
Exclusively locks.
void rack::engine::Engine::bypassModule | ( | Module * | module, |
bool | bypassed ) |
Sets the bypassed state and triggers a BypassEvent or UnBypassEvent of the given Module.
Exclusively locks.
json_t * rack::engine::Engine::moduleToJson | ( | Module * | module | ) |
Serializes the given Module with locking, ensuring that Module::process() is not called simultaneously.
Share-locks.
void rack::engine::Engine::moduleFromJson | ( | Module * | module, |
json_t * | rootJ ) |
Serializes the given Module with locking, ensuring that Module::process() is not called simultaneously.
Exclusively locks.
void rack::engine::Engine::prepareSaveModule | ( | Module * | module | ) |
Dispatches Save event to a module.
Share-locks.
void rack::engine::Engine::prepareSave | ( | ) |
Dispatches Save event to all modules.
Share-locks.
size_t rack::engine::Engine::getNumCables | ( | ) |
size_t rack::engine::Engine::getCableIds | ( | int64_t * | cableIds, |
size_t | len ) |
Fills cableIds
with up to len
cable IDs in the rack.
Returns the number of IDs written. This C-like method does no allocations. The vector C++ version below does. Share-locks.
std::vector< int64_t > rack::engine::Engine::getCableIds | ( | ) |
Returns a vector of cable IDs in the rack.
Share-locks.
void rack::engine::Engine::addCable | ( | Cable * | cable | ) |
Adds a Cable to the rack.
The cable ID must not be taken by another cable. If the cable ID is -1, an ID is automatically assigned. Does not transfer pointer ownership. Exclusively locks.
void rack::engine::Engine::removeCable | ( | Cable * | cable | ) |
Removes a Cable from the rack.
Exclusively locks.
bool rack::engine::Engine::hasCable | ( | Cable * | cable | ) |
Checks whether a Cable is in the rack.
Share-locks.
Cable * rack::engine::Engine::getCable | ( | int64_t | cableId | ) |
Returns the Cable with the given ID in the rack.
Share-locks.
void rack::engine::Engine::setParamValue | ( | Module * | module, |
int | paramId, | ||
float | value ) |
float rack::engine::Engine::getParamValue | ( | Module * | module, |
int | paramId ) |
void rack::engine::Engine::setParamSmoothValue | ( | Module * | module, |
int | paramId, | ||
float | value ) |
Requests the parameter to smoothly change toward value
.
float rack::engine::Engine::getParamSmoothValue | ( | Module * | module, |
int | paramId ) |
Returns the target value before smoothing.
void rack::engine::Engine::addParamHandle | ( | ParamHandle * | paramHandle | ) |
Adds a ParamHandle to the rack.
Does not automatically update the ParamHandle. Exclusively locks.
void rack::engine::Engine::removeParamHandle | ( | ParamHandle * | paramHandle | ) |
Exclusively locks.
PRIVATE void rack::engine::Engine::removeParamHandle_NoLock | ( | ParamHandle * | paramHandle | ) |
ParamHandle * rack::engine::Engine::getParamHandle | ( | int64_t | moduleId, |
int | paramId ) |
Returns the unique ParamHandle for the given paramId Share-locks.
ParamHandle * rack::engine::Engine::getParamHandle_NoLock | ( | int64_t | moduleId, |
int | paramId ) |
DEPRECATED ParamHandle * rack::engine::Engine::getParamHandle | ( | Module * | module, |
int | paramId ) |
Use getParamHandle(moduleId, paramId) instead.
Share-locks.
void rack::engine::Engine::updateParamHandle | ( | ParamHandle * | paramHandle, |
int64_t | moduleId, | ||
int | paramId, | ||
bool | overwrite = true ) |
Sets the ParamHandle IDs and module pointer.
If overwrite
is true and another ParamHandle points to the same param, unsets that one and replaces it with the given handle. Exclusively locks.
void rack::engine::Engine::updateParamHandle_NoLock | ( | ParamHandle * | paramHandle, |
int64_t | moduleId, | ||
int | paramId, | ||
bool | overwrite = true ) |
json_t * rack::engine::Engine::toJson | ( | ) |
Serializes the rack.
Share-locks.
void rack::engine::Engine::fromJson | ( | json_t * | rootJ | ) |
Deserializes the rack.
Exclusively locks.
PRIVATE void rack::engine::Engine::startFallbackThread | ( | ) |
If no master module is set, the fallback Engine thread will step blocks, using the CPU clock for timing.
Internal* rack::engine::Engine::internal |