Refactor variables and constants
This commit is contained in:
parent
4ecc95977a
commit
8c1af2dc0d
|
@ -28,37 +28,37 @@
|
|||
|
||||
using Analyzer::Scope;
|
||||
|
||||
const uint BoomAnalyzer::COLUMN_WIDTH = 4;
|
||||
const uint BoomAnalyzer::MAX_BAND_COUNT = 256;
|
||||
const uint BoomAnalyzer::MIN_BAND_COUNT = 32;
|
||||
const uint BoomAnalyzer::kColumnWidth = 4;
|
||||
const uint BoomAnalyzer::kMaxBandCount = 256;
|
||||
const uint BoomAnalyzer::kMinBandCount = 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
|
||||
bands_(0),
|
||||
scope_(kMinBandCount),
|
||||
fg_(palette().color(QPalette::Highlight)),
|
||||
K_barHeight_(1.271) // 1.471
|
||||
,
|
||||
F_peakSpeed(1.103) // 1.122
|
||||
F_peakSpeed_(1.103) // 1.122
|
||||
,
|
||||
F(1.0),
|
||||
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);
|
||||
F_(1.0),
|
||||
bar_height_(kMaxBandCount, 0),
|
||||
peak_height_(kMaxBandCount, 0),
|
||||
peak_speed_(kMaxBandCount, 0.01),
|
||||
barPixmap_(kColumnWidth, 50) {
|
||||
setMinimumWidth(kMinBandCount * (kColumnWidth + 1) - 1);
|
||||
setMaximumWidth(kMaxBandCount * (kColumnWidth + 1) - 1);
|
||||
}
|
||||
|
||||
void BoomAnalyzer::changeK_barHeight(int newValue) {
|
||||
K_barHeight = static_cast<double>(newValue) / 1000;
|
||||
K_barHeight_ = static_cast<double>(newValue) / 1000;
|
||||
}
|
||||
|
||||
void BoomAnalyzer::changeF_peakSpeed(int newValue) {
|
||||
F_peakSpeed = static_cast<double>(newValue) / 1000;
|
||||
F_peakSpeed_ = static_cast<double>(newValue) / 1000;
|
||||
}
|
||||
|
||||
void BoomAnalyzer::resizeEvent(QResizeEvent* e) {
|
||||
|
@ -67,26 +67,26 @@ void BoomAnalyzer::resizeEvent(QResizeEvent* e) {
|
|||
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)) +
|
||||
bands_ = qMin(
|
||||
static_cast<uint>(static_cast<double>(width() + 1) / (kColumnWidth + 1)) +
|
||||
1,
|
||||
MAX_BAND_COUNT);
|
||||
m_scope.resize(m_bands);
|
||||
kMaxBandCount);
|
||||
scope_.resize(bands_);
|
||||
|
||||
F = static_cast<double>(HEIGHT) / (log10(256) * 1.1 /*<- max. amplitude*/);
|
||||
F_ = static_cast<double>(HEIGHT) / (log10(256) * 1.1 /*<- max. amplitude*/);
|
||||
|
||||
barPixmap = QPixmap(COLUMN_WIDTH - 2, HEIGHT);
|
||||
barPixmap_ = QPixmap(kColumnWidth - 2, HEIGHT);
|
||||
canvas_ = QPixmap(size());
|
||||
canvas_.fill(palette().color(QPalette::Background));
|
||||
|
||||
QPainter p(&barPixmap);
|
||||
QPainter p(&barPixmap_);
|
||||
for (uint y = 0; y < HEIGHT; ++y) {
|
||||
const double F = static_cast<double>(y) * h;
|
||||
|
||||
p.setPen(QColor(qMax(0, 255 - static_cast<int>(229.0 * F)),
|
||||
qMax(0, 255 - static_cast<int>(229.0 * F)),
|
||||
qMax(0, 255 - static_cast<int>(191.0 * F))));
|
||||
p.drawLine(0, y, COLUMN_WIDTH - 2, y);
|
||||
p.drawLine(0, y, kColumnWidth - 2, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,8 +96,8 @@ void BoomAnalyzer::transform(Scope& s) {
|
|||
m_fht->spectrum(front);
|
||||
m_fht->scale(front, 1.0 / 50);
|
||||
|
||||
s.resize(m_scope.size() <= MAX_BAND_COUNT / 2 ? MAX_BAND_COUNT / 2
|
||||
: m_scope.size());
|
||||
s.resize(scope_.size() <= kMaxBandCount / 2 ? kMaxBandCount / 2
|
||||
: scope_.size());
|
||||
}
|
||||
|
||||
void BoomAnalyzer::analyze(QPainter& p, const Scope& scope, bool new_frame) {
|
||||
|
@ -111,48 +111,48 @@ void BoomAnalyzer::analyze(QPainter& p, const Scope& scope, bool new_frame) {
|
|||
QPainter canvas_painter(&canvas_);
|
||||
canvas_.fill(palette().color(QPalette::Background));
|
||||
|
||||
Analyzer::interpolate(scope, m_scope);
|
||||
Analyzer::interpolate(scope, scope_);
|
||||
|
||||
for (uint i = 0, x = 0, y; i < m_bands; ++i, x += COLUMN_WIDTH + 1) {
|
||||
h = log10(m_scope[i] * 256.0) * F;
|
||||
for (uint i = 0, x = 0, y; i < bands_; ++i, x += kColumnWidth + 1) {
|
||||
h = log10(scope_[i] * 256.0) * F_;
|
||||
|
||||
if (h > MAX_HEIGHT) h = MAX_HEIGHT;
|
||||
|
||||
if (h > bar_height[i]) {
|
||||
bar_height[i] = h;
|
||||
if (h > bar_height_[i]) {
|
||||
bar_height_[i] = h;
|
||||
|
||||
if (h > peak_height[i]) {
|
||||
peak_height[i] = h;
|
||||
peak_speed[i] = 0.01;
|
||||
if (h > peak_height_[i]) {
|
||||
peak_height_[i] = h;
|
||||
peak_speed_[i] = 0.01;
|
||||
} else {
|
||||
goto peak_handling;
|
||||
}
|
||||
} else {
|
||||
if (bar_height[i] > 0.0) {
|
||||
bar_height[i] -= K_barHeight; // 1.4
|
||||
if (bar_height[i] < 0.0) bar_height[i] = 0.0;
|
||||
if (bar_height_[i] > 0.0) {
|
||||
bar_height_[i] -= K_barHeight_; // 1.4
|
||||
if (bar_height_[i] < 0.0) bar_height_[i] = 0.0;
|
||||
}
|
||||
|
||||
peak_handling:
|
||||
|
||||
if (peak_height[i] > 0.0) {
|
||||
peak_height[i] -= peak_speed[i];
|
||||
peak_speed[i] *= F_peakSpeed; // 1.12
|
||||
if (peak_height_[i] > 0.0) {
|
||||
peak_height_[i] -= peak_speed_[i];
|
||||
peak_speed_[i] *= F_peakSpeed_; // 1.12
|
||||
|
||||
if (peak_height[i] < bar_height[i]) peak_height[i] = bar_height[i];
|
||||
if (peak_height[i] < 0.0) peak_height[i] = 0.0;
|
||||
if (peak_height_[i] < bar_height_[i]) peak_height_[i] = bar_height_[i];
|
||||
if (peak_height_[i] < 0.0) peak_height_[i] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
y = height() - uint(bar_height[i]);
|
||||
canvas_painter.drawPixmap(x + 1, y, barPixmap, 0, y, -1, -1);
|
||||
canvas_painter.setPen(m_fg);
|
||||
if (bar_height[i] > 0)
|
||||
canvas_painter.drawRect(x, y, COLUMN_WIDTH - 1, height() - y - 1);
|
||||
y = height() - uint(bar_height_[i]);
|
||||
canvas_painter.drawPixmap(x + 1, y, barPixmap_, 0, y, -1, -1);
|
||||
canvas_painter.setPen(fg_);
|
||||
if (bar_height_[i] > 0)
|
||||
canvas_painter.drawRect(x, y, kColumnWidth - 1, height() - y - 1);
|
||||
|
||||
y = height() - uint(peak_height[i]);
|
||||
y = height() - uint(peak_height_[i]);
|
||||
canvas_painter.setPen(palette().color(QPalette::Midlight));
|
||||
canvas_painter.drawLine(x, y, x + COLUMN_WIDTH - 1, y);
|
||||
canvas_painter.drawLine(x, y, x + kColumnWidth - 1, y);
|
||||
}
|
||||
|
||||
p.drawPixmap(0, 0, canvas_);
|
||||
|
@ -161,5 +161,5 @@ void BoomAnalyzer::analyze(QPainter& p, const Scope& scope, bool new_frame) {
|
|||
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);
|
||||
fg_ = palette().color(QPalette::Highlight);
|
||||
}
|
||||
|
|
|
@ -46,21 +46,21 @@ class BoomAnalyzer : public Analyzer::Base {
|
|||
void resizeEvent(QResizeEvent* e);
|
||||
void paletteChange(const QPalette&);
|
||||
|
||||
static const uint COLUMN_WIDTH;
|
||||
static const uint MAX_BAND_COUNT;
|
||||
static const uint MIN_BAND_COUNT;
|
||||
static const uint kColumnWidth;
|
||||
static const uint kMaxBandCount;
|
||||
static const uint kMinBandCount;
|
||||
|
||||
uint m_bands;
|
||||
Analyzer::Scope m_scope;
|
||||
QColor m_fg;
|
||||
uint bands_;
|
||||
Analyzer::Scope scope_;
|
||||
QColor fg_;
|
||||
|
||||
double K_barHeight, F_peakSpeed, F;
|
||||
double K_barHeight_, F_peakSpeed_, F_;
|
||||
|
||||
std::vector<float> bar_height;
|
||||
std::vector<float> peak_height;
|
||||
std::vector<float> peak_speed;
|
||||
std::vector<float> bar_height_;
|
||||
std::vector<float> peak_height_;
|
||||
std::vector<float> peak_speed_;
|
||||
|
||||
QPixmap barPixmap;
|
||||
QPixmap barPixmap_;
|
||||
QPixmap canvas_;
|
||||
};
|
||||
|
||||
|
|
|
@ -42,59 +42,59 @@ void TurbineAnalyzer::analyze(QPainter& p, const Scope& scope, bool new_frame) {
|
|||
|
||||
float h;
|
||||
const uint hd2 = height() / 2;
|
||||
const uint MAX_HEIGHT = hd2 - 1;
|
||||
const uint kMaxHeight = hd2 - 1;
|
||||
|
||||
QPainter canvas_painter(&canvas_);
|
||||
canvas_.fill(palette().color(QPalette::Background));
|
||||
|
||||
Analyzer::interpolate(scope, m_scope);
|
||||
Analyzer::interpolate(scope, 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;
|
||||
for (uint i = 0, x = 0, y; i < bands_; ++i, x += kColumnWidth + 1) {
|
||||
h = log10(scope_[i] * 256.0) * F_ * 0.5;
|
||||
|
||||
if (h > MAX_HEIGHT) h = MAX_HEIGHT;
|
||||
if (h > kMaxHeight) h = kMaxHeight;
|
||||
|
||||
if (h > bar_height[i]) {
|
||||
bar_height[i] = h;
|
||||
if (h > bar_height_[i]) {
|
||||
bar_height_[i] = h;
|
||||
|
||||
if (h > peak_height[i]) {
|
||||
peak_height[i] = h;
|
||||
peak_speed[i] = 0.01;
|
||||
if (h > peak_height_[i]) {
|
||||
peak_height_[i] = h;
|
||||
peak_speed_[i] = 0.01;
|
||||
} else {
|
||||
goto peak_handling;
|
||||
}
|
||||
} else {
|
||||
if (bar_height[i] > 0.0) {
|
||||
bar_height[i] -= K_barHeight; // 1.4
|
||||
if (bar_height[i] < 0.0) bar_height[i] = 0.0;
|
||||
if (bar_height_[i] > 0.0) {
|
||||
bar_height_[i] -= K_barHeight_; // 1.4
|
||||
if (bar_height_[i] < 0.0) bar_height_[i] = 0.0;
|
||||
}
|
||||
|
||||
peak_handling:
|
||||
|
||||
if (peak_height[i] > 0.0) {
|
||||
peak_height[i] -= peak_speed[i];
|
||||
peak_speed[i] *= F_peakSpeed; // 1.12
|
||||
if (peak_height_[i] > 0.0) {
|
||||
peak_height_[i] -= peak_speed_[i];
|
||||
peak_speed_[i] *= F_peakSpeed_; // 1.12
|
||||
|
||||
if (peak_height[i] < bar_height[i]) peak_height[i] = bar_height[i];
|
||||
if (peak_height[i] < 0.0) peak_height[i] = 0.0;
|
||||
if (peak_height_[i] < bar_height_[i]) peak_height_[i] = bar_height_[i];
|
||||
if (peak_height_[i] < 0.0) peak_height_[i] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
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);
|
||||
canvas_painter.setPen(fg_);
|
||||
if (bar_height_[i] > 0)
|
||||
canvas_painter.drawRect(x, y, kColumnWidth - 1,
|
||||
static_cast<int>(bar_height_[i]) * 2 - 1);
|
||||
|
||||
const uint x2 = x + COLUMN_WIDTH - 1;
|
||||
const uint x2 = x + kColumnWidth - 1;
|
||||
canvas_painter.setPen(palette().color(QPalette::Midlight));
|
||||
y = hd2 - uint(peak_height[i]);
|
||||
y = hd2 - uint(peak_height_[i]);
|
||||
canvas_painter.drawLine(x, y, x2, y);
|
||||
y = hd2 + uint(peak_height[i]);
|
||||
y = hd2 + uint(peak_height_[i]);
|
||||
canvas_painter.drawLine(x, y, x2, y);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue