VCV Rack API v2
Loading...
Searching...
No Matches
rack::engine::Engine Struct Reference

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)
 
ModulegetMasterModule ()
 
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.
 
ModulegetModule (int64_t moduleId)
 Returns the Module with the given ID in the rack.
 
ModulegetModule_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.
 
CablegetCable (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)
 
ParamHandlegetParamHandle (int64_t moduleId, int paramId)
 Returns the unique ParamHandle for the given paramId Share-locks.
 
ParamHandlegetParamHandle_NoLock (int64_t moduleId, int paramId)
 
DEPRECATED ParamHandlegetParamHandle (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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Engine()

PRIVATE rack::engine::Engine::Engine ( )

◆ ~Engine()

PRIVATE rack::engine::Engine::~Engine ( )

Member Function Documentation

◆ clear()

void rack::engine::Engine::clear ( )

Removes all modules and cables.

Exclusively locks.

◆ clear_NoLock()

PRIVATE void rack::engine::Engine::clear_NoLock ( )

◆ stepBlock()

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.

◆ setMasterModule()

void rack::engine::Engine::setMasterModule ( Module * module)

Module does not need to belong to the Engine.

However, Engine will unset the master module when it is removed from the Engine. NULL will unset the master module. Exclusively locks.

◆ setMasterModule_NoLock()

void rack::engine::Engine::setMasterModule_NoLock ( Module * module)

◆ getMasterModule()

Module * rack::engine::Engine::getMasterModule ( )

◆ getSampleRate()

float rack::engine::Engine::getSampleRate ( )

Returns the sample rate used by the engine for stepping each module.

◆ setSampleRate()

PRIVATE void rack::engine::Engine::setSampleRate ( float sampleRate)

Sets the sample rate to step the modules.

Exclusively locks.

◆ setSuggestedSampleRate()

void rack::engine::Engine::setSuggestedSampleRate ( float suggestedSampleRate)

Sets the sample rate if the sample rate in the settings is "Auto".

Exclusively locks.

◆ getSampleTime()

float rack::engine::Engine::getSampleTime ( )

Returns the inverse of the current sample rate.

◆ yieldWorkers()

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.

◆ getFrame()

int64_t rack::engine::Engine::getFrame ( )

Returns the number of sample frames since the Engine was created.

◆ getBlock()

int64_t rack::engine::Engine::getBlock ( )

Returns the number of stepBlock() calls since the Engine was created.

◆ getBlockFrame()

int64_t rack::engine::Engine::getBlockFrame ( )

Returns the frame when stepBlock() was last called.

◆ getBlockTime()

double rack::engine::Engine::getBlockTime ( )

Returns the time in seconds when stepBlock() was last called.

◆ getBlockFrames()

int rack::engine::Engine::getBlockFrames ( )

Returns the number of frames requested by the last stepBlock() call.

◆ getBlockDuration()

double rack::engine::Engine::getBlockDuration ( )

Returns the total time that stepBlock() is advancing, in seconds.

Calculated by blockFrames / sampleRate.

◆ getMeterAverage()

double rack::engine::Engine::getMeterAverage ( )

Returns the average block processing time divided by block time in the last T seconds.

◆ getMeterMax()

double rack::engine::Engine::getMeterMax ( )

◆ getNumModules()

size_t rack::engine::Engine::getNumModules ( )

◆ getModuleIds() [1/2]

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.

◆ getModuleIds() [2/2]

std::vector< int64_t > rack::engine::Engine::getModuleIds ( )

Returns a vector of module IDs in the rack.

Share-locks.

◆ addModule()

void rack::engine::Engine::addModule ( Module * module)

Adds a Module to the rack.

The module ID must not be taken by another Module. If the module ID is -1, an ID is automatically assigned. Does not transfer pointer ownership. Exclusively locks.

◆ addModule_NoLock()

PRIVATE void rack::engine::Engine::addModule_NoLock ( Module * module)

◆ removeModule()

void rack::engine::Engine::removeModule ( Module * module)

Removes a Module from the rack.

Exclusively locks.

◆ removeModule_NoLock()

PRIVATE void rack::engine::Engine::removeModule_NoLock ( Module * module)

◆ hasModule()

bool rack::engine::Engine::hasModule ( Module * module)

Checks whether a Module is in the rack.

Share-locks.

◆ getModule()

Module * rack::engine::Engine::getModule ( int64_t moduleId)

Returns the Module with the given ID in the rack.

Share-locks.

◆ getModule_NoLock()

Module * rack::engine::Engine::getModule_NoLock ( int64_t moduleId)

◆ resetModule()

void rack::engine::Engine::resetModule ( Module * module)

Triggers a ResetEvent for the given Module.

Exclusively locks.

◆ randomizeModule()

void rack::engine::Engine::randomizeModule ( Module * module)

Triggers a RandomizeEvent for the given Module.

Exclusively locks.

◆ bypassModule()

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.

◆ moduleToJson()

json_t * rack::engine::Engine::moduleToJson ( Module * module)

Serializes the given Module with locking, ensuring that Module::process() is not called simultaneously.

Share-locks.

◆ moduleFromJson()

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.

◆ prepareSaveModule()

void rack::engine::Engine::prepareSaveModule ( Module * module)

Dispatches Save event to a module.

Share-locks.

◆ prepareSave()

void rack::engine::Engine::prepareSave ( )

Dispatches Save event to all modules.

Share-locks.

◆ getNumCables()

size_t rack::engine::Engine::getNumCables ( )

◆ getCableIds() [1/2]

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.

◆ getCableIds() [2/2]

std::vector< int64_t > rack::engine::Engine::getCableIds ( )

Returns a vector of cable IDs in the rack.

Share-locks.

◆ addCable()

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.

◆ addCable_NoLock()

PRIVATE void rack::engine::Engine::addCable_NoLock ( Cable * cable)

◆ removeCable()

void rack::engine::Engine::removeCable ( Cable * cable)

Removes a Cable from the rack.

Exclusively locks.

◆ removeCable_NoLock()

PRIVATE void rack::engine::Engine::removeCable_NoLock ( Cable * cable)

◆ hasCable()

bool rack::engine::Engine::hasCable ( Cable * cable)

Checks whether a Cable is in the rack.

Share-locks.

◆ getCable()

Cable * rack::engine::Engine::getCable ( int64_t cableId)

Returns the Cable with the given ID in the rack.

Share-locks.

◆ setParamValue()

void rack::engine::Engine::setParamValue ( Module * module,
int paramId,
float value )

◆ getParamValue()

float rack::engine::Engine::getParamValue ( Module * module,
int paramId )

◆ setParamSmoothValue()

void rack::engine::Engine::setParamSmoothValue ( Module * module,
int paramId,
float value )

Requests the parameter to smoothly change toward value.

◆ getParamSmoothValue()

float rack::engine::Engine::getParamSmoothValue ( Module * module,
int paramId )

Returns the target value before smoothing.

◆ addParamHandle()

void rack::engine::Engine::addParamHandle ( ParamHandle * paramHandle)

Adds a ParamHandle to the rack.

Does not automatically update the ParamHandle. Exclusively locks.

◆ removeParamHandle()

void rack::engine::Engine::removeParamHandle ( ParamHandle * paramHandle)

Exclusively locks.

◆ removeParamHandle_NoLock()

PRIVATE void rack::engine::Engine::removeParamHandle_NoLock ( ParamHandle * paramHandle)

◆ getParamHandle() [1/2]

ParamHandle * rack::engine::Engine::getParamHandle ( int64_t moduleId,
int paramId )

Returns the unique ParamHandle for the given paramId Share-locks.

◆ getParamHandle_NoLock()

ParamHandle * rack::engine::Engine::getParamHandle_NoLock ( int64_t moduleId,
int paramId )

◆ getParamHandle() [2/2]

DEPRECATED ParamHandle * rack::engine::Engine::getParamHandle ( Module * module,
int paramId )

Use getParamHandle(moduleId, paramId) instead.

Share-locks.

◆ updateParamHandle()

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.

◆ updateParamHandle_NoLock()

void rack::engine::Engine::updateParamHandle_NoLock ( ParamHandle * paramHandle,
int64_t moduleId,
int paramId,
bool overwrite = true )

◆ toJson()

json_t * rack::engine::Engine::toJson ( )

Serializes the rack.

Share-locks.

◆ fromJson()

void rack::engine::Engine::fromJson ( json_t * rootJ)

Deserializes the rack.

Exclusively locks.

◆ startFallbackThread()

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.

Member Data Documentation

◆ internal

Internal* rack::engine::Engine::internal

The documentation for this struct was generated from the following file: