-rw-r--r-- | noncore/multimedia/opierec/vumeter.cpp | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/noncore/multimedia/opierec/vumeter.cpp b/noncore/multimedia/opierec/vumeter.cpp index 0edc806..c28dbe4 100644 --- a/noncore/multimedia/opierec/vumeter.cpp +++ b/noncore/multimedia/opierec/vumeter.cpp | |||
@@ -1,240 +1,233 @@ | |||
1 | //************************************************************ | 1 | //************************************************************ |
2 | //=======-VUMeter | 2 | //=======-VUMeter |
3 | ///// copyright : (C) 1999 by Martin Lorenz | 3 | ///// copyright : (C) 1999 by Martin Lorenz |
4 | ////// email : lorenz@ch.tum.de | 4 | ////// email : lorenz@ch.tum.de |
5 | 5 | ||
6 | #include "vumeter.h" | 6 | #include "vumeter.h" |
7 | #include "qtrec.h" | 7 | #include "qtrec.h" |
8 | 8 | ||
9 | #include <qpe/config.h> | 9 | #include <qpe/config.h> |
10 | #include <qtimer.h> | 10 | #include <qtimer.h> |
11 | #include <qdrawutl.h> | 11 | #include <qdrawutl.h> |
12 | 12 | ||
13 | #include <opie2/odebug.h> | 13 | #include <opie2/odebug.h> |
14 | using namespace Opie::Core; | 14 | using namespace Opie::Core; |
15 | 15 | ||
16 | #include <math.h> | 16 | #include <math.h> |
17 | 17 | ||
18 | VUMeter::VUMeter(QWidget *parent, const char *name, const int tr) | 18 | VUMeter::VUMeter(QWidget *parent, const char *name, const int tr) |
19 | : QWidget( parent, name ) | 19 | : QWidget( parent, name ) |
20 | { | 20 | { |
21 | int tracks = tr; | 21 | int tracks = tr; |
22 | int i; | 22 | int i; |
23 | 23 | ||
24 | qWarning("initialize peakvalues"); | 24 | qWarning("initialize peakvalues"); |
25 | for(i = 0; i < tracks + 2; i++) { | 25 | for(i = 0; i < tracks + 2; i++) { |
26 | peak[i] = hold[i] = 32768; | 26 | peak[i] = hold[i] = 32768; |
27 | holdTime[i] = 20; | 27 | holdTime[i] = 20; |
28 | } | 28 | } |
29 | 29 | ||
30 | readConf(); | 30 | readConf(); |
31 | 31 | ||
32 | // QColor c; | ||
33 | // c.setHsv( (x * 255)/w, 255, 255 );// rainbow effect | ||
34 | // c.setRgb( 255, 0, 255); | ||
35 | // p.setPen(c); | ||
36 | |||
37 | //rainbow effect | 32 | //rainbow effect |
38 | if( colorScheme = 0 ) { | 33 | if( colorScheme == 0 ) { |
39 | for( i = 0; i < para.leds; i++) color[i] = green; | 34 | for( i = 0; i < para.leds; i++) color[i] = green; |
40 | color[0] = color[1] = red; | 35 | color[0] = color[1] = red; |
41 | color[2] = color[3] = color[4] = color[5] = yellow; | 36 | color[2] = color[3] = color[4] = color[5] = yellow; |
42 | } else { | 37 | } else { |
43 | int j = para.leds - 4; | 38 | int j = para.leds - 4; |
44 | for( i = 0; i < para.leds; i++) { | 39 | for( i = 0; i < para.leds; i++) { |
45 | int i16 = (j);// & 15; | 40 | int i16 = (j); |
46 | color[i] = QColor(( 15 - i16) * 16, 255, 255, QColor::Hsv); | 41 | color[i] = QColor(( 15 - i16) * 16, 255, 255, QColor::Hsv); |
47 | owarn << color[i].name() << oendl; | 42 | // owarn << color[i].name() << oendl; |
48 | j--; | 43 | j--; |
49 | } | 44 | } |
50 | } | 45 | } |
51 | 46 | ||
52 | buffer = new QPixmap(); | 47 | buffer = new QPixmap(); |
53 | setBackgroundMode(NoBackground); | 48 | setBackgroundMode(NoBackground); |
54 | vuTimer = new QTimer(this,"vu timer"); | 49 | vuTimer = new QTimer(this,"vu timer"); |
55 | 50 | ||
56 | connect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot())); | 51 | connect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot())); |
57 | } | 52 | } |
58 | 53 | ||
59 | VUMeter::~VUMeter(){ | 54 | VUMeter::~VUMeter(){ |
60 | writeConf(); | 55 | writeConf(); |
61 | } | 56 | } |
62 | 57 | ||
63 | void VUMeter::update(){ | 58 | void VUMeter::update(){ |
64 | qWarning("vumeter update"); | 59 | // qWarning("vumeter update"); |
65 | vuTimer->start(para.update, FALSE); | 60 | vuTimer->start(para.update, FALSE); |
66 | if (para.onOff) { | 61 | if (para.onOff) { |
67 | disconnect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot())); | 62 | disconnect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot())); |
68 | connect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot())); | 63 | connect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot())); |
69 | } else { | 64 | } else { |
70 | disconnect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot())); | 65 | disconnect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot())); |
71 | } | 66 | } |
72 | resize(); | 67 | resize(); |
73 | } | 68 | } |
74 | 69 | ||
75 | void VUMeter::slotOn() { | 70 | void VUMeter::slotOn() { |
76 | connect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot())); | 71 | connect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot())); |
77 | para.onOff=true; | 72 | para.onOff=true; |
78 | } | 73 | } |
79 | 74 | ||
80 | void VUMeter::slotOff() { | 75 | void VUMeter::slotOff() { |
81 | disconnect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot())); | 76 | disconnect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot())); |
82 | para.onOff=false; | 77 | para.onOff=false; |
83 | } | 78 | } |
84 | 79 | ||
85 | void VUMeter::slotProps() { | 80 | void VUMeter::slotProps() { |
86 | qDebug("VU-Dialog"); | 81 | qDebug("VU-Dialog"); |
87 | } | 82 | } |
88 | 83 | ||
89 | void VUMeter::paintEvent(QPaintEvent* e) { | 84 | void VUMeter::paintEvent(QPaintEvent* e) { |
90 | Q_UNUSED(e); | 85 | Q_UNUSED(e); |
91 | bitBlt(this, 0, 0, buffer); | 86 | bitBlt(this, 0, 0, buffer); |
92 | } | 87 | } |
93 | 88 | ||
94 | 89 | ||
95 | void VUMeter::mousePressEvent(QMouseEvent* e) { | 90 | void VUMeter::mousePressEvent(QMouseEvent* e) { |
96 | Q_UNUSED(e); | 91 | Q_UNUSED(e); |
97 | } | 92 | } |
98 | 93 | ||
99 | 94 | ||
100 | void VUMeter::resizeEvent(QResizeEvent* event) { | 95 | void VUMeter::resizeEvent(QResizeEvent* event) { |
101 | buffer->resize(event->size()); | 96 | buffer->resize(event->size()); |
102 | resize(); | 97 | resize(); |
103 | } | 98 | } |
104 | 99 | ||
105 | void VUMeter::resize() { | 100 | void VUMeter::resize() { |
106 | qWarning("resize VUMeter painting"); | 101 | qWarning("resize VUMeter painting"); |
107 | if(buffer == 0) | 102 | if(buffer == 0) |
108 | qDebug("Dude NULL pixmap buffer!"); | 103 | qDebug("Dude NULL pixmap buffer!"); |
109 | 104 | ||
110 | buffer->fill(black); | 105 | buffer->fill(black); |
111 | 106 | ||
112 | x = width() - 7; y = height() - 12; | 107 | x = width() - 7; y = height() - 12; |
113 | dx = x / (tracks + 2); dy = y / (para.leds + 2); // size of one LED + black frame | 108 | dx = x / (tracks + 2); dy = y / (para.leds + 2); // size of one LED + black frame |
114 | ox = dx / 6 + 4 + (x - (tracks + 2) * dx) / 2; | 109 | ox = dx / 6 + 4 + (x - (tracks + 2) * dx) / 2; |
115 | oy = dy / 5 + 5 + (y - (para.leds + 2) * dy) / 2; //offsets | 110 | oy = dy / 5 + 5 + (y - (para.leds + 2) * dy) / 2; //offsets |
116 | sx = (4 *dx) / 6; sy = (4 * dy) / 5; //size of one LED | 111 | sx = (4 *dx) / 6; sy = (4 * dy) / 5; //size of one LED |
117 | 112 | ||
118 | QPainter painter; QString str; QFont font; | 113 | QPainter painter; QString str; QFont font; |
119 | int i, textOffset=0; | 114 | int i, textOffset=0; |
120 | 115 | ||
121 | if( painter.begin(buffer) ==FALSE) | 116 | if( painter.begin(buffer) ==FALSE) |
122 | qWarning("Painting pixmap did not work!"); | 117 | qWarning("Painting pixmap did not work!"); |
123 | else { | 118 | else { |
124 | painter.setPen(green); | 119 | painter.setPen(green); |
125 | qDrawShadePanel ( &painter, 0,0, width(),height(), colorGroup(), TRUE, 2, 0); | 120 | qDrawShadePanel ( &painter, 0,0, width(),height(), colorGroup(), TRUE, 2, 0); |
126 | if (2 * dy - 2 == 10) textOffset = 1; | 121 | if (2 * dy - 2 == 10) textOffset = 1; |
127 | font = painter.font(); font.setPointSize( 2 * dy - 2); | 122 | font = painter.font(); font.setPointSize( 2 * dy - 2); |
128 | painter.setFont(font); | 123 | painter.setFont(font); |
129 | for(i = 0; i < tracks + 2; i++) { | 124 | for(i = 0; i < tracks + 2; i++) { |
130 | painter.setPen(green); painter.setBrush(green); | 125 | painter.setPen(green); painter.setBrush(green); |
131 | str.sprintf("%d",i+1); | 126 | str.sprintf("%d",i+1); |
132 | if (i == tracks) str.sprintf("L"); | 127 | if (i == tracks) str.sprintf("L"); |
133 | if (i == tracks + 1) str.sprintf("R"); | 128 | if (i == tracks + 1) str.sprintf("R"); |
134 | 129 | ||
135 | painter.drawRect(ox + dx * i, oy + dy * (para.leds) - 2, sx, 2 * dy - 1); | 130 | painter.drawRect(ox + dx * i, oy + dy * (para.leds) - 2, sx, 2 * dy - 1); |
136 | painter.setPen(black); | 131 | painter.setPen(black); |
137 | painter.drawText(textOffset + ox + dx * i, oy + dy * (para.leds) - 2, sx, 2 * dy, AlignCenter, str); | 132 | painter.drawText(textOffset + ox + dx * i, oy + dy * (para.leds) - 2, sx, 2 * dy, AlignCenter, str); |
138 | } | 133 | } |
139 | painter.end(); | 134 | painter.end(); |
140 | paint(); | 135 | paint(); |
141 | } | 136 | } |
142 | } | 137 | } |
143 | 138 | ||
144 | void VUMeter::timeSlot() { | 139 | void VUMeter::timeSlot() { |
145 | int i; | 140 | int i; |
146 | // getting stuck here | 141 | // getting stuck here |
147 | // qDebug("calling paint() from timeSlot()\n"); | 142 | // qDebug("calling paint() from timeSlot()\n"); |
148 | paint(); | 143 | paint(); |
149 | for(i = 0; i < tracks + 2; i++) { | 144 | for(i = 0; i < tracks + 2; i++) { |
150 | peak[i] /= para.resoFactor; | 145 | peak[i] /= para.resoFactor; |
151 | } | 146 | } |
152 | } | 147 | } |
153 | 148 | ||
154 | void VUMeter::paint() { | 149 | void VUMeter::paint() { |
155 | int i, k; | 150 | int i, k; |
156 | float p, h ; | 151 | float p, h ; |
157 | QPainter painter; | 152 | QPainter painter; |
158 | painter.begin(buffer); | 153 | painter.begin(buffer); |
159 | int c; | 154 | int c; |
160 | 155 | ||
161 | for(i = 0; i < tracks + 2; i++){ | 156 | for(i = 0; i < tracks + 2; i++){ |
162 | p = peak[i]; h = hold[i]; | 157 | p = peak[i]; h = hold[i]; |
163 | if (p >= 32767) p = 32768; | 158 | if (p >= 32767) p = 32768; |
164 | if (h >= 32767) h = 32768; | 159 | if (h >= 32767) h = 32768; |
165 | for(k = para.leds + 1; k >= 2; k--){ | 160 | for(k = para.leds + 1; k >= 2; k--){ |
166 | c = para.leds + 1 - k; | 161 | c = para.leds + 1 - k; |
167 | if (p >= 32768) { //LED on | 162 | if (p >= 32768) { //LED on |
168 | painter.setBrush(color[c]); | 163 | painter.setBrush(color[c]); |
169 | } else { //LED off | 164 | } else { //LED off |
170 | painter.setBrush(color[c].dark(300)); | 165 | painter.setBrush(color[c].dark(300)); |
171 | } | 166 | } |
172 | if (h >= 32768) { //LED-Frame on | 167 | if (h >= 32768) { //LED-Frame on |
173 | painter.setPen(color[c]); | 168 | painter.setPen(color[c]); |
174 | } else{ //LED off | 169 | } else{ //LED off |
175 | painter.setPen(color[c].dark(300)); | 170 | painter.setPen(color[c].dark(300)); |
176 | } | 171 | } |
177 | painter.drawRect(ox + dx * i, oy + dy * c, sx, sy); | 172 | painter.drawRect(ox + dx * i, oy + dy * c, sx, sy); |
178 | p *= para.resoFactor; h *= para.resoFactor; | 173 | p *= para.resoFactor; h *= para.resoFactor; |
179 | } | 174 | } |
180 | if ( --holdTime[i] <= 0) hold[i] = peak[i]; | 175 | if ( --holdTime[i] <= 0) hold[i] = peak[i]; |
181 | } | 176 | } |
182 | painter.end(); | 177 | painter.end(); |
183 | bitBlt(this, 0, 0, buffer); | 178 | bitBlt(this, 0, 0, buffer); |
184 | } | 179 | } |
185 | 180 | ||
186 | void VUMeter::setPeak(int a[]) { | 181 | void VUMeter::setPeak(int a[]) { |
187 | int i; | 182 | int i; |
188 | //qDebug("set peak int"); | 183 | //qDebug("set peak int"); |
189 | // cerr<<"setting peak\n"; | 184 | // cerr<<"setting peak\n"; |
190 | for(i = 0; i < tracks + 2; i++) { | 185 | for(i = 0; i < tracks + 2; i++) { |
191 | if (a[i] > i_peak[i]) i_peak[i] = a[i]; | 186 | if (a[i] > i_peak[i]) i_peak[i] = a[i]; |
192 | if (a[i] > i_hold[i]) { i_hold[i] = a[i]; holdTime[i] = para.hold; } | 187 | if (a[i] > i_hold[i]) { i_hold[i] = a[i]; holdTime[i] = para.hold; } |
193 | } | 188 | } |
194 | paint(); | 189 | paint(); |
195 | } | 190 | } |
196 | 191 | ||
197 | void VUMeter::setPeak(float a[]) { | 192 | void VUMeter::setPeak(float a[]) { |
198 | int i; | 193 | int i; |
199 | for(i = 0; i < tracks + 2; i++) { | 194 | for(i = 0; i < tracks + 2; i++) { |
200 | if (a[i] > peak[i]) peak[i] = a[i]; | 195 | if (a[i] > peak[i]) peak[i] = a[i]; |
201 | if (a[i] > hold[i]) { hold[i] = a[i]; holdTime[i] = para.hold; } | 196 | if (a[i] > hold[i]) { hold[i] = a[i]; holdTime[i] = para.hold; } |
202 | } | 197 | } |
203 | paint(); | 198 | paint(); |
204 | } | 199 | } |
205 | 200 | ||
206 | void VUMeter::startTimer() { | 201 | void VUMeter::startTimer() { |
207 | vuTimer->start(para.update, FALSE); | 202 | vuTimer->start(para.update, FALSE); |
208 | } | 203 | } |
209 | 204 | ||
210 | void VUMeter::stopTimer() { | 205 | void VUMeter::stopTimer() { |
211 | vuTimer->stop(); | 206 | vuTimer->stop(); |
212 | } | 207 | } |
213 | 208 | ||
214 | void VUMeter::readConf() { | 209 | void VUMeter::readConf() { |
215 | Config config("OpieRec"); | 210 | Config config("OpieRec"); |
216 | config.setGroup("VU-Meter"); | 211 | config.setGroup("VU-Meter"); |
217 | 212 | ||
218 | para.onOff = config.readBoolEntry("OnOff", true); | 213 | para.onOff = config.readBoolEntry("OnOff", true); |
219 | para.update = config.readNumEntry("Update", 25); | 214 | para.update = config.readNumEntry("Update", 25); |
220 | para.hold = config.readNumEntry("Hold", 20); | 215 | para.hold = config.readNumEntry("Hold", 20); |
221 | para.reso = config.readNumEntry("Resolution", 3); | 216 | para.reso = config.readNumEntry("Resolution", 3); |
222 | para.leds = config.readNumEntry("LEDs", 20); | 217 | para.leds = config.readNumEntry("LEDs", 20); |
223 | para.resoFactor = pow(2, para.reso / 6.0); | 218 | para.resoFactor = pow(2, para.reso / 6.0); |
224 | 219 | ||
225 | colorScheme = config.readNumEntry("colorScheme", 0); | 220 | colorScheme = config.readNumEntry("colorScheme", 1); |
226 | // update(); | ||
227 | // dia->updatePara(); | ||
228 | } | 221 | } |
229 | 222 | ||
230 | 223 | ||
231 | void VUMeter::writeConf() { | 224 | void VUMeter::writeConf() { |
232 | Config config("OpieRec"); | 225 | Config config("OpieRec"); |
233 | config.setGroup("VU-Meter"); | 226 | config.setGroup("VU-Meter"); |
234 | 227 | ||
235 | config.writeEntry("OnOff", para.onOff); | 228 | config.writeEntry("OnOff", para.onOff); |
236 | config.writeEntry("Update", para.update); | 229 | config.writeEntry("Update", para.update); |
237 | config.writeEntry("Hold", para.hold); | 230 | config.writeEntry("Hold", para.hold); |
238 | config.writeEntry("Resolution", para.reso); | 231 | config.writeEntry("Resolution", para.reso); |
239 | config.writeEntry("LEDs", para.leds); | 232 | config.writeEntry("LEDs", para.leds); |
240 | } | 233 | } |