diff options
Diffstat (limited to 'src/plugins/Ui')
| -rw-r--r-- | src/plugins/Ui/qsui/logo.cpp | 70 | ||||
| -rw-r--r-- | src/plugins/Ui/qsui/logo.h | 11 | ||||
| -rw-r--r-- | src/plugins/Ui/qsui/mainwindow.cpp | 4 | ||||
| -rw-r--r-- | src/plugins/Ui/qsui/qsuianalyzer.h | 2 | ||||
| -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 |
8 files changed, 107 insertions, 176 deletions
diff --git a/src/plugins/Ui/qsui/logo.cpp b/src/plugins/Ui/qsui/logo.cpp index d4454a4ee..af46bac2a 100644 --- a/src/plugins/Ui/qsui/logo.cpp +++ b/src/plugins/Ui/qsui/logo.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2011-2016 by Ilya Kotov * + * Copyright (C) 2011-2017 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -26,9 +26,6 @@ #include "inlines.h" #include "logo.h" -#define VISUAL_NODE_SIZE 128 //samples -#define VISUAL_BUFFER_SIZE (3*VISUAL_NODE_SIZE) - Logo::Logo(QWidget *parent) : Visual(parent) { QPixmap pixmap(":/qsui/terminus.png"); @@ -71,11 +68,10 @@ Logo::Logo(QWidget *parent) : Visual(parent) m_timer->setInterval(50); m_timer->start(); - m_buffer_at = 0; m_value = 0; m_elapsed = 0; - m_buffer = new float[VISUAL_BUFFER_SIZE]; - + m_left_buffer = new float[QMMP_VISUAL_NODE_SIZE]; + m_right_buffer = new float[QMMP_VISUAL_NODE_SIZE]; updateLetters(); Visual::add(this); } @@ -83,28 +79,13 @@ Logo::Logo(QWidget *parent) : Visual(parent) Logo::~Logo() { Visual::remove(this); - delete[] m_buffer; + delete[] m_left_buffer; + delete[] m_left_buffer; } -void Logo::add(float *data, size_t samples, int chan) -{ - Q_UNUSED(chan); - 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); +void Logo::start(){} - mono_from_multichannel(m_buffer + m_buffer_at, data, frames, chan); - m_buffer_at += frames; -} - -void Logo::clear() -{ - update(); -} +void Logo::stop(){} void Logo::paintEvent(QPaintEvent *) { @@ -159,7 +140,6 @@ void Logo::updateLetters() void Logo::processPreset1() { m_lines.clear(); - mutex()->lock(); QString line; for(int i = 0; i < m_source_lines.count(); ++i) { @@ -177,14 +157,12 @@ void Logo::processPreset1() } m_lines.append(line); } - mutex()->unlock(); update(); } void Logo::processPreset2() { m_lines.clear(); - mutex()->lock(); QString str = QString("..0000..");//.arg(Qmmp::strVersion().left(5)); int at = m_value % str.size(); @@ -199,14 +177,12 @@ void Logo::processPreset2() m_lines.append(line); } - mutex()->unlock(); update(); } void Logo::processPreset3() { m_lines.clear(); - mutex()->lock(); QString str = QString("...%1...").arg(Qmmp::strVersion().left(6)); int at = m_value % str.size(); @@ -221,38 +197,34 @@ void Logo::processPreset3() m_lines.append(line); } - mutex()->unlock(); update(); } void Logo::processPreset4() { m_lines.clear(); - mutex()->lock(); int max = 0; - if(m_buffer_at < VISUAL_NODE_SIZE) + if(takeData(m_left_buffer, m_right_buffer)) { - m_value -= 512; - m_value = qMax(m_value, max); - } - else - { - for(int j = 0; j < VISUAL_NODE_SIZE; j+=8) + for(int j = 0; j < QMMP_VISUAL_NODE_SIZE; j+=8) { - if(m_buffer[j] > max) - max = abs(m_buffer[j] * 65536.0); + if(m_left_buffer[j] > max) + max = abs(m_left_buffer[j] * 65536.0); } - - m_buffer_at -= VISUAL_NODE_SIZE; - memmove(m_buffer, m_buffer + VISUAL_NODE_SIZE, m_buffer_at * sizeof(float)); m_value -= 512; m_value = qMax(m_value, max); } + else + { + m_value -= 512; + m_value = qMax(m_value, max); + } - int at = 0; + //int at = 0; + /* foreach(QString line, m_source_lines) { @@ -261,7 +233,7 @@ void Logo::processPreset4() while(k < m_value * count / 2048 / 16 / 2) { - int value = abs(m_buffer[qMin(at++, m_buffer_at)] * 16); + int value = abs(m_left_buffer[qMin(at++, m_buffer_at)] * 16); line.replace(line.indexOf("X"), 1, QString("%1").arg(value, 0, 16).toUpper()); k++; } @@ -270,7 +242,7 @@ void Logo::processPreset4() while(k < m_value * count / 2048 / 16 / 2) { - int value = abs(m_buffer[qMin(at++, m_buffer_at)] * 16); + int value = abs(m_left_buffer[qMin(at++, m_buffer_at)] * 16); line.replace(line.lastIndexOf("X"), 1, QString("%1").arg(value, 0, 16).toUpper()); k++; } @@ -282,6 +254,6 @@ void Logo::processPreset4() m_lines.append(line); } - mutex()->unlock(); + */ update(); } diff --git a/src/plugins/Ui/qsui/logo.h b/src/plugins/Ui/qsui/logo.h index 15b50b539..10fef04f7 100644 --- a/src/plugins/Ui/qsui/logo.h +++ b/src/plugins/Ui/qsui/logo.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2011-2015 by Ilya Kotov * + * Copyright (C) 2011-2017 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -39,8 +39,9 @@ public: explicit Logo(QWidget *parent = 0); virtual ~Logo(); - void add(float *data, size_t samples, int chan); - void clear(); +public slots: + void start(); + void stop(); private slots: void updateLetters(); @@ -55,8 +56,8 @@ private: QHash <QChar, QPixmap> m_letters; QStringList m_lines; QStringList m_source_lines; - float *m_buffer; - int m_buffer_at; + float *m_left_buffer; + float *m_right_buffer; int m_value; qint64 m_elapsed; diff --git a/src/plugins/Ui/qsui/mainwindow.cpp b/src/plugins/Ui/qsui/mainwindow.cpp index aff4bcb78..ee13866a6 100644 --- a/src/plugins/Ui/qsui/mainwindow.cpp +++ b/src/plugins/Ui/qsui/mainwindow.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009-2016 by Ilya Kotov * + * Copyright (C) 2009-2017 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -209,7 +209,6 @@ void MainWindow::showState(Qmmp::State state) case Qmmp::Playing: { updateStatus(); - //m_analyzer->start(); m_analyzer->setCover(MetaDataManager::instance()->getCover(m_core->url())); CoverWidget *cw = qobject_cast<CoverWidget *>(m_ui.coverDockWidget->widget()); cw->setCover(MetaDataManager::instance()->getCover(m_core->url())); @@ -220,7 +219,6 @@ void MainWindow::showState(Qmmp::State state) break; case Qmmp::Stopped: updateStatus(); - //m_analyzer->stop(); m_timeLabel->clear(); m_positionSlider->setValue(0); m_analyzer->clearCover(); diff --git a/src/plugins/Ui/qsui/qsuianalyzer.h b/src/plugins/Ui/qsui/qsuianalyzer.h index 14af24f4f..dfb01b39e 100644 --- a/src/plugins/Ui/qsui/qsuianalyzer.h +++ b/src/plugins/Ui/qsui/qsuianalyzer.h @@ -41,8 +41,6 @@ public: void clear(); void clearCover(); QSize sizeHint() const; - //void start(); - //void stop(); public slots: void start(); 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; }; |
