From 581e201025b971c2a0ca6e1f2748340ab1a0fa68 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Fri, 13 Dec 2019 19:05:21 +0000 Subject: refactoring git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9136 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/Ui/qsui/CMakeLists.txt | 2 +- src/plugins/Ui/qsui/mainwindow.cpp | 8 +- src/plugins/Ui/qsui/mainwindow.h | 8 +- src/plugins/Ui/qsui/qsui.pro | 8 +- src/plugins/Ui/qsui/qsuianalyzer.cpp | 356 --------------------------- src/plugins/Ui/qsui/qsuianalyzer.h | 96 -------- src/plugins/Ui/qsui/qsuifactory.cpp | 8 +- src/plugins/Ui/qsui/qsuifactory.h | 2 +- src/plugins/Ui/qsui/qsuiquicksearch.cpp | 2 +- src/plugins/Ui/qsui/qsuiquicksearch.h | 4 +- src/plugins/Ui/qsui/qsuisettings.cpp | 28 +-- src/plugins/Ui/qsui/qsuisettings.h | 6 +- src/plugins/Ui/qsui/qsuivisualization.cpp | 390 ++++++++++++++++++++++++++++++ src/plugins/Ui/qsui/qsuivisualization.h | 125 ++++++++++ 14 files changed, 553 insertions(+), 490 deletions(-) delete mode 100644 src/plugins/Ui/qsui/qsuianalyzer.cpp delete mode 100644 src/plugins/Ui/qsui/qsuianalyzer.h create mode 100644 src/plugins/Ui/qsui/qsuivisualization.cpp create mode 100644 src/plugins/Ui/qsui/qsuivisualization.h (limited to 'src') diff --git a/src/plugins/Ui/qsui/CMakeLists.txt b/src/plugins/Ui/qsui/CMakeLists.txt index 7af2f503d..b6d46c77a 100644 --- a/src/plugins/Ui/qsui/CMakeLists.txt +++ b/src/plugins/Ui/qsui/CMakeLists.txt @@ -22,7 +22,7 @@ SET(libqsui_SRCS logo.cpp aboutqsuidialog.cpp keyboardmanager.cpp - qsuianalyzer.cpp + qsuivisualization.cpp fft.c colorwidget.cpp qsuitabwidget.cpp diff --git a/src/plugins/Ui/qsui/mainwindow.cpp b/src/plugins/Ui/qsui/mainwindow.cpp index 8db863d2a..421d5cbf5 100644 --- a/src/plugins/Ui/qsui/mainwindow.cpp +++ b/src/plugins/Ui/qsui/mainwindow.cpp @@ -42,7 +42,7 @@ #include "qsuitabbar.h" #include "toolbareditor.h" #include "actionmanager.h" -#include "qsuianalyzer.h" +#include "qsuivisualization.h" #include "visualmenu.h" #include "listwidget.h" #include "positionslider.h" @@ -148,10 +148,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) m_volumeSlider->setValue(m_core->volume()); updateVolumeIcon(); //quick search - m_quickSearch = new QSUIQuickSearch(m_listWidget, this); + m_quickSearch = new QSUiQuickSearch(m_listWidget, this); m_quickSearch->setMaximumWidth(250); //visualization - m_analyzer = new QSUiAnalyzer(this); + m_analyzer = new QSUIVisualization(this); m_ui.analyzerDockWidget->setWidget(m_analyzer); Visual::add(m_analyzer); //filesystem browser @@ -331,7 +331,7 @@ void MainWindow::showAndRaise() void MainWindow::showSettings() { ConfigDialog *confDialog = new ConfigDialog(this); - QSUISettings *simpleSettings = new QSUISettings(this); + QSUiSettings *simpleSettings = new QSUiSettings(this); confDialog->addPage(tr("Appearance"), simpleSettings, QIcon(":/qsui/qsui_settings.png")); confDialog->addPage(tr("Shortcuts"), new HotkeyEditor(this), QIcon(":/qsui/qsui_shortcuts.png")); confDialog->exec(); diff --git a/src/plugins/Ui/qsui/mainwindow.h b/src/plugins/Ui/qsui/mainwindow.h index 17ea17c03..f1ea2bb68 100644 --- a/src/plugins/Ui/qsui/mainwindow.h +++ b/src/plugins/Ui/qsui/mainwindow.h @@ -39,10 +39,10 @@ class GeneralHandler; class VisualMenu; class PositionSlider; class KeyboardManager; -class QSUiAnalyzer; +class QSUIVisualization; class ListWidget; class QSUiTabWidget; -class QSUIQuickSearch; +class QSUiQuickSearch; /** @@ -115,9 +115,9 @@ private: QMenu *m_pl_menu; QMenu *m_tab_menu; QSlider *m_volumeSlider; - QSUIQuickSearch *m_quickSearch; + QSUiQuickSearch *m_quickSearch; KeyboardManager *m_key_manager; - QSUiAnalyzer *m_analyzer; + QSUIVisualization *m_analyzer; QToolButton *m_addListButton, *m_tabListMenuButton; ListWidget *m_listWidget; MetaDataFormatter m_titleFormatter; diff --git a/src/plugins/Ui/qsui/qsui.pro b/src/plugins/Ui/qsui/qsui.pro index 380b40a0e..3bafd4311 100644 --- a/src/plugins/Ui/qsui/qsui.pro +++ b/src/plugins/Ui/qsui/qsui.pro @@ -18,7 +18,6 @@ SOURCES += \ aboutqsuidialog.cpp \ qsuifactory.cpp \ qsuisettings.cpp \ - qsuianalyzer.cpp \ fft.c \ colorwidget.cpp \ qsuitabwidget.cpp \ @@ -33,7 +32,8 @@ SOURCES += \ playlistheader.cpp \ hotkeyeditor.cpp \ volumeslider.cpp \ - qsuiquicksearch.cpp + qsuiquicksearch.cpp \ + qsuivisualization.cpp HEADERS += mainwindow.h \ listwidget.h \ visualmenu.h \ @@ -49,7 +49,6 @@ HEADERS += mainwindow.h \ aboutqsuidialog.h \ qsuifactory.h \ qsuisettings.h \ - qsuianalyzer.h \ fft.h \ inlines.h \ colorwidget.h \ @@ -65,7 +64,8 @@ HEADERS += mainwindow.h \ playlistheader.h \ hotkeyeditor.h \ volumeslider.h \ - qsuiquicksearch.h + qsuiquicksearch.h \ + qsuivisualization.h FORMS += forms/mainwindow.ui \ forms/shortcutdialog.ui \ diff --git a/src/plugins/Ui/qsui/qsuianalyzer.cpp b/src/plugins/Ui/qsui/qsuianalyzer.cpp deleted file mode 100644 index 273926438..000000000 --- a/src/plugins/Ui/qsui/qsuianalyzer.cpp +++ /dev/null @@ -1,356 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2012-2019 by Ilya Kotov * - * forkotov02@ya.ru * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fft.h" -#include "inlines.h" -#include "qsuianalyzer.h" - -QSUiAnalyzer::QSUiAnalyzer(QWidget *parent) : Visual (parent) -{ - m_pixLabel = new QLabel(this); - createMenu(); - - m_timer = new QTimer (this); - connect(m_timer, SIGNAL (timeout()), this, SLOT (timeout())); - - readSettings(); - clear(); -} - -QSUiAnalyzer::~QSUiAnalyzer() -{ - if(m_peaks) - delete [] m_peaks; - if(m_intern_vis_data) - delete [] m_intern_vis_data; - if(m_x_scale) - delete [] m_x_scale; -} - -void QSUiAnalyzer::clear() -{ - m_rows = 0; - m_cols = 0; - update(); -} - -void QSUiAnalyzer::clearCover() -{ - m_cover = QPixmap(); - updateCover(); - update(); -} - -QSize QSUiAnalyzer::sizeHint() const -{ - return QSize(200, 100); -} - -void QSUiAnalyzer::setCover(const QPixmap &pixmap) -{ - m_cover = pixmap; - updateCover(); -} - -void QSUiAnalyzer::timeout() -{ - if(takeData(m_buffer)) - { - process(); - update(); - } -} - -void QSUiAnalyzer::paintEvent (QPaintEvent * e) -{ - QPainter painter (this); - painter.fillRect(e->rect(),m_bgColor); - draw(&painter); -} - -void QSUiAnalyzer::hideEvent (QHideEvent *) -{ - m_timer->stop(); -} - -void QSUiAnalyzer::showEvent (QShowEvent *) -{ - if(m_running) - m_timer->start(); -} - -void QSUiAnalyzer::resizeEvent(QResizeEvent *) -{ - updateCover(); -} - -void QSUiAnalyzer::process() -{ - int rows = qMax((height() - 2) / m_cell_size.height(),2); - int cols = qMax((width() - m_offset - 2) / m_cell_size.width(),1); - - if(m_rows != rows || m_cols != cols) - { - m_rows = rows; - m_cols = cols; - if(m_peaks) - delete [] m_peaks; - if(m_intern_vis_data) - delete [] m_intern_vis_data; - if(m_x_scale) - delete [] m_x_scale; - m_peaks = new double[m_cols]; - m_intern_vis_data = new double[m_cols]; - m_x_scale = new int[m_cols + 1]; - - for(int i = 0; i < m_cols; ++i) - { - m_peaks[i] = 0; - m_intern_vis_data[i] = 0; - } - for(int i = 0; i < m_cols + 1; ++i) - m_x_scale[i] = pow(pow(255.0, 1.0 / m_cols), i); - } - short dest[256]; - - calc_freq (dest, m_buffer); - - double y_scale = (double) 1.25 * m_rows / log(256); - - for (int i = 0; i < m_cols; i++) - { - short y = 0; - int magnitude = 0; - - if(m_x_scale[i] == m_x_scale[i + 1]) - { - y = dest[i]; - } - for (int k = m_x_scale[i]; k < m_x_scale[i + 1]; k++) - { - y = qMax(dest[k], y); - } - - y >>= 7; //256 - - - if (y) - { - magnitude = int(log (y) * y_scale); - magnitude = qBound(0, magnitude, m_rows); - } - - - m_intern_vis_data[i] -= m_analyzer_falloff * m_rows / 15; - m_intern_vis_data[i] = magnitude > m_intern_vis_data[i] ? magnitude : m_intern_vis_data[i]; - - if (m_show_peaks) - { - m_peaks[i] -= m_peaks_falloff * m_rows / 15; - m_peaks[i] = magnitude > m_peaks[i] ? magnitude : m_peaks[i]; - } - } -} - -void QSUiAnalyzer::draw(QPainter *p) -{ - QBrush brush(Qt::SolidPattern); - - for (int j = 0; j < m_cols; ++j) - { - int x = m_offset + j * m_cell_size.width() + 1; - - for (int i = 0; i <= m_intern_vis_data[j]; ++i) - { - if (i <= m_rows / 3) - brush.setColor(m_color1); - else if (i > m_rows / 3 && i <= 2 * m_rows / 3) - brush.setColor(m_color2); - else - brush.setColor(m_color3); - - p->fillRect(x, height() - i * m_cell_size.height(), - m_cell_size.width() - 1, m_cell_size.height() - 4, brush); - } - - if (m_show_peaks) - { - p->fillRect(x, height() - int(m_peaks[j]) * m_cell_size.height(), - m_cell_size.width() - 1, m_cell_size.height() - 4, m_peakColor); - } - } -} - -void QSUiAnalyzer::createMenu() -{ - m_menu = new QMenu (this); - connect(m_menu, SIGNAL(triggered (QAction *)),SLOT(writeSettings())); - connect(m_menu, SIGNAL(triggered (QAction *)),SLOT(readSettings())); - - m_coverAction = m_menu->addAction(tr("Cover")); - m_coverAction->setCheckable(true); - - m_peaksAction = m_menu->addAction(tr("Peaks")); - m_peaksAction->setCheckable(true); - - QMenu *refreshRate = m_menu->addMenu(tr("Refresh Rate")); - m_fpsGroup = new QActionGroup(this); - m_fpsGroup->setExclusive(true); - m_fpsGroup->addAction(tr("50 fps"))->setData(50); - m_fpsGroup->addAction(tr("25 fps"))->setData(25); - m_fpsGroup->addAction(tr("10 fps"))->setData(10); - m_fpsGroup->addAction(tr("5 fps"))->setData(5); - for(QAction *act : m_fpsGroup->actions ()) - { - act->setCheckable(true); - refreshRate->addAction(act); - } - - QMenu *analyzerFalloff = m_menu->addMenu(tr("Analyzer Falloff")); - m_analyzerFalloffGroup = new QActionGroup(this); - m_analyzerFalloffGroup->setExclusive(true); - m_analyzerFalloffGroup->addAction(tr("Slowest"))->setData(1.2); - m_analyzerFalloffGroup->addAction(tr("Slow"))->setData(1.8); - m_analyzerFalloffGroup->addAction(tr("Medium"))->setData(2.2); - m_analyzerFalloffGroup->addAction(tr("Fast"))->setData(2.4); - m_analyzerFalloffGroup->addAction(tr("Fastest"))->setData(2.8); - for(QAction *act : m_analyzerFalloffGroup->actions ()) - { - act->setCheckable(true); - analyzerFalloff->addAction(act); - } - - QMenu *peaksFalloff = m_menu->addMenu(tr("Peaks Falloff")); - m_peaksFalloffGroup = new QActionGroup(this); - m_peaksFalloffGroup->setExclusive(true); - m_peaksFalloffGroup->addAction(tr("Slowest"))->setData(0.05); - m_peaksFalloffGroup->addAction(tr("Slow"))->setData(0.1); - m_peaksFalloffGroup->addAction(tr("Medium"))->setData(0.2); - m_peaksFalloffGroup->addAction(tr("Fast"))->setData(0.4); - m_peaksFalloffGroup->addAction(tr("Fastest"))->setData(0.8); - for(QAction *act : m_peaksFalloffGroup->actions ()) - { - act->setCheckable(true); - peaksFalloff->addAction(act); - } - update(); -} - -void QSUiAnalyzer::updateCover() -{ - if(m_show_cover && !m_cover.isNull()) - { - m_offset = height(); - m_pixLabel->setGeometry(10,10, height() - 20, height() - 20); - m_pixLabel->setPixmap(m_cover.scaled(m_pixLabel->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); - m_pixLabel->show(); - } - else - { - m_offset = 0; - m_pixLabel->hide(); - } -} - -void QSUiAnalyzer::mousePressEvent (QMouseEvent *e) -{ - if (e->button() == Qt::RightButton) - m_menu->exec(e->globalPos()); -} - -void QSUiAnalyzer::readSettings() -{ - QSettings settings(Qmmp::configFile(), QSettings::IniFormat); - settings.beginGroup("Simple"); - m_peaks_falloff = settings.value("vis_peaks_falloff", 0.2).toDouble(); - m_analyzer_falloff = settings.value("vis_analyzer_falloff", 2.2).toDouble(); - m_show_peaks = settings.value("vis_show_peaks", true).toBool(); - m_show_cover = settings.value("vis_show_cover", true).toBool(); - m_timer->setInterval(1000 / settings.value("vis_refresh_rate", 25).toInt()); - m_color1.setNamedColor(settings.value("vis_color1", "#BECBFF").toString()); - m_color2.setNamedColor(settings.value("vis_color2", "#BECBFF").toString()); - m_color3.setNamedColor(settings.value("vis_color3", "#BECBFF").toString()); - m_bgColor.setNamedColor(settings.value("vis_bg_color", "Black").toString()); - m_peakColor.setNamedColor(settings.value("vis_peak_color", "#DDDDDD").toString()); - m_cell_size = QSize(14, 8); - if(!m_update) - { - m_update = true; - m_coverAction->setChecked(m_show_cover); - m_peaksAction->setChecked(m_show_peaks); - - for(QAction *act : m_fpsGroup->actions ()) - { - if (m_timer->interval() == 1000 / act->data().toInt()) - act->setChecked(true); - } - for(QAction *act : m_peaksFalloffGroup->actions ()) - { - if (m_peaks_falloff == act->data().toDouble()) - act->setChecked(true); - } - for(QAction *act : m_analyzerFalloffGroup->actions ()) - { - if (m_analyzer_falloff == act->data().toDouble()) - act->setChecked(true); - } - } - updateCover(); - settings.endGroup(); -} - -void QSUiAnalyzer::writeSettings() -{ - QSettings settings(Qmmp::configFile(), QSettings::IniFormat); - settings.beginGroup("Simple"); - - QAction *act = m_fpsGroup->checkedAction (); - settings.setValue("vis_refresh_rate", act ? act->data().toInt() : 25); - act = m_peaksFalloffGroup->checkedAction (); - settings.setValue("vis_peaks_falloff", act ? act->data().toDouble() : 0.2); - act = m_analyzerFalloffGroup->checkedAction (); - settings.setValue("vis_analyzer_falloff", act ? act->data().toDouble() : 2.2); - settings.setValue("vis_show_peaks", m_peaksAction->isChecked()); - settings.setValue("vis_show_cover", m_coverAction->isChecked()); - settings.endGroup(); -} - -void QSUiAnalyzer::start() -{ - m_running = true; - if(isVisible()) - m_timer->start(); -} - -void QSUiAnalyzer::stop() -{ - m_running = false; - m_timer->stop(); - clear(); -} diff --git a/src/plugins/Ui/qsui/qsuianalyzer.h b/src/plugins/Ui/qsui/qsuianalyzer.h deleted file mode 100644 index 7d19dc2bb..000000000 --- a/src/plugins/Ui/qsui/qsuianalyzer.h +++ /dev/null @@ -1,96 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2012-2019 by Ilya Kotov * - * forkotov02@ya.ru * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef QSUIANALYZER_H -#define QSUIANALYZER_H - -#include -#include -#include - -class QTimer; -class QMenu; -class QActionGroup; -class QLabel; - - -class QSUiAnalyzer : public Visual -{ - Q_OBJECT -public: - QSUiAnalyzer(QWidget *parent = nullptr); - virtual ~QSUiAnalyzer(); - - void setCover(const QPixmap &pixmap); - void clear(); - void clearCover(); - QSize sizeHint() const override; - -public slots: - void start() override; - void stop() override; - void readSettings(); - -private slots: - void timeout(); - void writeSettings(); - -private: - void paintEvent(QPaintEvent *) override; - void mousePressEvent(QMouseEvent *) override; - void hideEvent(QHideEvent *) override; - void showEvent(QShowEvent *) override; - void resizeEvent(QResizeEvent *) override; - void process(); - void draw(QPainter *p); - void createMenu(); - void updateCover(); - - QPixmap m_cover; - QTimer *m_timer; - double *m_intern_vis_data = nullptr; - double *m_peaks = nullptr; - int *m_x_scale = nullptr; - double m_peaks_falloff; - double m_analyzer_falloff; - bool m_show_peaks; - bool m_show_cover = false; - float m_buffer[QMMP_VISUAL_NODE_SIZE]; - int m_cols = 0, m_rows = 0; - int m_offset = 0; - bool m_update = false; - QLabel *m_pixLabel; - //colors - QColor m_color1; - QColor m_color2; - QColor m_color3; - QColor m_bgColor; - QColor m_peakColor; - QSize m_cell_size; - QMenu *m_menu; - QAction *m_peaksAction; - QAction *m_coverAction; - QActionGroup *m_fpsGroup; - QActionGroup *m_analyzerFalloffGroup; - QActionGroup *m_peaksFalloffGroup; - bool m_running = false; -}; - - -#endif //QSUIANALYZER_H diff --git a/src/plugins/Ui/qsui/qsuifactory.cpp b/src/plugins/Ui/qsui/qsuifactory.cpp index 012a054ef..654c00507 100644 --- a/src/plugins/Ui/qsui/qsuifactory.cpp +++ b/src/plugins/Ui/qsui/qsuifactory.cpp @@ -25,7 +25,7 @@ #include "aboutqsuidialog.h" #include "qsuifactory.h" -UiProperties QSUIFactory::properties() const +UiProperties QSUiFactory::properties() const { UiProperties props; props.hasAbout = true; @@ -34,19 +34,19 @@ UiProperties QSUIFactory::properties() const return props; } -QObject *QSUIFactory::QSUIFactory::create() +QObject *QSUiFactory::QSUiFactory::create() { QmmpSettings::instance()->readEqSettings(EqSettings::EQ_BANDS_15); return new MainWindow(); } -void QSUIFactory::showAbout(QWidget *parent) +void QSUiFactory::showAbout(QWidget *parent) { AboutQSUIDialog about(parent); about.exec(); } -QString QSUIFactory::translation() const +QString QSUiFactory::translation() const { return QLatin1String(":/qsui_plugin_"); } diff --git a/src/plugins/Ui/qsui/qsuifactory.h b/src/plugins/Ui/qsui/qsuifactory.h index b74374750..c2ef341a9 100644 --- a/src/plugins/Ui/qsui/qsuifactory.h +++ b/src/plugins/Ui/qsui/qsuifactory.h @@ -26,7 +26,7 @@ /*! * @author Ilya Kotov */ -class QSUIFactory : public QObject, public UiFactory +class QSUiFactory : public QObject, public UiFactory { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qmmp.qmmpui.UiFactoryInterface.1.0") diff --git a/src/plugins/Ui/qsui/qsuiquicksearch.cpp b/src/plugins/Ui/qsui/qsuiquicksearch.cpp index 19509c9c6..92bb7a047 100644 --- a/src/plugins/Ui/qsui/qsuiquicksearch.cpp +++ b/src/plugins/Ui/qsui/qsuiquicksearch.cpp @@ -29,7 +29,7 @@ #include "listwidget.h" #include "qsuiquicksearch.h" -QSUIQuickSearch::QSUIQuickSearch(ListWidget *listWidget, QWidget *parent) : +QSUiQuickSearch::QSUiQuickSearch(ListWidget *listWidget, QWidget *parent) : QWidget(parent) { m_listWidget = listWidget; diff --git a/src/plugins/Ui/qsui/qsuiquicksearch.h b/src/plugins/Ui/qsui/qsuiquicksearch.h index ec04e3b89..7e7091af5 100644 --- a/src/plugins/Ui/qsui/qsuiquicksearch.h +++ b/src/plugins/Ui/qsui/qsuiquicksearch.h @@ -31,11 +31,11 @@ class ListWidget; /** @author Ilya Kotov */ -class QSUIQuickSearch : public QWidget +class QSUiQuickSearch : public QWidget { Q_OBJECT public: - explicit QSUIQuickSearch(ListWidget *listWidget, QWidget *parent = nullptr); + explicit QSUiQuickSearch(ListWidget *listWidget, QWidget *parent = nullptr); private: QLineEdit *m_lineEdit; diff --git a/src/plugins/Ui/qsui/qsuisettings.cpp b/src/plugins/Ui/qsui/qsuisettings.cpp index c6f4b2f1d..64c6267c7 100644 --- a/src/plugins/Ui/qsui/qsuisettings.cpp +++ b/src/plugins/Ui/qsui/qsuisettings.cpp @@ -32,7 +32,7 @@ #include "toolbareditor.h" #include "qsuisettings.h" -QSUISettings::QSUISettings(QWidget *parent) : QWidget(parent) +QSUiSettings::QSUiSettings(QWidget *parent) : QWidget(parent) { m_ui.setupUi(this); //setup icons @@ -51,10 +51,10 @@ QSUISettings::QSUISettings(QWidget *parent) : QWidget(parent) createActions(); } -QSUISettings::~QSUISettings() +QSUiSettings::~QSUiSettings() {} -void QSUISettings::on_plFontButton_clicked() +void QSUiSettings::on_plFontButton_clicked() { bool ok = false; QFont font = m_ui.plFontLabel->font(); @@ -66,7 +66,7 @@ void QSUISettings::on_plFontButton_clicked() } } -void QSUISettings::on_columnFontButton_clicked() +void QSUiSettings::on_columnFontButton_clicked() { bool ok = false; QFont font = m_ui.columnFontLabel->font(); @@ -78,7 +78,7 @@ void QSUISettings::on_columnFontButton_clicked() } } -void QSUISettings::on_tabsFontButton_clicked() +void QSUiSettings::on_tabsFontButton_clicked() { bool ok = false; QFont font = m_ui.tabsFontLabel->font(); @@ -90,13 +90,13 @@ void QSUISettings::on_tabsFontButton_clicked() } } -void QSUISettings::showEvent(QShowEvent *) +void QSUiSettings::showEvent(QShowEvent *) { m_ui.hiddenCheckBox->setEnabled(UiHelper::instance()->visibilityControl()); m_ui.hideOnCloseCheckBox->setEnabled(UiHelper::instance()->visibilityControl()); } -void QSUISettings::loadFonts() +void QSUiSettings::loadFonts() { QString fontName; QFont font; @@ -121,7 +121,7 @@ void QSUISettings::loadFonts() m_ui.columnFontLabel->setFont(font); } -void QSUISettings::createActions() +void QSUiSettings::createActions() { MetaDataFormatterMenu *menu = new MetaDataFormatterMenu(MetaDataFormatterMenu::TITLE_MENU, this); m_ui.windowTitleButton->setMenu(menu); @@ -129,20 +129,20 @@ void QSUISettings::createActions() connect(menu, SIGNAL(patternSelected(QString)), SLOT(addWindowTitleString(QString))); } -void QSUISettings::on_popupTemplateButton_clicked() +void QSUiSettings::on_popupTemplateButton_clicked() { PopupSettings *p = new PopupSettings(this); p->exec(); p->deleteLater(); } -void QSUISettings::on_customizeToolBarButton_clicked() +void QSUiSettings::on_customizeToolBarButton_clicked() { ToolBarEditor editor(this); editor.exec(); } -void QSUISettings::on_resetFontsButton_clicked() +void QSUiSettings::on_resetFontsButton_clicked() { QSettings settings (Qmmp::configFile(), QSettings::IniFormat); settings.remove("Simple/pl_font"); @@ -151,7 +151,7 @@ void QSUISettings::on_resetFontsButton_clicked() loadFonts(); } -void QSUISettings::readSettings() +void QSUiSettings::readSettings() { QSettings settings (Qmmp::configFile(), QSettings::IniFormat); settings.beginGroup("Simple"); @@ -204,7 +204,7 @@ void QSUISettings::readSettings() settings.endGroup(); } -void QSUISettings::writeSettings() +void QSUiSettings::writeSettings() { QSettings settings (Qmmp::configFile(), QSettings::IniFormat); settings.beginGroup("Simple"); @@ -248,7 +248,7 @@ void QSUISettings::writeSettings() settings.endGroup(); } -void QSUISettings::addWindowTitleString(const QString &str) +void QSUiSettings::addWindowTitleString(const QString &str) { if (m_ui.windowTitleLineEdit->cursorPosition () < 1) m_ui.windowTitleLineEdit->insert(str); diff --git a/src/plugins/Ui/qsui/qsuisettings.h b/src/plugins/Ui/qsui/qsuisettings.h index 905959786..91a7bf732 100644 --- a/src/plugins/Ui/qsui/qsuisettings.h +++ b/src/plugins/Ui/qsui/qsuisettings.h @@ -28,12 +28,12 @@ /** @author Ilya Kotov */ -class QSUISettings : public QWidget +class QSUiSettings : public QWidget { Q_OBJECT public: - explicit QSUISettings(QWidget *parent = nullptr); - virtual ~QSUISettings(); + explicit QSUiSettings(QWidget *parent = nullptr); + virtual ~QSUiSettings(); void writeSettings(); diff --git a/src/plugins/Ui/qsui/qsuivisualization.cpp b/src/plugins/Ui/qsui/qsuivisualization.cpp new file mode 100644 index 000000000..fcc851bda --- /dev/null +++ b/src/plugins/Ui/qsui/qsuivisualization.cpp @@ -0,0 +1,390 @@ +/*************************************************************************** + * Copyright (C) 2012-2019 by Ilya Kotov * + * forkotov02@ya.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "fft.h" +#include "inlines.h" +#include "qsuivisualization.h" + +QSUIVisualization::QSUIVisualization(QWidget *parent) : Visual (parent) +{ + m_pixLabel = new QLabel(this); + createMenu(); + + m_timer = new QTimer (this); + connect(m_timer, SIGNAL (timeout()), this, SLOT (timeout())); + + readSettings(); + clear(); +} + +QSUIVisualization::~QSUIVisualization() +{ + if(m_peaks) + delete [] m_peaks; + if(m_intern_vis_data) + delete [] m_intern_vis_data; + if(m_x_scale) + delete [] m_x_scale; +} + +void QSUIVisualization::clear() +{ + m_rows = 0; + m_cols = 0; + update(); +} + +void QSUIVisualization::clearCover() +{ + m_cover = QPixmap(); + updateCover(); + update(); +} + +QSize QSUIVisualization::sizeHint() const +{ + return QSize(200, 100); +} + +void QSUIVisualization::setCover(const QPixmap &pixmap) +{ + m_cover = pixmap; + updateCover(); +} + +void QSUIVisualization::timeout() +{ + if(takeData(m_buffer)) + { + process(); + update(); + } +} + +void QSUIVisualization::paintEvent (QPaintEvent * e) +{ + QPainter painter (this); + painter.fillRect(e->rect(),m_bgColor); + draw(&painter); +} + +void QSUIVisualization::hideEvent (QHideEvent *) +{ + m_timer->stop(); +} + +void QSUIVisualization::showEvent (QShowEvent *) +{ + if(m_running) + m_timer->start(); +} + +void QSUIVisualization::resizeEvent(QResizeEvent *) +{ + updateCover(); +} + +void QSUIVisualization::process() +{ + int rows = qMax((height() - 2) / m_cell_size.height(),2); + int cols = qMax((width() - m_offset - 2) / m_cell_size.width(),1); + + if(m_rows != rows || m_cols != cols) + { + m_rows = rows; + m_cols = cols; + if(m_peaks) + delete [] m_peaks; + if(m_intern_vis_data) + delete [] m_intern_vis_data; + if(m_x_scale) + delete [] m_x_scale; + m_peaks = new double[m_cols]; + m_intern_vis_data = new double[m_cols]; + m_x_scale = new int[m_cols + 1]; + + for(int i = 0; i < m_cols; ++i) + { + m_peaks[i] = 0; + m_intern_vis_data[i] = 0; + } + for(int i = 0; i < m_cols + 1; ++i) + m_x_scale[i] = pow(pow(255.0, 1.0 / m_cols), i); + } + short dest[256]; + + calc_freq (dest, m_buffer); + + double y_scale = (double) 1.25 * m_rows / log(256); + + for (int i = 0; i < m_cols; i++) + { + short y = 0; + int magnitude = 0; + + if(m_x_scale[i] == m_x_scale[i + 1]) + { + y = dest[i]; + } + for (int k = m_x_scale[i]; k < m_x_scale[i + 1]; k++) + { + y = qMax(dest[k], y); + } + + y >>= 7; //256 + + + if (y) + { + magnitude = int(log (y) * y_scale); + magnitude = qBound(0, magnitude, m_rows); + } + + + m_intern_vis_data[i] -= m_analyzer_falloff * m_rows / 15; + m_intern_vis_data[i] = magnitude > m_intern_vis_data[i] ? magnitude : m_intern_vis_data[i]; + + if (m_show_peaks) + { + m_peaks[i] -= m_peaks_falloff * m_rows / 15; + m_peaks[i] = magnitude > m_peaks[i] ? magnitude : m_peaks[i]; + } + } +} + +void QSUIVisualization::draw(QPainter *p) +{ + QBrush brush(Qt::SolidPattern); + + for (int j = 0; j < m_cols; ++j) + { + int x = m_offset + j * m_cell_size.width() + 1; + + for (int i = 0; i <= m_intern_vis_data[j]; ++i) + { + if (i <= m_rows / 3) + brush.setColor(m_color1); + else if (i > m_rows / 3 && i <= 2 * m_rows / 3) + brush.setColor(m_color2); + else + brush.setColor(m_color3); + + p->fillRect(x, height() - i * m_cell_size.height(), + m_cell_size.width() - 1, m_cell_size.height() - 4, brush); + } + + if (m_show_peaks) + { + p->fillRect(x, height() - int(m_peaks[j]) * m_cell_size.height(), + m_cell_size.width() - 1, m_cell_size.height() - 4, m_peakColor); + } + } +} + +void QSUIVisualization::createMenu() +{ + m_menu = new QMenu (this); + connect(m_menu, SIGNAL(triggered (QAction *)),SLOT(writeSettings())); + connect(m_menu, SIGNAL(triggered (QAction *)),SLOT(readSettings())); + + m_coverAction = m_menu->addAction(tr("Cover")); + m_coverAction->setCheckable(true); + + m_peaksAction = m_menu->addAction(tr("Peaks")); + m_peaksAction->setCheckable(true); + + QMenu *refreshRate = m_menu->addMenu(tr("Refresh Rate")); + m_fpsGroup = new QActionGroup(this); + m_fpsGroup->setExclusive(true); + m_fpsGroup->addAction(tr("50 fps"))->setData(50); + m_fpsGroup->addAction(tr("25 fps"))->setData(25); + m_fpsGroup->addAction(tr("10 fps"))->setData(10); + m_fpsGroup->addAction(tr("5 fps"))->setData(5); + for(QAction *act : m_fpsGroup->actions ()) + { + act->setCheckable(true); + refreshRate->addAction(act); + } + + QMenu *analyzerFalloff = m_menu->addMenu(tr("Analyzer Falloff")); + m_analyzerFalloffGroup = new QActionGroup(this); + m_analyzerFalloffGroup->setExclusive(true); + m_analyzerFalloffGroup->addAction(tr("Slowest"))->setData(1.2); + m_analyzerFalloffGroup->addAction(tr("Slow"))->setData(1.8); + m_analyzerFalloffGroup->addAction(tr("Medium"))->setData(2.2); + m_analyzerFalloffGroup->addAction(tr("Fast"))->setData(2.4); + m_analyzerFalloffGroup->addAction(tr("Fastest"))->setData(2.8); + for(QAction *act : m_analyzerFalloffGroup->actions ()) + { + act->setCheckable(true); + analyzerFalloff->addAction(act); + } + + QMenu *peaksFalloff = m_menu->addMenu(tr("Peaks Falloff")); + m_peaksFalloffGroup = new QActionGroup(this); + m_peaksFalloffGroup->setExclusive(true); + m_peaksFalloffGroup->addAction(tr("Slowest"))->setData(0.05); + m_peaksFalloffGroup->addAction(tr("Slow"))->setData(0.1); + m_peaksFalloffGroup->addAction(tr("Medium"))->setData(0.2); + m_peaksFalloffGroup->addAction(tr("Fast"))->setData(0.4); + m_peaksFalloffGroup->addAction(tr("Fastest"))->setData(0.8); + for(QAction *act : m_peaksFalloffGroup->actions ()) + { + act->setCheckable(true); + peaksFalloff->addAction(act); + } + update(); +} + +void QSUIVisualization::updateCover() +{ + if(m_show_cover && !m_cover.isNull()) + { + m_offset = height(); + m_pixLabel->setGeometry(10,10, height() - 20, height() - 20); + m_pixLabel->setPixmap(m_cover.scaled(m_pixLabel->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + m_pixLabel->show(); + } + else + { + m_offset = 0; + m_pixLabel->hide(); + } +} + +void QSUIVisualization::mousePressEvent (QMouseEvent *e) +{ + if (e->button() == Qt::RightButton) + m_menu->exec(e->globalPos()); +} + +void QSUIVisualization::readSettings() +{ + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + settings.beginGroup("Simple"); + m_peaks_falloff = settings.value("vis_peaks_falloff", 0.2).toDouble(); + m_analyzer_falloff = settings.value("vis_analyzer_falloff", 2.2).toDouble(); + m_show_peaks = settings.value("vis_show_peaks", true).toBool(); + m_show_cover = settings.value("vis_show_cover", true).toBool(); + m_timer->setInterval(1000 / settings.value("vis_refresh_rate", 25).toInt()); + m_color1.setNamedColor(settings.value("vis_color1", "#BECBFF").toString()); + m_color2.setNamedColor(settings.value("vis_color2", "#BECBFF").toString()); + m_color3.setNamedColor(settings.value("vis_color3", "#BECBFF").toString()); + m_bgColor.setNamedColor(settings.value("vis_bg_color", "Black").toString()); + m_peakColor.setNamedColor(settings.value("vis_peak_color", "#DDDDDD").toString()); + m_cell_size = QSize(14, 8); + if(!m_update) + { + m_update = true; + m_coverAction->setChecked(m_show_cover); + m_peaksAction->setChecked(m_show_peaks); + + for(QAction *act : m_fpsGroup->actions ()) + { + if (m_timer->interval() == 1000 / act->data().toInt()) + act->setChecked(true); + } + for(QAction *act : m_peaksFalloffGroup->actions ()) + { + if (m_peaks_falloff == act->data().toDouble()) + act->setChecked(true); + } + for(QAction *act : m_analyzerFalloffGroup->actions ()) + { + if (m_analyzer_falloff == act->data().toDouble()) + act->setChecked(true); + } + } + updateCover(); + settings.endGroup(); +} + +void QSUIVisualization::writeSettings() +{ + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + settings.beginGroup("Simple"); + + QAction *act = m_fpsGroup->checkedAction (); + settings.setValue("vis_refresh_rate", act ? act->data().toInt() : 25); + act = m_peaksFalloffGroup->checkedAction (); + settings.setValue("vis_peaks_falloff", act ? act->data().toDouble() : 0.2); + act = m_analyzerFalloffGroup->checkedAction (); + settings.setValue("vis_analyzer_falloff", act ? act->data().toDouble() : 2.2); + settings.setValue("vis_show_peaks", m_peaksAction->isChecked()); + settings.setValue("vis_show_cover", m_coverAction->isChecked()); + settings.endGroup(); +} + +void QSUIVisualization::start() +{ + m_running = true; + if(isVisible()) + m_timer->start(); +} + +void QSUIVisualization::stop() +{ + m_running = false; + m_timer->stop(); + clear(); +} + +void QSUiAnalyzer::draw(QPainter *p) +{ + QBrush brush(Qt::SolidPattern); + + for (int j = 0; j < m_cols; ++j) + { + int x = m_offset + j * m_cell_size.width() + 1; + + for (int i = 0; i <= m_intern_vis_data[j]; ++i) + { + if (i <= m_rows / 3) + brush.setColor(m_color1); + else if (i > m_rows / 3 && i <= 2 * m_rows / 3) + brush.setColor(m_color2); + else + brush.setColor(m_color3); + + //p->fillRect(x, height() - i * m_cell_size.height(), + // m_cell_size.width() - 1, m_cell_size.height() - 4, brush); + } + + if (m_show_peaks) + { + //p->fillRect(x, height() - int(m_peaks[j]) * m_cell_size.height(), + // m_cell_size.width() - 1, m_cell_size.height() - 4, m_peakColor); + } + } +} + +void QSUiAnalyzer::readSettings() +{ + +} diff --git a/src/plugins/Ui/qsui/qsuivisualization.h b/src/plugins/Ui/qsui/qsuivisualization.h new file mode 100644 index 000000000..5d2257131 --- /dev/null +++ b/src/plugins/Ui/qsui/qsuivisualization.h @@ -0,0 +1,125 @@ +/*************************************************************************** + * Copyright (C) 2012-2019 by Ilya Kotov * + * forkotov02@ya.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef QSUIVISUALIZATION_H +#define QSUIVISUALIZATION_H + +#include +#include +#include + +class QTimer; +class QMenu; +class QActionGroup; +class QLabel; +class QPainter; +class QSUiVisualDrawer; + +class QSUIVisualization : public Visual +{ + Q_OBJECT +public: + QSUIVisualization(QWidget *parent = nullptr); + virtual ~QSUIVisualization(); + + void setCover(const QPixmap &pixmap); + void clear(); + void clearCover(); + QSize sizeHint() const override; + +public slots: + void start() override; + void stop() override; + void readSettings(); + +private slots: + void timeout(); + void writeSettings(); + +private: + void paintEvent(QPaintEvent *) override; + void mousePressEvent(QMouseEvent *) override; + void hideEvent(QHideEvent *) override; + void showEvent(QShowEvent *) override; + void resizeEvent(QResizeEvent *) override; + void process(); + void draw(QPainter *p); + void createMenu(); + void updateCover(); + + QPixmap m_cover; + QTimer *m_timer; + double *m_intern_vis_data = nullptr; + double *m_peaks = nullptr; + int *m_x_scale = nullptr; + double m_peaks_falloff; + double m_analyzer_falloff; + bool m_show_peaks; + bool m_show_cover = false; + float m_buffer[QMMP_VISUAL_NODE_SIZE]; + int m_cols = 0, m_rows = 0; + int m_offset = 0; + bool m_update = false; + QLabel *m_pixLabel; + //colors + QColor m_color1; + QColor m_color2; + QColor m_color3; + QColor m_bgColor; + QColor m_peakColor; + QSize m_cell_size; + QMenu *m_menu; + QAction *m_peaksAction; + QAction *m_coverAction; + QActionGroup *m_fpsGroup; + QActionGroup *m_analyzerFalloffGroup; + QActionGroup *m_peaksFalloffGroup; + bool m_running = false; +}; + +class QSUiVisualDrawer +{ +public: + virtual void draw(QPainter *p) = 0; + virtual void readSettings() = 0; +}; + +class QSUiAnalyzer : public QSUiVisualDrawer +{ +public: + void draw(QPainter *p) override; + void readSettings() override; + +private: + int m_cols = 0, m_rows = 0, m_offset = 0; + QColor m_color1; + QColor m_color2; + QColor m_color3; + QColor m_bgColor; + QColor m_peakColor; + QSize m_cell_size; + bool m_show_peaks = false; + double *m_intern_vis_data = nullptr; + double *m_peaks = nullptr; + int *m_x_scale = nullptr; + +}; + + +#endif //QSUIVISUALIZATION_H -- cgit v1.2.3-13-gbd6f