VCV Rack API v2
Loading...
Searching...
No Matches
Engine.hpp
Go to the documentation of this file.
1#pragma once
2#include <vector>
3
4#include <common.hpp>
5#include <engine/Module.hpp>
6#include <engine/Cable.hpp>
8
9
10namespace rack {
13namespace engine {
14
15
22struct Engine {
23 struct Internal;
24 Internal* internal;
25
28
32 void clear();
38 void stepBlock(int frames);
44 void setMasterModule(Module* module);
47
54 PRIVATE void setSampleRate(float sampleRate);
58 void setSuggestedSampleRate(float suggestedSampleRate);
68 int64_t getFrame();
71 int64_t getBlock();
74 int64_t getBlockFrame();
77 double getBlockTime();
88 double getMeterMax();
89
90 // Modules
91 size_t getNumModules();
97 size_t getModuleIds(int64_t* moduleIds, size_t len);
101 std::vector<int64_t> getModuleIds();
108 void addModule(Module* module);
113 void removeModule(Module* module);
118 bool hasModule(Module* module);
122 Module* getModule(int64_t moduleId);
123 Module* getModule_NoLock(int64_t moduleId);
127 void resetModule(Module* module);
131 void randomizeModule(Module* module);
135 void bypassModule(Module* module, bool bypassed);
139 json_t* moduleToJson(Module* module);
143 void moduleFromJson(Module* module, json_t* rootJ);
152
153 // Cables
154 size_t getNumCables();
160 size_t getCableIds(int64_t* cableIds, size_t len);
164 std::vector<int64_t> getCableIds();
171 void addCable(Cable* cable);
176 void removeCable(Cable* cable);
181 bool hasCable(Cable* cable);
185 Cable* getCable(int64_t cableId);
186
187 // Params
188 void setParamValue(Module* module, int paramId, float value);
189 float getParamValue(Module* module, int paramId);
192 void setParamSmoothValue(Module* module, int paramId, float value);
195 float getParamSmoothValue(Module* module, int paramId);
196
197 // ParamHandles
202 void addParamHandle(ParamHandle* paramHandle);
206 void removeParamHandle(ParamHandle* paramHandle);
211 ParamHandle* getParamHandle(int64_t moduleId, int paramId);
212 ParamHandle* getParamHandle_NoLock(int64_t moduleId, int paramId);
221 void updateParamHandle(ParamHandle* paramHandle, int64_t moduleId, int paramId, bool overwrite = true);
222 void updateParamHandle_NoLock(ParamHandle* paramHandle, int64_t moduleId, int paramId, bool overwrite = true);
223
227 json_t* toJson();
231 void fromJson(json_t* rootJ);
232
236};
237
238
239} // namespace engine
240} // namespace rack
#define PRIVATE
Attribute for private functions not intended to be called by plugins.
Definition common.hpp:32
#define DEPRECATED
Attribute for deprecated functions and symbols.
Definition common.hpp:26
Root namespace for the Rack API.
Definition AudioDisplay.hpp:9
Definition Cable.hpp:10
Manages Modules and Cables and steps them in time.
Definition Engine.hpp:22
void stepBlock(int frames)
Advances the engine by frames frames.
DEPRECATED ParamHandle * getParamHandle(Module *module, int paramId)
Use getParamHandle(moduleId, paramId) instead.
void addCable(Cable *cable)
Adds a Cable to the rack.
void prepareSaveModule(Module *module)
Dispatches Save event to a module.
void removeCable(Cable *cable)
Removes a Cable from the rack.
void moduleFromJson(Module *module, json_t *rootJ)
Serializes the given Module with locking, ensuring that Module::process() is not called simultaneousl...
PRIVATE void removeCable_NoLock(Cable *cable)
void yieldWorkers()
Causes worker threads to block on a mutex instead of spinlock.
double getBlockDuration()
Returns the total time that stepBlock() is advancing, in seconds.
Module * getModule_NoLock(int64_t moduleId)
float getParamSmoothValue(Module *module, int paramId)
Returns the target value before smoothing.
void addParamHandle(ParamHandle *paramHandle)
Adds a ParamHandle to the rack.
std::vector< int64_t > getCableIds()
Returns a vector of cable IDs in the rack.
int getBlockFrames()
Returns the number of frames requested by the last stepBlock() call.
bool hasModule(Module *module)
Checks whether a Module is in the rack.
void clear()
Removes all modules and cables.
size_t getCableIds(int64_t *cableIds, size_t len)
Fills cableIds with up to len cable IDs in the rack.
double getBlockTime()
Returns the time in seconds when stepBlock() was last called.
Internal * internal
Definition Engine.hpp:24
Module * getModule(int64_t moduleId)
Returns the Module with the given ID in the rack.
PRIVATE void addModule_NoLock(Module *module)
json_t * toJson()
Serializes the rack.
void setParamValue(Module *module, int paramId, float value)
Cable * getCable(int64_t cableId)
Returns the Cable with the given ID in the rack.
std::vector< int64_t > getModuleIds()
Returns a vector of module IDs in the rack.
size_t getModuleIds(int64_t *moduleIds, size_t len)
Fills moduleIds with up to len module IDs in the rack.
Module * getMasterModule()
void setMasterModule(Module *module)
Module does not need to belong to the Engine.
int64_t getFrame()
Returns the number of sample frames since the Engine was created.
PRIVATE void addCable_NoLock(Cable *cable)
float getSampleRate()
Returns the sample rate used by the engine for stepping each module.
int64_t getBlockFrame()
Returns the frame when stepBlock() was last called.
void updateParamHandle(ParamHandle *paramHandle, int64_t moduleId, int paramId, bool overwrite=true)
Sets the ParamHandle IDs and module pointer.
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)
void resetModule(Module *module)
Triggers a ResetEvent for the given Module.
float getSampleTime()
Returns the inverse of the current sample rate.
void addModule(Module *module)
Adds a Module to the rack.
PRIVATE void setSampleRate(float sampleRate)
Sets the sample rate to step the modules.
void removeParamHandle(ParamHandle *paramHandle)
Exclusively locks.
int64_t getBlock()
Returns the number of stepBlock() calls since the Engine was created.
PRIVATE void startFallbackThread()
If no master module is set, the fallback Engine thread will step blocks, using the CPU clock for timi...
void setParamSmoothValue(Module *module, int paramId, float value)
Requests the parameter to smoothly change toward value.
PRIVATE void clear_NoLock()
float getParamValue(Module *module, int paramId)
void removeModule(Module *module)
Removes a Module from the rack.
PRIVATE void removeModule_NoLock(Module *module)
void updateParamHandle_NoLock(ParamHandle *paramHandle, int64_t moduleId, int paramId, bool overwrite=true)
json_t * moduleToJson(Module *module)
Serializes the given Module with locking, ensuring that Module::process() is not called simultaneousl...
double getMeterAverage()
Returns the average block processing time divided by block time in the last T seconds.
void randomizeModule(Module *module)
Triggers a RandomizeEvent for the given Module.
void setMasterModule_NoLock(Module *module)
PRIVATE void removeParamHandle_NoLock(ParamHandle *paramHandle)
void setSuggestedSampleRate(float suggestedSampleRate)
Sets the sample rate if the sample rate in the settings is "Auto".
void prepareSave()
Dispatches Save event to all modules.
void bypassModule(Module *module, bool bypassed)
Sets the bypassed state and triggers a BypassEvent or UnBypassEvent of the given Module.
bool hasCable(Cable *cable)
Checks whether a Cable is in the rack.
void fromJson(json_t *rootJ)
Deserializes the rack.
DSP processor instance for your module.
Definition Module.hpp:29
A weak handle to a Param.
Definition ParamHandle.hpp:13