File indexing completed on 2024-05-12 04:50:07

0001 /*
0002     SPDX-FileCopyrightText: 2004 Max Howell <max.howell@methylblue.com>
0003     SPDX-FileCopyrightText: 2009  Martin Sandsmark <sandsmark@samfundet.no>
0004 
0005     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 */
0007 
0008 #ifndef ANALYZERBASE_H
0009 #define ANALYZERBASE_H
0010 
0011 #ifdef __FreeBSD__
0012 #include <sys/types.h>
0013 #endif
0014 
0015 #include "fht.h" //stack allocated and convenience
0016 #include <QPixmap> //stack allocated and convenience
0017 #include <QTimer> //stack allocated
0018 #include <QWidget> //baseclass
0019 #include <vector> //included for convenience
0020 
0021 #include <phonon/audiodataoutput.h>
0022 
0023 class QEvent;
0024 class QPaintEvent;
0025 class QResizeEvent;
0026 
0027 namespace Analyzer
0028 {
0029 
0030 typedef std::vector<float> Scope;
0031 
0032 class Base : public QWidget
0033 {
0034     Q_OBJECT
0035 
0036 public Q_SLOTS:
0037     void drawFrame(const QMap<Phonon::AudioDataOutput::Channel, QVector<qint16>> &thescope);
0038 
0039 protected:
0040     Base(QWidget *, uint = 7);
0041     ~Base() override
0042     {
0043         delete m_fht;
0044     }
0045 
0046     int resizeExponent(int);
0047     int resizeForBands(int);
0048     virtual void transform(QVector<float> &);
0049     virtual void analyze(const QVector<float> &) = 0;
0050     virtual void paused();
0051 public Q_SLOTS:
0052     void demo();
0053 
0054 protected:
0055     FHT *m_fht;
0056 };
0057 
0058 class Base2D : public Base
0059 {
0060     Q_OBJECT
0061 public:
0062     const QPixmap *canvas() const
0063     {
0064         return &m_canvas;
0065     }
0066 
0067     // private Q_SLOTS:
0068     //     void draw() { drawFrame(); bitBlt( this, 0, 0, canvas() ); }
0069 
0070     void enableDemo(bool enable)
0071     {
0072         enable ? timer.start() : timer.stop();
0073     }
0074 
0075 protected:
0076     Base2D(QWidget *, uint scopeSize = 7);
0077 
0078     QPixmap *canvas()
0079     {
0080         return &m_canvas;
0081     }
0082     void eraseCanvas()
0083     {
0084         m_canvas.fill(Qt::transparent);
0085     }
0086 
0087     void paintEvent(QPaintEvent *) override;
0088     void resizeEvent(QResizeEvent *) override;
0089 
0090 protected Q_SLOTS:
0091     virtual void init()
0092     {
0093     }
0094 
0095 private:
0096     QPixmap m_canvas;
0097     QTimer timer;
0098 };
0099 
0100 class Factory
0101 {
0102     // Currently this is a rather small class, its only purpose
0103     // to ensure that making changes to analyzers will not require
0104     // rebuilding the world!
0105 
0106     // eventually it would be better to make analyzers pluggable
0107     // but I can't be arsed, nor can I see much reason to do so
0108     // yet!
0109 public:
0110     static QWidget *createAnalyzer(QWidget *);
0111     static QWidget *createPlaylistAnalyzer(QWidget *);
0112 };
0113 
0114 void interpolate(const QVector<float> &, QVector<float> &);
0115 void initSin(QVector<float> &, const uint = 6000);
0116 
0117 } // END namespace Analyzer
0118 
0119 using Analyzer::Scope;
0120 
0121 #endif