diff options
Diffstat (limited to 'src/plugins/Ui/skinned')
| -rw-r--r-- | src/plugins/Ui/skinned/mainvisual.cpp | 65 | ||||
| -rw-r--r-- | src/plugins/Ui/skinned/mainvisual.h | 17 | ||||
| -rw-r--r-- | src/plugins/Ui/skinned/shadedvisual.cpp | 94 | ||||
| -rw-r--r-- | src/plugins/Ui/skinned/shadedvisual.h | 20 |
4 files changed, 79 insertions, 117 deletions
diff --git a/src/plugins/Ui/skinned/mainvisual.cpp b/src/plugins/Ui/skinned/mainvisual.cpp index 9ed464048..7a705a24d 100644 --- a/src/plugins/Ui/skinned/mainvisual.cpp +++ b/src/plugins/Ui/skinned/mainvisual.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007-2012 by Ilya Kotov * + * Copyright (C) 2007-2017 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -31,9 +31,6 @@ #include "inlines.h" #include "mainvisual.h" -#define VISUAL_NODE_SIZE 512 //samples -#define VISUAL_BUFFER_SIZE (5*VISUAL_NODE_SIZE) - MainVisual *MainVisual::m_instance = 0; MainVisual *MainVisual::instance() @@ -50,10 +47,11 @@ MainVisual::MainVisual (QWidget *parent) : Visual (parent), m_vis (0) connect(m_skin, SIGNAL(skinChanged()), this, SLOT(readSettings())); m_timer = new QTimer (this); connect(m_timer, SIGNAL (timeout()), this, SLOT (timeout())); - m_buffer = new float[VISUAL_BUFFER_SIZE]; - m_buffer_at = 0; + m_left_buffer = new float[QMMP_VISUAL_NODE_SIZE]; + m_right_buffer = new float[QMMP_VISUAL_NODE_SIZE]; m_instance = this; m_update = false; + m_running = false; createMenu(); readSettings(); } @@ -67,7 +65,8 @@ MainVisual::~MainVisual() delete m_vis; m_vis = 0; } - delete [] m_buffer; + delete [] m_left_buffer; + delete [] m_right_buffer; m_instance = 0; } @@ -88,52 +87,22 @@ void MainVisual::setVisual (VisualBase *newvis) void MainVisual::clear() { - m_buffer_at = 0; if (m_vis) m_vis->clear(); m_pixmap = m_bg; update(); } -void MainVisual::add (float *data, size_t samples, int chan) -{ - if (!m_timer->isActive () || !m_vis) - return; - - if(VISUAL_BUFFER_SIZE == m_buffer_at) - { - m_buffer_at -= VISUAL_NODE_SIZE; - memmove(m_buffer, m_buffer + VISUAL_NODE_SIZE, m_buffer_at * sizeof(float)); - return; - } - - int frames = qMin(int(samples/chan), VISUAL_BUFFER_SIZE - m_buffer_at); - mono16_from_multichannel(m_buffer + m_buffer_at, data, frames, chan); - - m_buffer_at += frames; -} - void MainVisual::timeout() { - mutex()->lock (); - - if(m_buffer_at < VISUAL_NODE_SIZE) - { - mutex()->unlock (); - return; - } - - if (m_vis) + if(m_vis && takeData(m_left_buffer, m_right_buffer)) { - m_vis->process (m_buffer); - m_buffer_at -= VISUAL_NODE_SIZE; - memmove(m_buffer, m_buffer + VISUAL_NODE_SIZE, m_buffer_at*sizeof(float)); + m_vis->process(m_left_buffer); m_pixmap = m_bg; QPainter p(&m_pixmap); m_vis->draw (&p); + update(); } - mutex()->unlock (); - update(); } void MainVisual::paintEvent (QPaintEvent *) @@ -149,7 +118,7 @@ void MainVisual::hideEvent (QHideEvent *) void MainVisual::showEvent (QShowEvent *) { - if (m_vis) + if (m_vis && m_running) m_timer->start(); } @@ -180,6 +149,18 @@ void MainVisual::mousePressEvent (QMouseEvent *e) } } +void MainVisual::start() +{ + m_running = true; + if(isVisible()) + m_timer->start(); +} + +void MainVisual::stop() +{ + m_timer->stop(); +} + void MainVisual::drawBackGround() { m_bg = QPixmap (76 * m_ratio, 16 * m_ratio); @@ -552,7 +533,7 @@ Scope::~Scope() bool Scope::process(float *l) { - int step = (VISUAL_NODE_SIZE << 8)/76; + int step = (QMMP_VISUAL_NODE_SIZE << 8)/76; int pos = 0; for (int i = 0; i < 76; ++i) diff --git a/src/plugins/Ui/skinned/mainvisual.h b/src/plugins/Ui/skinned/mainvisual.h index 2998d48ce..13cd60d31 100644 --- a/src/plugins/Ui/skinned/mainvisual.h +++ b/src/plugins/Ui/skinned/mainvisual.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007-2012 by Ilya Kotov * + * Copyright (C) 2007-2017 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -45,13 +45,12 @@ class MainVisual : public Visual Q_OBJECT public: - MainVisual( QWidget *parent = 0); + MainVisual(QWidget *parent = 0); virtual ~MainVisual(); static MainVisual *instance(); void setVisual(VisualBase *newvis); - void add(float *data, size_t samples, int chan); - void clear(); + void paintEvent(QPaintEvent *); protected: @@ -60,13 +59,16 @@ protected: virtual void mousePressEvent (QMouseEvent *); public slots: - void timeout(); + void start(); + void stop(); private slots: + void timeout(); void readSettings(); void writeSettings(); private: + void clear(); void drawBackGround(); void createMenu(); @@ -88,9 +90,10 @@ private: QAction *m_peaksAction; QAction *m_transparentAction; int m_ratio; - float *m_buffer; - int m_buffer_at; + float *m_left_buffer; + float *m_right_buffer; bool m_update; + bool m_running; }; namespace mainvisual diff --git a/src/plugins/Ui/skinned/shadedvisual.cpp b/src/plugins/Ui/skinned/shadedvisual.cpp index ab522211f..94eac8961 100644 --- a/src/plugins/Ui/skinned/shadedvisual.cpp +++ b/src/plugins/Ui/skinned/shadedvisual.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007-2015 by Ilya Kotov * + * Copyright (C) 2007-2017 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -25,9 +25,6 @@ #include "inlines.h" #include "shadedvisual.h" -#define VISUAL_NODE_SIZE 512 //samples -#define VISUAL_BUFFER_SIZE (5*VISUAL_NODE_SIZE) - ShadedVisual::ShadedVisual(QWidget *parent) : Visual(parent) { m_skin = Skin::instance(); @@ -37,9 +34,9 @@ ShadedVisual::ShadedVisual(QWidget *parent) : Visual(parent) m_timer = new QTimer(this); connect(m_timer, SIGNAL (timeout()), this, SLOT (timeout())); connect(m_skin, SIGNAL(skinChanged()), this, SLOT(updateSkin())); - m_left_buffer = new float[VISUAL_BUFFER_SIZE]; - m_right_buffer = new float[VISUAL_BUFFER_SIZE]; - m_buffer_at = 0; + m_left_buffer = new float[QMMP_VISUAL_NODE_SIZE]; + m_right_buffer = new float[QMMP_VISUAL_NODE_SIZE]; + m_running = false; m_timer->setInterval(50); m_timer->start(); clear(); @@ -51,29 +48,8 @@ ShadedVisual::~ShadedVisual() delete [] m_right_buffer; } -void ShadedVisual::add(float *data, size_t samples, int chan) -{ - if (!m_timer->isActive ()) - return; - - if(VISUAL_BUFFER_SIZE == m_buffer_at) - { - m_buffer_at -= VISUAL_NODE_SIZE; - memmove(m_left_buffer, m_left_buffer + VISUAL_NODE_SIZE, m_buffer_at * sizeof(float)); - memmove(m_right_buffer, m_right_buffer + VISUAL_NODE_SIZE, m_buffer_at * sizeof(float)); - return; - } - - int frames = qMin(int(samples/chan), VISUAL_BUFFER_SIZE - m_buffer_at); - - stereo16_from_multichannel(m_left_buffer + m_buffer_at, - m_right_buffer + m_buffer_at, data, frames, chan); - m_buffer_at += frames; -} - void ShadedVisual::clear() { - m_buffer_at = 0; m_l = 0; m_r = 0; m_pixmap.fill(m_skin->getVisColor(0)); @@ -84,26 +60,32 @@ void ShadedVisual::timeout() { m_pixmap.fill(m_skin->getVisColor(0)); - mutex()->lock (); - if(m_buffer_at < VISUAL_NODE_SIZE) + if(takeData(m_left_buffer, m_right_buffer)) { - mutex()->unlock (); - return; + process(); + QPainter p(&m_pixmap); + draw (&p); + update(); } +} - process (m_left_buffer, m_right_buffer); - m_buffer_at -= VISUAL_NODE_SIZE; - memmove(m_left_buffer, m_left_buffer + VISUAL_NODE_SIZE, m_buffer_at * sizeof(float)); - memmove(m_right_buffer, m_right_buffer + VISUAL_NODE_SIZE, m_buffer_at * sizeof(float)); - QPainter p(&m_pixmap); - draw (&p); - mutex()->unlock (); - update(); +void ShadedVisual::start() +{ + m_running = true; + if(isVisible()) + m_timer->start(); +} + +void ShadedVisual::stop() +{ + m_running = false; + m_timer->stop(); + clear(); } -void ShadedVisual::process (float *left, float *right) +void ShadedVisual::process () { - int step = (VISUAL_NODE_SIZE << 8)/74; + int step = (QMMP_VISUAL_NODE_SIZE << 8)/74; int pos = 0; int l = 0; int r = 0; @@ -113,21 +95,16 @@ void ShadedVisual::process (float *left, float *right) { pos += step; - if (left) - { - j_l = abs(left[pos >> 8] * 8.0); - - if (j_l > 15) - j_l = 15; - l = qMax(l, j_l); - } - if (right) - { - j_r = abs(right[pos >> 8] * 8.0); - if (j_r > 15) - j_r = 15; - r = qMax(r, j_r); - } + j_l = abs(m_left_buffer[pos >> 8] * 8.0); + + if (j_l > 15) + j_l = 15; + l = qMax(l, j_l); + + j_r = abs(m_right_buffer[pos >> 8] * 8.0); + if (j_r > 15) + j_r = 15; + r = qMax(r, j_r); } m_l -= 0.5; m_l = qMax(m_l, (double)l); @@ -160,7 +137,8 @@ void ShadedVisual::hideEvent (QHideEvent *) void ShadedVisual::showEvent (QShowEvent *) { - m_timer->start(); + if(m_running) + m_timer->start(); } void ShadedVisual::updateSkin() diff --git a/src/plugins/Ui/skinned/shadedvisual.h b/src/plugins/Ui/skinned/shadedvisual.h index 0089139bc..2febec8ca 100644 --- a/src/plugins/Ui/skinned/shadedvisual.h +++ b/src/plugins/Ui/skinned/shadedvisual.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007-2015 by Ilya Kotov * + * Copyright (C) 2007-2017 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -39,30 +39,30 @@ public: ~ShadedVisual(); - void add(float *data, size_t samples, int chan); - void clear(); - - void paintEvent (QPaintEvent *); - void hideEvent (QHideEvent *); - void showEvent (QShowEvent *); - public slots: void timeout(); + void start(); + void stop(); private slots: void updateSkin(); private: - void process (float *l, float *r); + void clear(); + void paintEvent (QPaintEvent *); + void hideEvent (QHideEvent *); + void showEvent (QShowEvent *); + void process (); void draw (QPainter *); + Skin *m_skin; QTimer *m_timer; QPixmap m_pixmap; float *m_left_buffer; float *m_right_buffer; - int m_buffer_at; double m_l, m_r; int m_ratio; + bool m_running; }; |
