From 7b0ce9740609cfc492f4de69f2986d7254c5d06c Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 25 Sep 2019 06:01:23 -0400 Subject: [PATCH] Add Engine > Frame rate menu bar item. --- CHANGELOG.md | 7 ++++--- src/app/MenuBar.cpp | 28 ++++++++++++++++++++++++++++ src/app/Scene.cpp | 5 ----- src/window.cpp | 8 ++++---- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ca14cfe..787ab181 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,13 +4,14 @@ In this document, Mod is Ctrl on Windows/Linux and Cmd on Mac. ### 1.1.5 (in development) - Swap order of tags and brands in Module Browser. -- Disable smoothing for MIDI CC buttons in MIDI-Map. -- Automatically unzip update on Mac. -- Stop worker threads when engine is paused to save CPU. +- Add Engine > Frame rate menu bar item. - Hide menu and scrollbars when fullscreen. - Add key command (F3) for engine CPU meter. - Add numpad key commands. +- Automatically unzip update on Mac. +- Stop worker threads when engine is paused to save CPU. - Core + - Disable smoothing for MIDI CC buttons in MIDI-Map. - Fix sustain pedal release bug when using polyphonic mode in MIDI-CV. - API - Add libsamplerate library. diff --git a/src/app/MenuBar.cpp b/src/app/MenuBar.cpp index 5b7292cb..3ac41eef 100644 --- a/src/app/MenuBar.cpp +++ b/src/app/MenuBar.cpp @@ -327,6 +327,30 @@ struct CursorLockItem : ui::MenuItem { } }; +struct FrameRateValueItem : ui::MenuItem { + int frameSwapInterval; + void onAction(const event::Action& e) override { + settings::frameSwapInterval = frameSwapInterval; + } +}; + +struct FrameRateItem : ui::MenuItem { + ui::Menu* createChildMenu() override { + ui::Menu* menu = new ui::Menu; + + for (int i = 1; i <= 6; i++) { + float frameRate = 60.f / i; + + FrameRateValueItem* item = new FrameRateValueItem; + item->frameSwapInterval = i; + item->text = string::f("%.0f Hz", frameRate); + item->rightText += CHECKMARK(settings::frameSwapInterval == i); + menu->addChild(item); + } + return menu; + } +}; + struct FullscreenItem : ui::MenuItem { void onAction(const event::Action& e) override { APP->window->setFullScreen(!APP->window->isFullScreen()); @@ -366,6 +390,10 @@ struct ViewButton : MenuButton { cableTensionSlider->box.size.x = 200.0; menu->addChild(cableTensionSlider); + FrameRateItem* frameRateItem = new FrameRateItem; + frameRateItem->text = "Frame rate"; + menu->addChild(frameRateItem); + FullscreenItem* fullscreenItem = new FullscreenItem; fullscreenItem->text = "Fullscreen"; fullscreenItem->rightText = "F11"; diff --git a/src/app/Scene.cpp b/src/app/Scene.cpp index 25fc7d2e..add47c34 100644 --- a/src/app/Scene.cpp +++ b/src/app/Scene.cpp @@ -56,11 +56,6 @@ void Scene::step() { void Scene::draw(const DrawArgs& args) { Widget::draw(args); - - // nvgBeginPath(args.vg); - // nvgRect(args.vg, 0, 0, box.size.x, box.size.y); - // nvgFillColor(args.vg, color::mult(color::WHITE, APP->window->frame % 2)); - // nvgFill(args.vg); } void Scene::onHoverKey(const event::HoverKey& e) { diff --git a/src/window.cpp b/src/window.cpp index c40fa126..d58b198d 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -325,7 +325,10 @@ Window::~Window() { void Window::run() { frame = 0; while (!glfwWindowShouldClose(win)) { - frameTimeStart = glfwGetTime(); + double frameTime = glfwGetTime(); + // double frameRate = 1.0 / (frameTime - frameTimeStart); + // DEBUG("%g fps", frameRate); + frameTimeStart = frameTime; // Make event handlers and step() have a clean nanovg context nvgReset(vg); @@ -406,9 +409,6 @@ void Window::run() { glfwSwapBuffers(win); - // Compute actual frame rate - double frameTimeEnd = glfwGetTime(); - DEBUG("%g fps", 1 / (frameTimeEnd - frameTimeStart)); frame++; } }