Update Boom and Turbine analyzers

Boom and Turbine remain small fixed-size analyzers with a few issues with regards to colours.
This update attempts to remedy these issues.
Changes:
-Both analyzers now resize to fit the size of their container, and scale to the lower frequencies if in a small window
-The colour now does not change as the main window gains/loses focus
-The peak bars now use a colour which is actually visible (I did't even know they existed before!)
This commit is contained in:
Mark Furneaux 2015-06-26 16:40:25 -04:00
parent 73ae416534
commit 4ecc95977a
3 changed files with 56 additions and 39 deletions

View File

@ -2,7 +2,7 @@
Copyright 2004, Max Howell <max.howell@methylblue.com>
Copyright 2009-2010, David Sansome <davidsansome@gmail.com>
Copyright 2010, 2014, John Maguire <john.maguire@gmail.com>
Copyright 2014, Mark Furneaux <mark@romaco.ca>
Copyright 2014-2015, Mark Furneaux <mark@furneaux.ca>
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
Clementine is free software: you can redistribute it and/or modify
@ -28,20 +28,30 @@
using Analyzer::Scope;
const uint BoomAnalyzer::COLUMN_WIDTH = 4;
const uint BoomAnalyzer::MAX_BAND_COUNT = 256;
const uint BoomAnalyzer::MIN_BAND_COUNT = 32;
const char* BoomAnalyzer::kName =
QT_TRANSLATE_NOOP("AnalyzerContainer", "Boom analyzer");
BoomAnalyzer::BoomAnalyzer(QWidget* parent)
: Analyzer::Base(parent, 9),
m_bands(0),
m_scope(MIN_BAND_COUNT),
m_fg(palette().color(QPalette::Highlight)),
K_barHeight(1.271) // 1.471
,
F_peakSpeed(1.103) // 1.122
,
F(1.0),
bar_height(BAND_COUNT, 0),
peak_height(BAND_COUNT, 0),
peak_speed(BAND_COUNT, 0.01),
barPixmap(COLUMN_WIDTH, 50) {}
bar_height(MAX_BAND_COUNT, 0),
peak_height(MAX_BAND_COUNT, 0),
peak_speed(MAX_BAND_COUNT, 0.01),
barPixmap(COLUMN_WIDTH, 50) {
setMinimumWidth(MIN_BAND_COUNT * (COLUMN_WIDTH + 1) - 1);
setMaximumWidth(MAX_BAND_COUNT * (COLUMN_WIDTH + 1) - 1);
}
void BoomAnalyzer::changeK_barHeight(int newValue) {
K_barHeight = static_cast<double>(newValue) / 1000;
@ -51,12 +61,18 @@ void BoomAnalyzer::changeF_peakSpeed(int newValue) {
F_peakSpeed = static_cast<double>(newValue) / 1000;
}
void BoomAnalyzer::resizeEvent(QResizeEvent*) { init(); }
void BoomAnalyzer::resizeEvent(QResizeEvent* e) {
QWidget::resizeEvent(e);
void BoomAnalyzer::init() {
const uint HEIGHT = height() - 2;
const double h = 1.2 / HEIGHT;
m_bands = qMin(
static_cast<uint>(static_cast<double>(width() + 1) / (COLUMN_WIDTH + 1)) +
1,
MAX_BAND_COUNT);
m_scope.resize(m_bands);
F = static_cast<double>(HEIGHT) / (log10(256) * 1.1 /*<- max. amplitude*/);
barPixmap = QPixmap(COLUMN_WIDTH - 2, HEIGHT);
@ -78,19 +94,10 @@ void BoomAnalyzer::transform(Scope& s) {
float* front = static_cast<float*>(&s.front());
m_fht->spectrum(front);
m_fht->scale(front, 1.0 / 60);
m_fht->scale(front, 1.0 / 50);
Scope scope(32, 0);
const uint xscale[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 19, 24, 29, 36,
43, 52, 63, 76, 91, 108, 129, 153, 182, 216, 255};
for (uint j, i = 0; i < 32; i++)
for (j = xscale[i]; j < xscale[i + 1]; j++)
if (s[j] > scope[i]) scope[i] = s[j];
s = scope;
s.resize(m_scope.size() <= MAX_BAND_COUNT / 2 ? MAX_BAND_COUNT / 2
: m_scope.size());
}
void BoomAnalyzer::analyze(QPainter& p, const Scope& scope, bool new_frame) {
@ -104,8 +111,10 @@ void BoomAnalyzer::analyze(QPainter& p, const Scope& scope, bool new_frame) {
QPainter canvas_painter(&canvas_);
canvas_.fill(palette().color(QPalette::Background));
for (uint i = 0, x = 0, y; i < BAND_COUNT; ++i, x += COLUMN_WIDTH + 1) {
h = log10(scope[i] * 256.0) * F;
Analyzer::interpolate(scope, m_scope);
for (uint i = 0, x = 0, y; i < m_bands; ++i, x += COLUMN_WIDTH + 1) {
h = log10(m_scope[i] * 256.0) * F;
if (h > MAX_HEIGHT) h = MAX_HEIGHT;
@ -137,14 +146,20 @@ void BoomAnalyzer::analyze(QPainter& p, const Scope& scope, bool new_frame) {
y = height() - uint(bar_height[i]);
canvas_painter.drawPixmap(x + 1, y, barPixmap, 0, y, -1, -1);
canvas_painter.setPen(palette().color(QPalette::Highlight));
canvas_painter.setPen(m_fg);
if (bar_height[i] > 0)
canvas_painter.drawRect(x, y, COLUMN_WIDTH - 1, height() - y - 1);
y = height() - uint(peak_height[i]);
canvas_painter.setPen(palette().color(QPalette::Base));
canvas_painter.setPen(palette().color(QPalette::Midlight));
canvas_painter.drawLine(x, y, x + COLUMN_WIDTH - 1, y);
}
p.drawPixmap(0, 0, canvas_);
}
void BoomAnalyzer::paletteChange(const QPalette&) {
// the highlight colour changes when the main window loses focus,
// so we use save and use the focused colour
m_fg = palette().color(QPalette::Highlight);
}

View File

@ -1,7 +1,7 @@
/* This file is part of Clementine.
Copyright 2004, Max Howell <max.howell@methylblue.com>
Copyright 2009-2010, David Sansome <davidsansome@gmail.com>
Copyright 2014, Mark Furneaux <mark@romaco.ca>
Copyright 2014-2015, Mark Furneaux <mark@furneaux.ca>
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
Copyright 2014, John Maguire <john.maguire@gmail.com>
@ -27,10 +27,6 @@
#include "analyzerbase.h"
/**
@author Max Howell
*/
class BoomAnalyzer : public Analyzer::Base {
Q_OBJECT
@ -39,7 +35,6 @@ class BoomAnalyzer : public Analyzer::Base {
static const char* kName;
virtual void init();
virtual void transform(Analyzer::Scope& s);
virtual void analyze(QPainter& p, const Analyzer::Scope&, bool new_frame);
@ -49,9 +44,15 @@ class BoomAnalyzer : public Analyzer::Base {
protected:
void resizeEvent(QResizeEvent* e);
void paletteChange(const QPalette&);
static const uint COLUMN_WIDTH = 4;
static const uint BAND_COUNT = 32;
static const uint COLUMN_WIDTH;
static const uint MAX_BAND_COUNT;
static const uint MIN_BAND_COUNT;
uint m_bands;
Analyzer::Scope m_scope;
QColor m_fg;
double K_barHeight, F_peakSpeed, F;

View File

@ -2,7 +2,7 @@
Copyright 2003, Stanislav Karchebny <berkus@users.sf.net>
Copyright 2003, Max Howell <max.howell@methylblue.com>
Copyright 2009-2010, David Sansome <davidsansome@gmail.com>
Copyright 2014, Mark Furneaux <mark@romaco.ca>
Copyright 2014-2015, Mark Furneaux <mark@furneaux.ca>
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
Copyright 2014, John Maguire <john.maguire@gmail.com>
@ -21,7 +21,7 @@
*/
/* Original Author: Stanislav Karchebny <berkus@users.sf.net> 2003
* Original Author: Max Howell <max.howell@methylblue.com> 2003
* Original Author: Max Howell <max.howell@methylblue.com> 2003
*/
#include <cmath>
@ -47,8 +47,10 @@ void TurbineAnalyzer::analyze(QPainter& p, const Scope& scope, bool new_frame) {
QPainter canvas_painter(&canvas_);
canvas_.fill(palette().color(QPalette::Background));
for (uint i = 0, x = 0, y; i < BAND_COUNT; ++i, x += COLUMN_WIDTH + 1) {
h = log10(scope[i] * 256.0) * F * 0.5;
Analyzer::interpolate(scope, m_scope);
for (uint i = 0, x = 0, y; i < m_bands; ++i, x += COLUMN_WIDTH + 1) {
h = log10(m_scope[i] * 256.0) * F * 0.5;
if (h > MAX_HEIGHT) h = MAX_HEIGHT;
@ -81,16 +83,15 @@ void TurbineAnalyzer::analyze(QPainter& p, const Scope& scope, bool new_frame) {
y = hd2 - static_cast<uint>(bar_height[i]);
canvas_painter.drawPixmap(x + 1, y, barPixmap, 0, y, -1, -1);
canvas_painter.drawPixmap(x + 1, hd2, barPixmap, 0,
static_cast<int>(bar_height[i]),
-1, -1);
static_cast<int>(bar_height[i]), -1, -1);
canvas_painter.setPen(palette().color(QPalette::Highlight));
canvas_painter.setPen(m_fg);
if (bar_height[i] > 0)
canvas_painter.drawRect(x, y, COLUMN_WIDTH - 1,
static_cast<int>(bar_height[i]) * 2 - 1);
const uint x2 = x + COLUMN_WIDTH - 1;
canvas_painter.setPen(palette().color(QPalette::Base));
canvas_painter.setPen(palette().color(QPalette::Midlight));
y = hd2 - uint(peak_height[i]);
canvas_painter.drawLine(x, y, x2, y);
y = hd2 + uint(peak_height[i]);