-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvis.cpp
More file actions
226 lines (223 loc) · 6.87 KB
/
vis.cpp
File metadata and controls
226 lines (223 loc) · 6.87 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#include "vis.h"
#include <QMessageBox>
#include <QSettings>
#define loadproc qDebug() << "Loading process in Vis:" <<
Vis::Vis(QWidget *parent) : QDialog(parent)
{
this->resize(320, 240);
this->setMaximumSize(1024, 768);
this->setMinimumSize(320, 240);
this->setWindowIcon(QIcon(":/res/icons/plugin.png"));
this->setWindowTitle("Visualization");
this->ctype = 1;
this->curr = -1;
this->setWindowFlags(Qt::Tool);
this->timer = new QTimer(this);
this->timer->setInterval((int)(1000 / FPS));
connect(this->timer, SIGNAL(timeout()), this, SLOT(update()));
this->libs = new QStringList();
this->libsinfo = new QList<VisInfo*>();
this->actions = new QList<QAction*>();
this->checkLibs();
this->createActions();
this->load();
this->setTitle();
if(this->isVisible())
this->timer->start();
}
Vis::~Vis()
{
}
void Vis::setChannel(HSTREAM chan){
this->chan = chan;
}
void Vis::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
break;
default:
break;
}
}
void Vis::paintEvent(QPaintEvent *event){
if(!this->isVisible()){
return;
}
BASS_ChannelGetData(this->chan, fft, BASS_DATA_FFT8192); //ïîëó÷åíèå äàíûõ ÁÔÏ
if(this->ctype == 1){
if(this->Draw){
QPainter paint(this);
this->Draw(paint, fft);
}
else{
qDebug() << "error: cold not resolve Draw...";
}
}
else if(this->ctype == 2){
if(this->Upd){
this->Upd(fft);
}
else{
err << "could't resolve Update()";
}
}
memset(fft, 0, sizeof(this->fft));
}
void Vis::checkLibs(){
loadproc "loading visualization plugins";
QDir dir(PLUGINPATH);
if(dir.exists()){
QStringList filters;
filters.append("vis_*.dll");
filters.append("vis_*.so");
filters.append("libvis_*.so");
filters.append("libvis_*.so*");
QStringList list = dir.entryList(filters, QDir::Files);
for(int i = 0; i < list.length(); i++){
if(QLibrary::isLibrary(PLUGINPATH + list.value(i))){
VisInf inf = (VisInf)QLibrary::resolve(PLUGINPATH + list.value(i), "Info");
if(!inf){
continue;
}
else{
VisInfo * vinf = new VisInfo();
inf(vinf);
this->libs->append(list.value(i));
this->libsinfo->append(vinf);
loadproc "plugin" << list.value(i) << "added";
}
}
}
}
}
void Vis::createActions(){
for(int i = 0; i < this->libs->length(); i++){
QAction *action = new QAction(this->libsinfo->value(i)->name, this);
action->setData(i);
action->setIcon(QIcon(":/res/icons/plugin.png"));
connect(action, SIGNAL(triggered()), this, SLOT(changeVis()));
this->actions->append(action);
}
QAction *about = new QAction("About", this);
about->setIcon(QIcon(":/res/icons/information.png"));
connect(about, SIGNAL(triggered()), this, SLOT(about()));
this->actions->append(about);
QAction *fs = new QAction("Toggle Fullscreen", this);
fs->setIcon(QIcon(":/res/icons/fullscreen.png"));
connect(fs, SIGNAL(triggered()), this, SLOT(toggleFullScreen()));
this->actions->append(fs);
}
void Vis::contextMenuEvent(QContextMenuEvent *event){
QMenu menu(this);
for(int i = 0; i < this->actions->length(); i++){
menu.addAction(this->actions->value(i));
}
menu.exec(event->globalPos());
}
void Vis::changeVis(){
QAction *act = qobject_cast<QAction*>(sender());
int libid = act->data().toInt();
this->unload();
this->load(this->libs->value(libid));
this->setTitle();
this->curr = libid;
}
void Vis::hideEvent(QHideEvent *event){
this->timer->stop();
if(this->curr != -1)
this->unload();
}
void Vis::showEvent(QShowEvent *event){
if(this->curr != -1)
this->load(this->libs->value(this->curr));
this->timer->start();
}
void Vis::about(){
if(this->vislib->isLoaded()){
VisInf inf = (VisInf)this->vislib->resolve("Info");
if(inf){
VisInfo *vinf = new VisInfo();
inf(vinf);
QMessageBox::about(this, "About " + vinf->name,
"<h2>" + vinf->name + "</h2><br />" +
"<div style='text-align: left;'>" +
"<b>Autor:</b> " + vinf->autor + "<br />" +
"<b>Version:</b> " + vinf->version +
"</div>"
);
}
}
}
void Vis::toggleFullScreen(){
if(!this->isFullScreen()){
this->setWindowState(Qt::WindowFullScreen);
}
else{
this->setWindowState(Qt::WindowNoState);
}
}
void Vis::save(){
QSettings s(PATH + VISSETTING, QSettings::IniFormat);
s.setValue("dll", this->curr == -1 ? "" : this->libs->value(this->curr));
s.setValue("W", this->width());
s.setValue("H", this->height());
}
void Vis::load(QString dll){
this->vislib = new QLibrary(PLUGINPATH + dll);
VisInf inf = (VisInf)this->vislib->resolve("Info");
if(inf){
VisInfo *vinf = new VisInfo();
inf(vinf);
if(vinf->ver == 2){
this->ctype = 2;
INIT init = (INIT)this->vislib->resolve("Init");
if(init){
init(this->window());
this->Upd = (UPDATE)this->vislib->resolve("Update");
}
else{
err << "could't resolve Init()";
}
}
else{
this->ctype = 1;
this->Draw = (Drawer)this->vislib->resolve("Draw");
}
}
this->curr = this->libs->indexOf(dll, 0);
}
void Vis::load(){
QSettings s(PATH + VISSETTING, QSettings::IniFormat);
this->resize(s.value("W", this->minimumWidth()).toInt(), s.value("H", this->minimumHeight()).toInt());
this->load(s.value("dll", "vis_spect.dll").toString());
}
void Vis::unload(){
if(this->ctype == 2){
this->Upd = NULL;
STOP stop = (STOP)this->vislib->resolve("Stop");
if(stop){
stop();
}
}
else{
this->Draw = NULL;
}
this->vislib->unload();
delete this->vislib;
}
void Vis::setTitle(){
VisInf inf = (VisInf)this->vislib->resolve("Info");
if(inf){
VisInfo *info = new VisInfo();
inf(info);
this->setWindowTitle(info->name);
delete info;
return;
}
else{
qDebug() << "error: could't resolve Info()";
}
this->setWindowTitle("Visualization");
}