Rename AnalyzerBase

This commit is contained in:
Jonas Kvinge 2023-04-22 19:45:21 +02:00
parent e9f3281694
commit 4c1c322b54
12 changed files with 71 additions and 84 deletions

View File

@ -50,7 +50,7 @@
// Make an INSTRUCTIONS file
// can't mod scope in analyze you have to use transform for 2D use setErasePixmap Qt function insetead of m_background
Analyzer::Base::Base(QWidget *parent, const uint scopeSize)
AnalyzerBase::AnalyzerBase(QWidget *parent, const uint scopeSize)
: QWidget(parent),
fht_(new FHT(scopeSize)),
engine_(nullptr),
@ -63,19 +63,19 @@ Analyzer::Base::Base(QWidget *parent, const uint scopeSize)
}
Analyzer::Base::~Base() {
AnalyzerBase::~AnalyzerBase() {
delete fht_;
}
void Analyzer::Base::showEvent(QShowEvent*) {
void AnalyzerBase::showEvent(QShowEvent*) {
timer_.start(timeout(), this);
}
void Analyzer::Base::hideEvent(QHideEvent*) {
void AnalyzerBase::hideEvent(QHideEvent*) {
timer_.stop();
}
void Analyzer::Base::ChangeTimeout(const int timeout) {
void AnalyzerBase::ChangeTimeout(const int timeout) {
timeout_ = timeout;
if (timer_.isActive()) {
@ -85,7 +85,7 @@ void Analyzer::Base::ChangeTimeout(const int timeout) {
}
void Analyzer::Base::transform(Scope &scope) {
void AnalyzerBase::transform(Scope &scope) {
QVector<float> aux(fht_->size());
if (static_cast<unsigned long int>(aux.size()) >= scope.size()) {
@ -102,7 +102,7 @@ void Analyzer::Base::transform(Scope &scope) {
}
void Analyzer::Base::paintEvent(QPaintEvent *e) {
void AnalyzerBase::paintEvent(QPaintEvent *e) {
QPainter p(this);
p.fillRect(e->rect(), palette().color(QPalette::Window));
@ -140,7 +140,7 @@ void Analyzer::Base::paintEvent(QPaintEvent *e) {
}
int Analyzer::Base::resizeExponent(int exp) {
int AnalyzerBase::resizeExponent(int exp) {
if (exp < 3) {
exp = 3;
@ -157,7 +157,7 @@ int Analyzer::Base::resizeExponent(int exp) {
}
int Analyzer::Base::resizeForBands(const int bands) {
int AnalyzerBase::resizeForBands(const int bands) {
int exp = 0;
if (bands <= 8) {
@ -184,7 +184,7 @@ int Analyzer::Base::resizeForBands(const int bands) {
}
void Analyzer::Base::demo(QPainter &p) {
void AnalyzerBase::demo(QPainter &p) {
static int t = 201; // FIXME make static to namespace perhaps
@ -209,7 +209,7 @@ void Analyzer::Base::demo(QPainter &p) {
}
void Analyzer::interpolate(const Scope &inVec, Scope &outVec) {
void AnalyzerBase::interpolate(const Scope &inVec, Scope &outVec) {
double pos = 0.0;
const double step = static_cast<double>(inVec.size()) / static_cast<double>(outVec.size());
@ -235,7 +235,7 @@ void Analyzer::interpolate(const Scope &inVec, Scope &outVec) {
}
void Analyzer::initSin(Scope &v, const uint size) {
void AnalyzerBase::initSin(Scope &v, const uint size) {
double step = (M_PI * 2) / size;
double radian = 0;
@ -247,7 +247,7 @@ void Analyzer::initSin(Scope &v, const uint size) {
}
void Analyzer::Base::timerEvent(QTimerEvent *e) {
void AnalyzerBase::timerEvent(QTimerEvent *e) {
QWidget::timerEvent(e);
if (e->timerId() != timer_.timerId()) {

View File

@ -46,15 +46,11 @@ class QShowEvent;
class QPaintEvent;
class QTimerEvent;
namespace Analyzer {
using Scope = std::vector<float>;
class Base : public QWidget {
class AnalyzerBase : public QWidget {
Q_OBJECT
public:
~Base() override;
~AnalyzerBase() override;
int timeout() const { return timeout_; }
@ -65,7 +61,8 @@ class Base : public QWidget {
virtual void framerateChanged() {}
protected:
explicit Base(QWidget*, const uint scopeSize = 7);
using Scope = std::vector<float>;
explicit AnalyzerBase(QWidget*, const uint scopeSize = 7);
void hideEvent(QHideEvent*) override;
void showEvent(QShowEvent*) override;
@ -79,6 +76,9 @@ class Base : public QWidget {
virtual void analyze(QPainter &p, const Scope&, const bool new_frame) = 0;
virtual void demo(QPainter &p);
void interpolate(const Scope&, Scope&);
void initSin(Scope&, const uint = 6000);
protected:
QBasicTimer timer_;
FHT *fht_;
@ -90,10 +90,5 @@ class Base : public QWidget {
int timeout_;
};
void interpolate(const Scope&, Scope&);
void initSin(Scope&, const uint = 6000);
} // namespace Analyzer
#endif // ANALYZERBASE_H

View File

@ -83,8 +83,8 @@ AnalyzerContainer::AnalyzerContainer(QWidget *parent)
AddAnalyzerType<BlockAnalyzer>();
AddAnalyzerType<BoomAnalyzer>();
AddAnalyzerType<Rainbow::NyanCatAnalyzer>();
AddAnalyzerType<Rainbow::RainbowDashAnalyzer>();
AddAnalyzerType<NyanCatAnalyzer>();
AddAnalyzerType<RainbowDashAnalyzer>();
AddAnalyzerType<Sonogram>();
disable_action_ = context_menu_->addAction(tr("No analyzer"), this, &AnalyzerContainer::DisableAnalyzer);
@ -149,7 +149,7 @@ void AnalyzerContainer::ChangeAnalyzer(const int id) {
}
delete current_analyzer_;
current_analyzer_ = qobject_cast<Analyzer::Base*>(instance);
current_analyzer_ = qobject_cast<AnalyzerBase*>(instance);
current_analyzer_->set_engine(engine_);
// Even if it is not supposed to happen, I don't want to get a dbz error
current_framerate_ = current_framerate_ == 0 ? kMediumFramerate : current_framerate_;

View File

@ -36,9 +36,7 @@ class QTimer;
class QMouseEvent;
class QWheelEvent;
namespace Analyzer {
class Base;
} // namespace Analyzer
class AnalyzerBase;
class AnalyzerContainer : public QWidget {
Q_OBJECT
@ -94,7 +92,7 @@ class AnalyzerContainer : public QWidget {
QPoint last_click_pos_;
bool ignore_next_click_;
Analyzer::Base *current_analyzer_;
AnalyzerBase *current_analyzer_;
EngineBase *engine_;
};

View File

@ -46,7 +46,7 @@ const int BlockAnalyzer::kFadeSize = 90;
const char *BlockAnalyzer::kName = QT_TRANSLATE_NOOP("AnalyzerContainer", "Block analyzer");
BlockAnalyzer::BlockAnalyzer(QWidget *parent)
: Analyzer::Base(parent, 9),
: AnalyzerBase(parent, 9),
columns_(0),
rows_(0),
y_(0),
@ -124,7 +124,7 @@ void BlockAnalyzer::framerateChanged() {
determineStep();
}
void BlockAnalyzer::transform(Analyzer::Scope &s) {
void BlockAnalyzer::transform(Scope &s) {
for (uint x = 0; x < s.size(); ++x) s[x] *= 2;
@ -136,7 +136,7 @@ void BlockAnalyzer::transform(Analyzer::Scope &s) {
}
void BlockAnalyzer::analyze(QPainter &p, const Analyzer::Scope &s, bool new_frame) {
void BlockAnalyzer::analyze(QPainter &p, const Scope &s, bool new_frame) {
// y = 2 3 2 1 0 2
// . . . . # .
@ -158,7 +158,7 @@ void BlockAnalyzer::analyze(QPainter &p, const Analyzer::Scope &s, bool new_fram
QPainter canvas_painter(&canvas_);
Analyzer::interpolate(s, scope_);
interpolate(s, scope_);
// Paint the background
canvas_painter.drawPixmap(0, 0, background_);

View File

@ -37,7 +37,7 @@
class QWidget;
class QResizeEvent;
class BlockAnalyzer : public Analyzer::Base {
class BlockAnalyzer : public AnalyzerBase {
Q_OBJECT
public:
@ -53,8 +53,8 @@ class BlockAnalyzer : public Analyzer::Base {
static const char *kName;
protected:
void transform(Analyzer::Scope&) override;
void analyze(QPainter &p, const Analyzer::Scope&, bool new_frame) override;
void transform(Scope&) override;
void analyze(QPainter &p, const Scope&, bool new_frame) override;
void resizeEvent(QResizeEvent*) override;
virtual void paletteChange(const QPalette&);
void framerateChanged() override;
@ -71,7 +71,7 @@ class BlockAnalyzer : public Analyzer::Base {
QPixmap topbarpixmap_;
QPixmap background_;
QPixmap canvas_;
Analyzer::Scope scope_; // so we don't create a vector every frame
Scope scope_; // so we don't create a vector every frame
QVector<double> store_; // current bar heights
QVector<double> yscale_;

View File

@ -36,8 +36,6 @@
#include "fht.h"
#include "analyzerbase.h"
using Analyzer::Scope;
const int BoomAnalyzer::kColumnWidth = 4;
const int BoomAnalyzer::kMaxBandCount = 256;
const int BoomAnalyzer::kMinBandCount = 32;
@ -45,7 +43,7 @@ const int BoomAnalyzer::kMinBandCount = 32;
const char *BoomAnalyzer::kName = QT_TRANSLATE_NOOP("AnalyzerContainer", "Boom analyzer");
BoomAnalyzer::BoomAnalyzer(QWidget *parent)
: Analyzer::Base(parent, 9),
: AnalyzerBase(parent, 9),
bands_(0),
scope_(kMinBandCount),
fg_(palette().color(QPalette::Highlight)),
@ -119,7 +117,7 @@ void BoomAnalyzer::analyze(QPainter &p, const Scope &scope, const bool new_frame
QPainter canvas_painter(&canvas_);
canvas_.fill(palette().color(QPalette::Window));
Analyzer::interpolate(scope, scope_);
interpolate(scope, scope_);
for (int i = 0, x = 0, y = 0; i < bands_; ++i, x += kColumnWidth + 1) {
h = log10(scope_[i] * 256.0) * F_;

View File

@ -36,7 +36,7 @@
class QWidget;
class QResizeEvent;
class BoomAnalyzer : public Analyzer::Base {
class BoomAnalyzer : public AnalyzerBase {
Q_OBJECT
public:
@ -44,8 +44,8 @@ class BoomAnalyzer : public Analyzer::Base {
static const char *kName;
void transform(Analyzer::Scope &s) override;
void analyze(QPainter &p, const Analyzer::Scope&, const bool new_frame) override;
void transform(Scope &s) override;
void analyze(QPainter &p, const Scope&, const bool new_frame) override;
public slots:
void changeK_barHeight(int);
@ -59,7 +59,7 @@ class BoomAnalyzer : public Analyzer::Base {
static const int kMinBandCount;
int bands_;
Analyzer::Scope scope_;
Scope scope_;
QColor fg_;
double K_barHeight_, F_peakSpeed_, F_;

View File

@ -41,23 +41,21 @@
#include "fht.h"
#include "analyzerbase.h"
using Analyzer::Scope;
const int RainbowAnalyzer::kHeight[] = { 21, 33 };
const int RainbowAnalyzer::kWidth[] = { 34, 53 };
const int RainbowAnalyzer::kFrameCount[] = { 6, 16 };
const int RainbowAnalyzer::kRainbowHeight[] = { 21, 16 };
const int RainbowAnalyzer::kRainbowOverlap[] = { 13, 15 };
const int RainbowAnalyzer::kSleepingHeight[] = { 24, 33 };
const int Rainbow::RainbowAnalyzer::kHeight[] = { 21, 33 };
const int Rainbow::RainbowAnalyzer::kWidth[] = { 34, 53 };
const int Rainbow::RainbowAnalyzer::kFrameCount[] = { 6, 16 };
const int Rainbow::RainbowAnalyzer::kRainbowHeight[] = { 21, 16 };
const int Rainbow::RainbowAnalyzer::kRainbowOverlap[] = { 13, 15 };
const int Rainbow::RainbowAnalyzer::kSleepingHeight[] = { 24, 33 };
const char *NyanCatAnalyzer::kName = "Nyanalyzer Cat";
const char *RainbowDashAnalyzer::kName = "Rainbow Dash";
const float RainbowAnalyzer::kPixelScale = 0.02F;
const char *Rainbow::NyanCatAnalyzer::kName = "Nyanalyzer Cat";
const char *Rainbow::RainbowDashAnalyzer::kName = "Rainbow Dash";
const float Rainbow::RainbowAnalyzer::kPixelScale = 0.02F;
RainbowAnalyzer::RainbowType RainbowAnalyzer::rainbowtype;
Rainbow::RainbowAnalyzer::RainbowType Rainbow::RainbowAnalyzer::rainbowtype;
Rainbow::RainbowAnalyzer::RainbowAnalyzer(const RainbowType rbtype, QWidget *parent)
: Analyzer::Base(parent, 9),
RainbowAnalyzer::RainbowAnalyzer(const RainbowType rbtype, QWidget *parent)
: AnalyzerBase(parent, 9),
timer_id_(startTimer(kFrameIntervalMs)),
frame_(0),
current_buffer_(0),
@ -81,20 +79,20 @@ Rainbow::RainbowAnalyzer::RainbowAnalyzer(const RainbowType rbtype, QWidget *par
}
void Rainbow::RainbowAnalyzer::transform(Scope &s) { fht_->spectrum(s.data()); }
void RainbowAnalyzer::transform(Scope &s) { fht_->spectrum(s.data()); }
void Rainbow::RainbowAnalyzer::timerEvent(QTimerEvent *e) {
void RainbowAnalyzer::timerEvent(QTimerEvent *e) {
if (e->timerId() == timer_id_) {
frame_ = (frame_ + 1) % kFrameCount[rainbowtype];
}
else {
Analyzer::Base::timerEvent(e);
AnalyzerBase::timerEvent(e);
}
}
void Rainbow::RainbowAnalyzer::resizeEvent(QResizeEvent *e) {
void RainbowAnalyzer::resizeEvent(QResizeEvent *e) {
Q_UNUSED(e);
@ -108,7 +106,7 @@ void Rainbow::RainbowAnalyzer::resizeEvent(QResizeEvent *e) {
}
void Rainbow::RainbowAnalyzer::analyze(QPainter &p, const Analyzer::Scope &s, bool new_frame) {
void RainbowAnalyzer::analyze(QPainter &p, const Scope &s, bool new_frame) {
// Discard the second half of the transform
const int scope_size = static_cast<int>(s.size() / 2);
@ -203,8 +201,8 @@ void Rainbow::RainbowAnalyzer::analyze(QPainter &p, const Analyzer::Scope &s, bo
}
Rainbow::NyanCatAnalyzer::NyanCatAnalyzer(QWidget *parent)
: RainbowAnalyzer(Rainbow::RainbowAnalyzer::Nyancat, parent) {}
NyanCatAnalyzer::NyanCatAnalyzer(QWidget *parent)
: RainbowAnalyzer(RainbowAnalyzer::Nyancat, parent) {}
Rainbow::RainbowDashAnalyzer::RainbowDashAnalyzer(QWidget *parent)
: RainbowAnalyzer(Rainbow::RainbowAnalyzer::Dash, parent) {}
RainbowDashAnalyzer::RainbowDashAnalyzer(QWidget *parent)
: RainbowAnalyzer(RainbowAnalyzer::Dash, parent) {}

View File

@ -40,8 +40,7 @@ class QWidget;
class QTimerEvent;
class QResizeEvent;
namespace Rainbow {
class RainbowAnalyzer : public Analyzer::Base {
class RainbowAnalyzer : public AnalyzerBase {
Q_OBJECT
public:
@ -53,8 +52,8 @@ class RainbowAnalyzer : public Analyzer::Base {
RainbowAnalyzer(const RainbowType rbtype, QWidget *parent);
protected:
void transform(Analyzer::Scope&) override;
void analyze(QPainter &p, const Analyzer::Scope&, bool new_frame) override;
void transform(Scope&) override;
void analyze(QPainter &p, const Scope&, bool new_frame) override;
void timerEvent(QTimerEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
@ -142,6 +141,5 @@ class RainbowDashAnalyzer : public RainbowAnalyzer {
static const char *kName;
};
} // namespace Rainbow
#endif // RAINBOWANALYZER_H

View File

@ -31,7 +31,7 @@
const char *Sonogram::kName = QT_TRANSLATE_NOOP("AnalyzerContainer", "Sonogram");
Sonogram::Sonogram(QWidget *parent)
: Analyzer::Base(parent, 9) {}
: AnalyzerBase(parent, 9) {}
void Sonogram::resizeEvent(QResizeEvent *e) {
@ -42,7 +42,7 @@ void Sonogram::resizeEvent(QResizeEvent *e) {
}
void Sonogram::analyze(QPainter &p, const Analyzer::Scope &s, bool new_frame) {
void Sonogram::analyze(QPainter &p, const Scope &s, bool new_frame) {
if (!new_frame || engine_->state() == EngineBase::State::Paused) {
p.drawPixmap(0, 0, canvas_);
@ -52,7 +52,7 @@ void Sonogram::analyze(QPainter &p, const Analyzer::Scope &s, bool new_frame) {
QPainter canvas_painter(&canvas_);
canvas_painter.drawPixmap(0, 0, canvas_, 1, 0, width() - 1, -1);
Analyzer::Scope::const_iterator it = s.begin(), end = s.end();
Scope::const_iterator it = s.begin(), end = s.end();
for (int y = height() - 1; y;) {
QColor c;
@ -81,7 +81,7 @@ void Sonogram::analyze(QPainter &p, const Analyzer::Scope &s, bool new_frame) {
}
void Sonogram::transform(Analyzer::Scope &scope) {
void Sonogram::transform(Scope &scope) {
fht_->power2(scope.data());
fht_->scale(scope.data(), 1.0 / 256);
@ -90,5 +90,5 @@ void Sonogram::transform(Analyzer::Scope &scope) {
}
void Sonogram::demo(QPainter &p) {
analyze(p, Analyzer::Scope(fht_->size(), 0), new_frame_);
analyze(p, Scope(fht_->size(), 0), new_frame_);
}

View File

@ -29,7 +29,7 @@
#include "analyzerbase.h"
class Sonogram : public Analyzer::Base {
class Sonogram : public AnalyzerBase {
Q_OBJECT
public:
Q_INVOKABLE explicit Sonogram(QWidget *parent);
@ -38,8 +38,8 @@ class Sonogram : public Analyzer::Base {
protected:
void resizeEvent(QResizeEvent *e) override;
void analyze(QPainter &p, const Analyzer::Scope &s, bool new_frame) override;
void transform(Analyzer::Scope &scope) override;
void analyze(QPainter &p, const Scope &s, bool new_frame) override;
void transform(Scope &scope) override;
void demo(QPainter &p) override;
private: