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