~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to noatun/noatun/modules/winskin/guiSpectrumAnalyser.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Children, thank the author for letting you play in his yard with the BSD
 
3
  license.  "Thank you Mr. Samuels"
 
4
 
 
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>
 
8
 
 
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:
 
15
 
 
16
  The above copyright notice and this permission notice shall be included in
 
17
  all copies or substantial portions of the Software.
 
18
 
 
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.
 
25
 
 
26
 */
 
27
 
 
28
#include <guiSpectrumAnalyser.h>
 
29
#include <plugin.h>
 
30
#include <kpixmapeffect.h>
 
31
#include <kpixmap.h>
 
32
#include <kconfig.h>
 
33
#include <qcolor.h>
 
34
 
 
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;
 
39
 
 
40
GuiSpectrumAnalyser::GuiSpectrumAnalyser( QWidget *parent, const char *name, int refresh)
 
41
  : QWidget(parent,name)
 
42
  , MonoFFTScope(refresh)
 
43
  , bars(guiSpectrumHeight)
 
44
{
 
45
  mFGColor.setRgb(0, 255, 0);
 
46
  mBGColor.setRgb(0, 0, 0);
 
47
 
 
48
  setBands(guiSpectrumBarMagic);
 
49
 
 
50
  int w = guiSpectrumBars;
 
51
  int wmult = w;
 
52
  while (w < guiSpectrumWidth)
 
53
    w += wmult;
 
54
 
 
55
  mBarWidth=w/wmult;
 
56
 
 
57
  // generate vis cache
 
58
  QPixmap blankBar(mBarWidth, guiSpectrumHeight);
 
59
  blankBar.fill(mBGColor);
 
60
 
 
61
  memoryManager.setAutoDelete(true);
 
62
 
 
63
  // bars[0] is blank
 
64
  {
 
65
    QPixmap *newBar = new QPixmap(blankBar);
 
66
    bars[0] = newBar;
 
67
    memoryManager.append(newBar);
 
68
  }
 
69
 
 
70
        QColor red(255,0,0);
 
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);
 
76
 
 
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);
 
81
 
 
82
    QPixmap *newBar = new QPixmap(blankBar);
 
83
    bitBlt(newBar, 0, guiSpectrumHeight - i, &canvas);
 
84
    bars[i] = newBar;
 
85
    memoryManager.append(newBar);
 
86
  }
 
87
  start();
 
88
}
 
89
 
 
90
void GuiSpectrumAnalyser::mousePressEvent ( QMouseEvent* ) {
 
91
}
 
92
 
 
93
QSize GuiSpectrumAnalyser::sizeHint() const {
 
94
  return QSize(guiSpectrumWidth, guiSpectrumHeight);
 
95
}
 
96
 
 
97
void GuiSpectrumAnalyser::scopeEvent(float *d, int size)
 
98
{
 
99
  QPainter p(this);
 
100
  int x = 0;
 
101
  int y = 0;
 
102
  int w = width();
 
103
  int h = height();
 
104
  float *start = d;
 
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)
 
110
  {
 
111
    float n = fheight * log(*start + 1.0) * 5;
 
112
    int amp = (int)n;
 
113
    if(amp < 0)
 
114
      amp = 0;
 
115
    else if(amp > h)
 
116
      amp = h;
 
117
 
 
118
    p.drawPixmap(x, 0, *bars[amp]);
 
119
 
 
120
    x += mBarWidth;
 
121
  }
 
122
}
 
123
 
 
124
void GuiSpectrumAnalyser::reload()
 
125
{
 
126
        stop();
 
127
        mFGColor.setRgb(0, 255, 0);
 
128
        mBGColor.setRgb(0, 0, 0);
 
129
 
 
130
        setBands(guiSpectrumBarMagic);
 
131
 
 
132
        int w = guiSpectrumBars;
 
133
        int wmult = w;
 
134
        while (w < guiSpectrumWidth)
 
135
        w += wmult;
 
136
 
 
137
        mBarWidth=w/wmult;
 
138
 
 
139
        // generate vis cache
 
140
        QPixmap blankBar(mBarWidth, guiSpectrumHeight);
 
141
        blankBar.fill(mBGColor);
 
142
 
 
143
        memoryManager.setAutoDelete(true);
 
144
 
 
145
        // bars[0] is blank
 
146
        {
 
147
                QPixmap *newBar = new QPixmap(blankBar);
 
148
                bars[0] = newBar;
 
149
                memoryManager.append(newBar);
 
150
        }
 
151
 
 
152
        QColor red(255,0,0);
 
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));
 
159
        
 
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);
 
164
 
 
165
                QPixmap *newBar = new QPixmap(blankBar);
 
166
                bitBlt(newBar, 0, guiSpectrumHeight - i, &canvas);
 
167
                bars[i] = newBar;
 
168
                memoryManager.append(newBar);
 
169
        }
 
170
        start();
 
171
}
 
172
#include "guiSpectrumAnalyser.moc"
 
173
 
 
174
// TODO: fix this
 
175
// See http://derkarl.org/s-and-s.html for details
 
176
// vim: ts=2 et