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