From 4fe9282a9b13ac41e256f2b0fb4405dbcc46f2dd Mon Sep 17 00:00:00 2001 From: mio Date: Sun, 20 Oct 2024 17:27:01 +1000 Subject: Fix the audio analyzer Most of the code was already borrowed from Amarok, but wasn't properly finished. This just updates the code to more closely match what is currently in TDE's Amarok. The Analyzer still sits in the statusBar(), which is cool, but can have some delays when watching a video (the video itself is unaffected). See: TDE/codeine#23 Signed-off-by: mio (cherry picked from commit a3ea0ee70fe8590a96df03dca43ca77f3f28791e) --- src/app/analyzer.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 8 deletions(-) (limited to 'src/app/analyzer.h') diff --git a/src/app/analyzer.h b/src/app/analyzer.h index 3339c9d..7b8daac 100644 --- a/src/app/analyzer.h +++ b/src/app/analyzer.h @@ -8,6 +8,7 @@ #include #endif +#include "fht.h" #include //stack allocated and convenience #include //stack allocated #include //baseclass @@ -23,10 +24,13 @@ namespace Analyzer uint timeout() const { return m_timeout; } protected: - Base( TQWidget*, uint ); + Base( TQWidget*, uint, uint = 7 ); + ~Base() { delete m_fht; } + void drawFrame(); virtual void transform( Scope& ) = 0; virtual void analyze( const Scope& ) = 0; + virtual void demo(); private: virtual bool event( TQEvent* ); @@ -34,42 +38,91 @@ namespace Analyzer protected: TQTimer m_timer; uint m_timeout; + FHT *m_fht; }; class Base2D : public Base { TQ_OBJECT public: + const TQPixmap *background() const { return &m_background; } const TQPixmap *canvas() const { return &m_canvas; } private slots: - void draw(); + void draw() { drawFrame(); bitBlt(this, 0, 0, canvas()); } protected: - Base2D( TQWidget*, uint timeout ); + Base2D( TQWidget*, uint timeout, uint scopeSize = 7 ); + TQPixmap *background() { return &m_background; } TQPixmap *canvas() { return &m_canvas; } - void paintEvent( TQPaintEvent* ) { if( !m_canvas.isNull() ) bitBlt( this, 0, 0, canvas() ); } - void resizeEvent( TQResizeEvent* ); + void eraseCanvas() + { + bitBlt(canvas(), 0, 0, background()); + } + + void paintEvent( TQPaintEvent* ) override { if( !m_canvas.isNull() ) bitBlt( this, 0, 0, canvas() ); } + void resizeEvent( TQResizeEvent* ) override; + void paletteChange( const TQPalette& ) override; private: + TQPixmap m_background; TQPixmap m_canvas; }; class Block : public Analyzer::Base2D { public: - Block( TQWidget* ); + explicit Block( TQWidget* ); + + static constexpr int HEIGHT = 2; + static constexpr int FADE_SIZE = 90; + static constexpr int MIN_COLUMNS = 32; + static constexpr int MAX_COLUMNS = 256; + static constexpr int MIN_ROWS = 3; + static constexpr int WIDTH = 4; protected: virtual void transform( Analyzer::Scope& ); virtual void analyze( const Analyzer::Scope& ); + void paletteChange(const TQPalette&) override; + void resizeEvent(TQResizeEvent *) override; + + void determineStep(); + void drawBackground(); + + private: + TQPixmap *bar() + { + return &m_barPixmap; + } - virtual int heightForWidth( int ) const; + // So we don't create a vector each frame. + Scope m_scope; + TQPixmap m_barPixmap; + TQPixmap m_topBarPixmap; - virtual void show() {} //TODO temporary as the scope plugin causes freezes + // Current bar heights + std::vector m_store; + std::vector m_yScale; + + std::vector m_fadeBars; + std::vector m_fadeIntensity; + std::vector m_fadePos; + + // Number of rows and columns of blocks + unsigned m_columns; + unsigned m_rows; + + // y-offset from top of widget + unsigned m_y; + + // rows to fall per-step + float m_step; }; + + void interpolate(const Scope&, Scope&); } #endif -- cgit v1.2.3