-rw-r--r-- | noncore/multimedia/opierec/device.cpp | 286 | ||||
-rw-r--r-- | noncore/multimedia/opierec/device.h | 4 | ||||
-rw-r--r-- | noncore/multimedia/opierec/qtrec.cpp | 121 | ||||
-rw-r--r-- | noncore/multimedia/opierec/waveform.cpp | 2 |
4 files changed, 125 insertions, 288 deletions
diff --git a/noncore/multimedia/opierec/device.cpp b/noncore/multimedia/opierec/device.cpp index cb47b77..e7e0f4b 100644 --- a/noncore/multimedia/opierec/device.cpp +++ b/noncore/multimedia/opierec/device.cpp | |||
@@ -1,374 +1,276 @@ | |||
1 | // device.cpp | 1 | // device.cpp |
2 | 2 | ||
3 | #include "device.h" | 3 | #include "device.h" |
4 | 4 | ||
5 | #include <qpe/config.h> | 5 | #include <qpe/config.h> |
6 | #include <qpe/qcopenvelope_qws.h> | 6 | #include <qpe/qcopenvelope_qws.h> |
7 | 7 | ||
8 | #include <opie2/odebug.h> | ||
9 | |||
8 | /* STD */ | 10 | /* STD */ |
9 | #include <fcntl.h> | 11 | #include <fcntl.h> |
10 | #include <stdio.h> | 12 | #include <stdio.h> |
11 | #include <stdlib.h> | 13 | #include <stdlib.h> |
12 | #include <sys/ioctl.h> | 14 | #include <sys/ioctl.h> |
13 | #include <sys/soundcard.h> | 15 | #include <sys/soundcard.h> |
14 | #include <unistd.h> | 16 | #include <unistd.h> |
15 | #include <sys/wait.h> | 17 | #include <sys/wait.h> |
16 | #include <unistd.h> | 18 | #include <unistd.h> |
17 | #include <errno.h> | 19 | #include <errno.h> |
18 | 20 | ||
19 | //extern QtRec *qperec; | 21 | //extern QtRec *qperec; |
22 | #if defined(QT_QWS_SL5XXX) | ||
23 | ///#if defined(QT_QWS_EBX) | ||
24 | |||
25 | #define DSPSTROUT "/dev/dsp" | ||
26 | #define DSPSTRMIXEROUT "/dev/mixer" | ||
27 | |||
28 | #ifdef SHARP | ||
29 | #define DSPSTRIN "/dev/dsp1" | ||
30 | #define DSPSTRMIXERIN "/dev/mixer1" | ||
31 | #else | ||
32 | #define DSPSTRIN "/dev/dsp" | ||
33 | #define DSPSTRMIXERIN "/dev/mixer" | ||
34 | #endif | ||
35 | |||
36 | #else | ||
37 | |||
38 | #ifdef QT_QWS_DEVFS | ||
39 | #define DSPSTROUT "/dev/sound/dsp" | ||
40 | #define DSPSTRIN "/dev/sound/dsp" | ||
41 | #define DSPSTRMIXERIN "/dev/sound/mixer" | ||
42 | #define DSPSTRMIXEROUT "/dev/sound/mixer" | ||
43 | #else | ||
44 | #define DSPSTROUT "/dev/dsp" | ||
45 | #define DSPSTRIN "/dev/dsp" | ||
46 | #define DSPSTRMIXERIN "/dev/mixer" | ||
47 | #define DSPSTRMIXEROUT "/dev/mixer" | ||
48 | #endif | ||
49 | |||
50 | #endif | ||
20 | 51 | ||
21 | Device::Device( QObject * parent, const char * dsp, const char * mixr, bool record ) | 52 | Device::Device( QObject * parent, bool record ) |
22 | : QObject( parent) | 53 | : QObject( parent) |
23 | { | 54 | { |
24 | dspstr = (char *)dsp; | 55 | // dspstr = dsp; |
25 | mixstr = (char *)mixr; | 56 | devForm = -1; |
26 | 57 | devCh = -1; | |
27 | devForm=-1; | 58 | devRate = -1; |
28 | devCh=-1; | ||
29 | devRate=-1; | ||
30 | 59 | ||
31 | if( !record){ //playing | 60 | if( !record){ //playing |
32 | qDebug( "setting up DSP for playing" ); | 61 | owarn << "setting up DSP for playing" << oendl; |
33 | flags = O_WRONLY; | 62 | flags = O_WRONLY; |
34 | } else { //recording | 63 | } else { //recording |
35 | qDebug( "setting up DSP for recording" ); | 64 | owarn << "setting up DSP for recording" << oendl; |
36 | flags = O_RDWR; | 65 | flags = O_RDWR; |
37 | // flags = O_RDONLY; | 66 | // flags = O_RDONLY; |
38 | 67 | selectMicInput(); | |
39 | // selectMicInput(); | ||
40 | |||
41 | } | 68 | } |
42 | } | 69 | } |
43 | 70 | ||
44 | bool Device::openDsp() { | 71 | bool Device::openDsp() { |
45 | if( openDevice( flags) == -1) { | 72 | if( openDevice( flags) == -1) { |
46 | perror("<<<<<<<<<<<<<<ioctl(\"Open device\")"); | 73 | perror("<<<<<<<<<<<<<<ioctl(\"Open device\")"); |
47 | return false; | 74 | return false; |
48 | } | 75 | } |
49 | return true; | 76 | return true; |
50 | } | 77 | } |
51 | 78 | ||
52 | int Device::openDevice( int flags) { | 79 | int Device::openDevice( int flags) { |
53 | /* pid_t pid; | 80 | owarn << "Opening"<< dspstr; |
54 | int status; | 81 | |
55 | int pipefd[2]; | 82 | if (( sd = ::open( DSPSTROUT, flags)) == -1) { |
56 | char message[20]; | 83 | perror("open(\"/dev/dsp\")"); |
57 | if (pipe(pipefd) == -1){ | 84 | QString errorMsg="Could not open audio device\n /dev/dsp\n" |
58 | perror ("Error creating pipe"); | 85 | +(QString)strerror(errno); |
59 | exit(1); | 86 | qDebug( "XXXXXXXXXXXXXXXXXXXXXXX "+errorMsg ); |
60 | } | 87 | return -1; |
61 | switch (pid = fork()) { | 88 | } |
62 | case -1: | 89 | |
63 | perror("The fork failed!"); | 90 | if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){ |
64 | break; | 91 | perror("ioctl RESET"); |
65 | case 0: { | 92 | } |
66 | */ | ||
67 | qDebug( "Opening %s",dspstr); | ||
68 | if (( sd = ::open( dspstr, flags)) == -1) { | ||
69 | perror("open(\"/dev/dsp\")"); | ||
70 | QString errorMsg="Could not open audio device\n /dev/dsp\n" | ||
71 | +(QString)strerror(errno); | ||
72 | qDebug( "XXXXXXXXXXXXXXXXXXXXXXX "+errorMsg ); | ||
73 | return -1; | ||
74 | } | ||
75 | |||
76 | qDebug( "Opening mixer" ); | ||
77 | int mixerHandle=0; | ||
78 | #ifdef QT_QWS_DEVFS | ||
79 | if (( mixerHandle = open("/dev/sound/mixer",O_RDWR))<0) { | ||
80 | #else | ||
81 | if (( mixerHandle = open("/dev/mixer",O_RDWR))<0) { | ||
82 | #endif | ||
83 | perror("open(\"/dev/mixer\")"); | ||
84 | QString errorMsg="Could not open audio device\n /dev/dsp\n" | ||
85 | +(QString)strerror(errno); | ||
86 | qDebug( "XXXXXXXXXXXXXXXXXXXXXX "+errorMsg ); | ||
87 | } | ||
88 | |||
89 | if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){ | ||
90 | perror("ioctl RESET"); | ||
91 | } | ||
92 | // sprintf(message, "%d", sd); | ||
93 | |||
94 | /* QFile f1("/pid"); | ||
95 | f1.open(IO_WriteOnly ); | ||
96 | f1.writeBlock(message, strlen(message)); | ||
97 | f1.close(); | ||
98 | */ | ||
99 | /* close(pipefd[0]); | ||
100 | write(pipefd[1], message, sizeof(message)); | ||
101 | close(pipefd[1]); | ||
102 | // qDebug( "" + soundDevice->sd ); | ||
103 | _exit(0); | ||
104 | } | ||
105 | default: | ||
106 | // pid greater than zero is parent getting the child's pid | ||
107 | printf("Child's pid is %d\n",pid); | ||
108 | QString s; | ||
109 | close(pipefd[1]); | ||
110 | read(pipefd[0], message, sizeof(message)); | ||
111 | s = message; | ||
112 | close(pipefd[0]); | ||
113 | |||
114 | // while(wait(NULL)!=pid) | ||
115 | // ; | ||
116 | printf("child %ld terminated normally, return status is zero\n", (long) pid); | ||
117 | */ | ||
118 | // filePara.sd=(long) pid; | ||
119 | /* QFile f2("/pid"); | ||
120 | f2.open(IO_ReadOnly); | ||
121 | QTextStream t(&f2); | ||
122 | // for(int f=0; f < t.atEnd() ;f++) { | ||
123 | s = t.readLine(); | ||
124 | // } | ||
125 | */ | ||
126 | // bool ok; | ||
127 | // sd = s.toInt(&ok, 10); | ||
128 | // qDebug( "<<<<<<<<<<<<<>>>>>>>>>>>>"+s ); | ||
129 | |||
130 | // f2.close(); | ||
131 | // } | ||
132 | ::close(mixerHandle ); | ||
133 | // qDebug( "open device " + dspstr ); | ||
134 | // qDebug( "success! " + sd ); | ||
135 | return sd; | 93 | return sd; |
136 | } | 94 | } |
137 | 95 | ||
96 | int Device::getInVolume() { | ||
97 | unsigned int volume = 0; | ||
98 | Config cfg("qpe"); | ||
99 | cfg.setGroup("Volume"); | ||
100 | |||
101 | return cfg.readNumEntry("Mic"); | ||
102 | } | ||
138 | 103 | ||
139 | int Device::getOutVolume( ) { | 104 | int Device::getOutVolume( ) { |
140 | unsigned int volume; | 105 | unsigned int volume; |
141 | int mixerHandle = open( mixstr, O_RDWR ); | ||
142 | if ( mixerHandle >= 0 ) { | ||
143 | if(ioctl( mixerHandle, MIXER_READ(SOUND_MIXER_VOLUME), &volume )==-1) | ||
144 | perror("<<<<<<<<<<<<<<ioctl(\"MIXER_READ\")"); | ||
145 | ::close( mixerHandle ); | ||
146 | } else | ||
147 | perror("open(\"/dev/mixer\")"); | ||
148 | printf("<<<<<<<<<<<<<<<<<<<<output volume %d\n",volume); | ||
149 | |||
150 | Config cfg("qpe"); | 106 | Config cfg("qpe"); |
151 | cfg.setGroup("Volume"); | 107 | cfg.setGroup("Volume"); |
152 | 108 | ||
153 | return cfg.readNumEntry("VolumePercent"); | 109 | return cfg.readNumEntry("VolumePercent"); |
154 | } | 110 | } |
155 | 111 | ||
156 | int Device::getInVolume() { | ||
157 | unsigned int volume=0; | ||
158 | int mixerHandle = ::open( mixstr, O_RDWR ); | ||
159 | if ( mixerHandle >= 0 ) { | ||
160 | if(ioctl( mixerHandle, MIXER_READ(SOUND_MIXER_MIC), &volume )==-1) | ||
161 | perror("<<<<<<<<<<<<<<<ioctl(\"MIXER_READ\")"); | ||
162 | ::close( mixerHandle ); | ||
163 | } else | ||
164 | perror("open(\"/dev/mixer\")"); | ||
165 | printf("<<<<<<<<<<<<<<input volume %d\n", volume ); | ||
166 | Config cfg("qpe"); | ||
167 | cfg.setGroup("Volume"); | ||
168 | 112 | ||
169 | return cfg.readNumEntry("Mic"); | 113 | void Device::changedInVolume(int vol ) { |
114 | Config cfg("qpe"); | ||
115 | cfg.setGroup("Volume"); | ||
116 | cfg.writeEntry("Mic", QString::number(vol )); | ||
117 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << false; | ||
170 | } | 118 | } |
171 | 119 | ||
172 | void Device::changedOutVolume(int vol) { | 120 | void Device::changedOutVolume(int vol) { |
173 | int level = (vol << 8) + vol; | 121 | Config cfg("qpe"); |
174 | int fd = 0; | 122 | cfg.setGroup("Volume"); |
175 | #ifdef QT_QWS_DEVFS | 123 | cfg.writeEntry("VolumePercent", QString::number( vol )); |
176 | if ((fd = open("/dev/sound/mixer", O_RDWR))>=0) { | ||
177 | #else | ||
178 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { | ||
179 | #endif | ||
180 | if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_VOLUME), &level) == -1) | ||
181 | perror("ioctl(\"MIXER_IN_WRITE\")"); | ||
182 | |||
183 | Config cfg("qpe"); | ||
184 | cfg.setGroup("Volume"); | ||
185 | cfg.writeEntry("VolumePercent", QString::number( vol )); | ||
186 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; | ||
187 | qDebug("changing output vol %d" ,vol ); | ||
188 | } | ||
189 | ::close(fd); | ||
190 | } | ||
191 | 124 | ||
192 | void Device::changedInVolume(int vol ) { | 125 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; |
193 | int level = (vol << 8) + vol; | 126 | |
194 | int fd = 0; | 127 | owarn << "changing output vol " << vol << oendl; |
195 | #ifdef QT_QWS_DEVFS | ||
196 | if ((fd = open("/dev/sound/mixer", O_RDWR))>=0) { | ||
197 | #else | ||
198 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { | ||
199 | #endif | ||
200 | if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &level) == -1) | ||
201 | perror("ioctl(\"MIXER_IN_WRITE\")"); | ||
202 | Config cfg("qpe"); | ||
203 | cfg.setGroup("Volume"); | ||
204 | cfg.writeEntry("Mic", QString::number(vol )); | ||
205 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << false; | ||
206 | qDebug("changing input volume %d",vol); | ||
207 | } | ||
208 | ::close(fd); | ||
209 | } | 128 | } |
210 | 129 | ||
211 | bool Device::selectMicInput() { | 130 | bool Device::selectMicInput() { |
212 | 131 | ||
213 | int md=0; | 132 | int md = 0; |
214 | int info=MIXER_WRITE(SOUND_MIXER_MIC); | 133 | int info = SOUND_MASK_MIC;//MIXER_WRITE(SOUND_MIXER_MIC); |
215 | #ifdef QT_QWS_DEVFS | 134 | owarn << "sectMicInput" << oendl; |
216 | md = ::open( "/dev/sound/mixer", O_RDWR ); | 135 | md = ::open( DSPSTRMIXEROUT, O_RDWR ); |
217 | #else | 136 | |
218 | md = ::open( "/dev/mixer", O_RDWR ); | 137 | if ( md <= 0) { |
219 | #endif | 138 | QString err; |
220 | if ( md == -1) | 139 | err.sprintf("open %s", DSPSTRMIXEROUT); |
221 | perror("open(\"/dev/mixer\")"); | 140 | perror(err.latin1()); |
222 | else { | 141 | } else { |
223 | if( ioctl( md, SOUND_MIXER_WRITE_RECSRC, &info) == -1) | 142 | if( ioctl( md, SOUND_MIXER_WRITE_RECSRC, &info) == -1) |
224 | perror("ioctl(\"SOUND_MIXER_WRITE_RECSRC\")"); | 143 | perror("ioctl(\"SOUND_MIXER_WRITE_RECSRC\")"); |
225 | ::close(md); | 144 | ::close(md); |
226 | return false; | 145 | return false; |
227 | } | 146 | } |
228 | ::close(md); | 147 | ::close(md); |
229 | 148 | ||
230 | return true; | 149 | return true; |
231 | } | 150 | } |
232 | 151 | ||
233 | bool Device::closeDevice( bool) { | 152 | bool Device::closeDevice( bool) { |
234 | // if(b) {//close now | ||
235 | // if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { | ||
236 | // perror("ioctl(\"SNDCTL_DSP_RESET\")"); | ||
237 | // } | ||
238 | // } else { //let play | ||
239 | // if (ioctl( sd, SNDCTL_DSP_SYNC, 0) == -1) { | ||
240 | // perror("ioctl(\"SNDCTL_DSP_SYNC\")"); | ||
241 | // } | ||
242 | // } | ||
243 | |||
244 | ::close( sd); //close sound device | 153 | ::close( sd); //close sound device |
245 | // sdfd=0; | ||
246 | // sd=0; | ||
247 | // qDebug( "closed dsp" ); | ||
248 | return true; | 154 | return true; |
249 | } | 155 | } |
250 | 156 | ||
251 | bool Device::setDeviceFormat( int form) { | 157 | bool Device::setDeviceFormat( int form) { |
252 | qDebug( "set device res %d: %d ",form, sd ); | 158 | qDebug( "set device res %d: %d ",form, sd ); |
253 | if (ioctl( sd, SNDCTL_DSP_SETFMT, &form)==-1) { //set format | 159 | if (ioctl( sd, SNDCTL_DSP_SETFMT, &form)==-1) { //set format |
254 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 160 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
255 | return false; | 161 | return false; |
256 | } | 162 | } |
257 | devRes=form; | 163 | devRes=form; |
258 | return true; | 164 | return true; |
259 | } | 165 | } |
260 | 166 | ||
261 | bool Device::setDeviceChannels( int ch) { | 167 | bool Device::setDeviceChannels( int ch) { |
262 | qDebug( "set channels %d: %d",ch ,sd); | 168 | qDebug( "set channels %d: %d",ch ,sd); |
263 | if (ioctl( sd, SNDCTL_DSP_CHANNELS, &ch)==-1) { | 169 | if (ioctl( sd, SNDCTL_DSP_CHANNELS, &ch)==-1) { |
264 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 170 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
265 | return false; | 171 | return false; |
266 | } | 172 | } |
267 | devCh=ch; | 173 | devCh=ch; |
268 | return true; | 174 | return true; |
269 | } | 175 | } |
270 | 176 | ||
271 | bool Device::setDeviceRate( int rate) { | 177 | bool Device::setDeviceRate( int rate) { |
272 | qDebug( "set rate %d: %d",rate,sd); | 178 | qDebug( "set rate %d: %d",rate,sd); |
273 | if (ioctl( sd, SNDCTL_DSP_SPEED, &rate) == -1) { | 179 | if (ioctl( sd, SNDCTL_DSP_SPEED, &rate) == -1) { |
274 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 180 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
275 | return false; | 181 | return false; |
276 | } | 182 | } |
277 | 183 | ||
278 | devRate=rate; | 184 | devRate=rate; |
279 | 185 | ||
280 | return true; | 186 | return true; |
281 | } | 187 | } |
282 | 188 | ||
283 | int Device::getRes() { | 189 | int Device::getRes() { |
284 | return devRes; | 190 | return devRes; |
285 | } | 191 | } |
286 | 192 | ||
287 | int Device::getFormat() { | 193 | int Device::getFormat() { |
288 | return devForm; | 194 | return devForm; |
289 | } | 195 | } |
290 | 196 | ||
291 | int Device::getRate() { | 197 | int Device::getRate() { |
292 | return devRate; | 198 | return devRate; |
293 | } | 199 | } |
294 | 200 | ||
295 | int Device::getChannels() { | 201 | int Device::getChannels() { |
296 | return devCh; | 202 | return devCh; |
297 | } | 203 | } |
298 | 204 | ||
299 | int Device::getDeviceFormat() { | 205 | int Device::getDeviceFormat() { |
300 | return 0; | 206 | return 0; |
301 | } | 207 | } |
302 | 208 | ||
303 | 209 | ||
304 | int Device::getDeviceRate() { | 210 | int Device::getDeviceRate() { |
305 | int dRate=0; | 211 | int dRate = 0; |
306 | if (ioctl( sd, SOUND_PCM_READ_RATE, &dRate) == -1) { | 212 | if (ioctl( sd, SOUND_PCM_READ_RATE, &dRate) == -1) { |
307 | perror("ioctl(\"SNDCTL_PCM_READ_RATE\")"); | 213 | perror("ioctl(\"SNDCTL_PCM_READ_RATE\")"); |
308 | } | 214 | } |
309 | return dRate; | 215 | return dRate; |
310 | 216 | ||
311 | } | 217 | } |
312 | 218 | ||
313 | int Device::getDeviceBits() { | 219 | int Device::getDeviceBits() { |
314 | int dBits=0; | 220 | int dBits = 0; |
315 | #ifndef QT_QWS_EBX // zaurus doesnt have this | ||
316 | if (ioctl( sd, SOUND_PCM_READ_BITS, &dBits) == -1) { | 221 | if (ioctl( sd, SOUND_PCM_READ_BITS, &dBits) == -1) { |
317 | perror("ioctl(\"SNDCTL_PCM_READ_BITS\")"); | 222 | perror("ioctl(\"SNDCTL_PCM_READ_BITS\")"); |
318 | } | 223 | } |
319 | #endif | ||
320 | return dBits; | 224 | return dBits; |
321 | } | 225 | } |
322 | 226 | ||
323 | int Device::getDeviceChannels() { | 227 | int Device::getDeviceChannels() { |
324 | int dCh=0; | 228 | int dCh = 0; |
325 | if (ioctl( sd, SOUND_PCM_READ_CHANNELS, &dCh) == -1) { | 229 | if (ioctl( sd, SOUND_PCM_READ_CHANNELS, &dCh) == -1) { |
326 | perror("ioctl(\"SNDCTL_PCM_READ_CHANNELS\")"); | 230 | perror("ioctl(\"SNDCTL_PCM_READ_CHANNELS\")"); |
327 | } | 231 | } |
328 | return dCh; | 232 | return dCh; |
329 | } | 233 | } |
330 | 234 | ||
331 | int Device::getDeviceFragSize() { | 235 | int Device::getDeviceFragSize() { |
332 | int frag_size; | 236 | int frag_size; |
333 | 237 | ||
334 | if (ioctl( sd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1) { | 238 | if (ioctl( sd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1) { |
335 | qDebug( "no fragsize" ); | 239 | qDebug( "no fragsize" ); |
336 | } else { | 240 | } else { |
337 | qDebug( "driver says frag size is %d",frag_size); | 241 | qDebug( "driver says frag size is %d",frag_size); |
338 | } | 242 | } |
339 | return frag_size; | 243 | return frag_size; |
340 | } | 244 | } |
341 | 245 | ||
342 | bool Device::setFragSize(int frag) { | 246 | bool Device::setFragSize(int frag) { |
343 | if (ioctl(sd, SNDCTL_DSP_SETFRAGMENT, &frag)) { | 247 | if (ioctl(sd, SNDCTL_DSP_SETFRAGMENT, &frag)) { |
344 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); | 248 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); |
345 | return false; | 249 | return false; |
346 | } | 250 | } |
347 | return true; | 251 | return true; |
348 | } | 252 | } |
349 | 253 | ||
350 | bool Device::reset() { | 254 | bool Device::reset() { |
351 | closeDevice(true); | 255 | closeDevice(true); |
352 | openDsp(); | 256 | openDsp(); |
353 | if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { | 257 | if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { |
354 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 258 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
355 | return false; | 259 | return false; |
356 | } | 260 | } |
357 | return true; | 261 | return true; |
358 | } | 262 | } |
359 | 263 | ||
360 | int Device::devRead(int soundDescriptor, short *buf, int size) { | 264 | int Device::devRead(int soundDescriptor, short *buf, int size) { |
361 | Q_UNUSED(soundDescriptor); | 265 | Q_UNUSED(soundDescriptor); |
362 | int number = 0; | 266 | int number = 0; |
363 | number = ::read( sd /*soundDescriptor*/, (char *)buf, size); | 267 | number = ::read( sd /*soundDescriptor*/, (char *)buf, size); |
364 | return number; | 268 | return number; |
365 | } | 269 | } |
366 | 270 | ||
367 | int Device::devWrite(int soundDescriptor, short * buf, int size) { | 271 | int Device::devWrite(int soundDescriptor, short * buf, int size) { |
368 | Q_UNUSED(soundDescriptor); | 272 | Q_UNUSED(soundDescriptor); |
369 | int bytesWritten = 0; | 273 | int bytesWritten = 0; |
370 | bytesWritten = ::write( sd /*soundDescriptor*/, buf, size); | 274 | bytesWritten = ::write( sd /*soundDescriptor*/, buf, size); |
371 | return bytesWritten; | 275 | return bytesWritten; |
372 | } | 276 | } |
373 | |||
374 | |||
diff --git a/noncore/multimedia/opierec/device.h b/noncore/multimedia/opierec/device.h index 8152e85..dbc7b00 100644 --- a/noncore/multimedia/opierec/device.h +++ b/noncore/multimedia/opierec/device.h | |||
@@ -1,48 +1,48 @@ | |||
1 | 1 | ||
2 | #ifndef DEVICE_H | 2 | #ifndef DEVICE_H |
3 | #define DEVICE_H | 3 | #define DEVICE_H |
4 | #include <qobject.h> | 4 | #include <qobject.h> |
5 | #include <sys/soundcard.h> | 5 | #include <sys/soundcard.h> |
6 | 6 | ||
7 | class Device : public QObject { | 7 | class Device : public QObject { |
8 | Q_OBJECT | 8 | Q_OBJECT |
9 | public: | 9 | public: |
10 | Device( QObject * parent=0, const char * dspStr=0, const char * mixerStr=0, bool record=0 ); | 10 | Device( QObject * parent=0, bool record=0 ); |
11 | ~Device() {}; | 11 | ~Device() {}; |
12 | bool closeDevice( bool); | 12 | bool closeDevice( bool); |
13 | int getChannels(); | 13 | int getChannels(); |
14 | int getFormat(); | 14 | int getFormat(); |
15 | int getInVolume(); | 15 | int getInVolume(); |
16 | int getOutVolume(); | 16 | int getOutVolume(); |
17 | int getRate(); | 17 | int getRate(); |
18 | int getRes(); | 18 | int getRes(); |
19 | int sd; //sound descriptor | 19 | int sd; //sound descriptor |
20 | void changedInVolume(int); | 20 | void changedInVolume(int); |
21 | void changedOutVolume(int); | 21 | void changedOutVolume(int); |
22 | bool openDsp(); | 22 | bool openDsp(); |
23 | int getDeviceFormat(); | 23 | int getDeviceFormat(); |
24 | int getDeviceRate(); | 24 | int getDeviceRate(); |
25 | int getDeviceBits(); | 25 | int getDeviceBits(); |
26 | int getDeviceChannels(); | 26 | int getDeviceChannels(); |
27 | int getDeviceFragSize(); | 27 | int getDeviceFragSize(); |
28 | bool setFragSize(int); | 28 | bool setFragSize(int); |
29 | bool setDeviceChannels(int); | 29 | bool setDeviceChannels(int); |
30 | bool setDeviceRate(int); | 30 | bool setDeviceRate(int); |
31 | bool setDeviceFormat(int); | 31 | bool setDeviceFormat(int); |
32 | bool reset(); | 32 | bool reset(); |
33 | 33 | ||
34 | int devRead(int, short *, int); | 34 | int devRead(int, short *, int); |
35 | int devWrite(int, short *, int); | 35 | int devWrite(int, short *, int); |
36 | 36 | ||
37 | private: | 37 | private: |
38 | int devRes, devCh, devRate, devForm, flags; | 38 | int devRes, devCh, devRate, devForm, flags; |
39 | char *dspstr, *mixstr; | 39 | QString dspstr, mixstr; |
40 | bool selectMicInput(); | 40 | bool selectMicInput(); |
41 | int openDevice( int ); | 41 | int openDevice( int ); |
42 | private slots: | 42 | private slots: |
43 | 43 | ||
44 | protected: | 44 | protected: |
45 | 45 | ||
46 | }; | 46 | }; |
47 | 47 | ||
48 | #endif | 48 | #endif |
diff --git a/noncore/multimedia/opierec/qtrec.cpp b/noncore/multimedia/opierec/qtrec.cpp index 6793b4e..e827083 100644 --- a/noncore/multimedia/opierec/qtrec.cpp +++ b/noncore/multimedia/opierec/qtrec.cpp | |||
@@ -1,2051 +1,1986 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | // qtrec.cpp | 2 | // qtrec.cpp |
3 | Created: Thu Jan 17 11:19:58 2002 | 3 | Created: Thu Jan 17 11:19:58 2002 |
4 | copyright 2002 by L.J. Potter <ljp@llornkcor.com> | 4 | copyright 2002 by L.J. Potter <ljp@llornkcor.com> |
5 | ****************************************************************************/ | 5 | ****************************************************************************/ |
6 | #define DEV_VERSION | 6 | //#define DEV_VERSION |
7 | 7 | ||
8 | #include "pixmaps.h" | 8 | #include "pixmaps.h" |
9 | #include "qtrec.h" | 9 | #include "qtrec.h" |
10 | #include "waveform.h" | 10 | #include "waveform.h" |
11 | extern "C" { | 11 | extern "C" { |
12 | #include "adpcm.h" | 12 | #include "adpcm.h" |
13 | } | 13 | } |
14 | 14 | ||
15 | /* OPIE */ | 15 | /* OPIE */ |
16 | #include <opie2/odebug.h> | 16 | #include <opie2/odebug.h> |
17 | #include <qpe/config.h> | 17 | #include <qpe/config.h> |
18 | #include <qpe/qcopenvelope_qws.h> | 18 | #include <qpe/qcopenvelope_qws.h> |
19 | #include <qpe/qpeapplication.h> | 19 | #include <qpe/qpeapplication.h> |
20 | #include <qpe/resource.h> | 20 | #include <qpe/resource.h> |
21 | #include <qpe/storage.h> | 21 | #include <qpe/storage.h> |
22 | using namespace Opie::Core; | 22 | using namespace Opie::Core; |
23 | 23 | ||
24 | /* QT */ | 24 | /* QT */ |
25 | #include <qcheckbox.h> | 25 | #include <qcheckbox.h> |
26 | #include <qcombobox.h> | 26 | #include <qcombobox.h> |
27 | #include <qdir.h> | 27 | #include <qdir.h> |
28 | #include <qgroupbox.h> | 28 | #include <qgroupbox.h> |
29 | #include <qlabel.h> | 29 | #include <qlabel.h> |
30 | #include <qlayout.h> | 30 | #include <qlayout.h> |
31 | #include <qlistview.h> | 31 | #include <qlistview.h> |
32 | #include <qmessagebox.h> | 32 | #include <qmessagebox.h> |
33 | #include <qpopupmenu.h> | 33 | #include <qpopupmenu.h> |
34 | #include <qpushbutton.h> | 34 | #include <qpushbutton.h> |
35 | #include <qslider.h> | 35 | #include <qslider.h> |
36 | #include <qtabwidget.h> | 36 | #include <qtabwidget.h> |
37 | #include <qtimer.h> | 37 | #include <qtimer.h> |
38 | 38 | ||
39 | /* STD */ | 39 | /* STD */ |
40 | #include <errno.h> | 40 | #include <errno.h> |
41 | #include <fcntl.h> | 41 | #include <fcntl.h> |
42 | #include <math.h> | 42 | #include <math.h> |
43 | #include <mntent.h> | 43 | #include <mntent.h> |
44 | #include <stdio.h> | 44 | #include <stdio.h> |
45 | #include <stdlib.h> | 45 | #include <stdlib.h> |
46 | #include <sys/ioctl.h> | 46 | #include <sys/ioctl.h> |
47 | #include <sys/soundcard.h> | 47 | #include <sys/soundcard.h> |
48 | #include <sys/stat.h> | 48 | #include <sys/stat.h> |
49 | #include <sys/time.h> | 49 | #include <sys/time.h> |
50 | #include <sys/types.h> | 50 | #include <sys/types.h> |
51 | #include <sys/vfs.h> | 51 | #include <sys/vfs.h> |
52 | #include <unistd.h> | 52 | #include <unistd.h> |
53 | #include <sys/wait.h> | 53 | #include <sys/wait.h> |
54 | #include <sys/signal.h> | 54 | #include <sys/signal.h> |
55 | #include <pthread.h> | 55 | #include <pthread.h> |
56 | 56 | ||
57 | #ifdef PDAUDIO //ALSA | 57 | #ifdef PDAUDIO //ALSA |
58 | #include <alsa/asoundlib.h> | 58 | #include <alsa/asoundlib.h> |
59 | static int deviceSampleRates[8] = { 32000, 44100, 48000, 88200, 96000, 176400, 192000, -1 }; | 59 | static int deviceSampleRates[8] = { 32000, 44100, 48000, 88200, 96000, 176400, 192000, -1 }; |
60 | static int deviceBitRates[] = { 8, 16, 24, 32, -1 }; | 60 | static int deviceBitRates[] = { 8, 16, 24, 32, -1 }; |
61 | #else //OSS | 61 | #else //OSS |
62 | static int deviceSampleRates[6] = { 11025, 16000, 22050, 32000, 44100, -1 }; | 62 | static int deviceSampleRates[6] = { 11025, 16000, 22050, 32000, 44100, -1 }; |
63 | static int deviceBitRates[] = { 8, 16, -1 }; | 63 | static int deviceBitRates[] = { 8, 16, -1 }; |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | #if defined(QT_QWS_SL5XXX) | ||
67 | ///#if defined(QT_QWS_EBX) | ||
68 | |||
69 | #define DSPSTROUT "/dev/dsp" | ||
70 | #define DSPSTRMIXEROUT "/dev/mixer" | ||
71 | |||
72 | #ifdef SHARP | ||
73 | #define DSPSTRIN "/dev/dsp1" | ||
74 | #define DSPSTRMIXERIN "/dev/mixer1" | ||
75 | #else | ||
76 | #define DSPSTRIN "/dev/dsp" | ||
77 | #define DSPSTRMIXERIN "/dev/mixer" | ||
78 | #endif | ||
79 | |||
80 | #else | ||
81 | |||
82 | #ifdef QT_QWS_DEVFS | ||
83 | #define DSPSTROUT "/dev/sound/dsp" | ||
84 | #define DSPSTRIN "/dev/sound/dsp" | ||
85 | #define DSPSTRMIXERIN "/dev/sound/mixer" | ||
86 | #define DSPSTRMIXEROUT "/dev/sound/mixer" | ||
87 | #else | ||
88 | #define DSPSTROUT "/dev/dsp" | ||
89 | #define DSPSTRIN "/dev/dsp" | ||
90 | #define DSPSTRMIXERIN "/dev/mixer" | ||
91 | #define DSPSTRMIXEROUT "/dev/mixer" | ||
92 | #endif | ||
93 | |||
94 | #endif | ||
95 | 66 | ||
96 | //#define ZAURUS 0 | 67 | //#define ZAURUS 0 |
97 | struct adpcm_state encoder_state; | 68 | struct adpcm_state encoder_state; |
98 | struct adpcm_state decoder_state; | 69 | struct adpcm_state decoder_state; |
99 | 70 | ||
100 | typedef struct { | 71 | typedef struct { |
101 | int sampleRate; | 72 | int sampleRate; |
102 | /* int fragSize; */ | 73 | /* int fragSize; */ |
103 | /* int blockSize; */ | 74 | /* int blockSize; */ |
104 | int resolution; //bitrate | 75 | int resolution; //bitrate |
105 | int channels; //number of channels | 76 | int channels; //number of channels |
106 | int fd; //file descriptor | 77 | int fd; //file descriptor |
107 | int sd; //sound device descriptor | 78 | int sd; //sound device descriptor |
108 | int numberSamples; //total number of samples | 79 | int numberSamples; //total number of samples |
109 | int SecondsToRecord; // number of seconds that should be recorded | 80 | int SecondsToRecord; // number of seconds that should be recorded |
110 | float numberOfRecordedSeconds; //total number of samples recorded | 81 | float numberOfRecordedSeconds; //total number of samples recorded |
111 | int samplesToRecord; //number of samples to be recorded | 82 | int samplesToRecord; //number of samples to be recorded |
112 | int inVol; //input volume | 83 | int inVol; //input volume |
113 | int outVol; //output volume | 84 | int outVol; //output volume |
114 | int format; //wavfile format PCM.. ADPCM | 85 | int format; //wavfile format PCM.. ADPCM |
115 | const char *fileName; //name of fiel to be played/recorded | 86 | const char *fileName; //name of fiel to be played/recorded |
116 | } fileParameters; | 87 | } fileParameters; |
117 | 88 | ||
118 | fileParameters filePara; | 89 | fileParameters filePara; |
119 | 90 | ||
120 | bool monitoring, recording, playing; | 91 | bool monitoring, recording, playing; |
121 | bool stopped; | 92 | bool stopped; |
122 | QLabel *timeLabel; | 93 | QLabel *timeLabel; |
123 | QSlider *timeSlider; | 94 | QSlider *timeSlider; |
124 | int sd; | 95 | int sd; |
125 | 96 | ||
126 | Waveform* waveform; | 97 | Waveform* waveform; |
127 | Device *soundDevice; | 98 | Device *soundDevice; |
128 | 99 | ||
129 | 100 | ||
130 | #ifdef THREADED | 101 | #ifdef THREADED |
131 | void quickRec() | 102 | void quickRec() |
132 | #else | 103 | #else |
133 | void QtRec::quickRec() | 104 | void QtRec::quickRec() |
134 | #endif | 105 | #endif |
135 | { | 106 | { |
136 | 107 | ||
137 | odebug << ( filePara.numberSamples/filePara.sampleRate * filePara.channels ) << oendl; | 108 | odebug << ( filePara.numberSamples/filePara.sampleRate * filePara.channels ) << oendl; |
138 | odebug << "samples " << filePara.numberSamples << ", rate " << filePara.sampleRate | 109 | odebug << "samples " << filePara.numberSamples << ", rate " << filePara.sampleRate |
139 | << ", channels " << filePara.channels << oendl; | 110 | << ", channels " << filePara.channels << oendl; |
140 | 111 | ||
141 | int total = 0; // Total number of bytes read in so far. | 112 | int total = 0; // Total number of bytes read in so far. |
142 | int bytesWritten, number; | 113 | int bytesWritten, number; |
143 | 114 | ||
144 | bytesWritten = 0; | 115 | bytesWritten = 0; |
145 | number = 0; | 116 | number = 0; |
146 | QString num; | 117 | QString num; |
147 | int level = 0; | 118 | int level = 0; |
148 | int threshold = 0; | 119 | int threshold = 0; |
149 | int bits = filePara.resolution; | 120 | int bits = filePara.resolution; |
150 | odebug << "bits " << bits << "" << oendl; | 121 | odebug << "bits " << bits << "" << oendl; |
151 | 122 | ||
152 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) | 123 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) |
153 | odebug << "AFMT_S16_LE size " << filePara.SecondsToRecord << "" << oendl; | 124 | odebug << "AFMT_S16_LE size " << filePara.SecondsToRecord << "" << oendl; |
154 | odebug << "samples to record " << filePara.samplesToRecord << "" << oendl; | 125 | odebug << "samples to record " << filePara.samplesToRecord << "" << oendl; |
155 | odebug << "" << filePara.sd << "" << oendl; | 126 | odebug << "" << filePara.sd << "" << oendl; |
156 | level = 7; | 127 | level = 7; |
157 | threshold = 0; | 128 | threshold = 0; |
158 | 129 | ||
159 | if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { | 130 | if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { |
160 | odebug << "start recording WAVE_FORMAT_DVI_ADPCM" << oendl; | 131 | odebug << "start recording WAVE_FORMAT_DVI_ADPCM" << oendl; |
161 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> | 132 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> |
162 | char abuf[ BUFSIZE/2 ]; | 133 | char abuf[ BUFSIZE/2 ]; |
163 | short sbuf[ BUFSIZE ]; | 134 | short sbuf[ BUFSIZE ]; |
164 | short sbuf2[ BUFSIZE ]; | 135 | short sbuf2[ BUFSIZE ]; |
165 | memset( abuf, 0, BUFSIZE/2); | 136 | memset( abuf, 0, BUFSIZE/2); |
166 | memset( sbuf, 0, BUFSIZE); | 137 | memset( sbuf, 0, BUFSIZE); |
167 | memset( sbuf2, 0, BUFSIZE); | 138 | memset( sbuf2, 0, BUFSIZE); |
168 | 139 | ||
169 | for(;;) { | 140 | for(;;) { |
170 | if ( stopped) { | 141 | if ( stopped) { |
171 | odebug << "quickRec:: stopped" << oendl; | 142 | odebug << "quickRec:: stopped" << oendl; |
172 | break; | 143 | break; |
173 | } | 144 | } |
174 | 145 | ||
175 | // number=::read( filePara.sd, sbuf, BUFSIZE); | 146 | // number=::read( filePara.sd, sbuf, BUFSIZE); |
176 | number = soundDevice->devRead( filePara.sd, sbuf, BUFSIZE); | 147 | number = soundDevice->devRead( filePara.sd, sbuf, BUFSIZE); |
177 | 148 | ||
178 | if(number <= 0) { | 149 | if(number <= 0) { |
179 | perror("recording error "); | 150 | perror("recording error "); |
180 | odebug << "" << filePara.fileName << " " << number << "" << oendl; | 151 | odebug << "" << filePara.fileName << " " << number << "" << oendl; |
181 | stopped = true; | 152 | stopped = true; |
182 | return; | 153 | return; |
183 | } | 154 | } |
184 | //if(stereo == 2) { | 155 | //if(stereo == 2) { |
185 | // adpcm_coder( sbuf2, abuf, number/2, &encoder_state); | 156 | // adpcm_coder( sbuf2, abuf, number/2, &encoder_state); |
186 | adpcm_coder( sbuf, abuf, number/2, &encoder_state); | 157 | adpcm_coder( sbuf, abuf, number/2, &encoder_state); |
187 | 158 | ||
188 | bytesWritten = ::write( filePara.fd , (short *)abuf, number/4); | 159 | bytesWritten = ::write( filePara.fd , (short *)abuf, number/4); |
189 | 160 | ||
190 | waveform->newSamples( sbuf, number ); | 161 | waveform->newSamples( sbuf, number ); |
191 | 162 | ||
192 | total += bytesWritten; | 163 | total += bytesWritten; |
193 | filePara.numberSamples = total; | 164 | filePara.numberSamples = total; |
194 | timeSlider->setValue( total); | 165 | timeSlider->setValue( total); |
195 | 166 | ||
196 | printf("%d, bytes %d,total %d\r",number, bytesWritten, total); | 167 | printf("%d, bytes %d,total %d\r", number, bytesWritten, total); |
197 | fflush(stdout); | 168 | fflush(stdout); |
198 | 169 | ||
199 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2/ filePara.channels; | 170 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2/ filePara.channels; |
200 | 171 | ||
201 | qApp->processEvents(); | 172 | qApp->processEvents(); |
202 | if( total >= filePara.samplesToRecord) { | 173 | if( total >= filePara.samplesToRecord) { |
203 | stopped = true; | 174 | stopped = true; |
204 | break; | 175 | break; |
205 | } | 176 | } |
206 | } | 177 | } |
207 | } else { | 178 | } else { |
208 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> | 179 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> |
209 | odebug << "start recording WAVE_FORMAT_PCM" << oendl; | 180 | odebug << "start recording WAVE_FORMAT_PCM" << oendl; |
210 | short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; | 181 | short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; |
211 | memset( inbuffer, 0, BUFSIZE); | 182 | memset( inbuffer, 0, BUFSIZE); |
212 | memset( outbuffer, 0, BUFSIZE); | 183 | memset( outbuffer, 0, BUFSIZE); |
213 | 184 | ||
214 | for(;;) { | 185 | for(;;) { |
215 | if ( stopped) { | 186 | if ( stopped) { |
216 | odebug << "quickRec:: stopped" << oendl; | 187 | odebug << "quickRec:: stopped" << oendl; |
217 | stopped = true; | 188 | stopped = true; |
218 | break; // stop if playing was set to false | 189 | break; // stop if playing was set to false |
219 | return; | 190 | return; |
220 | } | 191 | } |
221 | 192 | ||
222 | number = soundDevice->devRead( soundDevice->sd /*filePara.sd*/, (short *)inbuffer, BUFSIZE); | 193 | number = soundDevice->devRead( soundDevice->sd /*filePara.sd*/, (short *)inbuffer, BUFSIZE); |
223 | 194 | ||
224 | if( number <= 0) { | 195 | if( number <= 0) { |
225 | perror( "recording error "); | 196 | perror( "recording error "); |
226 | odebug << filePara.fileName << oendl; | 197 | odebug << filePara.fileName << oendl; |
227 | stopped = true; | 198 | stopped = true; |
228 | return; | 199 | return; |
229 | } | 200 | } |
230 | 201 | ||
231 | bytesWritten = ::write( filePara.fd , inbuffer, number); | 202 | bytesWritten = ::write( filePara.fd , inbuffer, number); |
232 | waveform->newSamples( inbuffer, number ); | 203 | waveform->newSamples( inbuffer, number ); |
233 | 204 | ||
234 | if( bytesWritten < 0) { | 205 | if( bytesWritten < 0) { |
235 | perror("File writing error "); | 206 | perror("File writing error "); |
236 | stopped = true; | 207 | stopped = true; |
237 | return; | 208 | return; |
238 | } | 209 | } |
239 | 210 | ||
240 | total += bytesWritten; | 211 | total += bytesWritten; |
241 | 212 | ||
242 | filePara.numberSamples = total; | 213 | filePara.numberSamples = total; |
243 | 214 | ||
244 | if( filePara.SecondsToRecord != 0) | 215 | if( filePara.SecondsToRecord != 0) |
245 | timeSlider->setValue( total); | 216 | timeSlider->setValue( total); |
246 | printf("%d, bytes %d,total %d\r",number, bytesWritten , total); | 217 | printf("%d, bytes %d,total %d\r",number, bytesWritten , total); |
247 | fflush(stdout); | 218 | fflush(stdout); |
248 | 219 | ||
249 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate | 220 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate |
250 | / (float)2/filePara.channels; | 221 | / (float)2/filePara.channels; |
251 | qApp->processEvents(); | 222 | qApp->processEvents(); |
252 | 223 | ||
253 | if( total >= filePara.samplesToRecord) { | 224 | if( total >= filePara.samplesToRecord) { |
254 | stopped = true; | 225 | stopped = true; |
255 | break; | 226 | break; |
256 | } | 227 | } |
257 | } | 228 | } |
258 | } //end main loop | 229 | } //end main loop |
259 | 230 | ||
260 | } else { | 231 | } else { |
261 | // <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8; | 232 | // <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8; |
262 | unsigned char unsigned_inbuffer[ BUFSIZE ], unsigned_outbuffer[ BUFSIZE ]; | 233 | unsigned char unsigned_inbuffer[ BUFSIZE ], unsigned_outbuffer[ BUFSIZE ]; |
263 | memset( unsigned_inbuffer, 0, BUFSIZE); | 234 | memset( unsigned_inbuffer, 0, BUFSIZE); |
264 | memset( unsigned_outbuffer, 0, BUFSIZE); | 235 | memset( unsigned_outbuffer, 0, BUFSIZE); |
265 | 236 | ||
266 | for(;;) { | 237 | for(;;) { |
267 | if ( stopped) { | 238 | if ( stopped) { |
268 | odebug << "quickRec:: stopped" << oendl; | 239 | odebug << "quickRec:: stopped" << oendl; |
269 | break; // stop if playing was set to false | 240 | break; // stop if playing was set to false |
270 | } | 241 | } |
271 | 242 | ||
272 | number = ::read( soundDevice->sd /*filePara.sd*/ , unsigned_inbuffer, BUFSIZE); | 243 | number = ::read( soundDevice->sd /*filePara.sd*/ , unsigned_inbuffer, BUFSIZE); |
273 | bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number); | 244 | bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number); |
274 | waveform->newSamples( (const short *) unsigned_inbuffer, number ); | 245 | waveform->newSamples( (const short *) unsigned_inbuffer, number ); |
275 | 246 | ||
276 | if(bytesWritten < 0) { | 247 | if(bytesWritten < 0) { |
277 | stopped = true; | 248 | stopped = true; |
278 | QMessageBox::message("Note","<p>There was a problem writing to the file</p>"); | 249 | QMessageBox::message("Note","<p>There was a problem writing to the file</p>"); |
279 | perror("File writing error "); | 250 | perror("File writing error "); |
280 | return; | 251 | return; |
281 | } | 252 | } |
282 | 253 | ||
283 | total += bytesWritten; | 254 | total += bytesWritten; |
284 | filePara.numberSamples = total; | 255 | filePara.numberSamples = total; |
285 | // printf("%d, bytes %d,total %d \r",number, bytesWritten , total); | 256 | // printf("%d, bytes %d,total %d \r",number, bytesWritten , total); |
286 | // fflush(stdout); | 257 | // fflush(stdout); |
287 | if( filePara.SecondsToRecord !=0) | 258 | if( filePara.SecondsToRecord !=0) |
288 | timeSlider->setValue( total); | 259 | timeSlider->setValue( total); |
289 | 260 | ||
290 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; | 261 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; |
291 | 262 | ||
292 | qApp->processEvents(); | 263 | qApp->processEvents(); |
293 | if( total >= filePara.samplesToRecord) { | 264 | if( total >= filePara.samplesToRecord) { |
294 | stopped = true; | 265 | stopped = true; |
295 | break; | 266 | break; |
296 | } | 267 | } |
297 | } //end main loop | 268 | } //end main loop |
298 | } | 269 | } |
270 | printf("\n"); | ||
299 | } /// END quickRec() | 271 | } /// END quickRec() |
300 | 272 | ||
301 | 273 | ||
302 | #ifdef THREADED | 274 | #ifdef THREADED |
303 | void playIt() | 275 | void playIt() |
304 | #else | 276 | #else |
305 | void QtRec::playIt() | 277 | void QtRec::playIt() |
306 | #endif | 278 | #endif |
307 | { | 279 | { |
308 | int bytesWritten = 0; | 280 | int bytesWritten = 0; |
309 | int number = 0; | 281 | int number = 0; |
310 | int total = 0; // Total number of bytes read in so far. | 282 | int total = 0; // Total number of bytes read in so far. |
311 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) { | 283 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) { |
312 | if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { | 284 | if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { |
313 | char abuf[ BUFSIZE / 2 ]; | 285 | char abuf[ BUFSIZE / 2 ]; |
314 | short sbuf[ BUFSIZE ]; | 286 | short sbuf[ BUFSIZE ]; |
315 | short sbuf2[ BUFSIZE * 2 ]; | 287 | short sbuf2[ BUFSIZE * 2 ]; |
316 | memset( abuf, 0, BUFSIZE / 2); | 288 | memset( abuf, 0, BUFSIZE / 2); |
317 | memset( sbuf, 0, BUFSIZE); | 289 | memset( sbuf, 0, BUFSIZE); |
318 | memset( sbuf2, 0, BUFSIZE * 2); | 290 | memset( sbuf2, 0, BUFSIZE * 2); |
319 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> | 291 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> |
320 | for(;;) { // play loop | 292 | for(;;) { // play loop |
321 | if ( stopped) { | 293 | if ( stopped) { |
322 | break; | 294 | break; |
323 | return; | 295 | return; |
324 | }// stop if playing was set to false | 296 | }// stop if playing was set to false |
325 | 297 | ||
326 | number = ::read( filePara.fd, abuf, BUFSIZE / 2); | 298 | number = ::read( filePara.fd, abuf, BUFSIZE / 2); |
327 | adpcm_decoder( abuf, sbuf, number * 2, &decoder_state); | 299 | adpcm_decoder( abuf, sbuf, number * 2, &decoder_state); |
328 | 300 | ||
329 | // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel | 301 | // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel |
330 | // sbuf2[i+1]=sbuf2[i]=sbuf[i]; | 302 | // sbuf2[i+1]=sbuf2[i]=sbuf[i]; |
331 | // } | 303 | // } |
332 | bytesWritten = write ( filePara.sd, sbuf, number * 4); | 304 | bytesWritten = write ( filePara.sd, sbuf, number * 4); |
333 | waveform->newSamples( (const short *)sbuf, number *4); | 305 | waveform->newSamples( (const short *)sbuf, number *4); |
334 | // if(filePara.channels==1) | 306 | // if(filePara.channels==1) |
335 | // total += bytesWritten/2; //mono | 307 | // total += bytesWritten/2; //mono |
336 | // else | 308 | // else |
337 | total += bytesWritten; | 309 | total += bytesWritten; |
338 | filePara.numberSamples = total/4; | 310 | filePara.numberSamples = total/4; |
339 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / 2; | 311 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / 2; |
340 | 312 | ||
341 | timeSlider->setValue( total/4); | 313 | timeSlider->setValue( total/4); |
342 | // timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); | 314 | // timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); |
343 | // if(filePara.numberOfRecordedSeconds>1) | 315 | // if(filePara.numberOfRecordedSeconds>1) |
344 | // timeLabel->setText( timeString+ tr(" seconds")); | 316 | // timeLabel->setText( timeString+ tr(" seconds")); |
345 | // printf("playing number %d, bytes %d, total %d\n",number, bytesWritten, total/4); | 317 | // printf("playing number %d, bytes %d, total %d\n",number, bytesWritten, total/4); |
346 | // fflush(stdout); | 318 | // fflush(stdout); |
347 | 319 | ||
348 | qApp->processEvents(); | 320 | qApp->processEvents(); |
349 | 321 | ||
350 | if( /*total >= filePara.numberSamples || */ bytesWritten == 0) { | 322 | if( /*total >= filePara.numberSamples || */ bytesWritten == 0) { |
351 | // if( total >= filePara.numberSamples ){//|| secCount > filePara.numberOfRecordedSeconds ) { | 323 | // if( total >= filePara.numberSamples ){//|| secCount > filePara.numberOfRecordedSeconds ) { |
352 | stopped = true; | 324 | stopped = true; |
353 | break; | 325 | break; |
354 | } | 326 | } |
355 | } | 327 | } |
356 | } else { | 328 | } else { |
357 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> | 329 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> |
358 | short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; | 330 | short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; |
359 | memset( inbuffer, 0, BUFSIZE); | 331 | memset( inbuffer, 0, BUFSIZE); |
360 | memset( outbuffer, 0, BUFSIZE); | 332 | memset( outbuffer, 0, BUFSIZE); |
361 | 333 | ||
362 | for(;;) { // play loop | 334 | for(;;) { // play loop |
363 | if ( stopped) { | 335 | if ( stopped) { |
364 | break; | 336 | break; |
365 | return; | 337 | return; |
366 | } | 338 | } |
367 | // stop if playing was set to false | 339 | // stop if playing was set to false |
368 | number = ::read( filePara.fd, inbuffer, BUFSIZE); | 340 | number = ::read( filePara.fd, inbuffer, BUFSIZE); |
369 | // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel | 341 | // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel |
370 | // // for (int i=0;i< number ; i++) { //2*i is left channel | 342 | // // for (int i=0;i< number ; i++) { //2*i is left channel |
371 | // outbuffer[i+1]= outbuffer[i]=inbuffer[i]; | 343 | // outbuffer[i+1]= outbuffer[i]=inbuffer[i]; |
372 | // } | 344 | // } |
373 | bytesWritten = ::write( filePara.sd, inbuffer, number); | 345 | bytesWritten = ::write( filePara.sd, inbuffer, number); |
374 | waveform->newSamples( inbuffer, number); | 346 | waveform->newSamples( inbuffer, number); |
375 | //-------------->>>> out to device | 347 | //-------------->>>> out to device |
376 | // total+=bytesWritten; | 348 | // total+=bytesWritten; |
377 | // if(filePara.channels==1) | 349 | // if(filePara.channels==1) |
378 | // total += bytesWritten/2; //mono | 350 | // total += bytesWritten/2; //mono |
379 | // else | 351 | // else |
380 | total += bytesWritten; | 352 | total += bytesWritten; |
381 | timeSlider->setValue( total); | 353 | timeSlider->setValue( total); |
382 | 354 | ||
383 | filePara.numberSamples = total; | 355 | filePara.numberSamples = total; |
384 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2; | 356 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2; |
385 | 357 | ||
386 | // timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds); | 358 | // timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds); |
387 | // timeLabel->setText( timeString + tr(" seconds")); | 359 | // timeLabel->setText( timeString + tr(" seconds")); |
388 | 360 | ||
389 | qApp->processEvents(); | 361 | qApp->processEvents(); |
390 | 362 | ||
391 | if( /*total >= filePara.numberSamples || */ bytesWritten == 0) { | 363 | if( /*total >= filePara.numberSamples || */ bytesWritten == 0) { |
392 | owarn << "Jane! Stop this crazy thing!" << oendl; | 364 | owarn << "Jane! Stop this crazy thing!" << oendl; |
393 | stopped = true; | 365 | stopped = true; |
394 | // playing = false; | 366 | // playing = false; |
395 | break; | 367 | break; |
396 | } | 368 | } |
397 | } | 369 | } |
398 | // printf("\nplaying number %d, bytes %d, total %d\r",number, bytesWritten, total); | 370 | // printf("\nplaying number %d, bytes %d, total %d\r",number, bytesWritten, total); |
399 | // fflush(stdout); | 371 | // fflush(stdout); |
400 | } //end loop | 372 | } //end loop |
401 | } else { | 373 | } else { |
402 | /////////////////////////////// format = AFMT_U8; | 374 | /////////////////////////////// format = AFMT_U8; |
403 | unsigned char unsigned_inbuffer[ BUFSIZE ]; //, unsigned_outbuffer[BUFSIZE]; | 375 | unsigned char unsigned_inbuffer[ BUFSIZE ]; //, unsigned_outbuffer[BUFSIZE]; |
404 | memset( unsigned_inbuffer, 0, BUFSIZE); | 376 | memset( unsigned_inbuffer, 0, BUFSIZE); |
405 | for(;;) { | 377 | for(;;) { |
406 | // main loop | 378 | // main loop |
407 | if (stopped) { | 379 | if (stopped) { |
408 | break; // stop if playing was set to false | 380 | break; // stop if playing was set to false |
409 | return; | 381 | return; |
410 | } | 382 | } |
411 | number = ::read( filePara.fd, unsigned_inbuffer, BUFSIZE); | 383 | number = ::read( filePara.fd, unsigned_inbuffer, BUFSIZE); |
412 | //data = (val >> 8) ^ 0x80; | 384 | //data = (val >> 8) ^ 0x80; |
413 | // unsigned_outbuffer = (unsigned_inbuffer >> 8) ^ 0x80; | 385 | // unsigned_outbuffer = (unsigned_inbuffer >> 8) ^ 0x80; |
414 | bytesWritten = write ( filePara.sd, unsigned_inbuffer, number); | 386 | bytesWritten = write ( filePara.sd, unsigned_inbuffer, number); |
415 | waveform->newSamples( (const short *)unsigned_inbuffer, bytesWritten ); | 387 | waveform->newSamples( (const short *)unsigned_inbuffer, bytesWritten ); |
416 | total += bytesWritten; | 388 | total += bytesWritten; |
417 | 389 | ||
418 | timeSlider->setValue( total); | 390 | timeSlider->setValue( total); |
419 | filePara.numberSamples = total; | 391 | filePara.numberSamples = total; |
420 | 392 | ||
421 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; | 393 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; |
422 | // timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds); | 394 | // timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds); |
423 | // timeLabel->setText( timeString + tr(" seconds")); | 395 | // timeLabel->setText( timeString + tr(" seconds")); |
424 | qApp->processEvents(); | 396 | qApp->processEvents(); |
425 | 397 | ||
426 | if( /*total >= filePara.numberSamples || */ bytesWritten == 0) { | 398 | if( /*total >= filePara.numberSamples || */ bytesWritten == 0) { |
427 | // if( total >= filePara.numberSamples ) { | 399 | // if( total >= filePara.numberSamples ) { |
428 | stopped = true; | 400 | stopped = true; |
429 | break; | 401 | break; |
430 | } | 402 | } |
431 | // printf("Writing number %d, bytes %d, total %d, numberSamples %d\r",number, bytesWritten , total, filePara.numberSamples); | 403 | // printf("Writing number %d, bytes %d, total %d, numberSamples %d\r",number, bytesWritten , total, filePara.numberSamples); |
432 | // fflush(stdout); | 404 | // fflush(stdout); |
433 | } | 405 | } |
434 | } | 406 | } |
435 | } | 407 | } |
436 | 408 | ||
437 | 409 | ||
438 | QtRec::QtRec( QWidget* parent, const char* name, WFlags fl ) | 410 | QtRec::QtRec( QWidget* parent, const char* name, WFlags fl ) |
439 | : QWidget( parent, name, fl ) | 411 | : QWidget( parent, name, fl ) |
440 | { | 412 | { |
441 | if ( !name ) | 413 | if ( !name ) |
442 | setName( "OpieRec" ); | 414 | setName( "OpieRec" ); |
443 | init(); | 415 | init(); |
444 | initConfig(); | 416 | initConfig(); |
445 | initConnections(); | 417 | initConnections(); |
446 | renameBox = 0; | 418 | renameBox = 0; |
447 | 419 | ||
448 | // open sound device to get volumes | 420 | // open sound device to get volumes |
449 | Config hwcfg("OpieRec"); | 421 | Config hwcfg("OpieRec"); |
450 | hwcfg.setGroup("Hardware"); | 422 | hwcfg.setGroup("Hardware"); |
451 | 423 | ||
452 | 424 | ||
453 | soundDevice = new Device( this, | 425 | soundDevice = new Device( this, false); //open play |
454 | hwcfg.readEntry( "Audio",DSPSTROUT), | ||
455 | hwcfg.readEntry( "Mixer",DSPSTRMIXEROUT), false); | ||
456 | // soundDevice = new Device( this, hwcfg.readEntry( "Audio","hw:0"), hwcfg.readEntry( "Mixer","hw:0"), false); | ||
457 | |||
458 | // soundDevice->setDeviceFormat(AFMT_S16_LE); | ||
459 | // soundDevice->setDeviceChannels(1); | ||
460 | // soundDevice->setDeviceRate( 22050); | ||
461 | 426 | ||
462 | getInVol(); | 427 | getInVol(); |
463 | getOutVol(); | 428 | getOutVol(); |
464 | 429 | ||
465 | soundDevice->closeDevice( true); | 430 | soundDevice->closeDevice( true); |
466 | soundDevice->sd = -1; | 431 | soundDevice->sd = -1; |
467 | soundDevice = 0; | 432 | soundDevice = 0; |
468 | wavFile = 0; | 433 | wavFile = 0; |
469 | // if( soundDevice) delete soundDevice; | 434 | // if( soundDevice) delete soundDevice; |
470 | QTimer::singleShot(100,this, SLOT(initIconView())); | 435 | QTimer::singleShot(100,this, SLOT(initIconView())); |
471 | 436 | ||
472 | if( autoMute) | 437 | if( autoMute) |
473 | doMute( true); | 438 | doMute( true); |
474 | // ListView1->setFocus(); | 439 | // ListView1->setFocus(); |
475 | playing = false; | 440 | playing = false; |
476 | } | 441 | } |
477 | 442 | ||
478 | QtRec::~QtRec() { | 443 | QtRec::~QtRec() { |
479 | // if( soundDevice) delete soundDevice; | 444 | // if( soundDevice) delete soundDevice; |
480 | 445 | ||
481 | } | 446 | } |
482 | 447 | ||
483 | void QtRec::cleanUp() { | 448 | void QtRec::cleanUp() { |
484 | 449 | ||
485 | if( !stopped) { | 450 | if( !stopped) { |
486 | stopped = true; | 451 | stopped = true; |
487 | endRecording(); | 452 | endRecording(); |
488 | } | 453 | } |
489 | 454 | ||
490 | ListView1->clear(); | 455 | ListView1->clear(); |
491 | 456 | ||
492 | if( autoMute) | 457 | if( autoMute) |
493 | doMute(false); | 458 | doMute(false); |
494 | 459 | ||
495 | // if( wavFile) delete wavFile; | 460 | // if( wavFile) delete wavFile; |
496 | // if(soundDevice) delete soundDevice; | 461 | // if(soundDevice) delete soundDevice; |
497 | } | 462 | } |
498 | 463 | ||
499 | void QtRec::init() { | 464 | void QtRec::init() { |
500 | 465 | ||
501 | needsStereoOut = false; | 466 | needsStereoOut = false; |
502 | QPixmap image3( ( const char** ) image3_data ); | 467 | QPixmap image3( ( const char** ) image3_data ); |
503 | QPixmap image4( ( const char** ) image4_data ); | 468 | QPixmap image4( ( const char** ) image4_data ); |
504 | QPixmap image6( ( const char** ) image6_data ); | 469 | QPixmap image6( ( const char** ) image6_data ); |
505 | 470 | ||
506 | stopped = true; | 471 | stopped = true; |
507 | setCaption( tr( "OpieRecord " ) + QString::number(VERSION) ); | 472 | setCaption( tr( "OpieRecord " )); |
508 | QGridLayout *layout = new QGridLayout( this ); | 473 | QGridLayout *layout = new QGridLayout( this ); |
509 | layout->setSpacing( 2); | 474 | layout->setSpacing( 2); |
510 | layout->setMargin( 2); | 475 | layout->setMargin( 2); |
511 | 476 | ||
512 | TabWidget = new QTabWidget( this, "TabWidget" ); | 477 | TabWidget = new QTabWidget( this, "TabWidget" ); |
513 | layout->addMultiCellWidget(TabWidget, 0, 7, 0, 8); | 478 | layout->addMultiCellWidget(TabWidget, 0, 7, 0, 8); |
514 | // TabWidget->setTabShape(QTabWidget::Triangular); | 479 | // TabWidget->setTabShape(QTabWidget::Triangular); |
515 | 480 | ||
516 | ///**********<<<<<<<<<<<<>>>>>>>>>>>>*************** | 481 | ///**********<<<<<<<<<<<<>>>>>>>>>>>>*************** |
517 | tab = new QWidget( TabWidget, "tab" ); | 482 | tab = new QWidget( TabWidget, "tab" ); |
518 | 483 | ||
519 | QGridLayout *layout1 = new QGridLayout( tab); | 484 | QGridLayout *layout1 = new QGridLayout( tab); |
520 | layout1->setSpacing( 2); | 485 | layout1->setSpacing( 2); |
521 | layout1->setMargin( 2); | 486 | layout1->setMargin( 2); |
522 | 487 | ||
523 | timeSlider = new QSlider( 0,100,10,0, QSlider::Horizontal, tab, (const char *) "timeSlider" ); | 488 | timeSlider = new QSlider( 0,100,10,0, QSlider::Horizontal, tab, (const char *) "timeSlider" ); |
524 | layout1->addMultiCellWidget( timeSlider, 1, 1, 0, 3); | 489 | layout1->addMultiCellWidget( timeSlider, 1, 1, 0, 3); |
525 | 490 | ||
526 | // timeLabel = new QLabel( tab, "TimeLabel" ); | 491 | // timeLabel = new QLabel( tab, "TimeLabel" ); |
527 | // layout1->addMultiCellWidget( timeLabel, 0, 0, 0, 3); | 492 | // layout1->addMultiCellWidget( timeLabel, 0, 0, 0, 3); |
528 | 493 | ||
529 | // playLabel2 = new QLabel(tab, "PlayLabel2" ); | 494 | // playLabel2 = new QLabel(tab, "PlayLabel2" ); |
530 | // playLabel2->setText(tr("Play") ); | 495 | // playLabel2->setText(tr("Play") ); |
531 | // playLabel2->setFixedHeight( 18); | 496 | // playLabel2->setFixedHeight( 18); |
532 | // layout1->addMultiCellWidget( playLabel2, 0, 0, 4, 4); | 497 | // layout1->addMultiCellWidget( playLabel2, 0, 0, 4, 4); |
533 | 498 | ||
534 | Stop_PushButton = new QPushButton( tab, "Stop_PushButton" ); | 499 | Stop_PushButton = new QPushButton( tab, "Stop_PushButton" ); |
535 | layout1->addMultiCellWidget( Stop_PushButton, 1, 1, 4, 4); | 500 | layout1->addMultiCellWidget( Stop_PushButton, 1, 1, 4, 4); |
536 | Stop_PushButton->setFixedSize( 22, 22); | 501 | Stop_PushButton->setFixedSize( 22, 22); |
537 | Stop_PushButton->setPixmap( image4 ); | 502 | Stop_PushButton->setPixmap( image4 ); |
538 | 503 | ||
539 | toBeginningButton = new QPushButton( tab, "Beginning_PushButton" ); | 504 | toBeginningButton = new QPushButton( tab, "Beginning_PushButton" ); |
540 | layout1->addMultiCellWidget(toBeginningButton, 1, 1, 5, 5); | 505 | layout1->addMultiCellWidget(toBeginningButton, 1, 1, 5, 5); |
541 | toBeginningButton->setFixedSize( 22, 22); | 506 | toBeginningButton->setFixedSize( 22, 22); |
542 | toBeginningButton->setPixmap( Resource::loadPixmap("fastback") ); | 507 | toBeginningButton->setPixmap( Resource::loadPixmap("fastback") ); |
543 | 508 | ||
544 | toEndButton = new QPushButton( tab, "End_PushButton" ); | 509 | toEndButton = new QPushButton( tab, "End_PushButton" ); |
545 | layout1->addMultiCellWidget( toEndButton, 1, 1, 6, 6); | 510 | layout1->addMultiCellWidget( toEndButton, 1, 1, 6, 6); |
546 | toEndButton->setFixedSize( 22, 22); | 511 | toEndButton->setFixedSize( 22, 22); |
547 | toEndButton->setPixmap( Resource::loadPixmap( "fastforward" ) ); | 512 | toEndButton->setPixmap( Resource::loadPixmap( "fastforward" ) ); |
548 | 513 | ||
549 | // QLabel *recLabel2; | 514 | // QLabel *recLabel2; |
550 | // recLabel2 = new QLabel( tab, "recLabel2" ); | 515 | // recLabel2 = new QLabel( tab, "recLabel2" ); |
551 | // recLabel2->setText(tr("Rec")); | 516 | // recLabel2->setText(tr("Rec")); |
552 | // recLabel2->setFixedHeight( 18); | 517 | // recLabel2->setFixedHeight( 18); |
553 | // layout1->addMultiCellWidget( recLabel2, 0, 0, 7, 7); | 518 | // layout1->addMultiCellWidget( recLabel2, 0, 0, 7, 7); |
554 | 519 | ||
555 | Rec_PushButton = new QPushButton( tab, "Rec_PushButton" ); | 520 | Rec_PushButton = new QPushButton( tab, "Rec_PushButton" ); |
556 | layout1->addMultiCellWidget( Rec_PushButton, 1, 1, 7, 7); | 521 | layout1->addMultiCellWidget( Rec_PushButton, 1, 1, 7, 7); |
557 | Rec_PushButton->setFixedSize( 22, 22); | 522 | Rec_PushButton->setFixedSize( 22, 22); |
558 | Rec_PushButton->setPixmap( image6 ); | 523 | Rec_PushButton->setPixmap( image6 ); |
559 | 524 | ||
560 | t = new QTimer( this ); | 525 | t = new QTimer( this ); |
561 | connect( t, SIGNAL( timeout() ), SLOT( timerBreak() ) ); | 526 | connect( t, SIGNAL( timeout() ), SLOT( timerBreak() ) ); |
562 | 527 | ||
563 | rewindTimer = new QTimer( this ); | 528 | rewindTimer = new QTimer( this ); |
564 | connect( rewindTimer, SIGNAL( timeout() ), | 529 | connect( rewindTimer, SIGNAL( timeout() ), |
565 | this, SLOT( rewindTimerTimeout() ) ); | 530 | this, SLOT( rewindTimerTimeout() ) ); |
566 | 531 | ||
567 | forwardTimer = new QTimer( this ); | 532 | forwardTimer = new QTimer( this ); |
568 | connect( forwardTimer, SIGNAL( timeout() ), | 533 | connect( forwardTimer, SIGNAL( timeout() ), |
569 | this, SLOT( forwardTimerTimeout() ) ); | 534 | this, SLOT( forwardTimerTimeout() ) ); |
570 | 535 | ||
571 | deleteSoundButton = new QPushButton( tab, "deleteSoundButton" ); | 536 | deleteSoundButton = new QPushButton( tab, "deleteSoundButton" ); |
572 | layout1->addMultiCellWidget( deleteSoundButton, 1, 1, 8, 8); | 537 | layout1->addMultiCellWidget( deleteSoundButton, 1, 1, 8, 8); |
573 | deleteSoundButton->setText( tr( "Del" ) ); | 538 | deleteSoundButton->setText( tr( "Del" ) ); |
574 | 539 | ||
575 | ListView1 = new QListView( tab, "IconView1" ); | 540 | ListView1 = new QListView( tab, "IconView1" ); |
576 | layout1->addMultiCellWidget( ListView1, 2, 2, 0, 8); | 541 | layout1->addMultiCellWidget( ListView1, 2, 2, 0, 8); |
577 | 542 | ||
578 | ListView1->addColumn( tr( "Name" ) ); | 543 | ListView1->addColumn( tr( "Name" ) ); |
579 | // ListView1->setColumnWidth( 0, 140); | ||
580 | ListView1->setSorting( 1, false); | 544 | ListView1->setSorting( 1, false); |
581 | ListView1->addColumn( tr( "Time" ) ); //in seconds | 545 | ListView1->addColumn( tr( "Time" ) ); //in seconds |
582 | // ListView1->setColumnWidth( 1, -1); | ||
583 | // ListView1->addColumn( tr("Location") ); | ||
584 | // ListView1->setColumnWidth( 2, -1); | ||
585 | // ListView1->addColumn( tr("Date") ); | ||
586 | // ListView1->setColumnWidth( 3, -1); | ||
587 | ListView1->setColumnWidthMode(0, QListView::Maximum); | 546 | ListView1->setColumnWidthMode(0, QListView::Maximum); |
588 | // ListView1->setColumnWidthMode(1, QListView::Maximum); | ||
589 | |||
590 | // ListView1->setColumnWidthMode( 0, QListView::Manual); | ||
591 | ListView1->setColumnAlignment( 1, QListView::AlignCenter); | 547 | ListView1->setColumnAlignment( 1, QListView::AlignCenter); |
592 | // ListView1->setColumnAlignment( 2, QListView::AlignRight); | ||
593 | // ListView1->setColumnAlignment( 3, QListView::AlignLeft); | ||
594 | ListView1->setAllColumnsShowFocus( true ); | 548 | ListView1->setAllColumnsShowFocus( true ); |
595 | QPEApplication::setStylusOperation( ListView1->viewport(), QPEApplication::RightOnHold); | 549 | QPEApplication::setStylusOperation( ListView1->viewport(), QPEApplication::RightOnHold); |
596 | 550 | ||
597 | TabWidget->insertTab( tab, tr( "Files" ) ); | 551 | TabWidget->insertTab( tab, tr( "Files" ) ); |
598 | 552 | ||
599 | ///**********<<<<<<<<<<<<>>>>>>>>>>>>*************** | 553 | ///**********<<<<<<<<<<<<>>>>>>>>>>>>*************** |
600 | tab_3 = new QWidget( TabWidget, "tab_3" ); | 554 | tab_3 = new QWidget( TabWidget, "tab_3" ); |
601 | QGridLayout *glayout3 = new QGridLayout( tab_3 ); | 555 | QGridLayout *glayout3 = new QGridLayout( tab_3 ); |
602 | glayout3->setSpacing( 2); | 556 | glayout3->setSpacing( 2); |
603 | glayout3->setMargin( 2); | 557 | glayout3->setMargin( 2); |
604 | //////////////////////////////////// | 558 | //////////////////////////////////// |
605 | sampleGroup = new QGroupBox( tab_3, "samplegroup" ); | 559 | sampleGroup = new QGroupBox( tab_3, "samplegroup" ); |
606 | sampleGroup->setTitle( tr( "Sample Rate" ) ); | 560 | sampleGroup->setTitle( tr( "Sample Rate" ) ); |
607 | sampleGroup->setFixedSize( 95,50); | 561 | sampleGroup->setFixedSize( 95,50); |
608 | 562 | ||
609 | sampleRateComboBox = new QComboBox( false, sampleGroup, "SampleRateComboBox" ); | 563 | sampleRateComboBox = new QComboBox( false, sampleGroup, "SampleRateComboBox" ); |
610 | sampleRateComboBox->setGeometry( QRect( 10, 20, 80, 25 ) ); | 564 | sampleRateComboBox->setGeometry( QRect( 10, 20, 80, 25 ) ); |
611 | //#ifndef QT_QWS_EBX | ||
612 | QString s; | 565 | QString s; |
613 | int z = 0; | 566 | int z = 0; |
614 | while( deviceSampleRates[z] != -1) { | 567 | while( deviceSampleRates[z] != -1) { |
615 | sampleRateComboBox->insertItem( s.setNum( deviceSampleRates[z], 10)); | 568 | sampleRateComboBox->insertItem( s.setNum( deviceSampleRates[z], 10)); |
616 | z++; | 569 | z++; |
617 | } | 570 | } |
618 | 571 | ||
619 | 572 | ||
620 | glayout3->addMultiCellWidget( sampleGroup, 0, 0, 0, 0); | 573 | glayout3->addMultiCellWidget( sampleGroup, 0, 0, 0, 0); |
621 | 574 | ||
622 | sizeGroup= new QGroupBox( tab_3, "sizeGroup" ); | 575 | sizeGroup= new QGroupBox( tab_3, "sizeGroup" ); |
623 | sizeGroup->setTitle( tr( "Limit Size" ) ); | 576 | sizeGroup->setTitle( tr( "Limit Size" ) ); |
624 | sizeGroup->setFixedSize( 80, 50); | 577 | sizeGroup->setFixedSize( 80, 50); |
625 | 578 | ||
626 | sizeLimitCombo = new QComboBox( false, sizeGroup, "sizeLimitCombo" ); | 579 | sizeLimitCombo = new QComboBox( false, sizeGroup, "sizeLimitCombo" ); |
627 | sizeLimitCombo ->setGeometry( QRect( 5, 20, 70, 25 ) ); | 580 | sizeLimitCombo ->setGeometry( QRect( 5, 20, 70, 25 ) ); |
628 | sizeLimitCombo->insertItem(tr("Unlimited")); | 581 | sizeLimitCombo->insertItem(tr("Unlimited")); |
629 | 582 | ||
630 | for(int i=1;i<13; i++) { | 583 | for(int i=1;i<13; i++) { |
631 | sizeLimitCombo->insertItem( QString::number( i * 5)); | 584 | sizeLimitCombo->insertItem( QString::number( i * 5)); |
632 | } | 585 | } |
633 | 586 | ||
634 | 587 | ||
635 | glayout3->addMultiCellWidget( sizeGroup, 0, 0, 1, 1); | 588 | glayout3->addMultiCellWidget( sizeGroup, 0, 0, 1, 1); |
636 | dirGroup = new QGroupBox( tab_3, "dirGroup" ); | 589 | dirGroup = new QGroupBox( tab_3, "dirGroup" ); |
637 | dirGroup->setTitle( tr( "File Directory" ) ); | 590 | dirGroup->setTitle( tr( "File Directory" ) ); |
638 | dirGroup->setFixedSize( 130, 50); | 591 | dirGroup->setFixedSize( 130, 50); |
639 | 592 | ||
640 | directoryComboBox = new QComboBox( false, dirGroup, "dirGroup" ); | 593 | directoryComboBox = new QComboBox( false, dirGroup, "dirGroup" ); |
641 | directoryComboBox->setGeometry( QRect( 10, 15, 115, 25 ) ); | 594 | directoryComboBox->setGeometry( QRect( 10, 15, 115, 25 ) ); |
642 | 595 | ||
643 | glayout3->addMultiCellWidget( dirGroup, 1, 1, 0, 0); | 596 | glayout3->addMultiCellWidget( dirGroup, 1, 1, 0, 0); |
644 | 597 | ||
645 | bitGroup = new QGroupBox( tab_3, "bitGroup" ); | 598 | bitGroup = new QGroupBox( tab_3, "bitGroup" ); |
646 | bitGroup->setTitle( tr( "Bit Depth" ) ); | 599 | bitGroup->setTitle( tr( "Bit Depth" ) ); |
647 | bitGroup->setFixedSize( 65, 50); | 600 | bitGroup->setFixedSize( 65, 50); |
648 | 601 | ||
649 | bitRateComboBox = new QComboBox( false, bitGroup, "BitRateComboBox" ); | 602 | bitRateComboBox = new QComboBox( false, bitGroup, "BitRateComboBox" ); |
650 | 603 | ||
651 | z = 0; | 604 | z = 0; |
652 | while( deviceBitRates[z] != -1) { | 605 | while( deviceBitRates[z] != -1) { |
653 | bitRateComboBox->insertItem( s.setNum( deviceBitRates[z], 10) ); | 606 | bitRateComboBox->insertItem( s.setNum( deviceBitRates[z], 10) ); |
654 | z++; | 607 | z++; |
655 | } | 608 | } |
656 | 609 | ||
657 | bitRateComboBox->setGeometry( QRect( 5, 20, 50, 25 ) ); | 610 | bitRateComboBox->setGeometry( QRect( 5, 20, 50, 25 ) ); |
658 | 611 | ||
659 | glayout3->addMultiCellWidget( bitGroup, 1, 1, 1, 1); | 612 | glayout3->addMultiCellWidget( bitGroup, 1, 1, 1, 1); |
660 | 613 | ||
661 | compressionCheckBox = new QCheckBox ( tr("Wave Compression (smaller files)"), tab_3 ); | 614 | compressionCheckBox = new QCheckBox ( tr("Wave Compression (smaller files)"), tab_3 ); |
662 | 615 | ||
663 | autoMuteCheckBox = new QCheckBox ( tr("Auto Mute"), tab_3 ); | 616 | autoMuteCheckBox = new QCheckBox ( tr("Auto Mute"), tab_3 ); |
664 | stereoCheckBox = new QCheckBox ( tr("Stereo"), tab_3 ); | 617 | stereoCheckBox = new QCheckBox ( tr("Stereo"), tab_3 ); |
665 | 618 | ||
666 | glayout3->addMultiCellWidget( compressionCheckBox, 2, 2, 0, 3); | 619 | glayout3->addMultiCellWidget( compressionCheckBox, 2, 2, 0, 3); |
667 | glayout3->addMultiCellWidget( autoMuteCheckBox, 3, 3, 0, 0); | 620 | glayout3->addMultiCellWidget( autoMuteCheckBox, 3, 3, 0, 0); |
668 | glayout3->addMultiCellWidget( stereoCheckBox, 3, 3, 1, 1); | 621 | glayout3->addMultiCellWidget( stereoCheckBox, 3, 3, 1, 1); |
669 | 622 | ||
670 | tab_5 = new QWidget( TabWidget, "tab_5" ); | 623 | tab_5 = new QWidget( TabWidget, "tab_5" ); |
671 | 624 | ||
672 | QHBoxLayout *Layout19a; | 625 | QHBoxLayout *Layout19a; |
673 | Layout19a = new QHBoxLayout( tab_5); | 626 | Layout19a = new QHBoxLayout( tab_5); |
674 | Layout19a->setSpacing( 2 ); | 627 | Layout19a->setSpacing( 2 ); |
675 | Layout19a->setMargin( 0 ); | 628 | Layout19a->setMargin( 0 ); |
676 | 629 | ||
677 | Layout15 = new QVBoxLayout( this); | 630 | Layout15 = new QVBoxLayout( this); |
678 | Layout15->setSpacing( 2 ); | 631 | Layout15->setSpacing( 2 ); |
679 | Layout15->setMargin( 0 ); | 632 | Layout15->setMargin( 0 ); |
680 | 633 | ||
681 | Layout15b = new QVBoxLayout( this); | 634 | Layout15b = new QVBoxLayout( this); |
682 | Layout15b->setSpacing( 2 ); | 635 | Layout15b->setSpacing( 2 ); |
683 | Layout15b->setMargin( 0 ); | 636 | Layout15b->setMargin( 0 ); |
684 | 637 | ||
685 | TextLabel2 = new QLabel( tab_5, "InputLabel" ); | 638 | TextLabel2 = new QLabel( tab_5, "InputLabel" ); |
686 | TextLabel2->setText( tr( "In")); | 639 | TextLabel2->setText( tr( "In")); |
687 | TextLabel2->setFixedWidth( 35); | 640 | TextLabel2->setFixedWidth( 35); |
688 | Layout15->addWidget( TextLabel2 ); | 641 | Layout15->addWidget( TextLabel2 ); |
689 | 642 | ||
690 | TextLabel3 = new QLabel( tab_5, "OutputLabel" ); | 643 | TextLabel3 = new QLabel( tab_5, "OutputLabel" ); |
691 | TextLabel3->setText( tr( "Out" ) ); | 644 | TextLabel3->setText( tr( "Out" ) ); |
692 | Layout15b->addWidget( TextLabel3 ); | 645 | Layout15b->addWidget( TextLabel3 ); |
693 | 646 | ||
694 | InputSlider = new QSlider( -100, 0, 10, 0, QSlider::Vertical, tab_5, (const char *) "InputSlider" ); | 647 | InputSlider = new QSlider( -100, 0, 10, 0, QSlider::Vertical, tab_5, (const char *) "InputSlider" ); |
695 | InputSlider->setTickmarks( QSlider::Both); | 648 | InputSlider->setTickmarks( QSlider::Both); |
696 | Layout15->addWidget( InputSlider); | 649 | Layout15->addWidget( InputSlider); |
697 | 650 | ||
698 | OutputSlider = new QSlider( -100,0,10,0, QSlider::Vertical,tab_5,(const char *) "OutputSlider" ); | 651 | OutputSlider = new QSlider( -100,0,10,0, QSlider::Vertical,tab_5,(const char *) "OutputSlider" ); |
699 | OutputSlider->setTickmarks( QSlider::Both); | 652 | OutputSlider->setTickmarks( QSlider::Both); |
700 | 653 | ||
701 | Layout15b->addWidget( OutputSlider ); | 654 | Layout15b->addWidget( OutputSlider ); |
702 | 655 | ||
703 | outMuteCheckBox = new QCheckBox ( tr("mute"), tab_5 ); | 656 | outMuteCheckBox = new QCheckBox ( tr("mute"), tab_5 ); |
704 | Layout15->addWidget( outMuteCheckBox ); | 657 | Layout15->addWidget( outMuteCheckBox ); |
705 | 658 | ||
706 | inMuteCheckBox = new QCheckBox ( tr("mute"), tab_5 ); | 659 | inMuteCheckBox = new QCheckBox ( tr("mute"), tab_5 ); |
707 | inMuteCheckBox-> setFocusPolicy ( QWidget::NoFocus ); | 660 | inMuteCheckBox-> setFocusPolicy ( QWidget::NoFocus ); |
708 | Layout15b->addWidget( inMuteCheckBox ); | 661 | Layout15b->addWidget( inMuteCheckBox ); |
709 | 662 | ||
710 | 663 | ||
711 | Layout19a->addLayout( Layout15 ); | 664 | Layout19a->addLayout( Layout15 ); |
712 | Layout19a->addLayout( Layout15b ); | 665 | Layout19a->addLayout( Layout15b ); |
713 | 666 | ||
714 | fillDirectoryCombo(); | 667 | fillDirectoryCombo(); |
715 | 668 | ||
716 | TabWidget->insertTab( tab_3, tr( "Options" ) ); | 669 | TabWidget->insertTab( tab_3, tr( "Options" ) ); |
717 | 670 | ||
718 | TabWidget->insertTab( tab_5, tr( "Volume" ) ); | 671 | TabWidget->insertTab( tab_5, tr( "Volume" ) ); |
719 | 672 | ||
720 | |||
721 | waveform = new Waveform( this, "waveform" ); | 673 | waveform = new Waveform( this, "waveform" ); |
722 | // waveform->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)3, waveform->sizePolicy().hasHeightForWidth() ) ); | ||
723 | waveform->setMinimumSize( QSize( 0, 50 ) ); | 674 | waveform->setMinimumSize( QSize( 0, 50 ) ); |
724 | 675 | ||
725 | layout->addMultiCellWidget( waveform, 8, 8, 0, 8); | 676 | layout->addMultiCellWidget( waveform, 8, 8, 0, 8); |
726 | waveform->setBackgroundColor ( black ); | 677 | waveform->setBackgroundColor ( black ); |
727 | } | 678 | } |
728 | 679 | ||
729 | void QtRec::initIconView() { | 680 | void QtRec::initIconView() { |
730 | owarn << "initIconView" << oendl; | ||
731 | ListView1->clear(); | 681 | ListView1->clear(); |
732 | Config cfg("OpieRec"); | 682 | Config cfg("OpieRec"); |
733 | cfg.setGroup("Sounds"); | 683 | cfg.setGroup("Sounds"); |
734 | QString temp; | 684 | QString temp; |
735 | QPixmap image0( ( const char** ) image0_data ); | 685 | QPixmap image0( ( const char** ) image0_data ); |
736 | 686 | ||
737 | int nFiles = cfg.readNumEntry("NumberofFiles",0); | 687 | int nFiles = cfg.readNumEntry("NumberofFiles",0); |
738 | owarn << "init number of files " << nFiles << "" << oendl; | 688 | // owarn << "init number of files " << nFiles << "" << oendl; |
739 | 689 | ||
740 | for(int i = 1; i <= nFiles; i++) { | 690 | for(int i = 1; i <= nFiles; i++) { |
741 | 691 | ||
742 | QListViewItem * item; | 692 | QListViewItem * item; |
743 | QString fileS, mediaLocation, fileDate, filePath; | 693 | QString fileS, mediaLocation, fileDate, filePath; |
744 | 694 | ||
745 | temp.sprintf( "%d",i); | 695 | temp.sprintf( "%d",i); |
746 | temp = cfg.readEntry( temp,""); //reads currentFile | 696 | temp = cfg.readEntry( temp,""); //reads currentFile |
747 | filePath = cfg.readEntry( temp,""); //currentFileName | 697 | filePath = cfg.readEntry( temp,""); //currentFileName |
748 | 698 | ||
749 | QFileInfo info(filePath); | 699 | QFileInfo info(filePath); |
750 | fileDate = info.lastModified().toString(); | 700 | fileDate = info.lastModified().toString(); |
751 | 701 | ||
752 | fileS = cfg.readEntry( filePath, "0" );// file length in seconds | 702 | fileS = cfg.readEntry( filePath, "0" );// file length in seconds |
753 | mediaLocation = getStorage( filePath); | 703 | mediaLocation = getStorage( filePath); |
754 | if( info.exists()) { | 704 | if( info.exists()) { |
755 | owarn << "new item " << temp << oendl; | 705 | // owarn << "new item " << temp << oendl; |
756 | item = new QListViewItem( ListView1, temp, fileS /*, mediaLocation, fileDate*/); | 706 | item = new QListViewItem( ListView1, temp, fileS /*, mediaLocation, fileDate*/); |
757 | item->setPixmap( 0, image0); | 707 | item->setPixmap( 0, image0); |
758 | if( currentFileName == filePath) | 708 | if( currentFileName == filePath) |
759 | ListView1->setSelected( item, true); | 709 | ListView1->setSelected( item, true); |
760 | } | 710 | } |
761 | } | 711 | } |
762 | } | 712 | } |
763 | 713 | ||
764 | void QtRec::initConnections() { | 714 | void QtRec::initConnections() { |
765 | connect(qApp,SIGNAL(aboutToQuit()),SLOT(cleanUp())); | 715 | connect(qApp,SIGNAL(aboutToQuit()),SLOT(cleanUp())); |
766 | 716 | ||
767 | connect(toBeginningButton,SIGNAL(pressed()),this,SLOT(rewindPressed())); | 717 | connect(toBeginningButton,SIGNAL(pressed()),this,SLOT(rewindPressed())); |
768 | connect(toBeginningButton,SIGNAL(released()),this,SLOT(rewindReleased())); | 718 | connect(toBeginningButton,SIGNAL(released()),this,SLOT(rewindReleased())); |
769 | connect(toEndButton,SIGNAL(pressed()),this,SLOT(FastforwardPressed())); | 719 | connect(toEndButton,SIGNAL(pressed()),this,SLOT(FastforwardPressed())); |
770 | connect(toEndButton,SIGNAL(released()),this,SLOT(FastforwardReleased())); | 720 | connect(toEndButton,SIGNAL(released()),this,SLOT(FastforwardReleased())); |
771 | connect(deleteSoundButton,SIGNAL(released()),this,SLOT(deleteSound())); | 721 | connect(deleteSoundButton,SIGNAL(released()),this,SLOT(deleteSound())); |
772 | connect(Stop_PushButton,SIGNAL(released()),this,SLOT(doPlayBtn())); | 722 | connect(Stop_PushButton,SIGNAL(released()),this,SLOT(doPlayBtn())); |
773 | connect(Rec_PushButton,SIGNAL(released()),this,SLOT(newSound())); | 723 | connect(Rec_PushButton,SIGNAL(released()),this,SLOT(newSound())); |
774 | 724 | ||
775 | connect(TabWidget,SIGNAL(currentChanged(QWidget*)),this,SLOT(thisTab(QWidget*))); | 725 | connect(TabWidget,SIGNAL(currentChanged(QWidget*)),this,SLOT(thisTab(QWidget*))); |
776 | 726 | ||
777 | connect(OutputSlider,SIGNAL(sliderReleased()),this,SLOT(changedOutVolume())); | 727 | connect(OutputSlider,SIGNAL(sliderReleased()),this,SLOT(changedOutVolume())); |
778 | connect(InputSlider,SIGNAL(sliderReleased()),this,SLOT(changedInVolume())); | 728 | connect(InputSlider,SIGNAL(sliderReleased()),this,SLOT(changedInVolume())); |
779 | 729 | ||
780 | connect(sampleRateComboBox,SIGNAL(activated(int)),this,SLOT(changesamplerateCombo(int))); | 730 | connect(sampleRateComboBox,SIGNAL(activated(int)),this,SLOT(changesamplerateCombo(int))); |
781 | connect(bitRateComboBox,SIGNAL(activated(int)),this,SLOT(changebitrateCombo(int))); | 731 | connect(bitRateComboBox,SIGNAL(activated(int)),this,SLOT(changebitrateCombo(int))); |
782 | connect(directoryComboBox,SIGNAL(activated(int)),this,SLOT(changeDirCombo(int))); | 732 | connect(directoryComboBox,SIGNAL(activated(int)),this,SLOT(changeDirCombo(int))); |
783 | connect(sizeLimitCombo,SIGNAL(activated(int)),this,SLOT(changeSizeLimitCombo(int))); | 733 | connect(sizeLimitCombo,SIGNAL(activated(int)),this,SLOT(changeSizeLimitCombo(int))); |
784 | 734 | ||
785 | connect(stereoCheckBox,SIGNAL(toggled(bool)),this,SLOT(changeStereoCheck(bool))); | 735 | connect(stereoCheckBox,SIGNAL(toggled(bool)),this,SLOT(changeStereoCheck(bool))); |
786 | connect(outMuteCheckBox,SIGNAL(toggled(bool)),this,SLOT(doVolMuting(bool))); | 736 | connect(outMuteCheckBox,SIGNAL(toggled(bool)),this,SLOT(doVolMuting(bool))); |
787 | connect(inMuteCheckBox,SIGNAL(toggled(bool)),this,SLOT(doMicMuting(bool))); | 737 | connect(inMuteCheckBox,SIGNAL(toggled(bool)),this,SLOT(doMicMuting(bool))); |
788 | 738 | ||
789 | connect(ListView1,SIGNAL(doubleClicked(QListViewItem*)),this,SLOT(itClick(QListViewItem*))); | 739 | connect(ListView1,SIGNAL(doubleClicked(QListViewItem*)),this,SLOT(itClick(QListViewItem*))); |
790 | connect(ListView1,SIGNAL(mouseButtonPressed(int,QListViewItem*,const QPoint&,int)),this,SLOT(listPressed(int,QListViewItem*,const QPoint&,int))); | 740 | connect(ListView1,SIGNAL(mouseButtonPressed(int,QListViewItem*,const QPoint&,int)),this,SLOT(listPressed(int,QListViewItem*,const QPoint&,int))); |
791 | 741 | ||
792 | connect(timeSlider,SIGNAL(sliderMoved(int)),this,SLOT(changeTimeSlider(int))); | 742 | connect(timeSlider,SIGNAL(sliderMoved(int)),this,SLOT(changeTimeSlider(int))); |
793 | connect(timeSlider,SIGNAL(sliderPressed()),this,SLOT(timeSliderPressed())); | 743 | connect(timeSlider,SIGNAL(sliderPressed()),this,SLOT(timeSliderPressed())); |
794 | connect(timeSlider,SIGNAL(sliderReleased()),this,SLOT(timeSliderReleased())); | 744 | connect(timeSlider,SIGNAL(sliderReleased()),this,SLOT(timeSliderReleased())); |
795 | 745 | ||
796 | connect(compressionCheckBox,SIGNAL(toggled(bool)),this,SLOT(compressionSelected(bool))); | 746 | connect(compressionCheckBox,SIGNAL(toggled(bool)),this,SLOT(compressionSelected(bool))); |
797 | connect(autoMuteCheckBox,SIGNAL(toggled(bool)),this,SLOT(slotAutoMute(bool))); | 747 | connect(autoMuteCheckBox,SIGNAL(toggled(bool)),this,SLOT(slotAutoMute(bool))); |
798 | } | 748 | } |
799 | 749 | ||
800 | void QtRec::initConfig() { | 750 | void QtRec::initConfig() { |
801 | int index, fred, i; | 751 | int index, fred, i; |
802 | Config cfg("OpieRec"); | 752 | Config cfg("OpieRec"); |
803 | cfg.setGroup("Settings"); | 753 | cfg.setGroup("Settings"); |
804 | 754 | ||
805 | index = cfg.readNumEntry("samplerate",22050); | 755 | index = cfg.readNumEntry("samplerate",22050); |
806 | bool ok; | 756 | bool ok; |
807 | 757 | ||
808 | for(int ws=0;ws<sampleRateComboBox->count();ws++) { | 758 | for(int ws=0;ws<sampleRateComboBox->count();ws++) { |
809 | fred = sampleRateComboBox->text(ws).toInt(&ok, 10); | 759 | fred = sampleRateComboBox->text(ws).toInt(&ok, 10); |
810 | if( index == fred) { | 760 | if( index == fred) { |
811 | filePara.sampleRate = fred; | 761 | filePara.sampleRate = fred; |
812 | sampleRateComboBox->setCurrentItem(ws); | 762 | sampleRateComboBox->setCurrentItem(ws); |
813 | } | 763 | } |
814 | } | 764 | } |
815 | 765 | ||
816 | i = cfg.readNumEntry("bitrate",16); | 766 | i = cfg.readNumEntry("bitrate",16); |
817 | if(i == 16) | 767 | if(i == 16) |
818 | bitRateComboBox->setCurrentItem( 1); | 768 | bitRateComboBox->setCurrentItem( 1); |
819 | else if(i == 24) | 769 | else if(i == 24) |
820 | bitRateComboBox->setCurrentItem( 2); | 770 | bitRateComboBox->setCurrentItem( 2); |
821 | else if(i == 32) | 771 | else if(i == 32) |
822 | bitRateComboBox->setCurrentItem( 3); | 772 | bitRateComboBox->setCurrentItem( 3); |
823 | else | 773 | else |
824 | bitRateComboBox->setCurrentItem( 0); | 774 | bitRateComboBox->setCurrentItem( 0); |
825 | 775 | ||
826 | filePara.resolution = i; | 776 | filePara.resolution = i; |
827 | 777 | ||
828 | i = cfg.readNumEntry("sizeLimit", 5 ); | 778 | i = cfg.readNumEntry("sizeLimit", 5 ); |
829 | QString temp; | 779 | QString temp; |
830 | sizeLimitCombo->setCurrentItem((i/5)); | 780 | sizeLimitCombo->setCurrentItem((i/5)); |
831 | 781 | ||
832 | stereoCheckBox->setChecked( cfg.readBoolEntry("stereo", 1)); | 782 | stereoCheckBox->setChecked( cfg.readBoolEntry("stereo", 1)); |
833 | if( stereoCheckBox->isChecked()) { | 783 | if( stereoCheckBox->isChecked()) { |
834 | filePara.channels = 2; | 784 | filePara.channels = 2; |
835 | } else { | 785 | } else { |
836 | filePara.channels = 1; | 786 | filePara.channels = 1; |
837 | } | 787 | } |
838 | 788 | ||
839 | compressionCheckBox->setChecked( cfg.readBoolEntry("wavCompression",1)); | 789 | compressionCheckBox->setChecked( cfg.readBoolEntry("wavCompression",1)); |
840 | if( compressionCheckBox->isChecked()) { | 790 | if( compressionCheckBox->isChecked()) { |
841 | bitRateComboBox->setEnabled(false); | 791 | bitRateComboBox->setEnabled(false); |
842 | bitRateComboBox->setCurrentItem(0); | 792 | bitRateComboBox->setCurrentItem(0); |
843 | filePara.resolution=16; | 793 | filePara.resolution=16; |
844 | } | 794 | } |
845 | 795 | ||
846 | autoMuteCheckBox->setChecked( cfg.readBoolEntry("useAutoMute",0)); | 796 | autoMuteCheckBox->setChecked( cfg.readBoolEntry("useAutoMute",0)); |
847 | if( autoMuteCheckBox->isChecked()) | 797 | if( autoMuteCheckBox->isChecked()) |
848 | slotAutoMute(true); | 798 | slotAutoMute(true); |
849 | else | 799 | else |
850 | slotAutoMute(false); | 800 | slotAutoMute(false); |
851 | 801 | ||
852 | Config cofg( "qpe"); | 802 | Config cofg( "qpe"); |
853 | cofg.setGroup( "Volume"); | 803 | cofg.setGroup( "Volume"); |
854 | outMuteCheckBox->setChecked( cofg.readBoolEntry( "Mute",0)); | 804 | outMuteCheckBox->setChecked( cofg.readBoolEntry( "Mute",0)); |
855 | inMuteCheckBox->setChecked( cofg.readBoolEntry( "MicMute",0)); | 805 | inMuteCheckBox->setChecked( cofg.readBoolEntry( "MicMute",0)); |
856 | } | 806 | } |
857 | 807 | ||
858 | void QtRec::stop() { | 808 | void QtRec::stop() { |
859 | owarn << "STOP" << oendl; | 809 | // owarn << "STOP" << oendl; |
860 | setRecordButton(false); | 810 | setRecordButton(false); |
861 | 811 | ||
862 | if( !recording) | 812 | if( !recording) |
863 | endPlaying(); | 813 | endPlaying(); |
864 | else | 814 | else |
865 | endRecording(); | 815 | endRecording(); |
866 | timeSlider->setValue(0); | 816 | timeSlider->setValue(0); |
867 | } | 817 | } |
868 | 818 | ||
869 | void QtRec::doPlayBtn() { | 819 | void QtRec::doPlayBtn() { |
870 | 820 | ||
871 | if(!stopped) { | 821 | if(!stopped) { |
872 | // playLabel2->setText(tr("Play")); | 822 | // playLabel2->setText(tr("Play")); |
873 | stop(); | 823 | stop(); |
874 | } else { | 824 | } else { |
875 | if(ListView1->currentItem() == 0) return; | 825 | if(ListView1->currentItem() == 0) return; |
876 | // playLabel2->setText(tr("Stop")); | 826 | // playLabel2->setText(tr("Stop")); |
877 | currentFile = ListView1->currentItem()->text(0); | 827 | currentFile = ListView1->currentItem()->text(0); |
878 | start(); | 828 | start(); |
879 | } | 829 | } |
880 | } | 830 | } |
881 | 831 | ||
882 | void QtRec::start() { //play | 832 | void QtRec::start() { //play |
883 | if( stopped) { | 833 | if( stopped) { |
884 | QPixmap image3( ( const char** ) image3_data ); | 834 | QPixmap image3( ( const char** ) image3_data ); |
885 | Stop_PushButton->setPixmap( image3 ); | 835 | Stop_PushButton->setPixmap( image3 ); |
886 | Stop_PushButton->setDown( true); | 836 | Stop_PushButton->setDown( true); |
887 | stopped = false; | 837 | stopped = false; |
888 | paused = false; | 838 | paused = false; |
889 | secCount = 1; | 839 | secCount = 1; |
890 | 840 | ||
891 | if( openPlayFile()) | 841 | if( openPlayFile()) |
892 | if( setupAudio( false)) //recording is false | 842 | if( setupAudio( false)) //recording is false |
893 | doPlay(); | 843 | doPlay(); |
894 | } | 844 | } |
895 | } | 845 | } |
896 | 846 | ||
897 | bool QtRec::rec() { //record | 847 | bool QtRec::rec() { //record |
898 | QString timeString; | 848 | QString timeString; |
899 | timeString.sprintf("%.0f", 0.0); | 849 | timeString.sprintf("%.0f", 0.0); |
900 | // timeLabel->setText( timeString+ " seconds"); | 850 | // timeLabel->setText( timeString+ " seconds"); |
901 | if(!stopped) { | 851 | if(!stopped) { |
902 | monitoring = true; | 852 | monitoring = true; |
903 | return false; | 853 | return false; |
904 | } else { | 854 | } else { |
905 | secCount = 1; | 855 | secCount = 1; |
906 | // playLabel2->setText(tr("Stop")); | 856 | // playLabel2->setText(tr("Stop")); |
907 | monitoring = false; | 857 | monitoring = false; |
908 | setRecordButton( true); | 858 | setRecordButton( true); |
909 | 859 | ||
910 | if( setupAudio( true)) | 860 | if( setupAudio( true)) |
911 | if(setUpFile()) { | 861 | if(setUpFile()) { |
912 | int fileSize = 0; | 862 | int fileSize = 0; |
913 | Config cfg("OpieRec"); | 863 | Config cfg("OpieRec"); |
914 | cfg.setGroup("Settings"); | 864 | cfg.setGroup("Settings"); |
915 | // odebug << "<<<<<<<Device bits " << soundDevice->getDeviceBits() | 865 | // odebug << "<<<<<<<Device bits " << soundDevice->getDeviceBits() |
916 | // << ", device rate " << soundDevice->getDeviceRate() | 866 | // << ", device rate " << soundDevice->getDeviceRate() |
917 | // << ", device channels " << soundDevice->getDeviceChannels() << oendl; | 867 | // << ", device channels " << soundDevice->getDeviceChannels() << oendl; |
918 | 868 | ||
919 | //filePara.sampleRate = cfg.readNumEntry("samplerate", 22050); | 869 | //filePara.sampleRate = cfg.readNumEntry("samplerate", 22050); |
920 | // odebug << "sample rate is " << filePara.sampleRate << "" << oendl; | 870 | // odebug << "sample rate is " << filePara.sampleRate << "" << oendl; |
921 | filePara.SecondsToRecord = getCurrentSizeLimit(); | 871 | filePara.SecondsToRecord = getCurrentSizeLimit(); |
922 | 872 | ||
923 | // odebug << "size limit " << filePara.SecondsToRecord << " sec" << oendl; | 873 | // odebug << "size limit " << filePara.SecondsToRecord << " sec" << oendl; |
924 | int diskSize = checkDiskSpace( (const QString &) wavFile->trackName()); | 874 | int diskSize = checkDiskSpace( (const QString &) wavFile->trackName()); |
925 | 875 | ||
926 | if( filePara.SecondsToRecord == 0) { | 876 | if( filePara.SecondsToRecord == 0) { |
927 | fileSize = diskSize; | 877 | fileSize = diskSize; |
928 | } else if( filePara.format == WAVE_FORMAT_PCM) { | 878 | } else if( filePara.format == WAVE_FORMAT_PCM) { |
929 | // odebug << "WAVE_FORMAT_PCM" << oendl; | 879 | // odebug << "WAVE_FORMAT_PCM" << oendl; |
930 | fileSize = (filePara.SecondsToRecord ) * filePara.channels | 880 | fileSize = (filePara.SecondsToRecord ) * filePara.channels |
931 | * filePara.sampleRate * ( filePara.resolution / 8) + 1000; | 881 | * filePara.sampleRate * ( filePara.resolution / 8) + 1000; |
932 | } else { | 882 | } else { |
933 | // odebug << "WAVE_FORMAT_DVI_ADPCM" << oendl; | 883 | // odebug << "WAVE_FORMAT_DVI_ADPCM" << oendl; |
934 | fileSize = ((filePara.SecondsToRecord) * filePara.channels | 884 | fileSize = ((filePara.SecondsToRecord) * filePara.channels |
935 | * filePara.sampleRate * ( filePara.resolution / 8) ) / 4 + 250; | 885 | * filePara.sampleRate * ( filePara.resolution / 8) ) / 4 + 250; |
936 | } | 886 | } |
937 | 887 | ||
938 | filePara.samplesToRecord = fileSize; | 888 | filePara.samplesToRecord = fileSize; |
939 | odebug << "filesize should be " << filePara.samplesToRecord | 889 | odebug << "filesize should be " << filePara.samplesToRecord |
940 | << ", bits " << filePara.resolution << ", rate " << filePara.sampleRate; | 890 | << ", bits " << filePara.resolution << ", rate " << filePara.sampleRate; |
941 | if( paused) { | 891 | if( paused) { |
942 | paused = false; | 892 | paused = false; |
943 | } | 893 | } |
944 | // else { | 894 | // else { |
945 | odebug << "Setting timeslider " << filePara.samplesToRecord << "" << oendl; | 895 | odebug << "Setting timeslider " << filePara.samplesToRecord << "" << oendl; |
946 | // if(fileSize != 0) | 896 | // if(fileSize != 0) |
947 | timeSlider->setRange(0, filePara.samplesToRecord); | 897 | timeSlider->setRange(0, filePara.samplesToRecord); |
948 | // } | 898 | // } |
949 | 899 | ||
950 | if( diskSize < fileSize/1024) { | 900 | if( diskSize < fileSize/1024) { |
951 | QMessageBox::warning(this, | 901 | QMessageBox::warning(this, |
952 | tr("Low Disk Space"), | 902 | tr("Low Disk Space"), |
953 | tr("You are running low of\nrecording space\n" | 903 | tr("You are running low of\nrecording space\n" |
954 | "or a card isn't being recognized")); | 904 | "or a card isn't being recognized")); |
955 | stopped = true; //we need to be stopped | 905 | stopped = true; //we need to be stopped |
956 | stop(); | 906 | stop(); |
957 | } else { | 907 | } else { |
958 | QString msg; | 908 | QString msg; |
959 | msg.sprintf("%d, %d, %d", filePara.sampleRate, filePara.channels, filePara.resolution); | 909 | msg.sprintf("%d, %d, %d", filePara.sampleRate, filePara.channels, filePara.resolution); |
960 | #ifdef DEV_VERSION | 910 | #ifdef DEV_VERSION |
961 | setCaption( msg); | 911 | setCaption( msg); |
962 | #endif | 912 | #endif |
963 | filePara.fileName=currentFile.latin1(); | 913 | filePara.fileName=currentFile.latin1(); |
964 | odebug << "Start recording" << oendl; | 914 | odebug << "Start recording" << oendl; |
965 | stopped = false; | 915 | stopped = false; |
966 | 916 | ||
967 | #ifdef THREADED | 917 | #ifdef THREADED |
968 | odebug << "Start recording thread" << oendl; | 918 | odebug << "Start recording thread" << oendl; |
969 | pthread_t thread1; | 919 | pthread_t thread1; |
970 | pthread_create( &thread1, NULL, (void * (*)(void *))quickRec, NULL/* &*/); | 920 | pthread_create( &thread1, NULL, (void * (*)(void *))quickRec, NULL/* &*/); |
971 | #endif | 921 | #endif |
972 | toBeginningButton->setEnabled( false); | 922 | toBeginningButton->setEnabled( false); |
973 | toEndButton->setEnabled( false); | 923 | toEndButton->setEnabled( false); |
974 | 924 | ||
975 | startTimer(1000); | 925 | startTimer(1000); |
976 | #ifndef THREADED | 926 | #ifndef THREADED |
977 | quickRec(); | 927 | quickRec(); |
978 | #endif | 928 | #endif |
979 | } | 929 | } |
980 | } //end setUpFile | 930 | } //end setUpFile |
981 | } //end setupAudio | 931 | } //end setupAudio |
982 | return true; | 932 | return true; |
983 | } | 933 | } |
984 | /* | 934 | /* |
985 | This happens when a tab is selected*/ | 935 | This happens when a tab is selected*/ |
986 | void QtRec::thisTab(QWidget* widg) { | 936 | void QtRec::thisTab(QWidget* widg) { |
987 | if(widg != NULL) { | 937 | if(widg != NULL) { |
988 | int index = TabWidget->currentPageIndex(); | 938 | int index = TabWidget->currentPageIndex(); |
989 | 939 | ||
990 | if(index == 0) { //file page | 940 | if(index == 0) { //file page |
991 | } | 941 | } |
992 | 942 | ||
993 | if(index == 1) { //control page | 943 | if(index == 1) { //control page |
994 | fillDirectoryCombo(); | 944 | fillDirectoryCombo(); |
995 | // soundDevice->getOutVol(); | 945 | // soundDevice->getOutVol(); |
996 | // soundDevice->getInVol(); | 946 | // soundDevice->getInVol(); |
997 | } | 947 | } |
998 | 948 | ||
999 | if( index==2) { //help page | 949 | if( index==2) { //help page |
1000 | } | 950 | } |
1001 | 951 | ||
1002 | qApp->processEvents(); | 952 | qApp->processEvents(); |
1003 | update(); | 953 | update(); |
1004 | } | 954 | } |
1005 | } | 955 | } |
1006 | 956 | ||
1007 | void QtRec::getOutVol( ) { | 957 | void QtRec::getOutVol( ) { |
1008 | filePara.outVol = soundDevice->getOutVolume(); | 958 | filePara.outVol = soundDevice->getOutVolume(); |
1009 | // odebug << "out vol " << filePara.outVol << "" << oendl; | 959 | // odebug << "out vol " << filePara.outVol << "" << oendl; |
1010 | OutputSlider->setValue( -filePara.outVol); | 960 | OutputSlider->setValue( -filePara.outVol); |
1011 | } | 961 | } |
1012 | 962 | ||
1013 | void QtRec::getInVol() { | 963 | void QtRec::getInVol() { |
1014 | filePara.inVol = soundDevice->getInVolume(); | 964 | filePara.inVol = soundDevice->getInVolume(); |
1015 | // odebug << "in vol " << filePara.inVol << "" << oendl; | 965 | // odebug << "in vol " << filePara.inVol << "" << oendl; |
1016 | InputSlider->setValue( -filePara.inVol); | 966 | InputSlider->setValue( -filePara.inVol); |
1017 | } | 967 | } |
1018 | 968 | ||
1019 | void QtRec::changedOutVolume() { | 969 | void QtRec::changedOutVolume() { |
1020 | soundDevice->changedOutVolume( -OutputSlider->value()); | 970 | soundDevice->changedOutVolume( -OutputSlider->value()); |
1021 | } | 971 | } |
1022 | 972 | ||
1023 | void QtRec::changedInVolume( ) { | 973 | void QtRec::changedInVolume( ) { |
1024 | soundDevice->changedInVolume( -InputSlider->value()); | 974 | soundDevice->changedInVolume( -InputSlider->value()); |
1025 | } | 975 | } |
1026 | 976 | ||
1027 | 977 | ||
1028 | bool QtRec::setupAudio( bool b) { | 978 | bool QtRec::setupAudio( bool b) { |
1029 | bool ok; | 979 | bool ok; |
1030 | int sampleformat, stereo, flags; | 980 | int sampleformat, stereo, flags; |
1031 | QString dspString, mixerString; | 981 | QString dspString, mixerString; |
1032 | 982 | ||
1033 | filePara.resolution = bitRateComboBox->currentText().toInt( &ok,10); //16 | 983 | filePara.resolution = bitRateComboBox->currentText().toInt( &ok,10); //16 |
1034 | 984 | ||
1035 | if( !b) { | 985 | if( !b) { |
1036 | // we want to play | 986 | // we want to play |
1037 | #ifdef PDAUDIO //ALSA | 987 | #ifdef PDAUDIO //ALSA |
1038 | if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) { | 988 | if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) { |
1039 | sampleformat = SND_PCM_FORMAT_S16; | 989 | sampleformat = SND_PCM_FORMAT_S16; |
1040 | filePara.resolution = 16; | 990 | filePara.resolution = 16; |
1041 | } else if( filePara.resolution == 24 || compressionCheckBox->isChecked() ) { | 991 | } else if( filePara.resolution == 24 || compressionCheckBox->isChecked() ) { |
1042 | sampleformat = SND_PCM_FORMAT_S24; | 992 | sampleformat = SND_PCM_FORMAT_S24; |
1043 | filePara.resolution = 24; | 993 | filePara.resolution = 24; |
1044 | } else if( filePara.resolution == 32 || compressionCheckBox->isChecked() ) { | 994 | } else if( filePara.resolution == 32 || compressionCheckBox->isChecked() ) { |
1045 | sampleformat = SND_PCM_FORMAT_S32; | 995 | sampleformat = SND_PCM_FORMAT_S32; |
1046 | filePara.resolution = 32; | 996 | filePara.resolution = 32; |
1047 | } else { | 997 | } else { |
1048 | sampleformat = SND_PCM_FORMAT_U8; | 998 | sampleformat = SND_PCM_FORMAT_U8; |
1049 | filePara.resolution = 8; | 999 | filePara.resolution = 8; |
1050 | } | 1000 | } |
1051 | #else | 1001 | #else |
1052 | // we want to play | 1002 | // we want to play |
1053 | if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) { | 1003 | if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) { |
1054 | sampleformat = AFMT_S16_LE; | 1004 | sampleformat = AFMT_S16_LE; |
1055 | filePara.resolution = 16; | 1005 | filePara.resolution = 16; |
1056 | } else { | 1006 | } else { |
1057 | sampleformat = AFMT_U8; | 1007 | sampleformat = AFMT_U8; |
1058 | filePara.resolution = 8; | 1008 | filePara.resolution = 8; |
1059 | } | 1009 | } |
1060 | #endif | 1010 | #endif |
1061 | 1011 | ||
1062 | stereo = filePara.channels; | 1012 | stereo = filePara.channels; |
1063 | flags = O_WRONLY; | 1013 | flags = O_WRONLY; |
1064 | Config hwcfg("OpieRec"); | ||
1065 | hwcfg.setGroup("Hardware"); | ||
1066 | dspString = hwcfg.readEntry( "Audio", DSPSTROUT); | ||
1067 | mixerString = hwcfg.readEntry( "Mixer", DSPSTRMIXEROUT); | ||
1068 | recording = false; | 1014 | recording = false; |
1069 | } else { // we want to record | 1015 | } else { // we want to record |
1070 | 1016 | ||
1071 | #ifdef PDAUDIO //ALSA | 1017 | #ifdef PDAUDIO //ALSA |
1072 | if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16") | 1018 | if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16") |
1073 | sampleformat = SND_PCM_FORMAT_S16; | 1019 | sampleformat = SND_PCM_FORMAT_S16; |
1074 | else if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "24") | 1020 | else if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "24") |
1075 | sampleformat = SND_PCM_FORMAT_S24; | 1021 | sampleformat = SND_PCM_FORMAT_S24; |
1076 | else if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "32") | 1022 | else if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "32") |
1077 | sampleformat = SND_PCM_FORMAT_S32; | 1023 | sampleformat = SND_PCM_FORMAT_S32; |
1078 | else | 1024 | else |
1079 | sampleformat = SND_PCM_FORMAT_U8; | 1025 | sampleformat = SND_PCM_FORMAT_U8; |
1080 | 1026 | ||
1081 | #else | 1027 | #else |
1082 | if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16") | 1028 | if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16") |
1083 | sampleformat = AFMT_S16_LE; | 1029 | sampleformat = AFMT_S16_LE; |
1084 | else | 1030 | else |
1085 | sampleformat = AFMT_U8; | 1031 | sampleformat = AFMT_U8; |
1086 | 1032 | ||
1087 | if( !compressionCheckBox->isChecked()) { | 1033 | if( !compressionCheckBox->isChecked()) { |
1088 | filePara.format = WAVE_FORMAT_PCM; | 1034 | filePara.format = WAVE_FORMAT_PCM; |
1089 | // odebug << "WAVE_FORMAT_PCM" << oendl; | 1035 | // odebug << "WAVE_FORMAT_PCM" << oendl; |
1090 | } else { | 1036 | } else { |
1091 | filePara.format = WAVE_FORMAT_DVI_ADPCM; | 1037 | filePara.format = WAVE_FORMAT_DVI_ADPCM; |
1092 | sampleformat = AFMT_S16_LE; | 1038 | sampleformat = AFMT_S16_LE; |
1093 | // odebug << "WAVE_FORMAT_DVI_ADPCM" << oendl; | 1039 | // odebug << "WAVE_FORMAT_DVI_ADPCM" << oendl; |
1094 | } | 1040 | } |
1095 | #endif | 1041 | #endif |
1096 | 1042 | ||
1097 | stereo = filePara.channels; | 1043 | stereo = filePara.channels; |
1098 | // filePara.sampleRate = sampleRateComboBox->currentText().toInt( &ok,10);//44100; | 1044 | // filePara.sampleRate = sampleRateComboBox->currentText().toInt( &ok,10);//44100; |
1099 | flags= O_RDWR; | 1045 | flags= O_RDWR; |
1100 | // flags= O_RDONLY; | 1046 | // flags= O_RDONLY; |
1101 | Config hwcfg("OpieRec"); | ||
1102 | hwcfg.setGroup("Hardware"); | ||
1103 | dspString = hwcfg.readEntry( "Audio", DSPSTRIN); | ||
1104 | mixerString = hwcfg.readEntry( "Mixer", DSPSTRMIXERIN); | ||
1105 | recording = true; | 1047 | recording = true; |
1106 | } | 1048 | } |
1107 | 1049 | ||
1108 | // if(soundDevice) delete soundDevice; | 1050 | // if(soundDevice) delete soundDevice; |
1109 | odebug << "<<<<<<<<<<<<<<<<<<<open dsp " << filePara.sampleRate << " " << filePara.channels << " " << sampleformat << "" << oendl; | 1051 | odebug << "<<<<<<<<<<<<<<<<<<<open dsp " << filePara.sampleRate << " " << filePara.channels << " " << sampleformat << "" << oendl; |
1110 | owarn << "change waveform settings" << oendl; | 1052 | // owarn << "change waveform settings" << oendl; |
1111 | waveform->changeSettings( filePara.sampleRate, filePara.channels ); | 1053 | waveform->changeSettings( filePara.sampleRate, filePara.channels ); |
1112 | 1054 | ||
1113 | soundDevice = new Device( this, dspString, mixerString, b); | 1055 | soundDevice = new Device( this, b); //open rec |
1114 | // soundDevice->openDsp(); | 1056 | // soundDevice->openDsp(); |
1115 | soundDevice->reset(); | 1057 | soundDevice->reset(); |
1116 | 1058 | ||
1117 | odebug << "device has been made " << soundDevice->sd << "" << oendl; | 1059 | odebug << "device has been made " << soundDevice->sd << "" << oendl; |
1118 | 1060 | ||
1119 | ////////////////// <<<<<<<<<<<<>>>>>>>>>>>> | 1061 | ////////////////// <<<<<<<<<<<<>>>>>>>>>>>> |
1120 | soundDevice->setDeviceFormat( sampleformat); | 1062 | soundDevice->setDeviceFormat( sampleformat); |
1121 | soundDevice->setDeviceChannels( filePara.channels); | 1063 | soundDevice->setDeviceChannels( filePara.channels); |
1122 | soundDevice->setDeviceRate( filePara.sampleRate); | 1064 | soundDevice->setDeviceRate( filePara.sampleRate); |
1123 | soundDevice->getDeviceFragSize(); | 1065 | soundDevice->getDeviceFragSize(); |
1124 | #ifdef QT_QWS_EBX | 1066 | #ifdef QT_QWS_EBX |
1125 | int frag = FRAGSIZE; | 1067 | int frag = FRAGSIZE; |
1126 | soundDevice->setFragSize( frag); | 1068 | soundDevice->setFragSize( frag); |
1127 | soundDevice->getDeviceFragSize(); | 1069 | soundDevice->getDeviceFragSize(); |
1128 | #endif | 1070 | #endif |
1129 | ///////////////// | 1071 | ///////////////// |
1130 | filePara.sd = soundDevice->sd; | 1072 | filePara.sd = soundDevice->sd; |
1131 | 1073 | ||
1132 | if ( filePara.sd == -1) { | 1074 | if ( filePara.sd == -1) { |
1133 | 1075 | ||
1134 | monitoring = false; | 1076 | monitoring = false; |
1135 | stopped = true; | 1077 | stopped = true; |
1136 | update(); | 1078 | update(); |
1137 | setCaption( tr( "OpieRecord " )+ QString::number(VERSION) ); | 1079 | setCaption( tr( "OpieRecord " )+ QString::number(VERSION) ); |
1138 | return false; | 1080 | return false; |
1139 | } | 1081 | } |
1140 | if(autoMute) | 1082 | if(autoMute) |
1141 | doMute(false); | 1083 | doMute(false); |
1142 | 1084 | ||
1143 | return true; | 1085 | return true; |
1144 | } | 1086 | } |
1145 | 1087 | ||
1146 | 1088 | ||
1147 | bool QtRec::setUpFile() { //setup file for recording | 1089 | bool QtRec::setUpFile() { //setup file for recording |
1148 | // odebug << "Setting up wavfile" << oendl; | 1090 | // odebug << "Setting up wavfile" << oendl; |
1149 | // if(wavFile) delete wavFile; | 1091 | // if(wavFile) delete wavFile; |
1150 | wavFile = new WavFile( this, (const QString &)"", | 1092 | wavFile = new WavFile( this, (const QString &)"", |
1151 | true, | 1093 | true, |
1152 | filePara.sampleRate, | 1094 | filePara.sampleRate, |
1153 | filePara.channels, | 1095 | filePara.channels, |
1154 | filePara.resolution, | 1096 | filePara.resolution, |
1155 | filePara.format); | 1097 | filePara.format); |
1156 | 1098 | ||
1157 | filePara.fd = wavFile->wavHandle(); | 1099 | filePara.fd = wavFile->wavHandle(); |
1158 | if(filePara.fd == -1) { | 1100 | if(filePara.fd == -1) { |
1159 | return false; | 1101 | return false; |
1160 | } else { | 1102 | } else { |
1161 | // filePara.channels=1; | 1103 | // filePara.channels=1; |
1162 | } | 1104 | } |
1163 | return true; | 1105 | return true; |
1164 | } | 1106 | } |
1165 | 1107 | ||
1166 | /// <<<<<<<<<<<<<<<< PLAY >>>>>>>>>>>>>>>>>>> | 1108 | /// <<<<<<<<<<<<<<<< PLAY >>>>>>>>>>>>>>>>>>> |
1167 | bool QtRec::doPlay() { | 1109 | bool QtRec::doPlay() { |
1168 | 1110 | ||
1169 | if( !paused) { | 1111 | if( !paused) { |
1170 | total = 0; | 1112 | total = 0; |
1171 | filePara.numberOfRecordedSeconds = 0; | 1113 | filePara.numberOfRecordedSeconds = 0; |
1172 | } else { | 1114 | } else { |
1173 | paused = false; | 1115 | paused = false; |
1174 | secCount = (int)filePara.numberOfRecordedSeconds; | 1116 | secCount = (int)filePara.numberOfRecordedSeconds; |
1175 | } | 1117 | } |
1176 | playing = true; | 1118 | playing = true; |
1177 | stopped = false; | 1119 | stopped = false; |
1178 | recording = false; | 1120 | recording = false; |
1179 | 1121 | ||
1180 | QString num; | 1122 | QString num; |
1181 | odebug << "Play number of samples " << filePara.numberSamples << "" << oendl; | 1123 | odebug << "Play number of samples " << filePara.numberSamples << "" << oendl; |
1182 | 1124 | ||
1183 | // timeSlider->setRange( 0, filePara.numberSamples); | 1125 | // timeSlider->setRange( 0, filePara.numberSamples); |
1184 | 1126 | ||
1185 | timeString.sprintf("%f", filePara.numberOfRecordedSeconds); | 1127 | timeString.sprintf("%f", filePara.numberOfRecordedSeconds); |
1186 | // timeLabel->setText( timeString+ tr(" seconds")); | 1128 | // timeLabel->setText( timeString+ tr(" seconds")); |
1187 | 1129 | ||
1188 | QString msg; | 1130 | QString msg; |
1189 | msg.sprintf("%d, %d, %d", | 1131 | msg.sprintf("%d, %d, %d", |
1190 | filePara.sampleRate, | 1132 | filePara.sampleRate, |
1191 | filePara.channels, | 1133 | filePara.channels, |
1192 | filePara.resolution); | 1134 | filePara.resolution); |
1193 | #ifdef DEV_VERSION | 1135 | #ifdef DEV_VERSION |
1194 | setCaption( msg); | 1136 | setCaption( msg); |
1195 | #endif | 1137 | #endif |
1196 | 1138 | ||
1197 | startTimer( 1000); | 1139 | startTimer( 1000); |
1198 | #ifdef THREADED | 1140 | #ifdef THREADED |
1199 | pthread_t thread2; | 1141 | pthread_t thread2; |
1200 | pthread_create( &thread2, NULL, (void * (*)(void *))playIt, NULL/* &*/); | 1142 | pthread_create( &thread2, NULL, (void * (*)(void *))playIt, NULL/* &*/); |
1201 | #endif | 1143 | #endif |
1202 | 1144 | ||
1203 | toBeginningButton->setEnabled( false); | 1145 | toBeginningButton->setEnabled( false); |
1204 | toEndButton->setEnabled( false); | 1146 | toEndButton->setEnabled( false); |
1205 | #ifndef THREADED | 1147 | #ifndef THREADED |
1206 | playIt(); | 1148 | playIt(); |
1207 | #endif | 1149 | #endif |
1208 | return true; | 1150 | return true; |
1209 | } | 1151 | } |
1210 | 1152 | ||
1211 | 1153 | ||
1212 | void QtRec::changebitrateCombo(int i) { | 1154 | void QtRec::changebitrateCombo(int i) { |
1213 | Config cfg("OpieRec"); | 1155 | Config cfg("OpieRec"); |
1214 | cfg.setGroup("Settings"); | 1156 | cfg.setGroup("Settings"); |
1215 | int bits = 0; | 1157 | int bits = 0; |
1216 | if( i == 1) { bits = 16; } | 1158 | if( i == 1) { bits = 16; } |
1217 | else if( i == 2) { bits = 24; } | 1159 | else if( i == 2) { bits = 24; } |
1218 | else if( i == 3) { bits = 32; } | 1160 | else if( i == 3) { bits = 32; } |
1219 | else { bits=8; } | 1161 | else { bits=8; } |
1220 | cfg.writeEntry("bitrate", bits); | 1162 | cfg.writeEntry("bitrate", bits); |
1221 | filePara.resolution = bits; | 1163 | filePara.resolution = bits; |
1222 | cfg.write(); | 1164 | cfg.write(); |
1223 | } | 1165 | } |
1224 | 1166 | ||
1225 | void QtRec::changesamplerateCombo(int i) { | 1167 | void QtRec::changesamplerateCombo(int i) { |
1226 | Config cfg("OpieRec"); | 1168 | Config cfg("OpieRec"); |
1227 | cfg.setGroup("Settings"); | 1169 | cfg.setGroup("Settings"); |
1228 | int rate=0; | 1170 | int rate=0; |
1229 | bool ok; | 1171 | bool ok; |
1230 | rate = sampleRateComboBox->text(i).toInt(&ok, 10); | 1172 | rate = sampleRateComboBox->text(i).toInt(&ok, 10); |
1231 | cfg.writeEntry( "samplerate",rate); | 1173 | cfg.writeEntry( "samplerate",rate); |
1232 | filePara.sampleRate=rate; | 1174 | filePara.sampleRate=rate; |
1233 | odebug << "Change sample rate " << rate << "" << oendl; | 1175 | odebug << "Change sample rate " << rate << "" << oendl; |
1234 | cfg.write(); | 1176 | cfg.write(); |
1235 | } | 1177 | } |
1236 | 1178 | ||
1237 | 1179 | ||
1238 | void QtRec::changeDirCombo(int index) { | 1180 | void QtRec::changeDirCombo(int index) { |
1239 | Config cfg("OpieRec"); | 1181 | Config cfg("OpieRec"); |
1240 | cfg.setGroup("Settings"); | 1182 | cfg.setGroup("Settings"); |
1241 | QString sName = directoryComboBox->text(index); | 1183 | QString sName = directoryComboBox->text(index); |
1242 | 1184 | ||
1243 | StorageInfo storageInfo; | 1185 | StorageInfo storageInfo; |
1244 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 1186 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
1245 | QListIterator<FileSystem> it ( fs ); | 1187 | QListIterator<FileSystem> it ( fs ); |
1246 | QString storage; | 1188 | QString storage; |
1247 | for( ; it.current(); ++it ){ | 1189 | for( ; it.current(); ++it ){ |
1248 | if( sName == (*it)->name()+" "+ (*it)->path() || | 1190 | if( sName == (*it)->name()+" "+ (*it)->path() || |
1249 | (*it)->name() == sName ) { | 1191 | (*it)->name() == sName ) { |
1250 | const QString path = (*it)->path(); | 1192 | const QString path = (*it)->path(); |
1251 | recDir = path; | 1193 | recDir = path; |
1252 | cfg.writeEntry("directory", recDir); | 1194 | cfg.writeEntry("directory", recDir); |
1253 | odebug << "new rec dir "+recDir << oendl; | 1195 | odebug << "new rec dir "+recDir << oendl; |
1254 | } | 1196 | } |
1255 | } | 1197 | } |
1256 | cfg.write(); | 1198 | cfg.write(); |
1257 | } | 1199 | } |
1258 | 1200 | ||
1259 | 1201 | ||
1260 | void QtRec::changeSizeLimitCombo(int) { | 1202 | void QtRec::changeSizeLimitCombo(int) { |
1261 | Config cfg("OpieRec"); | 1203 | Config cfg("OpieRec"); |
1262 | cfg.setGroup("Settings"); | 1204 | cfg.setGroup("Settings"); |
1263 | cfg.writeEntry("sizeLimit", getCurrentSizeLimit() ); | 1205 | cfg.writeEntry("sizeLimit", getCurrentSizeLimit() ); |
1264 | cfg.write(); | 1206 | cfg.write(); |
1265 | } | 1207 | } |
1266 | 1208 | ||
1267 | void QtRec::newSound() { | 1209 | void QtRec::newSound() { |
1268 | if( !rec()) { | 1210 | if( !rec()) { |
1269 | endRecording(); | 1211 | endRecording(); |
1270 | deleteSound(); | 1212 | deleteSound(); |
1271 | } | 1213 | } |
1272 | } | 1214 | } |
1273 | 1215 | ||
1274 | void QtRec::itClick(QListViewItem *item) { | 1216 | void QtRec::itClick(QListViewItem *item) { |
1275 | currentFile = item->text(0); | 1217 | currentFile = item->text(0); |
1276 | setCaption("OpieRecord "+currentFile); | 1218 | setCaption("OpieRecord "+currentFile); |
1277 | } | 1219 | } |
1278 | 1220 | ||
1279 | void QtRec::deleteSound() { | 1221 | void QtRec::deleteSound() { |
1280 | Config cfg("OpieRec"); | 1222 | Config cfg("OpieRec"); |
1281 | cfg.setGroup("Sounds"); | 1223 | cfg.setGroup("Sounds"); |
1282 | if( ListView1->currentItem() == NULL) | 1224 | if( ListView1->currentItem() == NULL) |
1283 | return; | 1225 | return; |
1284 | #ifndef DEV_VERSION | 1226 | // #ifndef DEV_VERSION |
1285 | switch ( QMessageBox::warning(this,tr("Delete"), | 1227 | // switch ( QMessageBox::warning(this,tr("Delete"), |
1286 | tr("Do you really want to <font size=+2><B>DELETE</B></font>\nthe selected file?"), | 1228 | // tr("Do you really want to <font size=+2><B>DELETE</B></font>\nthe selected file?"), |
1287 | tr("Yes"),tr("No"),0,1,1) ) { | 1229 | // tr("Yes"),tr("No"),0,1,1) ) { |
1288 | case 0: | 1230 | // case 0: |
1289 | #endif | 1231 | // #endif |
1290 | { | 1232 | // { |
1291 | QString file = ListView1->currentItem()->text(0); | 1233 | QString file = ListView1->currentItem()->text(0); |
1292 | QString fileName; | 1234 | QString fileName; |
1293 | fileName = cfg.readEntry( file, ""); | 1235 | fileName = cfg.readEntry( file, ""); |
1294 | QFile f( fileName); | 1236 | QFile f( fileName); |
1295 | if( f.exists()) | 1237 | if( f.exists()) |
1296 | if( !f.remove()) | 1238 | if( !f.remove()) |
1297 | QMessageBox::message( tr("Error"), tr("Could not remove file.")); | 1239 | QMessageBox::message( tr("Error"), tr("Could not remove file.")); |
1298 | 1240 | ||
1299 | int nFiles = cfg.readNumEntry( "NumberofFiles",0); | 1241 | int nFiles = cfg.readNumEntry( "NumberofFiles",0); |
1300 | bool found = false; | 1242 | bool found = false; |
1301 | for(int i=0;i<nFiles+1;i++) { | 1243 | for(int i=0;i<nFiles+1;i++) { |
1302 | 1244 | ||
1303 | if( cfg.readEntry( QString::number(i),"").find( file,0,true) != -1) { | 1245 | if( cfg.readEntry( QString::number(i),"").find( file,0,true) != -1) { |
1304 | found = true; | 1246 | found = true; |
1305 | cfg.writeEntry( QString::number(i), cfg.readEntry( QString::number(i+1),"")); | 1247 | cfg.writeEntry( QString::number(i), cfg.readEntry( QString::number(i+1),"")); |
1306 | } | 1248 | } |
1307 | if(found) | 1249 | if(found) |
1308 | cfg.writeEntry( QString::number(i), cfg.readEntry( QString::number(i+1),"")); | 1250 | cfg.writeEntry( QString::number(i), cfg.readEntry( QString::number(i+1),"")); |
1309 | } | 1251 | } |
1310 | 1252 | ||
1311 | cfg.removeEntry( cfg.readEntry( file)); | 1253 | cfg.removeEntry( cfg.readEntry( file)); |
1312 | cfg.removeEntry( file); | 1254 | cfg.removeEntry( file); |
1313 | cfg.writeEntry( "NumberofFiles", nFiles-1); | 1255 | cfg.writeEntry( "NumberofFiles", nFiles-1); |
1314 | cfg.write(); | 1256 | cfg.write(); |
1315 | 1257 | ||
1316 | ListView1->takeItem( ListView1->currentItem() ); | 1258 | ListView1->takeItem( ListView1->currentItem() ); |
1317 | delete ListView1->currentItem(); | 1259 | delete ListView1->currentItem(); |
1318 | 1260 | ||
1319 | ListView1->clear(); | 1261 | ListView1->clear(); |
1320 | ListView1->setSelected( ListView1->firstChild(), true); | 1262 | ListView1->setSelected( ListView1->firstChild(), true); |
1321 | initIconView(); | 1263 | initIconView(); |
1322 | update(); | 1264 | update(); |
1323 | } | 1265 | setCaption( tr( "OpieRecord " )); |
1324 | #ifndef DEV_VERSION | ||
1325 | }; | ||
1326 | #endif | ||
1327 | setCaption( tr( "OpieRecord " ) + QString::number(VERSION) ); | ||
1328 | |||
1329 | } | 1266 | } |
1330 | 1267 | ||
1331 | void QtRec::keyPressEvent( QKeyEvent *e) { | 1268 | void QtRec::keyPressEvent( QKeyEvent *e) { |
1332 | 1269 | ||
1333 | switch ( e->key() ) { | 1270 | switch ( e->key() ) { |
1334 | // case Key_F1: | 1271 | // case Key_F1: |
1335 | // if(stopped && !recording) | 1272 | // if(stopped && !recording) |
1336 | // newSound(); | 1273 | // newSound(); |
1337 | // else | 1274 | // else |
1338 | // stop(); | 1275 | // stop(); |
1339 | // break; | 1276 | // break; |
1340 | // case Key_F2: { | 1277 | // case Key_F2: { |
1341 | // if( !e->isAutoRepeat()) | 1278 | // if( !e->isAutoRepeat()) |
1342 | // rewindPressed(); | 1279 | // rewindPressed(); |
1343 | // } | 1280 | // } |
1344 | // break; | 1281 | // break; |
1345 | // case Key_F3: { | 1282 | // case Key_F3: { |
1346 | // if( !e->isAutoRepeat()) | 1283 | // if( !e->isAutoRepeat()) |
1347 | // FastforwardPressed(); | 1284 | // FastforwardPressed(); |
1348 | // } | 1285 | // } |
1349 | // break; | 1286 | // break; |
1350 | 1287 | ||
1351 | ////////////////////////////// Zaurus keys | 1288 | ////////////////////////////// Zaurus keys |
1352 | case Key_F9: //activity | 1289 | case Key_F9: //activity |
1353 | break; | 1290 | break; |
1354 | case Key_F10: //contacts | 1291 | case Key_F10: //contacts |
1355 | break; | 1292 | break; |
1356 | case Key_F11: //menu | 1293 | case Key_F11: //menu |
1357 | break; | 1294 | break; |
1358 | case Key_F12: //home | 1295 | case Key_F12: //home |
1359 | break; | 1296 | break; |
1360 | case Key_F13: //mail | 1297 | case Key_F13: //mail |
1361 | break; | 1298 | break; |
1362 | case Key_Space: | 1299 | case Key_Space: |
1363 | break; | 1300 | break; |
1364 | case Key_Delete: | 1301 | case Key_Delete: |
1365 | break; | 1302 | break; |
1366 | case Key_Up: | 1303 | case Key_Up: |
1367 | // stop(); | 1304 | // stop(); |
1368 | break; | 1305 | break; |
1369 | case Key_Down: | 1306 | case Key_Down: |
1370 | // newSound(); | 1307 | // newSound(); |
1371 | break; | 1308 | break; |
1372 | case Key_Left: { | 1309 | case Key_Left: { |
1373 | odebug << "rewinding" << oendl; | 1310 | odebug << "rewinding" << oendl; |
1374 | if( !e->isAutoRepeat()) | 1311 | if( !e->isAutoRepeat()) |
1375 | rewindPressed(); | 1312 | rewindPressed(); |
1376 | } | 1313 | } |
1377 | break; | 1314 | break; |
1378 | case Key_Right: { | 1315 | case Key_Right: { |
1379 | if( !e->isAutoRepeat()) | 1316 | if( !e->isAutoRepeat()) |
1380 | FastforwardPressed(); | 1317 | FastforwardPressed(); |
1381 | } | 1318 | } |
1382 | break; | 1319 | break; |
1383 | } | 1320 | } |
1384 | } | 1321 | } |
1385 | 1322 | ||
1386 | void QtRec::keyReleaseEvent( QKeyEvent *e) { | 1323 | void QtRec::keyReleaseEvent( QKeyEvent *e) { |
1387 | switch ( e->key() ) { | 1324 | switch ( e->key() ) { |
1388 | // case Key_F1: | 1325 | // case Key_F1: |
1389 | // if(stopped && !recording) | 1326 | // if(stopped && !recording) |
1390 | // newSound(); | 1327 | // newSound(); |
1391 | // else | 1328 | // else |
1392 | // stop(); | 1329 | // stop(); |
1393 | // break; | 1330 | // break; |
1394 | // case Key_F2: | 1331 | // case Key_F2: |
1395 | // rewindReleased(); | 1332 | // rewindReleased(); |
1396 | // break; | 1333 | // break; |
1397 | // case Key_F3: | 1334 | // case Key_F3: |
1398 | // FastforwardReleased(); | 1335 | // FastforwardReleased(); |
1399 | // break; | 1336 | // break; |
1400 | 1337 | ||
1401 | ////////////////////////////// Zaurus keys | 1338 | ////////////////////////////// Zaurus keys |
1402 | case Key_F9: //activity | 1339 | case Key_F9: //activity |
1403 | break; | 1340 | break; |
1404 | case Key_F10: //contacts | 1341 | case Key_F10: //contacts |
1405 | break; | 1342 | break; |
1406 | case Key_F11: //menu | 1343 | case Key_F11: //menu |
1407 | break; | 1344 | break; |
1408 | case Key_F12: //home | 1345 | case Key_F12: //home |
1409 | if(stopped) | 1346 | if(stopped) |
1410 | doPlayBtn(); | 1347 | doPlayBtn(); |
1411 | else | 1348 | else |
1412 | stop(); | 1349 | stop(); |
1413 | break; | 1350 | break; |
1414 | case Key_F13: //mail | 1351 | case Key_F13: //mail |
1415 | break; | 1352 | break; |
1416 | case Key_Space: | 1353 | case Key_Space: |
1417 | if(stopped && !recording) | 1354 | if(stopped && !recording) |
1418 | newSound(); | 1355 | newSound(); |
1419 | else | 1356 | else |
1420 | stop(); | 1357 | stop(); |
1421 | break; | 1358 | break; |
1422 | case Key_Delete: | 1359 | case Key_Delete: |
1423 | deleteSound(); | 1360 | deleteSound(); |
1424 | break; | 1361 | break; |
1425 | case Key_Up: | 1362 | case Key_Up: |
1426 | // stop(); | 1363 | // stop(); |
1427 | odebug << "Up" << oendl; | 1364 | odebug << "Up" << oendl; |
1428 | break; | 1365 | break; |
1429 | case Key_Down: | 1366 | case Key_Down: |
1430 | // start(); | 1367 | // start(); |
1431 | // odebug << "Down" << oendl; | 1368 | // odebug << "Down" << oendl; |
1432 | // newSound(); | 1369 | // newSound(); |
1433 | break; | 1370 | break; |
1434 | case Key_Left: | 1371 | case Key_Left: |
1435 | odebug << "Left" << oendl; | 1372 | odebug << "Left" << oendl; |
1436 | rewindReleased(); | 1373 | rewindReleased(); |
1437 | break; | 1374 | break; |
1438 | case Key_Right: | 1375 | case Key_Right: |
1439 | odebug << "Right" << oendl; | 1376 | odebug << "Right" << oendl; |
1440 | FastforwardReleased(); | 1377 | FastforwardReleased(); |
1441 | break; | 1378 | break; |
1442 | } | 1379 | } |
1443 | } | 1380 | } |
1444 | 1381 | ||
1445 | void QtRec::endRecording() { | 1382 | void QtRec::endRecording() { |
1383 | |||
1446 | monitoring = false; | 1384 | monitoring = false; |
1447 | recording = false; | 1385 | recording = false; |
1448 | stopped = true; | 1386 | stopped = true; |
1449 | waveform->reset(); | 1387 | waveform->reset(); |
1450 | setRecordButton( false); | 1388 | setRecordButton( false); |
1451 | 1389 | ||
1452 | toBeginningButton->setEnabled( true); | 1390 | toBeginningButton->setEnabled( true); |
1453 | toEndButton->setEnabled( true); | 1391 | toEndButton->setEnabled( true); |
1454 | 1392 | ||
1455 | killTimers(); | 1393 | killTimers(); |
1456 | 1394 | ||
1457 | if(autoMute) | 1395 | if(autoMute) |
1458 | doMute( true); | 1396 | doMute( true); |
1459 | 1397 | ||
1460 | soundDevice->closeDevice( true); | 1398 | soundDevice->closeDevice( true); |
1461 | 1399 | ||
1462 | if( wavFile->track.isOpen()) { | 1400 | if( wavFile->track.isOpen()) { |
1463 | wavFile->adjustHeaders( filePara.fd, filePara.numberSamples); | 1401 | wavFile->adjustHeaders( filePara.fd, filePara.numberSamples); |
1464 | // soundDevice->sd=-1; | 1402 | // soundDevice->sd=-1; |
1465 | filePara.numberSamples = 0; | 1403 | filePara.numberSamples = 0; |
1466 | // filePara.sd=-1; | 1404 | // filePara.sd=-1; |
1467 | wavFile->closeFile(); | 1405 | wavFile->closeFile(); |
1468 | filePara.fd=0; | 1406 | filePara.fd=0; |
1469 | 1407 | ||
1470 | if( wavFile->isTempFile()) { | 1408 | if( wavFile->isTempFile()) { |
1471 | // move tmp file to regular file | 1409 | // move tmp file to regular file |
1472 | QString cmd; | 1410 | QString cmd; |
1473 | cmd.sprintf("mv "+ wavFile->trackName() + " " + wavFile->currentFileName); | 1411 | cmd.sprintf("mv "+ wavFile->trackName() + " " + wavFile->currentFileName); |
1474 | odebug << "moving tmp file to "+currentFileName << oendl; | 1412 | odebug << "moving tmp file to "+currentFileName << oendl; |
1475 | system( cmd.latin1()); | 1413 | system( cmd.latin1()); |
1476 | } | 1414 | } |
1477 | 1415 | ||
1478 | odebug << "Just moved " + wavFile->currentFileName << oendl; | 1416 | odebug << "Just moved " + wavFile->currentFileName << oendl; |
1479 | Config cfg("OpieRec"); | 1417 | Config cfg("OpieRec"); |
1480 | cfg.setGroup("Sounds"); | 1418 | cfg.setGroup("Sounds"); |
1481 | 1419 | ||
1482 | int nFiles = cfg.readNumEntry( "NumberofFiles",0); | 1420 | int nFiles = cfg.readNumEntry( "NumberofFiles",0); |
1483 | 1421 | ||
1484 | currentFile = QFileInfo( wavFile->currentFileName).fileName(); | 1422 | currentFile = QFileInfo( wavFile->currentFileName).fileName(); |
1485 | currentFile = currentFile.left( currentFile.length() - 4); | 1423 | currentFile = currentFile.left( currentFile.length() - 4); |
1486 | 1424 | ||
1487 | cfg.writeEntry( "NumberofFiles", nFiles + 1); | 1425 | cfg.writeEntry( "NumberofFiles", nFiles + 1); |
1488 | cfg.writeEntry( QString::number( nFiles + 1), currentFile); | 1426 | cfg.writeEntry( QString::number( nFiles + 1), currentFile); |
1489 | cfg.writeEntry( currentFile, wavFile->currentFileName); | 1427 | cfg.writeEntry( currentFile, wavFile->currentFileName); |
1490 | 1428 | ||
1491 | QString time; | 1429 | QString time; |
1492 | time.sprintf("%.2f", filePara.numberOfRecordedSeconds); | 1430 | time.sprintf("%.2f", filePara.numberOfRecordedSeconds); |
1493 | cfg.writeEntry( wavFile->currentFileName, time ); | 1431 | cfg.writeEntry( wavFile->currentFileName, time ); |
1494 | odebug << "writing config numberOfRecordedSeconds "+time << oendl; | 1432 | odebug << "writing config numberOfRecordedSeconds "+time << oendl; |
1495 | 1433 | ||
1496 | cfg.write(); | 1434 | cfg.write(); |
1497 | odebug << "finished recording" << oendl; | 1435 | odebug << "finished recording" << oendl; |
1498 | // timeLabel->setText(""); | 1436 | // timeLabel->setText(""); |
1499 | } | 1437 | } |
1500 | 1438 | ||
1501 | // if(soundDevice) delete soundDevice; | 1439 | // if(soundDevice) delete soundDevice; |
1502 | 1440 | ||
1503 | timeSlider->setValue(0); | 1441 | timeSlider->setValue(0); |
1504 | initIconView(); | 1442 | initIconView(); |
1505 | selectItemByName( currentFile); | 1443 | selectItemByName( currentFile); |
1444 | setCaption( tr( "OpieRecord " )); | ||
1445 | |||
1506 | } | 1446 | } |
1507 | 1447 | ||
1508 | void QtRec::endPlaying() { | 1448 | void QtRec::endPlaying() { |
1509 | monitoring = false; | 1449 | monitoring = false; |
1510 | recording = false; | 1450 | recording = false; |
1511 | playing = false; | 1451 | playing = false; |
1512 | stopped = true; | 1452 | stopped = true; |
1513 | waveform->reset(); | 1453 | waveform->reset(); |
1514 | // errorStop(); | 1454 | // errorStop(); |
1515 | odebug << "end playing" << oendl; | 1455 | odebug << "end playing" << oendl; |
1516 | setRecordButton( false); | 1456 | setRecordButton( false); |
1517 | 1457 | ||
1518 | toBeginningButton->setEnabled( true); | 1458 | toBeginningButton->setEnabled( true); |
1519 | toEndButton->setEnabled( true); | 1459 | toEndButton->setEnabled( true); |
1520 | 1460 | ||
1521 | if(autoMute) | 1461 | if(autoMute) |
1522 | doMute( true); | 1462 | doMute( true); |
1523 | 1463 | ||
1524 | soundDevice->closeDevice( false); | 1464 | soundDevice->closeDevice( false); |
1525 | soundDevice->sd = -1; | 1465 | soundDevice->sd = -1; |
1526 | // if(soundDevice) delete soundDevice; | 1466 | // if(soundDevice) delete soundDevice; |
1527 | odebug << "file and sound device closed" << oendl; | 1467 | odebug << "file and sound device closed" << oendl; |
1528 | // timeLabel->setText(""); | 1468 | // timeLabel->setText(""); |
1529 | total = 0; | 1469 | total = 0; |
1530 | filePara.numberSamples = 0; | 1470 | filePara.numberSamples = 0; |
1531 | filePara.sd = -1; | 1471 | filePara.sd = -1; |
1532 | // wavFile->closeFile(); | 1472 | // wavFile->closeFile(); |
1533 | filePara.fd = 0; | 1473 | filePara.fd = 0; |
1534 | // if(wavFile) delete wavFile; //this crashes | 1474 | // if(wavFile) delete wavFile; //this crashes |
1535 | 1475 | ||
1536 | odebug << "track closed" << oendl; | 1476 | odebug << "track closed" << oendl; |
1537 | killTimers(); | 1477 | killTimers(); |
1538 | owarn << "reset slider" << oendl; | 1478 | // owarn << "reset slider" << oendl; |
1539 | timeSlider->setValue(0); | 1479 | timeSlider->setValue(0); |
1540 | 1480 | ||
1541 | // if(soundDevice) delete soundDevice; | 1481 | // if(soundDevice) delete soundDevice; |
1542 | 1482 | ||
1543 | } | 1483 | } |
1544 | 1484 | ||
1545 | bool QtRec::openPlayFile() { | 1485 | bool QtRec::openPlayFile() { |
1546 | 1486 | ||
1547 | qApp->processEvents(); | 1487 | qApp->processEvents(); |
1548 | if( currentFile.isEmpty()) { | 1488 | if( currentFile.isEmpty()) { |
1549 | QMessageBox::message(tr("Opierec"),tr("Please select file to play")); | 1489 | QMessageBox::message(tr("Opierec"),tr("Please select file to play")); |
1550 | endPlaying(); | 1490 | endPlaying(); |
1551 | return false; | 1491 | return false; |
1552 | } | 1492 | } |
1553 | QString currentFileName; | 1493 | QString currentFileName; |
1554 | Config cfg("OpieRec"); | 1494 | Config cfg("OpieRec"); |
1555 | cfg.setGroup("Sounds"); | 1495 | cfg.setGroup("Sounds"); |
1556 | int nFiles = cfg.readNumEntry( "NumberofFiles", 0); | 1496 | int nFiles = cfg.readNumEntry( "NumberofFiles", 0); |
1557 | for(int i=0;i<nFiles+1;i++) { //look for file | 1497 | for(int i=0;i<nFiles+1;i++) { //look for file |
1558 | if( cfg.readEntry( QString::number(i),"").find( currentFile,0,true) != -1) { | 1498 | if( cfg.readEntry( QString::number(i),"").find( currentFile,0,true) != -1) { |
1559 | currentFileName = cfg.readEntry( currentFile, "" ); | 1499 | currentFileName = cfg.readEntry( currentFile, "" ); |
1560 | odebug << "opening for play: " + currentFileName << oendl; | 1500 | odebug << "opening for play: " + currentFileName << oendl; |
1561 | } | 1501 | } |
1562 | } | 1502 | } |
1563 | wavFile = new WavFile(this, | 1503 | wavFile = new WavFile(this, |
1564 | currentFileName, | 1504 | currentFileName, |
1565 | false); | 1505 | false); |
1566 | filePara.fd = wavFile->wavHandle(); | 1506 | filePara.fd = wavFile->wavHandle(); |
1567 | if(filePara.fd == -1) { | 1507 | if(filePara.fd == -1) { |
1568 | // if(!track.open(IO_ReadOnly)) { | 1508 | // if(!track.open(IO_ReadOnly)) { |
1569 | QString errorMsg = (QString)strerror(errno); | 1509 | QString errorMsg = (QString)strerror(errno); |
1570 | monitoring = false; | 1510 | monitoring = false; |
1571 | setCaption( tr( "OpieRecord " ) + QString::number(VERSION) ); | 1511 | setCaption( tr( "OpieRecord " )); |
1572 | QMessageBox::message(tr("Note"), tr("Could not open audio file.\n") | 1512 | QMessageBox::message(tr("Note"), tr("Could not open audio file.\n") |
1573 | + errorMsg + "\n" + currentFile); | 1513 | + errorMsg + "\n" + currentFile); |
1574 | return false; | 1514 | return false; |
1575 | } else { | 1515 | } else { |
1576 | 1516 | ||
1577 | filePara.numberSamples = wavFile->getNumberSamples(); | 1517 | filePara.numberSamples = wavFile->getNumberSamples(); |
1578 | filePara.format = wavFile->getFormat(); | 1518 | filePara.format = wavFile->getFormat(); |
1579 | filePara.sampleRate = wavFile->getSampleRate(); | 1519 | filePara.sampleRate = wavFile->getSampleRate(); |
1580 | filePara.resolution = wavFile->getResolution(); | 1520 | filePara.resolution = wavFile->getResolution(); |
1581 | filePara.channels = wavFile->getChannels(); | 1521 | filePara.channels = wavFile->getChannels(); |
1582 | timeSlider->setPageStep(1); | 1522 | timeSlider->setPageStep(1); |
1583 | monitoring = true; | 1523 | monitoring = true; |
1584 | 1524 | ||
1585 | odebug << "file " << filePara.fd << ", samples " << filePara.numberSamples << " " << filePara.sampleRate << "" << oendl; | 1525 | odebug << "file " << filePara.fd << ", samples " << filePara.numberSamples << " " << filePara.sampleRate << "" << oendl; |
1586 | int sec = (int) (( filePara.numberSamples / filePara.sampleRate) / filePara.channels) / ( filePara.channels*( filePara.resolution/8)); | 1526 | int sec = (int) (( filePara.numberSamples / filePara.sampleRate) / filePara.channels) / ( filePara.channels*( filePara.resolution/8)); |
1587 | 1527 | ||
1588 | owarn << "seconds " << sec << "" << oendl; | 1528 | // owarn << "seconds " << sec << "" << oendl; |
1589 | 1529 | ||
1590 | timeSlider->setRange(0, filePara.numberSamples ); | 1530 | timeSlider->setRange(0, filePara.numberSamples ); |
1591 | } | 1531 | } |
1592 | 1532 | ||
1593 | return true; | 1533 | return true; |
1594 | } | 1534 | } |
1595 | 1535 | ||
1596 | void QtRec::listPressed( int mouse, QListViewItem *item, const QPoint &, int ) { | 1536 | void QtRec::listPressed( int mouse, QListViewItem *item, const QPoint &, int ) { |
1597 | if(item == NULL ) | 1537 | if(item == NULL ) |
1598 | return; | 1538 | return; |
1599 | switch (mouse) { | 1539 | switch (mouse) { |
1600 | case 1: { | 1540 | case 1: { |
1601 | if( renameBox != 0 ) //tricky | 1541 | if( renameBox != 0 ) //tricky |
1602 | cancelRename(); | 1542 | cancelRename(); |
1603 | 1543 | ||
1604 | currentFile = item->text(0); | 1544 | currentFile = item->text(0); |
1605 | setCaption( "OpieRecord " + currentFile); | 1545 | // setCaption( "OpieRecord " + currentFile); |
1606 | } | 1546 | } |
1607 | break; | 1547 | break; |
1608 | case 2: | 1548 | case 2: |
1609 | showListMenu(item); | 1549 | showListMenu(item); |
1610 | ListView1->clearSelection(); | 1550 | ListView1->clearSelection(); |
1611 | break; | 1551 | break; |
1612 | }; | 1552 | }; |
1613 | } | 1553 | } |
1614 | 1554 | ||
1615 | void QtRec::showListMenu(QListViewItem * item) { | 1555 | void QtRec::showListMenu(QListViewItem * item) { |
1616 | if(item == NULL) | 1556 | if(item == NULL) |
1617 | return; | 1557 | return; |
1618 | QPopupMenu *m = new QPopupMenu(this); | 1558 | QPopupMenu *m = new QPopupMenu(this); |
1619 | m->insertItem( tr("Play"), this, SLOT( doMenuPlay() )); | 1559 | m->insertItem( tr("Play"), this, SLOT( doMenuPlay() )); |
1620 | if(Ir::supported()) m->insertItem( tr( "Send with Ir" ), this, SLOT( doBeam() )); | 1560 | if(Ir::supported()) m->insertItem( tr( "Send with Ir" ), this, SLOT( doBeam() )); |
1621 | m->insertItem( tr( "Rename" ), this, SLOT( doRename() )); | 1561 | m->insertItem( tr( "Rename" ), this, SLOT( doRename() )); |
1622 | // #if defined (QTOPIA_INTERNAL_FSLP) | 1562 | // #if defined (QTOPIA_INTERNAL_FSLP) |
1623 | // m->insertItem( tr( "Properties" ), this, SLOT( doProperties() )); | 1563 | // m->insertItem( tr( "Properties" ), this, SLOT( doProperties() )); |
1624 | // #endif | 1564 | // #endif |
1625 | m->insertSeparator(); | 1565 | m->insertSeparator(); |
1626 | m->insertItem( tr("Delete"), this, SLOT( deleteSound() ) ); | 1566 | m->insertItem( tr("Delete"), this, SLOT( deleteSound() ) ); |
1627 | m->exec( QCursor::pos() ); | 1567 | m->exec( QCursor::pos() ); |
1628 | qApp->processEvents(); | 1568 | qApp->processEvents(); |
1629 | } | 1569 | } |
1630 | 1570 | ||
1631 | void QtRec::fileBeamFinished( Ir *ir) { | 1571 | void QtRec::fileBeamFinished( Ir *ir) { |
1632 | if(ir) | 1572 | if(ir) |
1633 | QMessageBox::message( tr("Ir Beam out"), tr("Ir sent.") ,tr("Ok") ); | 1573 | QMessageBox::message( tr("Ir Beam out"), tr("Ir sent.") ,tr("Ok") ); |
1634 | 1574 | ||
1635 | } | 1575 | } |
1636 | 1576 | ||
1637 | void QtRec::doBeam() { | 1577 | void QtRec::doBeam() { |
1638 | qApp->processEvents(); | 1578 | qApp->processEvents(); |
1639 | if( ListView1->currentItem() == NULL) | 1579 | if( ListView1->currentItem() == NULL) |
1640 | return; | 1580 | return; |
1641 | Ir ir; | 1581 | Ir ir; |
1642 | if( ir.supported()) { | 1582 | if( ir.supported()) { |
1643 | QString file = ListView1->currentItem()->text(0); | 1583 | QString file = ListView1->currentItem()->text(0); |
1644 | Config cfg("OpieRec"); | 1584 | Config cfg("OpieRec"); |
1645 | cfg.setGroup("Sounds"); | 1585 | cfg.setGroup("Sounds"); |
1646 | 1586 | ||
1647 | int nFiles = cfg.readNumEntry("NumberofFiles",0); | 1587 | int nFiles = cfg.readNumEntry("NumberofFiles",0); |
1648 | 1588 | ||
1649 | for(int i=0;i<nFiles+1;i++) { | 1589 | for(int i=0;i<nFiles+1;i++) { |
1650 | if( cfg.readEntry( QString::number( i),"").find( file, 0, true) != -1) { | 1590 | if( cfg.readEntry( QString::number( i),"").find( file, 0, true) != -1) { |
1651 | QString filePath = cfg.readEntry(file,""); | 1591 | QString filePath = cfg.readEntry(file,""); |
1652 | Ir *file = new Ir(this, "IR"); | 1592 | Ir *file = new Ir(this, "IR"); |
1653 | connect( file, SIGNAL( done(Ir*)), | 1593 | connect( file, SIGNAL( done(Ir*)), |
1654 | this, SLOT( fileBeamFinished(Ir*))); | 1594 | this, SLOT( fileBeamFinished(Ir*))); |
1655 | file->send( filePath, "OPieRec audio file\n" + filePath ); | 1595 | file->send( filePath, "OPieRec audio file\n" + filePath ); |
1656 | } | 1596 | } |
1657 | } | 1597 | } |
1658 | } | 1598 | } |
1659 | } | 1599 | } |
1660 | 1600 | ||
1661 | void QtRec::doMenuPlay() { | 1601 | void QtRec::doMenuPlay() { |
1662 | qApp->processEvents(); | 1602 | qApp->processEvents(); |
1663 | currentFile = ListView1->currentItem()->text(0); | 1603 | currentFile = ListView1->currentItem()->text(0); |
1664 | } | 1604 | } |
1665 | 1605 | ||
1666 | void QtRec::doRename() { | 1606 | void QtRec::doRename() { |
1667 | QRect r = ListView1->itemRect( ListView1->currentItem( )); | 1607 | QRect r = ListView1->itemRect( ListView1->currentItem( )); |
1668 | r = QRect( ListView1->viewportToContents( r.topLeft() ), r.size() ); | 1608 | r = QRect( ListView1->viewportToContents( r.topLeft() ), r.size() ); |
1669 | r.setX( ListView1->contentsX() ); | 1609 | r.setX( ListView1->contentsX() ); |
1670 | if ( r.width() > ListView1->visibleWidth() ) | 1610 | if ( r.width() > ListView1->visibleWidth() ) |
1671 | r.setWidth( ListView1->visibleWidth() ); | 1611 | r.setWidth( ListView1->visibleWidth() ); |
1672 | 1612 | ||
1673 | renameBox = new QLineEdit( ListView1->viewport(), "qt_renamebox" ); | 1613 | renameBox = new QLineEdit( ListView1->viewport(), "qt_renamebox" ); |
1674 | renameBox->setFrame(true); | 1614 | renameBox->setFrame(true); |
1675 | 1615 | ||
1676 | renameBox->setText( ListView1->currentItem()->text(0) ); | 1616 | renameBox->setText( ListView1->currentItem()->text(0) ); |
1677 | 1617 | ||
1678 | renameBox->selectAll(); | 1618 | renameBox->selectAll(); |
1679 | renameBox->installEventFilter( this ); | 1619 | renameBox->installEventFilter( this ); |
1680 | ListView1->addChild( renameBox, r.x(), r.y() ); | 1620 | ListView1->addChild( renameBox, r.x(), r.y() ); |
1681 | renameBox->resize( r.size() ); | 1621 | renameBox->resize( r.size() ); |
1682 | ListView1->viewport()->setFocusProxy( renameBox ); | 1622 | ListView1->viewport()->setFocusProxy( renameBox ); |
1683 | renameBox->setFocus(); | 1623 | renameBox->setFocus(); |
1684 | renameBox->show(); | 1624 | renameBox->show(); |
1685 | 1625 | ||
1686 | } | 1626 | } |
1687 | 1627 | ||
1688 | void QtRec::okRename() { | 1628 | void QtRec::okRename() { |
1689 | odebug << renameBox->text() << oendl; | 1629 | odebug << renameBox->text() << oendl; |
1690 | QString filename = renameBox->text(); | 1630 | QString filename = renameBox->text(); |
1691 | cancelRename(); | 1631 | cancelRename(); |
1692 | 1632 | ||
1693 | if( ListView1->currentItem() == NULL) | 1633 | if( ListView1->currentItem() == NULL) |
1694 | return; | 1634 | return; |
1695 | 1635 | ||
1696 | Config cfg("OpieRec"); | 1636 | Config cfg("OpieRec"); |
1697 | cfg.setGroup("Sounds"); | 1637 | cfg.setGroup("Sounds"); |
1698 | 1638 | ||
1699 | QString file = ListView1->currentItem()->text(0); | 1639 | QString file = ListView1->currentItem()->text(0); |
1700 | 1640 | ||
1701 | odebug << "filename is " + filename << oendl; | 1641 | odebug << "filename is " + filename << oendl; |
1702 | 1642 | ||
1703 | int nFiles = cfg.readNumEntry("NumberofFiles",0); | 1643 | int nFiles = cfg.readNumEntry("NumberofFiles",0); |
1704 | 1644 | ||
1705 | for(int i=0;i<nFiles+1;i++) { //look for file | 1645 | for(int i=0;i<nFiles+1;i++) { //look for file |
1706 | if( cfg.readEntry( QString::number(i),"").find(file,0,true) != -1) { | 1646 | if( cfg.readEntry( QString::number(i),"").find(file,0,true) != -1) { |
1707 | 1647 | ||
1708 | QString filePath = cfg.readEntry(file,""); | 1648 | QString filePath = cfg.readEntry(file,""); |
1709 | 1649 | ||
1710 | cfg.writeEntry( QString::number(i), filename ); | 1650 | cfg.writeEntry( QString::number(i), filename ); |
1711 | cfg.writeEntry( filename, filePath ); | 1651 | cfg.writeEntry( filename, filePath ); |
1712 | cfg.removeEntry( file); | 1652 | cfg.removeEntry( file); |
1713 | cfg.write(); | 1653 | cfg.write(); |
1714 | } | 1654 | } |
1715 | } | 1655 | } |
1716 | 1656 | ||
1717 | ListView1->takeItem( ListView1->currentItem() ); | 1657 | ListView1->takeItem( ListView1->currentItem() ); |
1718 | delete ListView1->currentItem(); | 1658 | delete ListView1->currentItem(); |
1719 | ListView1->clear(); | 1659 | ListView1->clear(); |
1720 | initIconView(); | 1660 | initIconView(); |
1721 | update(); | 1661 | update(); |
1722 | } | 1662 | } |
1723 | 1663 | ||
1724 | void QtRec::cancelRename() { | 1664 | void QtRec::cancelRename() { |
1725 | bool resetFocus = ListView1->viewport()->focusProxy() == renameBox; | 1665 | bool resetFocus = ListView1->viewport()->focusProxy() == renameBox; |
1726 | delete renameBox; | 1666 | delete renameBox; |
1727 | renameBox = 0; | 1667 | renameBox = 0; |
1728 | if ( resetFocus ) { | 1668 | if ( resetFocus ) { |
1729 | ListView1->viewport()->setFocusProxy( ListView1 ); | 1669 | ListView1->viewport()->setFocusProxy( ListView1 ); |
1730 | ListView1->setFocus(); | 1670 | ListView1->setFocus(); |
1731 | } | 1671 | } |
1732 | } | 1672 | } |
1733 | 1673 | ||
1734 | bool QtRec::eventFilter( QObject * o, QEvent * e ) { | 1674 | bool QtRec::eventFilter( QObject * o, QEvent * e ) { |
1735 | if ( o->inherits( "QLineEdit" ) ) { | 1675 | if ( o->inherits( "QLineEdit" ) ) { |
1736 | if ( e->type() == QEvent::KeyPress ) { | 1676 | if ( e->type() == QEvent::KeyPress ) { |
1737 | QKeyEvent *ke = (QKeyEvent*)e; | 1677 | QKeyEvent *ke = (QKeyEvent*)e; |
1738 | if ( ke->key() == Key_Return || | 1678 | if ( ke->key() == Key_Return || |
1739 | ke->key() == Key_Enter ) { | 1679 | ke->key() == Key_Enter ) { |
1740 | okRename(); | 1680 | okRename(); |
1741 | return true; | 1681 | return true; |
1742 | } else if ( ke->key() == Key_Escape ) { | 1682 | } else if ( ke->key() == Key_Escape ) { |
1743 | cancelRename(); | 1683 | cancelRename(); |
1744 | return true; | 1684 | return true; |
1745 | } | 1685 | } |
1746 | } else if ( e->type() == QEvent::FocusOut ) { | 1686 | } else if ( e->type() == QEvent::FocusOut ) { |
1747 | cancelRename(); | 1687 | cancelRename(); |
1748 | return true; | 1688 | return true; |
1749 | } | 1689 | } |
1750 | } | 1690 | } |
1751 | return QWidget::eventFilter( o, e ); | 1691 | return QWidget::eventFilter( o, e ); |
1752 | } | 1692 | } |
1753 | 1693 | ||
1754 | 1694 | ||
1755 | int QtRec::getCurrentSizeLimit() { | 1695 | int QtRec::getCurrentSizeLimit() { |
1756 | return sizeLimitCombo->currentItem() * 5; | 1696 | return sizeLimitCombo->currentItem() * 5; |
1757 | } | 1697 | } |
1758 | 1698 | ||
1759 | void QtRec::timerBreak() { | 1699 | void QtRec::timerBreak() { |
1760 | endPlaying(); | 1700 | endPlaying(); |
1761 | } | 1701 | } |
1762 | 1702 | ||
1763 | void QtRec::doVolMuting(bool b) { | 1703 | void QtRec::doVolMuting(bool b) { |
1764 | Config cfg( "qpe" ); | 1704 | Config cfg( "qpe" ); |
1765 | cfg. setGroup( "Volume" ); | 1705 | cfg. setGroup( "Volume" ); |
1766 | cfg.writeEntry( "Mute",b); | 1706 | cfg.writeEntry( "Mute",b); |
1767 | cfg.write(); | 1707 | cfg.write(); |
1768 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << b; | 1708 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << b; |
1769 | } | 1709 | } |
1770 | 1710 | ||
1771 | void QtRec::doMicMuting(bool b) { | 1711 | void QtRec::doMicMuting(bool b) { |
1772 | // odebug << "mic mute" << oendl; | 1712 | // odebug << "mic mute" << oendl; |
1773 | Config cfg( "qpe" ); | 1713 | Config cfg( "qpe" ); |
1774 | cfg. setGroup( "Volume" ); | 1714 | cfg. setGroup( "Volume" ); |
1775 | cfg.writeEntry( "MicMute",b); | 1715 | cfg.writeEntry( "MicMute",b); |
1776 | cfg.write(); | 1716 | cfg.write(); |
1777 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << b; | 1717 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << b; |
1778 | } | 1718 | } |
1779 | 1719 | ||
1780 | void QtRec::compressionSelected(bool b) { | 1720 | void QtRec::compressionSelected(bool b) { |
1781 | Config cfg("OpieRec"); | 1721 | Config cfg("OpieRec"); |
1782 | cfg.setGroup("Settings"); | 1722 | cfg.setGroup("Settings"); |
1783 | cfg.writeEntry("wavCompression", b); | 1723 | cfg.writeEntry("wavCompression", b); |
1784 | cfg.writeEntry("bitrate", 16); | 1724 | cfg.writeEntry("bitrate", 16); |
1785 | filePara.resolution = 16; | 1725 | filePara.resolution = 16; |
1786 | cfg.write(); | 1726 | cfg.write(); |
1787 | 1727 | ||
1788 | if(b) { | 1728 | if(b) { |
1789 | bitRateComboBox->setEnabled( false); | 1729 | bitRateComboBox->setEnabled( false); |
1790 | bitRateComboBox->setCurrentItem( 1); | 1730 | bitRateComboBox->setCurrentItem( 1); |
1791 | filePara.resolution = 16; | 1731 | filePara.resolution = 16; |
1792 | } else{ | 1732 | } else{ |
1793 | bitRateComboBox->setEnabled( true); | 1733 | bitRateComboBox->setEnabled( true); |
1794 | } | 1734 | } |
1795 | } | 1735 | } |
1796 | 1736 | ||
1797 | long QtRec::checkDiskSpace(const QString &path) { | 1737 | long QtRec::checkDiskSpace(const QString &path) { |
1798 | 1738 | ||
1799 | struct statfs fs; | 1739 | struct statfs fs; |
1800 | 1740 | ||
1801 | if ( !statfs( path.latin1(), &fs ) ) { | 1741 | if ( !statfs( path.latin1(), &fs ) ) { |
1802 | 1742 | ||
1803 | int blkSize = fs.f_bsize; | 1743 | int blkSize = fs.f_bsize; |
1804 | int availBlks = fs.f_bavail; | 1744 | int availBlks = fs.f_bavail; |
1805 | 1745 | ||
1806 | long mult = blkSize / 1024; | 1746 | long mult = blkSize / 1024; |
1807 | long div = 1024 / blkSize; | 1747 | long div = 1024 / blkSize; |
1808 | 1748 | ||
1809 | if ( !mult ) mult = 1; | 1749 | if ( !mult ) mult = 1; |
1810 | if ( !div ) div = 1; | 1750 | if ( !div ) div = 1; |
1811 | 1751 | ||
1812 | return availBlks * mult / div; | 1752 | return availBlks * mult / div; |
1813 | } | 1753 | } |
1814 | return -1; | 1754 | return -1; |
1815 | } | 1755 | } |
1816 | 1756 | ||
1817 | // short f_fstyp; /* File system type */ | 1757 | // short f_fstyp; /* File system type */ |
1818 | // long f_bsize; /* Block size */ | 1758 | // long f_bsize; /* Block size */ |
1819 | // long f_frsize; /* Fragment size */ | 1759 | // long f_frsize; /* Fragment size */ |
1820 | // long f_blocks; /* Total number of blocks*/ | 1760 | // long f_blocks; /* Total number of blocks*/ |
1821 | // long f_bfree; /* Count of free blocks */ | 1761 | // long f_bfree; /* Count of free blocks */ |
1822 | // long f_files; /* Total number of file nodes */ | 1762 | // long f_files; /* Total number of file nodes */ |
1823 | // long f_ffree; /* Count of free file nodes */ | 1763 | // long f_ffree; /* Count of free file nodes */ |
1824 | // char f_fname[6]; /* Volumename */ | 1764 | // char f_fname[6]; /* Volumename */ |
1825 | // char f_fpack[6]; /* Pack name */ | 1765 | // char f_fpack[6]; /* Pack name */ |
1826 | 1766 | ||
1827 | void QtRec::receive( const QCString &msg, const QByteArray & ) { | 1767 | void QtRec::receive( const QCString &msg, const QByteArray & ) { |
1828 | odebug << "Voicerecord received message "+msg << oendl; | 1768 | odebug << "Voicerecord received message "+msg << oendl; |
1829 | 1769 | ||
1830 | } | 1770 | } |
1831 | 1771 | ||
1832 | 1772 | ||
1833 | ///////////////////////////// timerEvent | 1773 | ///////////////////////////// timerEvent |
1834 | void QtRec::timerEvent( QTimerEvent * ) { | 1774 | void QtRec::timerEvent( QTimerEvent * ) { |
1835 | 1775 | ||
1836 | // if(!recording) | 1776 | // if(!recording) |
1837 | // timeSlider->setValue( secCount); | 1777 | // timeSlider->setValue( secCount); |
1838 | // else | 1778 | // else |
1839 | // timeSlider->setValue( filePara.numberOfRecordedSeconds); | 1779 | // timeSlider->setValue( filePara.numberOfRecordedSeconds); |
1840 | 1780 | ||
1841 | if( stopped && playing) { | 1781 | if( stopped && playing) { |
1842 | stop(); | 1782 | stop(); |
1843 | } | 1783 | } |
1844 | 1784 | ||
1845 | if( stopped && recording ){ | 1785 | if( stopped && recording ){ |
1846 | stop(); | 1786 | stop(); |
1847 | } | 1787 | } |
1848 | 1788 | ||
1849 | if( recording && filePara.SecondsToRecord < secCount && filePara.SecondsToRecord != 0) { | 1789 | if( recording && filePara.SecondsToRecord < secCount && filePara.SecondsToRecord != 0) { |
1850 | stop(); | 1790 | stop(); |
1851 | } | 1791 | } |
1852 | 1792 | ||
1853 | odebug << "" << secCount << "" << oendl; | 1793 | odebug << "" << secCount << "" << oendl; |
1854 | QString timeString; | 1794 | QString timeString; |
1855 | #ifdef DEV_VERSION | ||
1856 | QString msg; | ||
1857 | msg.sprintf("%d, %d, %d", filePara.sampleRate, filePara.channels, filePara.resolution); | ||
1858 | setCaption( msg +" :: "+QString::number(secCount)); | ||
1859 | #endif | ||
1860 | 1795 | ||
1861 | timeString.sprintf("%d", secCount); | 1796 | timeString.sprintf("%d", secCount); |
1862 | // timeLabel->setText( timeString + " seconds"); | 1797 | // timeLabel->setText( timeString + " seconds"); |
1863 | 1798 | ||
1864 | secCount++; | 1799 | secCount++; |
1865 | } | 1800 | } |
1866 | 1801 | ||
1867 | void QtRec::changeTimeSlider(int index) { | 1802 | void QtRec::changeTimeSlider(int index) { |
1868 | if( ListView1->currentItem() == 0 || !wavFile->track.isOpen()) return; | 1803 | if( ListView1->currentItem() == 0 || !wavFile->track.isOpen()) return; |
1869 | odebug << "Slider moved to " << index << "" << oendl; | 1804 | odebug << "Slider moved to " << index << "" << oendl; |
1870 | paused = true; | 1805 | paused = true; |
1871 | stopped = true; | 1806 | stopped = true; |
1872 | 1807 | ||
1873 | sliderPos=index; | 1808 | sliderPos=index; |
1874 | 1809 | ||
1875 | QString timeString; | 1810 | QString timeString; |
1876 | filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2; | 1811 | filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2; |
1877 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); | 1812 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); |
1878 | secCount = (int)filePara.numberOfRecordedSeconds; | 1813 | secCount = (int)filePara.numberOfRecordedSeconds; |
1879 | // timeLabel->setText( timeString + tr(" seconds")); | 1814 | // timeLabel->setText( timeString + tr(" seconds")); |
1880 | } | 1815 | } |
1881 | 1816 | ||
1882 | void QtRec::timeSliderPressed() { | 1817 | void QtRec::timeSliderPressed() { |
1883 | if( ListView1->currentItem() == 0) return; | 1818 | if( ListView1->currentItem() == 0) return; |
1884 | odebug << "slider pressed" << oendl; | 1819 | odebug << "slider pressed" << oendl; |
1885 | paused = true; | 1820 | paused = true; |
1886 | stopped = true; | 1821 | stopped = true; |
1887 | } | 1822 | } |
1888 | 1823 | ||
1889 | void QtRec::timeSliderReleased() { | 1824 | void QtRec::timeSliderReleased() { |
1890 | if( ListView1->currentItem() == 0) return; | 1825 | if( ListView1->currentItem() == 0) return; |
1891 | sliderPos = timeSlider->value(); | 1826 | sliderPos = timeSlider->value(); |
1892 | 1827 | ||
1893 | odebug << "slider released " << sliderPos << "" << oendl; | 1828 | odebug << "slider released " << sliderPos << "" << oendl; |
1894 | stopped = false; | 1829 | stopped = false; |
1895 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); | 1830 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); |
1896 | total = newPos*4; | 1831 | total = newPos*4; |
1897 | filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2; | 1832 | filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2; |
1898 | 1833 | ||
1899 | doPlay(); | 1834 | doPlay(); |
1900 | } | 1835 | } |
1901 | 1836 | ||
1902 | void QtRec::rewindPressed() { | 1837 | void QtRec::rewindPressed() { |
1903 | if( ListView1->currentItem() == 0) return; | 1838 | if( ListView1->currentItem() == 0) return; |
1904 | if( !wavFile->track.isOpen()) { | 1839 | if( !wavFile->track.isOpen()) { |
1905 | if( !openPlayFile() ) | 1840 | if( !openPlayFile() ) |
1906 | return; | 1841 | return; |
1907 | else | 1842 | else |
1908 | if( !setupAudio( false)) | 1843 | if( !setupAudio( false)) |
1909 | return; | 1844 | return; |
1910 | } else { | 1845 | } else { |
1911 | killTimers(); | 1846 | killTimers(); |
1912 | paused = true; | 1847 | paused = true; |
1913 | stopped = true; | 1848 | stopped = true; |
1914 | rewindTimer->start( 50, false); | 1849 | rewindTimer->start( 50, false); |
1915 | } | 1850 | } |
1916 | } | 1851 | } |
1917 | 1852 | ||
1918 | void QtRec::rewindTimerTimeout() { | 1853 | void QtRec::rewindTimerTimeout() { |
1919 | int sliderValue = timeSlider->value(); | 1854 | int sliderValue = timeSlider->value(); |
1920 | sliderValue = sliderValue - ( filePara.numberSamples / 100); | 1855 | sliderValue = sliderValue - ( filePara.numberSamples / 100); |
1921 | // if(toBeginningButton->isDown()) | 1856 | // if(toBeginningButton->isDown()) |
1922 | timeSlider->setValue( sliderValue ) ; | 1857 | timeSlider->setValue( sliderValue ) ; |
1923 | odebug << "" << sliderValue << "" << oendl; | 1858 | odebug << "" << sliderValue << "" << oendl; |
1924 | QString timeString; | 1859 | QString timeString; |
1925 | filePara.numberOfRecordedSeconds = (float)sliderValue / (float)filePara.sampleRate * (float)2; | 1860 | filePara.numberOfRecordedSeconds = (float)sliderValue / (float)filePara.sampleRate * (float)2; |
1926 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); | 1861 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); |
1927 | // timeLabel->setText( timeString+ tr(" seconds")); | 1862 | // timeLabel->setText( timeString+ tr(" seconds")); |
1928 | } | 1863 | } |
1929 | 1864 | ||
1930 | void QtRec::rewindReleased() { | 1865 | void QtRec::rewindReleased() { |
1931 | rewindTimer->stop(); | 1866 | rewindTimer->stop(); |
1932 | if( wavFile->track.isOpen()) { | 1867 | if( wavFile->track.isOpen()) { |
1933 | sliderPos=timeSlider->value(); | 1868 | sliderPos=timeSlider->value(); |
1934 | stopped = false; | 1869 | stopped = false; |
1935 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); | 1870 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); |
1936 | total = newPos * 4; | 1871 | total = newPos * 4; |
1937 | odebug << "rewind released " << total << "" << oendl; | 1872 | odebug << "rewind released " << total << "" << oendl; |
1938 | startTimer( 1000); | 1873 | startTimer( 1000); |
1939 | doPlay(); | 1874 | doPlay(); |
1940 | } | 1875 | } |
1941 | } | 1876 | } |
1942 | 1877 | ||
1943 | void QtRec::FastforwardPressed() { | 1878 | void QtRec::FastforwardPressed() { |
1944 | if( ListView1->currentItem() == 0) return; | 1879 | if( ListView1->currentItem() == 0) return; |
1945 | if( !wavFile->track.isOpen()) | 1880 | if( !wavFile->track.isOpen()) |
1946 | if( !openPlayFile() ) | 1881 | if( !openPlayFile() ) |
1947 | return; | 1882 | return; |
1948 | else | 1883 | else |
1949 | if( !setupAudio( false)) | 1884 | if( !setupAudio( false)) |
1950 | return; | 1885 | return; |
1951 | killTimers(); | 1886 | killTimers(); |
1952 | 1887 | ||
1953 | paused = true; | 1888 | paused = true; |
1954 | stopped = true; | 1889 | stopped = true; |
1955 | forwardTimer->start(50, false); | 1890 | forwardTimer->start(50, false); |
1956 | } | 1891 | } |
1957 | 1892 | ||
1958 | 1893 | ||
1959 | void QtRec::forwardTimerTimeout() { | 1894 | void QtRec::forwardTimerTimeout() { |
1960 | int sliderValue = timeSlider->value(); | 1895 | int sliderValue = timeSlider->value(); |
1961 | sliderValue = sliderValue + ( filePara.numberSamples / 100); | 1896 | sliderValue = sliderValue + ( filePara.numberSamples / 100); |
1962 | 1897 | ||
1963 | // if(toEndButton->isDown()) | 1898 | // if(toEndButton->isDown()) |
1964 | timeSlider->setValue( sliderValue); | 1899 | timeSlider->setValue( sliderValue); |
1965 | 1900 | ||
1966 | QString timeString; | 1901 | QString timeString; |
1967 | filePara.numberOfRecordedSeconds = (float)sliderValue / (float)filePara.sampleRate * (float)2; | 1902 | filePara.numberOfRecordedSeconds = (float)sliderValue / (float)filePara.sampleRate * (float)2; |
1968 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); | 1903 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); |
1969 | // timeLabel->setText( timeString+ tr(" seconds")); | 1904 | // timeLabel->setText( timeString+ tr(" seconds")); |
1970 | } | 1905 | } |
1971 | 1906 | ||
1972 | void QtRec::FastforwardReleased() { | 1907 | void QtRec::FastforwardReleased() { |
1973 | forwardTimer->stop(); | 1908 | forwardTimer->stop(); |
1974 | if( wavFile->track.isOpen()) { | 1909 | if( wavFile->track.isOpen()) { |
1975 | sliderPos=timeSlider->value(); | 1910 | sliderPos=timeSlider->value(); |
1976 | stopped = false; | 1911 | stopped = false; |
1977 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); | 1912 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); |
1978 | total = newPos * 4; | 1913 | total = newPos * 4; |
1979 | filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2; | 1914 | filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2; |
1980 | startTimer( 1000); | 1915 | startTimer( 1000); |
1981 | doPlay(); | 1916 | doPlay(); |
1982 | } | 1917 | } |
1983 | } | 1918 | } |
1984 | 1919 | ||
1985 | 1920 | ||
1986 | QString QtRec::getStorage(const QString &fileName) { | 1921 | QString QtRec::getStorage(const QString &fileName) { |
1987 | 1922 | ||
1988 | StorageInfo storageInfo; | 1923 | StorageInfo storageInfo; |
1989 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 1924 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
1990 | QListIterator<FileSystem> it ( fs ); | 1925 | QListIterator<FileSystem> it ( fs ); |
1991 | QString storage; | 1926 | QString storage; |
1992 | for( ; it.current(); ++it ){ | 1927 | for( ; it.current(); ++it ){ |
1993 | const QString name = ( *it)->name(); | 1928 | const QString name = ( *it)->name(); |
1994 | const QString path = ( *it)->path(); | 1929 | const QString path = ( *it)->path(); |
1995 | const QString disk = ( *it)->disk(); | 1930 | const QString disk = ( *it)->disk(); |
1996 | if( fileName.find( path,0,true) != -1) | 1931 | if( fileName.find( path,0,true) != -1) |
1997 | storage = name; | 1932 | storage = name; |
1998 | // const QString options = (*it)->options(); | 1933 | // const QString options = (*it)->options(); |
1999 | // if( name.find( tr("Internal"),0,true) == -1) { | 1934 | // if( name.find( tr("Internal"),0,true) == -1) { |
2000 | // storageComboBox->insertItem( name +" -> "+disk); | 1935 | // storageComboBox->insertItem( name +" -> "+disk); |
2001 | // odebug << name << oendl; | 1936 | // odebug << name << oendl; |
2002 | } | 1937 | } |
2003 | return storage; | 1938 | return storage; |
2004 | // struct mntent *me; | 1939 | // struct mntent *me; |
2005 | // // if(fileName == "/etc/mtab") { | 1940 | // // if(fileName == "/etc/mtab") { |
2006 | // FILE *mntfp = setmntent( fileName.latin1(), "r" ); | 1941 | // FILE *mntfp = setmntent( fileName.latin1(), "r" ); |
2007 | // if ( mntfp ) { | 1942 | // if ( mntfp ) { |
2008 | // while ( (me = getmntent( mntfp )) != 0 ) { | 1943 | // while ( (me = getmntent( mntfp )) != 0 ) { |
2009 | // QString filesystemType = me->mnt_type; | 1944 | // QString filesystemType = me->mnt_type; |
2010 | 1945 | ||
2011 | // } | 1946 | // } |
2012 | // } | 1947 | // } |
2013 | // endmntent( mntfp ); | 1948 | // endmntent( mntfp ); |
2014 | } | 1949 | } |
2015 | 1950 | ||
2016 | void QtRec::setRecordButton(bool b) { | 1951 | void QtRec::setRecordButton(bool b) { |
2017 | 1952 | ||
2018 | if(b) { //about to record or play | 1953 | if(b) { //about to record or play |
2019 | 1954 | ||
2020 | Rec_PushButton->setDown( true); | 1955 | Rec_PushButton->setDown( true); |
2021 | QPixmap image3( ( const char** ) image3_data ); | 1956 | QPixmap image3( ( const char** ) image3_data ); |
2022 | Stop_PushButton->setPixmap( image3 ); | 1957 | Stop_PushButton->setPixmap( image3 ); |
2023 | if(Stop_PushButton->isDown()) | 1958 | if(Stop_PushButton->isDown()) |
2024 | Stop_PushButton->setDown( true); | 1959 | Stop_PushButton->setDown( true); |
2025 | // playLabel2->setText( tr("Stop") ); | 1960 | // playLabel2->setText( tr("Stop") ); |
2026 | 1961 | ||
2027 | } else { //about to stop | 1962 | } else { //about to stop |
2028 | 1963 | ||
2029 | QPixmap image4( ( const char** ) image4_data ); | 1964 | QPixmap image4( ( const char** ) image4_data ); |
2030 | Stop_PushButton->setPixmap( image4); | 1965 | Stop_PushButton->setPixmap( image4); |
2031 | if(Stop_PushButton->isDown()) | 1966 | if(Stop_PushButton->isDown()) |
2032 | Stop_PushButton->setDown( false); | 1967 | Stop_PushButton->setDown( false); |
2033 | // playLabel2->setText( tr("Play") ); | 1968 | // playLabel2->setText( tr("Play") ); |
2034 | if(Rec_PushButton->isDown()) | 1969 | if(Rec_PushButton->isDown()) |
2035 | Rec_PushButton->setDown( false); | 1970 | Rec_PushButton->setDown( false); |
2036 | } | 1971 | } |
2037 | } | 1972 | } |
2038 | 1973 | ||
2039 | void QtRec::fillDirectoryCombo() { | 1974 | void QtRec::fillDirectoryCombo() { |
2040 | if( directoryComboBox->count() > 0) | 1975 | if( directoryComboBox->count() > 0) |
2041 | directoryComboBox->clear(); | 1976 | directoryComboBox->clear(); |
2042 | int index = 0; | 1977 | int index = 0; |
2043 | Config cfg("OpieRec"); | 1978 | Config cfg("OpieRec"); |
2044 | cfg.setGroup("Settings"); | 1979 | cfg.setGroup("Settings"); |
2045 | QString dir = cfg.readEntry("directory", "/"); | 1980 | QString dir = cfg.readEntry("directory", "/"); |
2046 | StorageInfo storageInfo; | 1981 | StorageInfo storageInfo; |
2047 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 1982 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
2048 | QListIterator<FileSystem> it ( fs ); | 1983 | QListIterator<FileSystem> it ( fs ); |
2049 | QString storage; | 1984 | QString storage; |
2050 | for( ; it.current(); ++it ){ | 1985 | for( ; it.current(); ++it ){ |
2051 | const QString name = ( *it)->name(); | 1986 | const QString name = ( *it)->name(); |
diff --git a/noncore/multimedia/opierec/waveform.cpp b/noncore/multimedia/opierec/waveform.cpp index 7c9a25f..d1838e1 100644 --- a/noncore/multimedia/opierec/waveform.cpp +++ b/noncore/multimedia/opierec/waveform.cpp | |||
@@ -1,163 +1,163 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "waveform.h" | 20 | #include "waveform.h" |
21 | 21 | ||
22 | /* OPIE */ | 22 | /* OPIE */ |
23 | #include <opie2/odebug.h> | 23 | #include <opie2/odebug.h> |
24 | using namespace Opie::Core; | 24 | using namespace Opie::Core; |
25 | 25 | ||
26 | /* QT */ | 26 | /* QT */ |
27 | #include <qpainter.h> | 27 | #include <qpainter.h> |
28 | 28 | ||
29 | Waveform::Waveform( QWidget *parent, const char *name, WFlags fl ) | 29 | Waveform::Waveform( QWidget *parent, const char *name, WFlags fl ) |
30 | : QWidget( parent, name, fl ) | 30 | : QWidget( parent, name, fl ) |
31 | { | 31 | { |
32 | pixmap = 0; | 32 | pixmap = 0; |
33 | windowSize = 100; | 33 | windowSize = 100; |
34 | samplesPerPixel = 8000 / (5 * windowSize); | 34 | samplesPerPixel = 8000 / (5 * windowSize); |
35 | currentValue = 0; | 35 | currentValue = 0; |
36 | numSamples = 0; | 36 | numSamples = 0; |
37 | windowPosn = 0; | 37 | windowPosn = 0; |
38 | window = 0; | 38 | window = 0; |
39 | } | 39 | } |
40 | 40 | ||
41 | 41 | ||
42 | void Waveform::changeSettings( int frequency, int channels ) | 42 | void Waveform::changeSettings( int frequency, int channels ) |
43 | { | 43 | { |
44 | makePixmap(); | 44 | makePixmap(); |
45 | // owarn << "change waveform " << frequency << ", " << channels << "" << oendl; | 45 | // owarn << "change waveform " << frequency << ", " << channels << "" << oendl; |
46 | samplesPerPixel = frequency * channels / (5 * windowSize); | 46 | samplesPerPixel = frequency * channels / (5 * windowSize); |
47 | owarn << "Waveform::changeSettings " << samplesPerPixel << "" << oendl; | 47 | // owarn << "Waveform::changeSettings " << samplesPerPixel << "" << oendl; |
48 | if ( !samplesPerPixel ) | 48 | if ( !samplesPerPixel ) |
49 | samplesPerPixel = 1; | 49 | samplesPerPixel = 1; |
50 | currentValue = 0; | 50 | currentValue = 0; |
51 | numSamples = 0; | 51 | numSamples = 0; |
52 | windowPosn = 0; | 52 | windowPosn = 0; |
53 | draw(); | 53 | draw(); |
54 | } | 54 | } |
55 | 55 | ||
56 | 56 | ||
57 | Waveform::~Waveform() | 57 | Waveform::~Waveform() |
58 | { | 58 | { |
59 | if ( window ) | 59 | if ( window ) |
60 | delete[] window; | 60 | delete[] window; |
61 | if ( pixmap ) | 61 | if ( pixmap ) |
62 | delete pixmap; | 62 | delete pixmap; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | void Waveform::reset() | 66 | void Waveform::reset() |
67 | { | 67 | { |
68 | makePixmap(); | 68 | makePixmap(); |
69 | currentValue = 0; | 69 | currentValue = 0; |
70 | numSamples = 0; | 70 | numSamples = 0; |
71 | windowPosn = 0; | 71 | windowPosn = 0; |
72 | draw(); | 72 | draw(); |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | void Waveform::newSamples( const short *buf, int len ) | 76 | void Waveform::newSamples( const short *buf, int len ) |
77 | { | 77 | { |
78 | // Cache the object values in local variables. | 78 | // Cache the object values in local variables. |
79 | int samplesPerPixel = this->samplesPerPixel; | 79 | int samplesPerPixel = this->samplesPerPixel; |
80 | int currentValue = this->currentValue; | 80 | int currentValue = this->currentValue; |
81 | int numSamples = this->numSamples; | 81 | int numSamples = this->numSamples; |
82 | short *window = this->window; | 82 | short *window = this->window; |
83 | int windowPosn = this->windowPosn; | 83 | int windowPosn = this->windowPosn; |
84 | int windowSize = this->windowSize; | 84 | int windowSize = this->windowSize; |
85 | 85 | ||
86 | // Average the incoming samples to scale them to the window. | 86 | // Average the incoming samples to scale them to the window. |
87 | while ( len > 0 ) { | 87 | while ( len > 0 ) { |
88 | currentValue += *buf++; | 88 | currentValue += *buf++; |
89 | --len; | 89 | --len; |
90 | if ( ++numSamples >= samplesPerPixel ) { | 90 | if ( ++numSamples >= samplesPerPixel ) { |
91 | window[windowPosn++] = (short)(currentValue / numSamples); | 91 | window[windowPosn++] = (short)(currentValue / numSamples); |
92 | if ( windowPosn >= windowSize ) { | 92 | if ( windowPosn >= windowSize ) { |
93 | this->windowPosn = windowPosn; | 93 | this->windowPosn = windowPosn; |
94 | draw(); | 94 | draw(); |
95 | windowPosn = 0; | 95 | windowPosn = 0; |
96 | } | 96 | } |
97 | numSamples = 0; | 97 | numSamples = 0; |
98 | currentValue = 0; | 98 | currentValue = 0; |
99 | } | 99 | } |
100 | } | 100 | } |
101 | 101 | ||
102 | // Copy the final state back to the object. | 102 | // Copy the final state back to the object. |
103 | //owarn << "" << currentValue << ", " << numSamples << ", " << windowPosn << "" << oendl; | 103 | //owarn << "" << currentValue << ", " << numSamples << ", " << windowPosn << "" << oendl; |
104 | this->currentValue = currentValue; | 104 | this->currentValue = currentValue; |
105 | this->numSamples = numSamples; | 105 | this->numSamples = numSamples; |
106 | this->windowPosn = windowPosn; | 106 | this->windowPosn = windowPosn; |
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
110 | void Waveform::makePixmap() | 110 | void Waveform::makePixmap() |
111 | { | 111 | { |
112 | if ( !pixmap ) { | 112 | if ( !pixmap ) { |
113 | pixmap = new QPixmap( size() ); | 113 | pixmap = new QPixmap( size() ); |
114 | windowSize = pixmap->width(); | 114 | windowSize = pixmap->width(); |
115 | window = new short [windowSize]; | 115 | window = new short [windowSize]; |
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | 119 | ||
120 | void Waveform::draw() | 120 | void Waveform::draw() |
121 | { | 121 | { |
122 | pixmap->fill( Qt::black ); | 122 | pixmap->fill( Qt::black ); |
123 | QPainter painter; | 123 | QPainter painter; |
124 | painter.begin( pixmap ); | 124 | painter.begin( pixmap ); |
125 | painter.setPen( Qt::green ); | 125 | painter.setPen( Qt::green ); |
126 | 126 | ||
127 | int middle = pixmap->height() / 2; | 127 | int middle = pixmap->height() / 2; |
128 | int mag; | 128 | int mag; |
129 | short *window = this->window; | 129 | short *window = this->window; |
130 | int posn; | 130 | int posn; |
131 | int size = windowPosn; | 131 | int size = windowPosn; |
132 | for( posn = 0; posn < size; ++posn ) | 132 | for( posn = 0; posn < size; ++posn ) |
133 | { | 133 | { |
134 | mag = (window[posn] * middle / 32768); | 134 | mag = (window[posn] * middle / 32768); |
135 | painter.drawLine(posn, middle - mag, posn, middle + mag); | 135 | painter.drawLine(posn, middle - mag, posn, middle + mag); |
136 | } | 136 | } |
137 | if ( windowPosn < windowSize ) | 137 | if ( windowPosn < windowSize ) |
138 | { | 138 | { |
139 | painter.drawLine(windowPosn, middle, windowSize, middle); | 139 | painter.drawLine(windowPosn, middle, windowSize, middle); |
140 | } | 140 | } |
141 | 141 | ||
142 | painter.end(); | 142 | painter.end(); |
143 | 143 | ||
144 | paintEvent( 0 ); | 144 | paintEvent( 0 ); |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | void Waveform::paintEvent( QPaintEvent * ) | 148 | void Waveform::paintEvent( QPaintEvent * ) |
149 | { | 149 | { |
150 | QPainter painter; | 150 | QPainter painter; |
151 | painter.begin( this ); | 151 | painter.begin( this ); |
152 | 152 | ||
153 | if ( pixmap ) { | 153 | if ( pixmap ) { |
154 | painter.drawPixmap( 0, 0, *pixmap ); | 154 | painter.drawPixmap( 0, 0, *pixmap ); |
155 | } else { | 155 | } else { |
156 | painter.setPen( Qt::green ); | 156 | painter.setPen( Qt::green ); |
157 | QSize sz = size(); | 157 | QSize sz = size(); |
158 | painter.drawLine(0, sz.height() / 2, sz.width(), sz.height() / 2); | 158 | painter.drawLine(0, sz.height() / 2, sz.width(), sz.height() / 2); |
159 | } | 159 | } |
160 | 160 | ||
161 | painter.end(); | 161 | painter.end(); |
162 | } | 162 | } |
163 | 163 | ||