Skip to content

Commit

Permalink
Rename analyzers and add turbine analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaski committed Jul 9, 2024
1 parent 79c28e7 commit 6259291
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 59 deletions.
10 changes: 6 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ set(SOURCES
analyzer/analyzercontainer.cpp
analyzer/blockanalyzer.cpp
analyzer/boomanalyzer.cpp
analyzer/turbineanalyzer.cpp
analyzer/sonogramanalyzer.cpp
analyzer/waverubberanalyzer.cpp
analyzer/rainbowanalyzer.cpp
analyzer/sonogram.cpp
analyzer/waverubber.cpp

equalizer/equalizer.cpp
equalizer/equalizerslider.cpp
Expand Down Expand Up @@ -331,9 +332,10 @@ set(HEADERS
analyzer/analyzercontainer.h
analyzer/blockanalyzer.h
analyzer/boomanalyzer.h
analyzer/turbineanalyzer.h
analyzer/sonogramanalyzer.h
analyzer/waverubberanalyzer.h
analyzer/rainbowanalyzer.h
analyzer/sonogram.h
analyzer/waverubber.h

equalizer/equalizer.h
equalizer/equalizerslider.h
Expand Down
12 changes: 7 additions & 5 deletions src/analyzer/analyzercontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@
#include "analyzerbase.h"
#include "blockanalyzer.h"
#include "boomanalyzer.h"
#include "turbineanalyzer.h"
#include "sonogramanalyzer.h"
#include "waverubberanalyzer.h"
#include "rainbowanalyzer.h"
#include "sonogram.h"
#include "waverubber.h"

#include "core/logging.h"
#include "core/shared_ptr.h"
Expand Down Expand Up @@ -88,10 +89,11 @@ AnalyzerContainer::AnalyzerContainer(QWidget *parent)

AddAnalyzerType<BlockAnalyzer>();
AddAnalyzerType<BoomAnalyzer>();
AddAnalyzerType<NyanCatAnalyzer>();
AddAnalyzerType<TurbineAnalyzer>();
AddAnalyzerType<SonogramAnalyzer>();
AddAnalyzerType<WaveRubberAnalyzer>();
AddAnalyzerType<RainbowDashAnalyzer>();
AddAnalyzerType<Sonogram>();
AddAnalyzerType<WaveRubber>();
AddAnalyzerType<NyanCatAnalyzer>();

disable_action_ = context_menu_->addAction(tr("No analyzer"), this, &AnalyzerContainer::DisableAnalyzer);
disable_action_->setCheckable(true);
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/blockanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void BlockAnalyzer::transform(Scope &s) {

}

void BlockAnalyzer::analyze(QPainter &p, const Scope &s, bool new_frame) {
void BlockAnalyzer::analyze(QPainter &p, const Scope &s, const bool new_frame) {

// y = 2 3 2 1 0 2
// . . . . # .
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/blockanalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class BlockAnalyzer : public AnalyzerBase {

protected:
void transform(Scope&) override;
void analyze(QPainter &p, const Scope&, bool new_frame) override;
void analyze(QPainter &p, const Scope &s, const bool new_frame) override;
void resizeEvent(QResizeEvent*) override;
virtual void paletteChange(const QPalette&);
void framerateChanged() override;
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/boomanalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class BoomAnalyzer : public AnalyzerBase {
static const char *kName;

void transform(Scope &s) override;
void analyze(QPainter &p, const Scope&, const bool new_frame) override;
void analyze(QPainter &p, const Scope &scope, const bool new_frame) override;

public slots:
void changeK_barHeight(int);
Expand Down
19 changes: 11 additions & 8 deletions src/analyzer/rainbowanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,21 @@
#include "fht.h"
#include "analyzerbase.h"

const char *NyanCatAnalyzer::kName = "Nyanalyzer Cat";
const char *RainbowDashAnalyzer::kName = "Rainbow Dash";

RainbowAnalyzer::RainbowType RainbowAnalyzer::rainbowtype;
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 char *NyanCatAnalyzer::kName = "Nyanalyzer Cat";
const char *RainbowDashAnalyzer::kName = "Rainbow Dash";
const float RainbowAnalyzer::kPixelScale = 0.02F;

RainbowAnalyzer::RainbowType RainbowAnalyzer::rainbowtype;
namespace {
constexpr int kFrameIntervalMs = 150;
constexpr int kRainbowHeight[] = { 21, 16 };
constexpr int kRainbowOverlap[] = { 13, 15 };
constexpr float kPixelScale = 0.02F;
} // namespace

RainbowAnalyzer::RainbowAnalyzer(const RainbowType rbtype, QWidget *parent)
: AnalyzerBase(parent, 9),
Expand Down Expand Up @@ -106,7 +109,7 @@ void RainbowAnalyzer::resizeEvent(QResizeEvent *e) {

}

void RainbowAnalyzer::analyze(QPainter &p, const Scope &s, bool new_frame) {
void RainbowAnalyzer::analyze(QPainter &p, const Scope &s, const bool new_frame) {

// Discard the second half of the transform
const int scope_size = static_cast<int>(s.size() / 2);
Expand Down
27 changes: 10 additions & 17 deletions src/analyzer/rainbowanalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,44 +49,37 @@ class RainbowAnalyzer : public AnalyzerBase {
Dash = 1
};

RainbowAnalyzer(const RainbowType rbtype, QWidget *parent);
explicit RainbowAnalyzer(const RainbowType rbtype, QWidget *parent);

protected:
void transform(Scope&) override;
void analyze(QPainter &p, const Scope&, bool new_frame) override;
void transform(Scope &s) override;
void analyze(QPainter &p, const Scope &s, const bool new_frame) override;

void timerEvent(QTimerEvent *e) override;
void resizeEvent(QResizeEvent *e) override;

private:
static const int kRainbowBands = 6;
static const int kHistorySize = 128;
static RainbowType rainbowtype;
static const int kHeight[];
static const int kWidth[];
static const int kFrameCount[];
static const int kRainbowHeight[];
static const int kRainbowOverlap[];
static const int kSleepingHeight[];

static const int kHistorySize = 128;
static const int kRainbowBands = 6;
static const float kPixelScale;

static const int kFrameIntervalMs = 150;

static RainbowType rainbowtype;

inline QRect SourceRect(RainbowType _rainbowtype) const {
inline QRect SourceRect(const RainbowType _rainbowtype) const {
return QRect(0, kHeight[_rainbowtype] * frame_, kWidth[_rainbowtype], kHeight[_rainbowtype]);
}

inline QRect SleepingSourceRect(RainbowType _rainbowtype) const {
inline QRect SleepingSourceRect(const RainbowType _rainbowtype) const {
return QRect(0, kHeight[_rainbowtype] * kFrameCount[_rainbowtype], kWidth[_rainbowtype], kSleepingHeight[_rainbowtype]);
}

inline QRect DestRect(RainbowType _rainbowtype) const {
inline QRect DestRect(const RainbowType _rainbowtype) const {
return QRect(width() - kWidth[_rainbowtype], (height() - kHeight[_rainbowtype]) / 2, kWidth[_rainbowtype], kHeight[_rainbowtype]);
}

inline QRect SleepingDestRect(RainbowType _rainbowtype) const {
inline QRect SleepingDestRect(const RainbowType _rainbowtype) const {
return QRect(width() - kWidth[_rainbowtype], (height() - kSleepingHeight[_rainbowtype]) / 2, kWidth[_rainbowtype], kSleepingHeight[_rainbowtype]);
}

Expand Down
14 changes: 7 additions & 7 deletions src/analyzer/sonogram.cpp → src/analyzer/sonogramanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

#include "engine/enginebase.h"

#include "sonogram.h"
#include "sonogramanalyzer.h"

const char *Sonogram::kName = QT_TRANSLATE_NOOP("AnalyzerContainer", "Sonogram");
const char *SonogramAnalyzer::kName = QT_TRANSLATE_NOOP("AnalyzerContainer", "Sonogram");

Sonogram::Sonogram(QWidget *parent)
SonogramAnalyzer::SonogramAnalyzer(QWidget *parent)
: AnalyzerBase(parent, 9) {}

void Sonogram::resizeEvent(QResizeEvent *e) {
void SonogramAnalyzer::resizeEvent(QResizeEvent *e) {

Q_UNUSED(e)

Expand All @@ -42,7 +42,7 @@ void Sonogram::resizeEvent(QResizeEvent *e) {

}

void Sonogram::analyze(QPainter &p, const Scope &s, bool new_frame) {
void SonogramAnalyzer::analyze(QPainter &p, const Scope &s, const bool new_frame) {

if (!new_frame || engine_->state() == EngineBase::State::Paused) {
p.drawPixmap(0, 0, canvas_);
Expand Down Expand Up @@ -81,14 +81,14 @@ void Sonogram::analyze(QPainter &p, const Scope &s, bool new_frame) {

}

void Sonogram::transform(Scope &scope) {
void SonogramAnalyzer::transform(Scope &scope) {

fht_->power2(scope.data());
fht_->scale(scope.data(), 1.0 / 256);
scope.resize(fht_->size() / 2);

}

void Sonogram::demo(QPainter &p) {
void SonogramAnalyzer::demo(QPainter &p) {
analyze(p, Scope(fht_->size(), 0), new_frame_);
}
13 changes: 7 additions & 6 deletions src/analyzer/sonogram.h → src/analyzer/sonogramanalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,30 @@
along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef SONOGRAM_H
#define SONOGRAM_H
#ifndef SONOGRAMANALYZER_H
#define SONOGRAMANALYZER_H

#include <QPixmap>
#include <QPainter>

#include "analyzerbase.h"

class Sonogram : public AnalyzerBase {
class SonogramAnalyzer : public AnalyzerBase {
Q_OBJECT

public:
Q_INVOKABLE explicit Sonogram(QWidget *parent);
Q_INVOKABLE explicit SonogramAnalyzer(QWidget *parent);

static const char *kName;

protected:
void resizeEvent(QResizeEvent *e) override;
void analyze(QPainter &p, const Scope &s, bool new_frame) override;
void analyze(QPainter &p, const Scope &s, const bool new_frame) override;
void transform(Scope &scope) override;
void demo(QPainter &p) override;

private:
QPixmap canvas_;
};

#endif // SONOGRAM_H
#endif // SONOGRAMANALYZER_H
100 changes: 100 additions & 0 deletions src/analyzer/turbineanalyzer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
Strawberry Music Player
This file was part of Clementine.
Copyright 2003, Stanislav Karchebny <[email protected]>
Copyright 2003, Max Howell <[email protected]>
Copyright 2009-2010, David Sansome <[email protected]>
Copyright 2014-2015, Mark Furneaux <[email protected]>
Copyright 2014, Krzysztof Sobiecki <[email protected]>
Copyright 2014, John Maguire <[email protected]>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/

#include "config.h"

#include <cmath>
#include <algorithm>

#include <QPainter>

#include "turbineanalyzer.h"
#include "engine/enginebase.h"

const char *TurbineAnalyzer::kName = QT_TRANSLATE_NOOP("AnalyzerContainer", "Turbine");

TurbineAnalyzer::TurbineAnalyzer(QWidget *parent) : BoomAnalyzer(parent) {}

void TurbineAnalyzer::analyze(QPainter &p, const Scope &scope, const bool new_frame) {

if (!new_frame || engine_->state() == EngineBase::State::Paused) {
p.drawPixmap(0, 0, canvas_);
return;
}

const uint hd2 = height() / 2;
const uint kMaxHeight = hd2 - 1;

QPainter canvas_painter(&canvas_);
canvas_.fill(palette().color(QPalette::Window));

AnalyzerBase::interpolate(scope, scope_);

for (uint i = 0, x = 0, y = 0; i < static_cast<uint>(bands_); ++i, x += kColumnWidth + 1) {
float h = static_cast<float>(std::min(log10(scope_[i] * 256.0) * F_ * 0.5, kMaxHeight * 1.0));

if (h > bar_height_[i]) {
bar_height_[i] = h;
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;
}

peak_handling:
if (peak_height_[i] > 0.0) {
peak_height_[i] -= peak_speed_[i];
peak_speed_[i] *= F_peakSpeed_; // 1.12
peak_height_[i] = std::max(0.0, std::max(bar_height_[i], peak_height_[i]));
}
}

y = hd2 - static_cast<uint>(bar_height_[i]);
canvas_painter.drawPixmap(static_cast<int>(x + 1), static_cast<int>(y), barPixmap_, 0, static_cast<int>(y), -1, -1);
canvas_painter.drawPixmap(static_cast<int>(x + 1), static_cast<int>(hd2), barPixmap_, 0, static_cast<int>(bar_height_[i]), -1, -1);

canvas_painter.setPen(fg_);
if (bar_height_[i] > 0) {
canvas_painter.drawRect(static_cast<int>(x), static_cast<int>(y), kColumnWidth - 1, static_cast<int>(bar_height_[i]) * 2 - 1);
}

const uint x2 = x + kColumnWidth - 1;
canvas_painter.setPen(palette().color(QPalette::Midlight));
y = hd2 - static_cast<uint>(peak_height_[i]);
canvas_painter.drawLine(static_cast<int>(x), static_cast<int>(y), static_cast<int>(x2), static_cast<int>(y));
y = hd2 + static_cast<uint>(peak_height_[i]);
canvas_painter.drawLine(static_cast<int>(x), static_cast<int>(y), static_cast<int>(x2), static_cast<int>(y));
}

p.drawPixmap(0, 0, canvas_);

}
41 changes: 41 additions & 0 deletions src/analyzer/turbineanalyzer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Strawberry Music Player
This file was part of Clementine.
Copyright 2003, Stanislav Karchebny <[email protected]>
Copyright 2009-2010, David Sansome <[email protected]>
Copyright 2014, Krzysztof Sobiecki <[email protected]>
Copyright 2014, John Maguire <[email protected]>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef TURBINEANALYZER_H
#define TURBINEANALYZER_H

#include "boomanalyzer.h"

class QPainter;

class TurbineAnalyzer : public BoomAnalyzer {
Q_OBJECT

public:
Q_INVOKABLE explicit TurbineAnalyzer(QWidget *parent);

void analyze(QPainter &p, const Scope &scope, const bool new_frame);

static const char *kName;
};

#endif // TURBINEANALYZER_H
Loading

0 comments on commit 6259291

Please sign in to comment.