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