Browse Source

Add Engine meter to menu bar.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
ea431882a7
3 changed files with 66 additions and 7 deletions
  1. +4
    -0
      include/engine/Engine.hpp
  2. +22
    -1
      src/app/MenuBar.cpp
  3. +40
    -6
      src/engine/Engine.cpp

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

@@ -85,6 +85,10 @@ struct Engine {
Calculated by `stepFrames / sampleRate`. Calculated by `stepFrames / sampleRate`.
*/ */
double getBlockDuration(); double getBlockDuration();
/** Returns the average block processing time divided by block time in the last T seconds.
*/
double getMeterAverage();
double getMeterMax();


// Modules // Modules
size_t getNumModules(); size_t getNumModules();


+ 22
- 1
src/app/MenuBar.cpp View File

@@ -1057,14 +1057,25 @@ struct HelpButton : MenuButton {
// MenuBar // MenuBar
//////////////////// ////////////////////


struct MeterLabel : widget::OpaqueWidget {
void draw(const DrawArgs& args) override {
double meterAverage = APP->engine->getMeterAverage();
double meterMax = APP->engine->getMeterMax();
std::string text = string::f("%.1f%% avg / %.1f%% max", meterAverage * 100, meterMax * 100);
bndMenuLabel(args.vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str());
}
};



struct MenuBar : widget::OpaqueWidget { struct MenuBar : widget::OpaqueWidget {
MeterLabel* meterLabel;

MenuBar() { MenuBar() {
const float margin = 5; const float margin = 5;
box.size.y = BND_WIDGET_HEIGHT + 2 * margin; box.size.y = BND_WIDGET_HEIGHT + 2 * margin;


ui::SequentialLayout* layout = new ui::SequentialLayout; ui::SequentialLayout* layout = new ui::SequentialLayout;
layout->box.pos = math::Vec(margin, margin);
layout->margin = math::Vec(margin, margin);
layout->spacing = math::Vec(0, 0); layout->spacing = math::Vec(0, 0);
addChild(layout); addChild(layout);


@@ -1095,6 +1106,11 @@ struct MenuBar : widget::OpaqueWidget {
MenuButton* alphaButton = new MenuButton; MenuButton* alphaButton = new MenuButton;
alphaButton->text = "Pre-alpha build. Not for release."; alphaButton->text = "Pre-alpha build. Not for release.";
layout->addChild(alphaButton); layout->addChild(alphaButton);

meterLabel = new MeterLabel;
meterLabel->box.pos.y = margin;
meterLabel->box.size.x = 160;
addChild(meterLabel);
} }


void draw(const DrawArgs& args) override { void draw(const DrawArgs& args) override {
@@ -1103,6 +1119,11 @@ struct MenuBar : widget::OpaqueWidget {


Widget::draw(args); Widget::draw(args);
} }

void step() override {
meterLabel->box.pos.x = box.size.x - meterLabel->box.size.x;
Widget::step();
}
}; };






+ 40
- 6
src/engine/Engine.cpp View File

@@ -201,6 +201,7 @@ struct Engine::Internal {
std::vector<Module*> modules; std::vector<Module*> modules;
std::vector<Cable*> cables; std::vector<Cable*> cables;
std::set<ParamHandle*> paramHandles; std::set<ParamHandle*> paramHandles;
Module* primaryModule = NULL;


// moduleId // moduleId
std::map<int64_t, Module*> modulesCache; std::map<int64_t, Module*> modulesCache;
@@ -216,7 +217,14 @@ struct Engine::Internal {
int64_t blockFrame = 0; int64_t blockFrame = 0;
double blockTime = 0.0; double blockTime = 0.0;
int blockFrames = 0; int blockFrames = 0;
Module* primaryModule = NULL;

// Meter
int meterCount = 0;
double meterTotal = 0.0;
double meterMax = 0.0;
double meterLastTime = -INFINITY;
double meterLastAverage = 0.0;
double meterLastMax = 0.0;


// Parameter smoothing // Parameter smoothing
Module* smoothModule = NULL; Module* smoothModule = NULL;
@@ -516,6 +524,9 @@ void Engine::clear_NoLock() {




void Engine::stepBlock(int frames) { void Engine::stepBlock(int frames) {
// Start timer before locking
double startTime = system::getTime();

std::lock_guard<std::mutex> stepLock(internal->blockMutex); std::lock_guard<std::mutex> stepLock(internal->blockMutex);
ReadLock lock(internal->mutex); ReadLock lock(internal->mutex);
// Configure thread // Configure thread
@@ -542,12 +553,25 @@ void Engine::stepBlock(int frames) {


yieldWorkers(); yieldWorkers();


double endTime = system::getTime();
float duration = endTime - internal->blockTime;
float blockDuration = internal->blockFrames * internal->sampleTime;
// DEBUG("%d %f / %f = %f%%", internal->blockFrames, duration, blockDuration, duration / blockDuration * 100.f);

internal->block++; internal->block++;

// Stop timer
double endTime = system::getTime();
double meter = (endTime - startTime) / (frames * internal->sampleTime);
internal->meterTotal += meter;
internal->meterMax = std::fmax(internal->meterMax, meter);
internal->meterCount++;

// Update meter values
const double meterUpdateDuration = 1.0;
if (startTime - internal->meterLastTime >= meterUpdateDuration) {
internal->meterLastAverage = internal->meterTotal / internal->meterCount;
internal->meterLastMax = internal->meterMax;
internal->meterLastTime = startTime;
internal->meterCount = 0;
internal->meterTotal = 0.0;
internal->meterMax = 0.0;
}
} }




@@ -643,6 +667,16 @@ double Engine::getBlockDuration() {
} }




double Engine::getMeterAverage() {
return internal->meterLastAverage;
}


double Engine::getMeterMax() {
return internal->meterLastMax;
}


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


Loading…
Cancel
Save