-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmountainplugin.cpp
100 lines (81 loc) · 1.92 KB
/
mountainplugin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "mountainplugin.h"
#include "mountainwidget.h"
#include "inlines.h"
#include <QMenu>
#include <QTimer>
#include <QBoxLayout>
MountainPlugin::MountainPlugin(QWidget *parent)
: Visual(parent)
{
setWindowTitle(tr("Mountain Widget"));
m_mountainWidget = new MountainWidget(this);
QHBoxLayout *layout = new QHBoxLayout(this);
layout->addWidget(m_mountainWidget);
layout->setContentsMargins(0, 0, 0, 0);
setLayout(layout);
m_timer = new QTimer(this);
m_timer->setInterval(40);
connect(m_timer, SIGNAL(timeout()), SLOT(updateVisual()));
m_screenAction = new QAction(tr("Fullscreen"), this);
m_screenAction->setCheckable(true);
connect(m_screenAction, SIGNAL(triggered(bool)), this, SLOT(setFullScreen(bool)));
}
MountainPlugin::~MountainPlugin()
{
}
void MountainPlugin::start()
{
if(isVisible())
{
m_timer->start();
}
}
void MountainPlugin::stop()
{
m_timer->stop();
}
void MountainPlugin::updateVisual()
{
if(takeData(m_left, m_right))
{
process(m_left, m_right);
update();
}
}
void MountainPlugin::setFullScreen(bool yes)
{
if(yes)
{
setWindowState(windowState() | Qt::WindowFullScreen);
}
else
{
setWindowState(windowState() & ~Qt::WindowFullScreen);
}
}
void MountainPlugin::hideEvent(QHideEvent *)
{
m_timer->stop();
}
void MountainPlugin::showEvent(QShowEvent *)
{
m_timer->start();
}
void MountainPlugin::contextMenuEvent(QContextMenuEvent *)
{
QMenu menu(this);
menu.addAction(m_screenAction);
menu.exec(QCursor::pos());
}
void MountainPlugin::process(float *left, float *)
{
constexpr int size = QMMP_VISUAL_NODE_SIZE / 2;
short dest_l[size];
calc_freq(dest_l, left);
float buffer[size];
for(int i = 0; i < size; ++i)
{
buffer[i] = dest_l[i] / ((QMMP_VISUAL_NODE_SIZE << 8) / (8.0 / 2));
}
m_mountainWidget->addBuffer(buffer);
}