diff options
Diffstat (limited to 'src')
| -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 | ||||
| -rw-r--r-- | src/plugins/Visual/Visual.pro | 2 | ||||
| -rw-r--r-- | src/plugins/Visual/analyzer/analyzer.cpp | 65 | ||||
| -rw-r--r-- | src/plugins/Visual/analyzer/analyzer.h | 15 | ||||
| -rw-r--r-- | src/qmmp/outputwriter.cpp | 26 | ||||
| -rw-r--r-- | src/qmmp/outputwriter_p.h | 3 | ||||
| -rw-r--r-- | src/qmmp/visual.cpp | 5 | ||||
| -rw-r--r-- | src/qmmp/visual.h | 32 |
15 files changed, 151 insertions, 280 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; }; diff --git a/src/plugins/Visual/Visual.pro b/src/plugins/Visual/Visual.pro index e3f6d5ecb..fad9d2b8d 100644 --- a/src/plugins/Visual/Visual.pro +++ b/src/plugins/Visual/Visual.pro @@ -3,5 +3,5 @@ TEMPLATE = subdirs SUBDIRS += analyzer contains(CONFIG, PROJECTM_PLUGIN){ - SUBDIRS += projectm +# SUBDIRS += projectm } diff --git a/src/plugins/Visual/analyzer/analyzer.cpp b/src/plugins/Visual/analyzer/analyzer.cpp index 62d6a5593..6675a0416 100644 --- a/src/plugins/Visual/analyzer/analyzer.cpp +++ b/src/plugins/Visual/analyzer/analyzer.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 * @@ -31,25 +31,22 @@ #include "inlines.h" #include "analyzer.h" -#define VISUAL_NODE_SIZE 512 //samples -#define VISUAL_BUFFER_SIZE (5*VISUAL_NODE_SIZE) - Analyzer::Analyzer (QWidget *parent) : Visual (parent) { m_intern_vis_data = 0; m_peaks = 0; m_x_scale = 0; - m_buffer_at = 0; m_rows = 0; m_cols = 0; m_update = false; + m_running = false; setWindowTitle (tr("Qmmp Analyzer")); setMinimumSize(2*300-30,105); m_timer = new QTimer (this); connect(m_timer, SIGNAL (timeout()), this, SLOT (timeout())); - m_left_buffer = new float[VISUAL_BUFFER_SIZE]; - m_right_buffer = new float[VISUAL_BUFFER_SIZE]; + m_left_buffer = new float[QMMP_VISUAL_NODE_SIZE]; + m_right_buffer = new float[QMMP_VISUAL_NODE_SIZE]; clear(); createMenu(); @@ -69,51 +66,34 @@ Analyzer::~Analyzer() delete [] m_x_scale; } -void Analyzer::add (float *data, size_t samples, int chan) +void Analyzer::start() { - 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); - - stereo_from_multichannel(m_left_buffer + m_buffer_at, - m_right_buffer + m_buffer_at, data, frames, chan); + m_running = true; + if(isVisible()) + m_timer->start(); +} - m_buffer_at += frames; +void Analyzer::stop() +{ + m_running = false; + m_timer->stop(); + clear(); } void Analyzer::clear() { - m_buffer_at = 0; m_rows = 0; m_cols = 0; update(); } - void Analyzer::timeout() { - mutex()->lock(); - if(m_buffer_at < VISUAL_NODE_SIZE) + if(takeData(m_left_buffer, m_right_buffer)) { - mutex()->unlock (); - return; + process(); + 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)); - mutex()->unlock (); - update(); } void Analyzer::toggleFullScreen() @@ -200,7 +180,8 @@ void Analyzer::hideEvent (QHideEvent *) void Analyzer::showEvent (QShowEvent *) { - m_timer->start(); + if(m_running) + m_timer->start(); } void Analyzer::closeEvent (QCloseEvent *event) @@ -224,7 +205,7 @@ void Analyzer::mousePressEvent(QMouseEvent *e) m_menu->exec(e->globalPos()); } -void Analyzer::process (float *left, float *right) +void Analyzer::process() { static fft_state *state = 0; if (!state) @@ -261,8 +242,8 @@ void Analyzer::process (float *left, float *right) short yl, yr; int j, k, magnitude_l, magnitude_r; - calc_freq (dest_l, left); - calc_freq (dest_r, right); + calc_freq (dest_l, m_left_buffer); + calc_freq (dest_r, m_right_buffer); double y_scale = (double) 1.25 * m_rows / log(256); @@ -314,7 +295,7 @@ void Analyzer::process (float *left, float *right) } } -void Analyzer::draw (QPainter *p) +void Analyzer::draw(QPainter *p) { QBrush brush(Qt::SolidPattern); int x = 0; diff --git a/src/plugins/Visual/analyzer/analyzer.h b/src/plugins/Visual/analyzer/analyzer.h index d2c2d6cd1..b6c93e39b 100644 --- a/src/plugins/Visual/analyzer/analyzer.h +++ b/src/plugins/Visual/analyzer/analyzer.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 * @@ -32,7 +32,6 @@ class QPaintEvent; class QHideEvent; class QShowEvent; - class Analyzer : public Visual { Q_OBJECT @@ -41,9 +40,9 @@ public: Analyzer( QWidget *parent = 0); virtual ~Analyzer(); - void add(float *data, size_t samples, int chan); - void clear(); - +public slots: + void start(); + void stop(); private slots: void timeout(); @@ -51,14 +50,14 @@ private slots: void readSettings(); void writeSettings(); - private: + void clear(); virtual void hideEvent (QHideEvent *); virtual void showEvent (QShowEvent *); virtual void closeEvent (QCloseEvent *); void paintEvent(QPaintEvent *); void mousePressEvent(QMouseEvent *e); - void process(float *l, float *r); + void process(); void draw(QPainter *p); void createMenu(); QTimer *m_timer; @@ -70,9 +69,9 @@ private: bool m_show_peaks; float *m_left_buffer; float *m_right_buffer; - int m_buffer_at; int m_cols, m_rows; bool m_update; + bool m_running; //colors QColor m_color1; QColor m_color2; diff --git a/src/qmmp/outputwriter.cpp b/src/qmmp/outputwriter.cpp index aa76ab140..dbaefe9de 100644 --- a/src/qmmp/outputwriter.cpp +++ b/src/qmmp/outputwriter.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2012-2016 by Ilya Kotov * + * Copyright (C) 2012-2017 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -190,26 +190,8 @@ void OutputWriter::dispatchVisual (Buffer *buffer) if(!buffer) return; - Visual::addAudio(buffer->data, buffer->samples, m_channels, m_totalWritten / m_bytesPerMillisecond, m_output->latency()); - foreach (Visual *visual, *Visual::visuals()) - { - visual->mutex()->lock (); - visual->add (buffer->data, buffer->samples, m_channels); - visual->mutex()->unlock(); - } -} - -void OutputWriter::clearVisuals() -{ - /* - Visual::clearBuffer(); - foreach (Visual *visual, *Visual::visuals()) - { - visual->mutex()->lock (); - visual->clear(); - visual->mutex()->unlock(); - } - */ + Visual::addAudio(buffer->data, buffer->samples, m_channels, + m_totalWritten / m_bytesPerMillisecond, m_output->latency()); } bool OutputWriter::prepareConverters() @@ -276,8 +258,6 @@ void OutputWriter::dispatch(const Qmmp::State &state) { if (m_handler) m_handler->dispatch(state); - //if (state == Qmmp::Stopped) - // clearVisuals(); } void OutputWriter::run() diff --git a/src/qmmp/outputwriter_p.h b/src/qmmp/outputwriter_p.h index 5cebfd91a..f80118323 100644 --- a/src/qmmp/outputwriter_p.h +++ b/src/qmmp/outputwriter_p.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2012-2016 by Ilya Kotov * + * Copyright (C) 2012-2017 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -117,7 +117,6 @@ private: int channels); void dispatch(const Qmmp::State &state); void dispatchVisual(Buffer *buffer); - void clearVisuals(); bool prepareConverters(); void startVisualization(); void stopVisualization(); diff --git a/src/qmmp/visual.cpp b/src/qmmp/visual.cpp index ecb16a162..20397a366 100644 --- a/src/qmmp/visual.cpp +++ b/src/qmmp/visual.cpp @@ -45,11 +45,6 @@ Visual::~Visual() qDebug("Visual::~Visual()"); } -QMutex *Visual::mutex() -{ - return &m_mutex; -} - void Visual::closeEvent (QCloseEvent *event) { m_visuals.removeAll(this); diff --git a/src/qmmp/visual.h b/src/qmmp/visual.h index 0ec244c25..6a5d7ef9c 100644 --- a/src/qmmp/visual.h +++ b/src/qmmp/visual.h @@ -52,23 +52,6 @@ public: */ virtual ~Visual(); /*! - * Adds data for visualization. - * Subclass should reimplement this function. - * @param data Audio data. - * @param samples Number of samples. - * @param chan Number of channels. - */ - virtual void add(float *data, size_t samples, int chan){} - /*! - * Resets visual plugin buffers and widgets. - * Subclass should reimplement this function. - */ - //virtual void clear() = 0; - /*! - * Returns mutex pointer. - */ - QMutex *mutex(); - /*! * Returns a list of visual factories. */ static QList<VisualFactory*> factories(); @@ -113,14 +96,18 @@ public: * @param parent Parent widget. */ static void showSettings(VisualFactory *factory, QWidget *parent); - - + /*! + * Adds data for visualization. + * @param ocm Audio data. + * @param samples Number of samples. + * @param chan Number of channels. + */ static void addAudio(float *pcm, int samples, int channels, qint64 ts, qint64 delay); static void clearBuffer(); public slots: - virtual void start(){} //= 0; - virtual void stop(){}// = 0; + virtual void start() = 0; + virtual void stop() = 0; signals: /*! @@ -135,12 +122,11 @@ protected: */ virtual void closeEvent (QCloseEvent *event); - virtual bool takeData(float *left, float *right); + bool takeData(float *left, float *right); private: Decoder *m_decoder; Output *m_output; - QMutex m_mutex; static QList<VisualFactory*> *m_factories; static QHash <VisualFactory*, QString> *m_files; |
