diff --git a/include/engine/Engine.hpp b/include/engine/Engine.hpp index 1679ec28..a9db9f6c 100644 --- a/include/engine/Engine.hpp +++ b/include/engine/Engine.hpp @@ -29,6 +29,7 @@ struct Engine { Call this in your Module::step() method to hint that the operation will take more than ~0.1 ms. */ void yieldWorkers(); + uint64_t getFrame(); // Modules /** Adds a module to the rack engine. diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index 907470d2..a16d5a01 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -178,6 +178,7 @@ struct Engine::Internal { bool running = false; float sampleRate; float sampleTime; + uint64_t frame = 0; int nextModuleId = 0; int nextCableId = 0; @@ -333,6 +334,8 @@ static void Engine_step(Engine *that) { internal->engineBarrier.wait(); Engine_stepModules(that, 0); internal->workerBarrier.wait(); + + internal->frame++; } static void Engine_updateExpander(Engine *that, Module::Expander *expander) { @@ -388,6 +391,7 @@ static void Engine_run(Engine *that) { // system::setThreadRealTime(); disableDenormals(); + internal->frame = 0; // Every time the that waits and locks a mutex, it steps this many frames const int mutexSteps = 128; // Time in seconds that the that is rushing ahead of the estimated clock time @@ -486,6 +490,10 @@ void Engine::yieldWorkers() { internal->workerBarrier.yield = true; } +uint64_t Engine::getFrame() { + return internal->frame; +} + void Engine::addModule(Module *module) { assert(module); VIPLock vipLock(internal->vipMutex);