commit 6ab2359b98a1b06fa9ddbb0ee8acf098a6f112c4
parent 452c5f4c515c1388a7abd09b9e99e6a6e04b2c55
Author: Matt Demanett <matt@fundera.com>
Date: Fri, 1 Dec 2017 18:52:20 -0500
Analyzer: axix labels.
Diffstat:
2 files changed, 55 insertions(+), 6 deletions(-)
diff --git a/res/fonts/inconsolata.ttf b/res/fonts/inconsolata.ttf
Binary files differ.
diff --git a/src/Analyzer.cpp b/src/Analyzer.cpp
@@ -154,10 +154,10 @@ void Analyzer::stepChannel(ChannelAnalyzer*& channelPointer, bool running, Input
struct AnalyzerDisplay : TransparentWidget {
- const int _insetLeft = 27;
+ const int _insetLeft = 14;
const int _insetRight = 4;
const int _insetTop = 2;
- const int _insetBottom = 18;
+ const int _insetBottom = 11;
const float _refDB0 = 20.0; // arbitrary; makes a 10.0-amplitude sine wave reach to about 0db on the output.
const float _displayDB = 120.0;
@@ -165,12 +165,14 @@ struct AnalyzerDisplay : TransparentWidget {
const float xAxisLogFactor = 1 / 3.321; // magic number.
const NVGcolor _axisColor = nvgRGBA(0xff, 0xff, 0xff, 0x70);
+ const NVGcolor _textColor = nvgRGBA(0xff, 0xff, 0xff, 0xc0);
const NVGcolor _channelAColor = nvgRGBA(0x00, 0xff, 0x00, 0xd0);
const NVGcolor _channelBColor = nvgRGBA(0xff, 0x00, 0x00, 0xd0);
Analyzer* _module;
const Vec _size;
const Vec _graphSize;
+ std::shared_ptr<Font> _font;
AnalyzerDisplay(
Analyzer* module,
@@ -179,21 +181,22 @@ struct AnalyzerDisplay : TransparentWidget {
: _module(module)
, _size(size)
, _graphSize(_size.x - _insetLeft - _insetRight, _size.y - _insetTop - _insetBottom)
+ , _font(Font::load(assetPlugin(plugin, "res/fonts/inconsolata.ttf")))
{
}
void draw(NVGcontext* vg) override;
- void drawBlank(NVGcontext* vg);
+ void drawBackground(NVGcontext* vg);
void drawYAxis(NVGcontext* vg);
void drawXAxis(NVGcontext* vg);
void drawXAxisLine(NVGcontext* vg, float hz, float maxHz);
void drawLine(NVGcontext* vg, float* bins, int binsN, NVGcolor color);
-
+ void drawText(NVGcontext* vg, const char* s, float x, float y, float rotation = 0.0);
int binValueToHeight(float value);
};
void AnalyzerDisplay::draw(NVGcontext* vg) {
- drawBlank(vg);
+ drawBackground(vg);
drawYAxis(vg);
drawXAxis(vg);
@@ -205,7 +208,7 @@ void AnalyzerDisplay::draw(NVGcontext* vg) {
}
}
-void AnalyzerDisplay::drawBlank(NVGcontext* vg) {
+void AnalyzerDisplay::drawBackground(NVGcontext* vg) {
nvgSave(vg);
nvgBeginPath(vg);
nvgRect(vg, 0, 0, _size.x, _size.y);
@@ -220,6 +223,8 @@ void AnalyzerDisplay::drawYAxis(NVGcontext* vg) {
nvgSave(vg);
nvgStrokeColor(vg, _axisColor);
const int lineX = _insetLeft - 2;
+ const int textX = 9;
+ const float textR = -M_PI/2.0;
nvgBeginPath(vg);
int lineY = _insetTop + (_graphSize.y - _graphSize.y*(_displayDB - 20.0)/_displayDB);
@@ -227,12 +232,16 @@ void AnalyzerDisplay::drawYAxis(NVGcontext* vg) {
nvgLineTo(vg, _size.x - _insetRight, lineY);
nvgStroke(vg);
+ drawText(vg, "0", textX, lineY + 2.3, textR);
+
nvgBeginPath(vg);
lineY = _insetTop + (_graphSize.y - _graphSize.y*(_displayDB - 70.0)/_displayDB);
nvgMoveTo(vg, lineX, lineY);
nvgLineTo(vg, _size.x - _insetRight, lineY);
nvgStroke(vg);
+ drawText(vg, "-50", textX, lineY + 10, textR);
+
nvgBeginPath(vg);
lineY = _insetTop + _graphSize.y + 1;
nvgMoveTo(vg, lineX, lineY);
@@ -243,6 +252,9 @@ void AnalyzerDisplay::drawYAxis(NVGcontext* vg) {
nvgMoveTo(vg, lineX, _insetTop);
nvgLineTo(vg, lineX, lineY);
nvgStroke(vg);
+
+ drawText(vg, "dB", textX, _size.y - _insetBottom, textR);
+
nvgRestore(vg);
}
@@ -268,6 +280,32 @@ void AnalyzerDisplay::drawXAxis(NVGcontext* vg) {
hz += 10000.0;
}
+ drawText(vg, "Hz", _insetLeft, _size.y - 2);
+ {
+ float x = 100.0 / maxHz;
+ x = powf(x, xAxisLogFactor);
+ if (x < 1.0) {
+ x *= _graphSize.x;
+ drawText(vg, "100", _insetLeft + x - 8, _size.y - 2);
+ }
+ }
+ {
+ float x = 1000.0 / maxHz;
+ x = powf(x, xAxisLogFactor);
+ if (x < 1.0) {
+ x *= _graphSize.x;
+ drawText(vg, "1k", _insetLeft + x - 4, _size.y - 2);
+ }
+ }
+ {
+ float x = 10000.0 / maxHz;
+ x = powf(x, xAxisLogFactor);
+ if (x < 1.0) {
+ x *= _graphSize.x;
+ drawText(vg, "10k", _insetLeft + x - 7, _size.y - 2);
+ }
+ }
+
nvgRestore(vg);
}
@@ -302,6 +340,17 @@ void AnalyzerDisplay::drawLine(NVGcontext* vg, float* bins, int binsN, NVGcolor
nvgRestore(vg);
}
+void AnalyzerDisplay::drawText(NVGcontext* vg, const char* s, float x, float y, float rotation) {
+ nvgSave(vg);
+ nvgTranslate(vg, x, y);
+ nvgRotate(vg, rotation);
+ nvgFontSize(vg, 10);
+ nvgFontFaceId(vg, _font->handle);
+ nvgFillColor(vg, _textColor);
+ nvgText(vg, 0, 0, s, NULL);
+ nvgRestore(vg);
+}
+
int AnalyzerDisplay::binValueToHeight(float value) {
value /= _refDB0;
value = log10(value);