author | llornkcor <llornkcor> | 2005-03-21 10:31:06 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2005-03-21 10:31:06 (UTC) |
commit | 18825d8195f05d1a82affc0111f524371dbdeb5f (patch) (unidiff) | |
tree | aa807f10454b77496bb18a24569e12bf38acb7cf | |
parent | da645ace9b556dd132ac998cd124fa1e062e0032 (diff) | |
download | opie-18825d8195f05d1a82affc0111f524371dbdeb5f.zip opie-18825d8195f05d1a82affc0111f524371dbdeb5f.tar.gz opie-18825d8195f05d1a82affc0111f524371dbdeb5f.tar.bz2 |
fix
-rw-r--r-- | noncore/multimedia/opierec/vumeter.cpp | 27 |
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,154 +1,151 @@ | |||
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> | ||
14 | using namespace Opie::Core; | ||
15 | |||
16 | #include <math.h> | 14 | #include <math.h> |
17 | 15 | ||
18 | VUMeter::VUMeter(QWidget *parent, const char *name, const int tr) | 16 | VUMeter::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 | ||
54 | VUMeter::~VUMeter(){ | 53 | VUMeter::~VUMeter(){ |
55 | writeConf(); | 54 | // writeConf(); |
56 | } | 55 | } |
57 | 56 | ||
58 | void VUMeter::update(){ | 57 | void 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 | ||
70 | void VUMeter::slotOn() { | 68 | void 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 | ||
75 | void VUMeter::slotOff() { | 73 | void 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 | ||
80 | void VUMeter::slotProps() { | 78 | void VUMeter::slotProps() { |
81 | qDebug("VU-Dialog"); | ||
82 | } | 79 | } |
83 | 80 | ||
84 | void VUMeter::paintEvent(QPaintEvent* e) { | 81 | void 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 | ||
90 | void VUMeter::mousePressEvent(QMouseEvent* e) { | 87 | void VUMeter::mousePressEvent(QMouseEvent* e) { |
91 | Q_UNUSED(e); | 88 | Q_UNUSED(e); |
92 | } | 89 | } |
93 | 90 | ||
94 | 91 | ||
95 | void VUMeter::resizeEvent(QResizeEvent* event) { | 92 | void VUMeter::resizeEvent(QResizeEvent* event) { |
96 | buffer->resize(event->size()); | 93 | buffer->resize(event->size()); |
97 | resize(); | 94 | resize(); |
98 | } | 95 | } |
99 | 96 | ||
100 | void VUMeter::resize() { | 97 | void 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 | ||
139 | void VUMeter::timeSlot() { | 138 | void 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 | ||
149 | void VUMeter::paint() { | 146 | void 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; |
@@ -171,26 +168,24 @@ void VUMeter::paint() { | |||
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 | ||
181 | void VUMeter::setPeak(int a[]) { | 178 | void 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 | ||
192 | void VUMeter::setPeak(float a[]) { | 187 | void 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; } |