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