BogaudioModules

BogaudioModules for VCV Rack
Log | Files | Refs | README | LICENSE

commit 3a0d82c0aab5b043313eb8b37e67ebbf8804c1fd
parent 8b9da6deca85b966e6016e213e5f1886d8ffdfda
Author: Matt Demanett <matt@demanett.net>
Date:   Wed,  7 Oct 2020 23:55:23 -0400

RANALYZER: while in freeze mode, left and right keys nudge the bin being displayed up and down. #141

Diffstat:
MREADME-prerelease.md | 1+
Msrc/analyzer_base.cpp | 22++++++++++++++++++++++
Msrc/analyzer_base.hpp | 3+++
3 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/README-prerelease.md b/README-prerelease.md @@ -994,6 +994,7 @@ Features: - The frequency analysis bin under the mouse pointer is highlighted. - An overlay box is displayed, with details about the bin number and frequency range, and the level in decibels for each signal at that frequency range. - Dragging the mouse left and right will update the highlight and overlay. + - While the mouse is held, the left and right keyboard keys can be used to change the analysis being displayed, up or down. Moving the mouse resets any bin offset introduced this way. This can be used to get to a specific bin in cases where the mouse tracking resolution is larger than the bin width (which can happen at higher frequencies). _Polyphony:_ Monophonic, with two exceptions: - If an input is polyphonic, its channels are summed, and the spectra of the summed signal is displayed. diff --git a/src/analyzer_base.cpp b/src/analyzer_base.cpp @@ -366,6 +366,7 @@ void AnalyzerDisplay::onButton(const event::Button& e) { } e.consume(this); _freezeMouse = e.pos; + _freezeLastBinI = -1; if (_freezeBufs) { delete[] _freezeBufs; @@ -390,6 +391,9 @@ void AnalyzerDisplay::onDragMove(const event::DragMove& e) { _freezeMouse.x += e.mouseDelta.x / zoom; _freezeMouse.y += e.mouseDelta.y / zoom; _freezeDraw = _freezeMouse.x > _insetLeft && _freezeMouse.x < _size.x - _insetRight && _freezeMouse.y > _insetTop && _freezeMouse.y < _size.y - _insetBottom; + if (e.mouseDelta.x != 0.0f) { + _freezeNudgeBin = 0; + } } void AnalyzerDisplay::onDragEnd(const event::DragEnd& e) { @@ -401,6 +405,22 @@ void AnalyzerDisplay::onDragEnd(const event::DragEnd& e) { } } +void AnalyzerDisplay::onHoverKey(const event::HoverKey &e) { + if (e.key == GLFW_KEY_LEFT) { + e.consume(this); + if (_freezeLastBinI > 0 && (e.action == GLFW_PRESS || e.action == GLFW_REPEAT)) { + _freezeNudgeBin--; + } + } + else if (e.key == GLFW_KEY_RIGHT) { + e.consume(this); + int binsN = _module->_core._size / _module->_core._binAverageN; + if (_freezeLastBinI < binsN - 1 && (e.action == GLFW_PRESS || e.action == GLFW_REPEAT)) { + _freezeNudgeBin++; + } + } +} + void AnalyzerDisplay::setChannelBinsReader(int channel, BinsReader* br) { assert(_channelBinsReaders); assert(_module); @@ -469,6 +489,7 @@ void AnalyzerDisplay::draw(const DrawArgs& args) { float freezeHighHz = 0.0f; if (_freezeDraw) { freezeValues(rangeMinHz, rangeMaxHz, freezeBinI, freezeLowHz, freezeHighHz); + _freezeLastBinI = freezeBinI; drawFreezeUnder(args, freezeLowHz, freezeHighHz, rangeMinHz, rangeMaxHz, strokeWidth); } @@ -823,6 +844,7 @@ void AnalyzerDisplay::freezeValues(float rangeMinHz, float rangeMaxHz, int& binI mouseHz *= rangeMaxHz - rangeMinHz; mouseHz += rangeMinHz; binI = mouseHz / binHz; + binI = std::min(binsN - 1, std::max(0, binI + _freezeNudgeBin)); lowHz = binI * binHz; highHz = (binI + 1) * binHz; } diff --git a/src/analyzer_base.hpp b/src/analyzer_base.hpp @@ -227,6 +227,8 @@ struct AnalyzerDisplay : TransparentWidget, AnalyzerTypes { Vec _freezeMouse; bool _freezeDraw = false; float* _freezeBufs = NULL; + int _freezeNudgeBin = 0; + int _freezeLastBinI = -1; AnalyzerDisplay( AnalyzerBase* module, @@ -262,6 +264,7 @@ struct AnalyzerDisplay : TransparentWidget, AnalyzerTypes { void onButton(const event::Button& e) override; void onDragMove(const event::DragMove& e) override; void onDragEnd(const event::DragEnd& e) override; + void onHoverKey(const event::HoverKey &e) override; void setChannelBinsReader(int channel, BinsReader* br); void displayChannel(int channel, bool display); void channelLabel(int channel, std::string label);