Formatting

This commit is contained in:
Jonas Kvinge
2021-08-23 21:21:08 +02:00
parent ed7794f396
commit ea2bfbda44
111 changed files with 833 additions and 425 deletions

View File

@@ -126,10 +126,12 @@ void Analyzer::Base::paintEvent(QPaintEvent *e) {
int Analyzer::Base::resizeExponent(int exp) {
if (exp < 3)
if (exp < 3) {
exp = 3;
else if (exp > 9)
}
else if (exp > 9) {
exp = 9;
}
if (exp != fht_->sizeExp()) {
delete fht_;
@@ -142,18 +144,24 @@ int Analyzer::Base::resizeExponent(int exp) {
int Analyzer::Base::resizeForBands(const int bands) {
int exp = 0;
if (bands <= 8)
if (bands <= 8) {
exp = 4;
else if (bands <= 16)
}
else if (bands <= 16) {
exp = 5;
else if (bands <= 32)
}
else if (bands <= 32) {
exp = 6;
else if (bands <= 64)
}
else if (bands <= 64) {
exp = 7;
else if (bands <= 128)
}
else if (bands <= 128) {
exp = 8;
else
}
else {
exp = 9;
}
resizeExponent(exp);
return fht_->size() / 2;
@@ -164,18 +172,22 @@ void Analyzer::Base::demo(QPainter &p) {
static int t = 201; // FIXME make static to namespace perhaps
if (t > 999) t = 1; // 0 = wasted calculations
if (t > 999) {
t = 1; // 0 = wasted calculations
}
if (t < 201) {
Scope s(32);
const double dt = double(t) / 200;
for (uint i = 0; i < s.size(); ++i)
for (uint i = 0; i < s.size(); ++i) {
s[i] = dt * (sin(M_PI + (i * M_PI) / s.size()) + 1.0);
}
analyze(p, s, new_frame_);
}
else
else {
analyze(p, Scope(32, 0), new_frame_);
}
++t;
@@ -196,11 +208,15 @@ void Analyzer::interpolate(const Scope &inVec, Scope &outVec) {
uint64_t indexLeft = offset + 0;
if (indexLeft >= inVec.size()) indexLeft = inVec.size() - 1;
if (indexLeft >= inVec.size()) {
indexLeft = inVec.size() - 1;
}
uint64_t indexRight = offset + 1;
if (indexRight >= inVec.size()) indexRight = inVec.size() - 1;
if (indexRight >= inVec.size()) {
indexRight = inVec.size() - 1;
}
outVec[i] = inVec[indexLeft] * (1.0 - error) + inVec[indexRight] * error;
}
@@ -222,7 +238,9 @@ void Analyzer::initSin(Scope &v, const uint size) {
void Analyzer::Base::timerEvent(QTimerEvent *e) {
QWidget::timerEvent(e);
if (e->timerId() != timer_.timerId()) return;
if (e->timerId() != timer_.timerId()) {
return;
}
new_frame_ = true;
update();

View File

@@ -103,7 +103,9 @@ AnalyzerContainer::AnalyzerContainer(QWidget *parent)
void AnalyzerContainer::mouseReleaseEvent(QMouseEvent *e) {
if (engine_->type() != Engine::EngineType::GStreamer) return;
if (engine_->type() != Engine::EngineType::GStreamer) {
return;
}
if (e->button() == Qt::RightButton) {
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
@@ -124,8 +126,10 @@ void AnalyzerContainer::wheelEvent(QWheelEvent *e) {
}
void AnalyzerContainer::SetEngine(EngineBase *engine) {
if (current_analyzer_) current_analyzer_->set_engine(engine);
engine_ = engine;
}
void AnalyzerContainer::DisableAnalyzer() {

View File

@@ -88,15 +88,17 @@ void BlockAnalyzer::resizeEvent(QResizeEvent *e) {
if (rows_ != oldRows) {
barpixmap_ = QPixmap(kWidth, rows_ * (kHeight + 1));
for (uint i = 0; i < kFadeSize; ++i)
for (uint i = 0; i < kFadeSize; ++i) {
fade_bars_[i] = QPixmap(kWidth, rows_ * (kHeight + 1));
}
yscale_.resize(rows_ + 1);
const int PRE = 1, PRO = 1; // PRE and PRO allow us to restrict the range somewhat
for (int z = 0; z < rows_; ++z)
for (int z = 0; z < rows_; ++z) {
yscale_[z] = 1 - (log10(PRE + z) / log10(PRE + rows_ + PRO));
}
yscale_[rows_] = 0;
@@ -168,10 +170,12 @@ void BlockAnalyzer::analyze(QPainter &p, const Analyzer::Scope &s, bool new_fram
for (y = 0; scope_[x] < yscale_[y]; ++y) continue;
// This is opposite to what you'd think, higher than y means the bar is lower than y (physically)
if (static_cast<double>(y) > store_[x])
if (static_cast<double>(y) > store_[x]) {
y = static_cast<int>(store_[x] += step_);
else
}
else {
store_[x] = y;
}
// If y is lower than fade_pos_, then the bar has exceeded the height of the fadeout
// if the fadeout is quite faded now, then display the new one
@@ -192,8 +196,9 @@ void BlockAnalyzer::analyze(QPainter &p, const Analyzer::Scope &s, bool new_fram
canvas_painter.drawPixmap(x * (kWidth + 1), y * (kHeight + 1) + y_, *bar(), 0, y * (kHeight + 1), bar()->width(), bar()->height());
}
for (int x = 0; x < store_.size(); ++x)
for (int x = 0; x < store_.size(); ++x) {
canvas_painter.drawPixmap(x * (kWidth + 1), static_cast<int>(store_[x]) * (kHeight + 1) + y_, topbarpixmap_);
}
p.drawPixmap(0, 0, canvas_);
@@ -279,20 +284,24 @@ QColor ensureContrast(const QColor &bg, const QColor &fg, int amount) {
// check the saturation for the two colours is sufficient that hue alone can
// provide sufficient contrast
if (ds > amount / 2 && (bs > 125 && fs > 125))
if (ds > amount / 2 && (bs > 125 && fs > 125)) {
return fg;
else if (dv > amount / 2 && (bv > 125 && fv > 125))
}
else if (dv > amount / 2 && (bv > 125 && fv > 125)) {
return fg;
}
}
if (fs < 50 && ds < 40) {
// low saturation on a low saturation is sad
const int tmp = 50 - fs;
fs = 50;
if (static_cast<int>(amount) > tmp)
if (static_cast<int>(amount) > tmp) {
amount -= tmp;
else
}
else {
amount = 0;
}
}
// test that there is available value to honor our contrast requirement
@@ -309,19 +318,24 @@ QColor ensureContrast(const QColor &bg, const QColor &fg, int amount) {
return QColor::fromHsv(fh, fs, fv);
}
if (fv > bv && bv > static_cast<int>(amount))
if (fv > bv && bv > static_cast<int>(amount)) {
return QColor::fromHsv(fh, fs, bv - static_cast<int>(amount));
}
if (fv < bv && fv > static_cast<int>(amount))
if (fv < bv && fv > static_cast<int>(amount)) {
return QColor::fromHsv(fh, fs, fv - amount);
}
if (fv > bv && (255 - fv > static_cast<int>(amount)))
if (fv > bv && (255 - fv > static_cast<int>(amount))) {
return QColor::fromHsv(fh, fs, fv + amount);
}
if (fv < bv && (255 - bv > static_cast<int>(amount)))
if (fv < bv && (255 - bv > static_cast<int>(amount))) {
return QColor::fromHsv(fh, fs, bv + amount);
}
return Qt::blue;
}
void BlockAnalyzer::paletteChange(const QPalette&) {
@@ -339,9 +353,10 @@ void BlockAnalyzer::paletteChange(const QPalette&) {
bar()->fill(bg);
QPainter p(bar());
for (int y = 0; y < rows_; ++y)
for (int y = 0; y < rows_; ++y) {
// graduate the fg color
p.fillRect(0, y * (kHeight + 1), kWidth, kHeight, QColor(r + static_cast<int>(dr * y), g + static_cast<int>(dg * y), b + static_cast<int>(db * y)));
}
{
const QColor bg2 = palette().color(QPalette::Window).darker(112);
@@ -387,8 +402,10 @@ void BlockAnalyzer::drawBackground() {
if (!p.paintEngine()) return;
for (int x = 0; x < columns_; ++x)
for (int y = 0; y < rows_; ++y)
for (int x = 0; x < columns_; ++x) {
for (int y = 0; y < rows_; ++y) {
p.fillRect(x * (kWidth + 1), y * (kHeight + 1) + y_, kWidth, kHeight, bgdark);
}
}
}

View File

@@ -158,8 +158,9 @@ void BoomAnalyzer::analyze(QPainter &p, const Scope &scope, const bool new_frame
y = height() - static_cast<int>(bar_height_[i]);
canvas_painter.drawPixmap(x + 1, y, barPixmap_, 0, y, -1, -1);
canvas_painter.setPen(fg_);
if (bar_height_[i] > 0)
if (bar_height_[i] > 0) {
canvas_painter.drawRect(x, y, kColumnWidth - 1, height() - y - 1);
}
y = height() - static_cast<int>(peak_height_[i]);
canvas_painter.setPen(palette().color(QPalette::Midlight));

View File

@@ -28,11 +28,13 @@
#include <QVector>
FHT::FHT(int n) : num_((n < 3) ? 0 : 1 << n), exp2_((n < 3) ? -1 : n) {
if (n > 3) {
buf_vector_.resize(num_);
tab_vector_.resize(num_ * 2);
makeCasTable();
}
}
FHT::~FHT() = default;
@@ -45,6 +47,7 @@ float *FHT::tab_() { return tab_vector_.data(); }
int *FHT::log_() { return log_vector_.data(); }
void FHT::makeCasTable(void) {
float *costab = tab_();
float *sintab = tab_() + num_ / 2 + 1;
@@ -56,6 +59,7 @@ void FHT::makeCasTable(void) {
sintab += 2;
if (sintab > tab_() + num_ * 2) sintab = tab_() + 1;
}
}
void FHT::scale(float *p, float d) const {
@@ -94,25 +98,33 @@ void FHT::logSpectrum(float *out, float *p) {
}
void FHT::semiLogSpectrum(float *p) {
power2(p);
for (int i = 0; i < (num_ / 2); i++, p++) {
float e = 10.0 * log10(sqrt(*p / 2));
*p = e < 0 ? 0 : e;
}
}
void FHT::spectrum(float *p) {
power2(p);
for (int i = 0; i < (num_ / 2); i++, p++)
for (int i = 0; i < (num_ / 2); i++, p++) {
*p = static_cast<float>(sqrt(*p / 2));
}
}
void FHT::power(float *p) {
power2(p);
for (int i = 0; i < (num_ / 2); i++) *p++ /= 2;
}
void FHT::power2(float *p) {
_transform(p, num_, 0);
*p = static_cast<float>(2 * pow(*p, 2));
@@ -124,13 +136,18 @@ void FHT::power2(float *p) {
p++;
q--;
}
}
void FHT::transform(float *p) {
if (num_ == 8)
if (num_ == 8) {
transform8(p);
else
}
else {
_transform(p, num_, 0);
}
}
void FHT::transform8(float *p) {