2
Children, thank the author for letting you play in his yard with the BSD
3
license. "Thank you Mr. Samuels"
5
a GUI for a spectrum analyser
6
Based on KJVis (C) 2000 Charles Samuels <charles@kde.org>
7
Ported to Winskin by (name redacted due to shame) <neil@qualityassistant.com>
9
Permission is hereby granted, free of charge, to any person obtaining a copy
10
of this software and associated documentation files (the "Software"), to deal
11
in the Software without restriction, including without limitation the rights
12
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
copies of the Software, and to permit persons to whom the Software is
14
furnished to do so, subject to the following conditions:
16
The above copyright notice and this permission notice shall be included in
17
all copies or substantial portions of the Software.
19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
#include <guiSpectrumAnalyser.h>
30
#include <kpixmapeffect.h>
35
static const int guiSpectrumHeight = 20;
36
static const int guiSpectrumWidth = 70;
37
static const int guiSpectrumBars = 35;
38
static const float guiSpectrumBarMagic = 1.125;
40
GuiSpectrumAnalyser::GuiSpectrumAnalyser( QWidget *parent, const char *name, int refresh)
41
: QWidget(parent,name)
42
, MonoFFTScope(refresh)
43
, bars(guiSpectrumHeight)
45
mFGColor.setRgb(0, 255, 0);
46
mBGColor.setRgb(0, 0, 0);
48
setBands(guiSpectrumBarMagic);
50
int w = guiSpectrumBars;
52
while (w < guiSpectrumWidth)
58
QPixmap blankBar(mBarWidth, guiSpectrumHeight);
59
blankBar.fill(mBGColor);
61
memoryManager.setAutoDelete(true);
65
QPixmap *newBar = new QPixmap(blankBar);
67
memoryManager.append(newBar);
71
QColor green(0,255,0);
72
KConfig *config = KGlobal::config();
73
config->setGroup("Winskin");
74
QColor firstColor = config->readColorEntry("ScopeBarColor1", &red);
75
QColor secondColor = config->readColorEntry("ScopeBarColor2", &green);
77
for (int i = 1; i < guiSpectrumHeight; i++) {
78
QPixmap qpixmap(mBarWidth, i);
79
KPixmap canvas(qpixmap);
80
KPixmapEffect::gradient(canvas, firstColor, secondColor, KPixmapEffect::VerticalGradient, 4);
82
QPixmap *newBar = new QPixmap(blankBar);
83
bitBlt(newBar, 0, guiSpectrumHeight - i, &canvas);
85
memoryManager.append(newBar);
90
void GuiSpectrumAnalyser::mousePressEvent ( QMouseEvent* ) {
93
QSize GuiSpectrumAnalyser::sizeHint() const {
94
return QSize(guiSpectrumWidth, guiSpectrumHeight);
97
void GuiSpectrumAnalyser::scopeEvent(float *d, int size)
105
float *end = d + size;
106
float fheight = (float)h;
107
repaint(rect(), false);
108
p.fillRect(0, 0, w, h, mBGColor);
109
for( ; start < end; ++start)
111
float n = fheight * log(*start + 1.0) * 5;
118
p.drawPixmap(x, 0, *bars[amp]);
124
void GuiSpectrumAnalyser::reload()
127
mFGColor.setRgb(0, 255, 0);
128
mBGColor.setRgb(0, 0, 0);
130
setBands(guiSpectrumBarMagic);
132
int w = guiSpectrumBars;
134
while (w < guiSpectrumWidth)
139
// generate vis cache
140
QPixmap blankBar(mBarWidth, guiSpectrumHeight);
141
blankBar.fill(mBGColor);
143
memoryManager.setAutoDelete(true);
147
QPixmap *newBar = new QPixmap(blankBar);
149
memoryManager.append(newBar);
153
QColor green(0,255,0);
154
KConfig *config = KGlobal::config();
155
config->setGroup("Winskin");
156
QColor firstColor = config->readColorEntry("ScopeBarColor1", &red);
157
QColor secondColor = config->readColorEntry("ScopeBarColor2", &green);
158
setInterval(config->readNumEntry("ScopeFPS", 2));
160
for (int i = 1; i < guiSpectrumHeight; i++) {
161
QPixmap qpixmap(mBarWidth, i);
162
KPixmap canvas(qpixmap);
163
KPixmapEffect::gradient(canvas, firstColor, secondColor, KPixmapEffect::VerticalGradient, 4);
165
QPixmap *newBar = new QPixmap(blankBar);
166
bitBlt(newBar, 0, guiSpectrumHeight - i, &canvas);
168
memoryManager.append(newBar);
172
#include "guiSpectrumAnalyser.moc"
175
// See http://derkarl.org/s-and-s.html for details