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