summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opierec/vumeter.cpp
authorllornkcor <llornkcor>2005-03-20 09:26:37 (UTC)
committer llornkcor <llornkcor>2005-03-20 09:26:37 (UTC)
commit421ee128d31c51f8530b0e37313ea0086e023237 (patch) (unidiff)
treee5738e366ba3b14559361fdde87c4c8ce1a19a59 /noncore/multimedia/opierec/vumeter.cpp
parentd5451e7abbfa3c3d14202311abccac8781736dae (diff)
downloadopie-421ee128d31c51f8530b0e37313ea0086e023237.zip
opie-421ee128d31c51f8530b0e37313ea0086e023237.tar.gz
opie-421ee128d31c51f8530b0e37313ea0086e023237.tar.bz2
add rainbow leds
Diffstat (limited to 'noncore/multimedia/opierec/vumeter.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/multimedia/opierec/vumeter.cpp130
1 files changed, 45 insertions, 85 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,80 +1,72 @@
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>
7using namespace Opie::Core; 14using 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
15VUMeter::VUMeter(QWidget *parent, const char *name, const int tr) 18VUMeter::VUMeter(QWidget *parent, const char *name, const int tr)
16 : QWidget( parent, name ) 19 : QWidget( parent, name )
17{ 20{
18// qDebug("Making VUMeter");
19 int tracks = tr; 21 int tracks = tr;
20 int i; 22 int i;
21 23
22 qWarning("initialize peakvalues"); 24 qWarning("initialize peakvalues");
23 for(i=0;i < tracks+2;i++) { 25 for(i=0;i < tracks+2;i++) {
24 peak[i] = hold[i] = 32768; 26 peak[i] = hold[i] = 32768;
25 // i_peak[i]=i_hold[i]=32768;
26 holdTime[i] = 20; 27 holdTime[i] = 20;
27 } 28 }
28 29
29 para.onOff = true; 30 readConf();
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 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
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;
42 } else {
43 int j = para.leds - 4;
44 for( i = 0; i < para.leds; i++) {
45 int i16 = (j);// & 15;
46 color[i] = QColor(( 15 - i16) * 16, 255, 255, QColor::Hsv);
47 owarn << color[i].name() << oendl;
48 j--;
49 }
50 }
39 51
40 buffer = new QPixmap(); 52 buffer = new QPixmap();
41 setBackgroundMode(NoBackground); 53 setBackgroundMode(NoBackground);
42 vuTimer = new QTimer(this,"vu timer"); 54 vuTimer = new QTimer(this,"vu timer");
43 55
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())); 56 connect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot()));
60 //update();
61} 57}
62 58
63VUMeter::~VUMeter(){ 59VUMeter::~VUMeter(){
64// delete vuProp; 60 writeConf();
65} 61}
66 62
67void VUMeter::update(){ 63void 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);
72// vuProp->setItemEnabled(1, TRUE);
73 disconnect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot())); 67 disconnect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot()));
74 connect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot())); 68 connect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot()));
75 } else { 69 } else {
76// vuProp->setItemEnabled(0, TRUE);
77// vuProp->setItemEnabled(1, FALSE);
78 disconnect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot())); 70 disconnect(vuTimer, SIGNAL(timeout()), this , SLOT(timeSlot()));
79 } 71 }
80 resize(); 72 resize();
@@ -83,22 +75,15 @@ void VUMeter::update(){
83void VUMeter::slotOn() { 75void 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
91void VUMeter::slotOff() { 80void 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
99void VUMeter::slotProps() { 85void VUMeter::slotProps() {
100 qDebug("VU-Dialog"); 86 qDebug("VU-Dialog");
101// dia->show();
102} 87}
103 88
104void VUMeter::paintEvent(QPaintEvent* e) { 89void VUMeter::paintEvent(QPaintEvent* e) {
@@ -109,8 +94,6 @@ void VUMeter::paintEvent(QPaintEvent* e) {
109 94
110void VUMeter::mousePressEvent(QMouseEvent* e) { 95void 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
@@ -138,10 +121,6 @@ void VUMeter::resize() {
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;
142 //c.setHsv( (x * 255)/w, 255, 255 );// rainbow effect
143 // c.setRgb( 255, 0, 255);
144// p.setPen(c);
145 painter.setPen(green); 124 painter.setPen(green);
146 qDrawShadePanel ( &painter, 0,0, width(),height(), colorGroup(), TRUE, 2, 0); 125 qDrawShadePanel ( &painter, 0,0, width(),height(), colorGroup(), TRUE, 2, 0);
147 if (2*dy-2 == 10) textOffset=1; 126 if (2*dy-2 == 10) textOffset=1;
@@ -154,10 +133,8 @@ void VUMeter::resize() {
154 if (i==tracks+1) str.sprintf("R"); 133 if (i==tracks+1) str.sprintf("R");
155 134
156 painter.drawRect(ox+dx*i,oy+dy*(para.leds)-2,sx,2*dy-1); 135 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); 136 painter.setPen(black);
159 painter.drawText(textOffset+ox+dx*i,oy+dy*(para.leds)-2,sx,2*dy,AlignCenter,str); 137 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 } 138 }
162 painter.end(); 139 painter.end();
163 paint(); 140 paint();
@@ -171,51 +148,36 @@ void VUMeter::timeSlot() {
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;
175 } 151 }
176//cout <<"VU "<<peak[0]<<"\n";
177
178} 152}
179 153
180void VUMeter::paint() { 154void VUMeter::paint() {
181 int i, k; 155 int i, k;
182 float p, h ; 156 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; 157 QPainter painter;
188 painter.begin(buffer); 158 painter.begin(buffer);
189 int c; 159 int c;
190 160
191 for(i=0;i<tracks+2;i++){ 161 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]; 162 p=peak[i]; h=hold[i];
194 if (p>=32767) p=32768; 163 if (p>=32767) p=32768;
195 // if (i_p>=32767) i_p=32768;
196 if (h>=32767) h=32768; 164 if (h>=32767) h=32768;
197 // if (i_h>=32767) i_h=32768;
198 for(k=para.leds+1; k>=2; k--){ 165 for(k=para.leds+1; k>=2; k--){
199 c=para.leds+1-k; 166 c=para.leds+1-k;
200 if (p>=32768) { //LED on 167 if (p>=32768) { //LED on
201 // if (i_p>=32768){ //LED on
202 painter.setBrush(color[c]); 168 painter.setBrush(color[c]);
203 } else { //LED off 169 } else { //LED off
204 //painter.setPen(color[c].dark(300));
205 painter.setBrush(color[c].dark(300)); 170 painter.setBrush(color[c].dark(300));
206 } 171 }
207 if (h>=32768) { //LED-Frame on 172 if (h>=32768) { //LED-Frame on
208 // if (i_h>=32768){ //LED-Frame on
209 painter.setPen(color[c]); 173 painter.setPen(color[c]);
210 } else{ //LED off 174 } else{ //LED off
211 painter.setPen(color[c].dark(300)); 175 painter.setPen(color[c].dark(300));
212 } 176 }
213 painter.drawRect(ox+dx*i,oy+dy*c,sx,sy); 177 painter.drawRect(ox+dx*i,oy+dy*c,sx,sy);
214 p*=para.resoFactor; h*=para.resoFactor; 178 p*=para.resoFactor; h*=para.resoFactor;
215 // i_p*=(int)para.resoFactor; i_h*=(int)para.resoFactor;
216 } 179 }
217 if (--holdTime[i]<=0) hold[i]=peak[i]; 180 if (--holdTime[i]<=0) hold[i]=peak[i];
218 // if (--holdTime[i]<=0) i_hold[i]=i_peak[i];
219 } 181 }
220 painter.end(); 182 painter.end();
221 bitBlt(this, 0, 0, buffer); 183 bitBlt(this, 0, 0, buffer);
@@ -234,8 +196,6 @@ void VUMeter::setPeak(int a[]) {
234 196
235void VUMeter::setPeak(float a[]) { 197void VUMeter::setPeak(float a[]) {
236 int i; 198 int i;
237 //owarn <<"set peak float"<< a[0]<< oendl;
238
239 for(i=0;i<tracks+2;i++) { 199 for(i=0;i<tracks+2;i++) {
240 if (a[i] > peak[i]) peak[i]= a[i]; 200 if (a[i] > peak[i]) peak[i]= a[i];
241 if (a[i] > hold[i]) {hold[i]= a[i]; holdTime[i]=para.hold;} 201 if (a[i] > hold[i]) {hold[i]= a[i]; holdTime[i]=para.hold;}
@@ -252,29 +212,29 @@ void VUMeter::stopTimer() {
252} 212}
253 213
254void VUMeter::readConf() { 214void VUMeter::readConf() {
255// Config config("QtRec"); 215 Config config("OpieRec");
256// config->setGroup("VU-Meter"); 216 config.setGroup("VU-Meter");
257 217
258// para.onOff=config->readBoolEntry("OnOff", true ) ; 218 para.onOff = config.readBoolEntry("OnOff", true);
259// para.update=config->readNumEntry("Update", 50 ); 219 para.update = config.readNumEntry("Update", 25);
260// para.hold=config->readNumEntry("Hold", 20 ); 220 para.hold = config.readNumEntry("Hold", 20);
261// para.reso=config->readNumEntry("Resolution", 3 ); 221 para.reso = config.readNumEntry("Resolution", 3);
262// para.leds=config->readNumEntry("LEDs", 16 ); 222 para.leds = config.readNumEntry("LEDs", 20);
263// para.resoFactor=pow(2,para.reso/6.0); 223 para.resoFactor = pow(2, para.reso / 6.0);
264 224
225 colorScheme = config.readNumEntry("colorScheme", 0);
265// update(); 226// update();
266// dia->updatePara(); 227// dia->updatePara();
267} 228}
268 229
269 230
270void VUMeter::writeConf() { 231void VUMeter::writeConf() {
271// Config config("QtRec"); 232 Config config("OpieRec");
272// config->setGroup("VU-Meter"); 233 config.setGroup("VU-Meter");
273 234
274// config->writeEntry("OnOff" ,para.onOff ); 235 config.writeEntry("OnOff", para.onOff);
275// config->writeEntry("Update" ,para.update ); 236 config.writeEntry("Update", para.update);
276// config->writeEntry("Hold" ,para.hold ); 237 config.writeEntry("Hold", para.hold);
277// config->writeEntry("Resolution" , para.reso ); 238 config.writeEntry("Resolution", para.reso);
278// config->writeEntry("LEDs" , para.leds); 239 config.writeEntry("LEDs", para.leds);
279
280} 240}