aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2019-12-14 20:24:51 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2019-12-14 20:24:51 +0000
commit5d2325d2e4915a0d33c942c35fbb32b9dc535b80 (patch)
tree868e779ae1437d15afbfa960ec531b962d8fe58d /src/plugins
parent581e201025b971c2a0ca6e1f2748340ab1a0fa68 (diff)
downloadqmmp-5d2325d2e4915a0d33c942c35fbb32b9dc535b80.tar.gz
qmmp-5d2325d2e4915a0d33c942c35fbb32b9dc535b80.tar.bz2
qmmp-5d2325d2e4915a0d33c942c35fbb32b9dc535b80.zip
qsui: refactoring
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9138 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Ui/qsui/qsuivisualization.cpp258
-rw-r--r--src/plugins/Ui/qsui/qsuivisualization.h33
2 files changed, 148 insertions, 143 deletions
diff --git a/src/plugins/Ui/qsui/qsuivisualization.cpp b/src/plugins/Ui/qsui/qsuivisualization.cpp
index fcc851bda..f9757add9 100644
--- a/src/plugins/Ui/qsui/qsuivisualization.cpp
+++ b/src/plugins/Ui/qsui/qsuivisualization.cpp
@@ -34,6 +34,7 @@
QSUIVisualization::QSUIVisualization(QWidget *parent) : Visual (parent)
{
m_pixLabel = new QLabel(this);
+ m_drawer = new QSUiAnalyzer;
createMenu();
m_timer = new QTimer (this);
@@ -45,19 +46,17 @@ QSUIVisualization::QSUIVisualization(QWidget *parent) : Visual (parent)
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;
+ if(m_drawer)
+ delete m_drawer;
}
void QSUIVisualization::clear()
{
- m_rows = 0;
- m_cols = 0;
- update();
+ if(m_drawer)
+ {
+ m_drawer->clear();
+ update();
+ }
}
void QSUIVisualization::clearCover()
@@ -89,9 +88,12 @@ void QSUIVisualization::timeout()
void QSUIVisualization::paintEvent (QPaintEvent * e)
{
- QPainter painter (this);
- painter.fillRect(e->rect(),m_bgColor);
- draw(&painter);
+ if(m_drawer)
+ {
+ QPainter painter (this);
+ painter.fillRect(e->rect(),m_bgColor);
+ m_drawer->draw(&painter, m_offset);
+ }
}
void QSUIVisualization::hideEvent (QHideEvent *)
@@ -112,99 +114,8 @@ void QSUIVisualization::resizeEvent(QResizeEvent *)
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);
- }
- }
+ if(m_drawer)
+ m_drawer->process(m_buffer, width() - m_offset, height());
}
void QSUIVisualization::createMenu()
@@ -288,22 +199,19 @@ 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();
+ //general settings
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);
+ //analyzer settings
+ double peaks_falloff = settings.value("vis_peaks_falloff", 0.2).toDouble();
+ double analyzer_falloff = settings.value("vis_analyzer_falloff", 2.2).toDouble();
+ bool show_peaks = settings.value("vis_show_peaks", true).toBool();
+
if(!m_update)
{
m_update = true;
m_coverAction->setChecked(m_show_cover);
- m_peaksAction->setChecked(m_show_peaks);
+ m_peaksAction->setChecked(show_peaks);
for(QAction *act : m_fpsGroup->actions ())
{
@@ -312,17 +220,20 @@ void QSUIVisualization::readSettings()
}
for(QAction *act : m_peaksFalloffGroup->actions ())
{
- if (m_peaks_falloff == act->data().toDouble())
+ if (peaks_falloff == act->data().toDouble())
act->setChecked(true);
}
for(QAction *act : m_analyzerFalloffGroup->actions ())
{
- if (m_analyzer_falloff == act->data().toDouble())
+ if (analyzer_falloff == act->data().toDouble())
act->setChecked(true);
}
}
updateCover();
settings.endGroup();
+
+ if(m_drawer)
+ m_drawer->readSettings();
}
void QSUIVisualization::writeSettings()
@@ -355,13 +266,95 @@ void QSUIVisualization::stop()
clear();
}
-void QSUiAnalyzer::draw(QPainter *p)
+QSUiVisualDrawer::~QSUiVisualDrawer()
+{}
+
+QSUiAnalyzer::~QSUiAnalyzer()
+{
+ if(m_intern_vis_data)
+ delete [] m_intern_vis_data;
+ if(m_peaks)
+ delete [] m_peaks;
+ if(m_x_scale)
+ delete [] m_x_scale;
+}
+
+void QSUiAnalyzer::process(float *buffer, int width, int height)
+{
+ int rows = qMax((height - 2) / m_cell_size.height(),2);
+ int cols = qMax((width - 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, 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, int offset)
{
QBrush brush(Qt::SolidPattern);
+ int height = m_rows * m_cell_size.height() + 2;
for (int j = 0; j < m_cols; ++j)
{
- int x = m_offset + j * m_cell_size.width() + 1;
+ int x = offset + j * m_cell_size.width() + 1;
for (int i = 0; i <= m_intern_vis_data[j]; ++i)
{
@@ -372,19 +365,36 @@ void QSUiAnalyzer::draw(QPainter *p)
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);
+ 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);
+ 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()
+void QSUiAnalyzer::clear()
{
+ m_rows = 0;
+ m_cols = 0;
+}
+void QSUiAnalyzer::readSettings()
+{
+ QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
+ settings.beginGroup("Simple");
+ 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);
+ 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();
+ settings.endGroup();
}
diff --git a/src/plugins/Ui/qsui/qsuivisualization.h b/src/plugins/Ui/qsui/qsuivisualization.h
index 5d2257131..7884ea242 100644
--- a/src/plugins/Ui/qsui/qsuivisualization.h
+++ b/src/plugins/Ui/qsui/qsuivisualization.h
@@ -59,31 +59,17 @@ private:
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;
+ QColor m_bgColor;
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;
@@ -91,34 +77,43 @@ private:
QActionGroup *m_analyzerFalloffGroup;
QActionGroup *m_peaksFalloffGroup;
bool m_running = false;
+ QSUiVisualDrawer *m_drawer = nullptr;
};
class QSUiVisualDrawer
{
public:
- virtual void draw(QPainter *p) = 0;
+ virtual ~QSUiVisualDrawer();
+ virtual void process(float *buffer, int width, int height) = 0;
+ virtual void draw(QPainter *p, int offset) = 0;
+ virtual void clear() = 0;
virtual void readSettings() = 0;
};
class QSUiAnalyzer : public QSUiVisualDrawer
{
public:
- void draw(QPainter *p) override;
+ QSUiAnalyzer() {}
+ virtual ~QSUiAnalyzer();
+ void process(float *buffer, int width, int height) override;
+ void draw(QPainter *p, int offset) override;
+ void clear() override;
void readSettings() override;
private:
- int m_cols = 0, m_rows = 0, m_offset = 0;
+ int m_cols = 0, m_rows = 0;
QColor m_color1;
QColor m_color2;
QColor m_color3;
QColor m_bgColor;
QColor m_peakColor;
QSize m_cell_size;
+ double m_peaks_falloff;
+ double m_analyzer_falloff;
bool m_show_peaks = false;
double *m_intern_vis_data = nullptr;
double *m_peaks = nullptr;
int *m_x_scale = nullptr;
-
};