Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

qtrec.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002          // qtrec.cpp
00003  Created: Thu Jan 17 11:19:58 2002
00004  copyright 2002 by L.J. Potter <ljp@llornkcor.com>
00005 ****************************************************************************/
00006 //#define DEV_VERSION
00007 
00008 #include "pixmaps.h"
00009 #include "qtrec.h"
00010 #include "waveform.h"
00011 extern "C" {
00012 #include "adpcm.h"
00013 }
00014 
00015 /* OPIE */
00016 #include <opie2/odebug.h>
00017 #include <opie2/oresource.h>
00018 #include <qpe/config.h>
00019 #include <qpe/qcopenvelope_qws.h>
00020 #include <qpe/qpeapplication.h>
00021 #include <qpe/storage.h>
00022 using namespace Opie::Core;
00023 
00024 /* QT */
00025 #include <qcheckbox.h>
00026 #include <qcombobox.h>
00027 #include <qdir.h>
00028 #include <qgroupbox.h>
00029 #include <qlabel.h>
00030 #include <qlayout.h>
00031 #include <qlistview.h>
00032 #include <qmessagebox.h>
00033 #include <qpopupmenu.h>
00034 #include <qpushbutton.h>
00035 #include <qslider.h>
00036 #include <qtabwidget.h>
00037 #include <qtimer.h>
00038 
00039 /* STD */
00040 #include <errno.h>
00041 #include <fcntl.h>
00042 #include <math.h>
00043 #include <mntent.h>
00044 #include <stdio.h>
00045 #include <stdlib.h>
00046 #include <sys/ioctl.h>
00047 #include <sys/soundcard.h>
00048 #include <sys/stat.h>
00049 #include <sys/time.h>
00050 #include <sys/types.h>
00051 #include <sys/vfs.h>
00052 #include <unistd.h>
00053 #include <sys/wait.h>
00054 #include <sys/signal.h>
00055 #include <pthread.h>
00056 
00057 #ifdef PDAUDIO //ALSA
00058 #include <alsa/asoundlib.h>
00059 static int deviceSampleRates[8] = { 32000, 44100, 48000, 88200, 96000, 176400, 192000, -1 };
00060 static int deviceBitRates[] = { 8, 16, 24, 32, -1 };
00061 #else //OSS
00062 static int deviceSampleRates[6] = { 11025, 16000, 22050, 32000, 44100, -1 };
00063 static int deviceBitRates[] = { 8, 16, -1 };
00064 #endif
00065 
00066 
00067 //#define ZAURUS 0
00068 struct adpcm_state encoder_state;
00069 struct adpcm_state decoder_state;
00070 
00071 typedef struct {
00072                 int sampleRate;
00073                         /*      int fragSize; */
00074                         /*      int blockSize; */
00075                 int resolution; //bitrate
00076                 int channels; //number of channels
00077                 int fd; //file descriptor
00078                 int sd; //sound device descriptor
00079                 int numberSamples; //total number of samples
00080                 int SecondsToRecord; // number of seconds that should be recorded
00081                 float numberOfRecordedSeconds; //total number of samples recorded
00082                 int samplesToRecord; //number of samples to be recorded
00083                 int inVol; //input volume
00084                 int outVol; //output volume
00085                 int format; //wavfile format PCM.. ADPCM
00086                 const  char *fileName; //name of fiel to be played/recorded
00087 } fileParameters;
00088 
00089 fileParameters filePara;
00090 
00091 bool monitoring, recording, playing;
00092 bool stopped;
00093 QLabel *timeLabel;
00094 QSlider *timeSlider;
00095 int sd;
00096 
00097 Waveform* waveform;
00098 Device *soundDevice;
00099 
00100 
00101 #ifdef THREADED
00102 void quickRec()
00103 #else
00104                 void QtRec::quickRec()
00105 #endif
00106 {
00107 
00108                 odebug << ( filePara.numberSamples/filePara.sampleRate * filePara.channels ) << oendl;
00109                 odebug << "samples " << filePara.numberSamples << ", rate " << filePara.sampleRate
00110                                          << ", channels " << filePara.channels << oendl;
00111 
00112                 int total = 0;  // Total number of bytes read in so far.
00113                 int bytesWritten, number;
00114 
00115                 bytesWritten = 0;
00116                 number = 0;
00117                 QString num;
00118                 int level = 0;
00119                 int threshold = 0;
00120                 int bits = filePara.resolution;
00121                 odebug << "bits " << bits << "" << oendl;
00122 
00123                 if( filePara.resolution == 16 ) { //AFMT_S16_LE)
00124                                 odebug << "AFMT_S16_LE size " << filePara.SecondsToRecord << "" << oendl;
00125                                 odebug << "samples to record " << filePara.samplesToRecord << "" << oendl;
00126                                 odebug << "" << filePara.sd << "" << oendl;
00127                                 level = 7;
00128                                 threshold = 0;
00129 
00130                                 if( filePara.format == WAVE_FORMAT_DVI_ADPCM) {
00131                                                 odebug << "start recording WAVE_FORMAT_DVI_ADPCM" << oendl;
00132 // <<<<<<<<<<<<<<<<<<<<<<<<<<<  WAVE_FORMAT_DVI_ADPCM  >>>>>>>>>>>>>>>>>>>>>>
00133                                                 char abuf[ BUFSIZE/2 ];
00134                                                 short sbuf[ BUFSIZE ];
00135                                                 short sbuf2[ BUFSIZE ];
00136                                                 memset( abuf, 0, BUFSIZE/2);
00137                                                 memset( sbuf, 0, BUFSIZE);
00138                                                 memset( sbuf2, 0, BUFSIZE);
00139 
00140                                                 for(;;) {
00141                                                                 if ( stopped) {
00142                                                                                 odebug << "quickRec:: stopped" << oendl;
00143                                                                                 break;
00144                                                                 }
00145 
00146 //             number=::read( filePara.sd, sbuf, BUFSIZE);
00147                                                                 number =  soundDevice->devRead( filePara.sd, sbuf, BUFSIZE);
00148 
00149                                                                 if(number <= 0) {
00150                                                                                 perror("recording error ");
00151                                                                                 odebug << "" << filePara.fileName << " " << number << "" << oendl;
00152                                                                                 stopped = true;
00153                                                                                 return;
00154                                                                 }
00155                                                                         //if(stereo == 2) {
00156 //        adpcm_coder( sbuf2, abuf, number/2, &encoder_state);
00157                                                                 adpcm_coder( sbuf, abuf, number/2, &encoder_state);
00158 
00159                                                                 bytesWritten = ::write( filePara.fd , abuf, number/4);
00160 
00161                                                                 waveform->newSamples( sbuf, number );
00162 
00163                                                                 total += bytesWritten;
00164                                                                 filePara.numberSamples = total;
00165                                                                 timeSlider->setValue( total);
00166 
00167                                                                 printf("%d, bytes %d,total %d\r", number, bytesWritten, total);
00168                                                                 fflush(stdout);
00169 
00170                                                                 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2;//      / filePara.channels;
00171 
00172                                                                 qApp->processEvents();
00173                                                                 if( total >= filePara.samplesToRecord) {
00174                                                                                 stopped = true;
00175                                                                                 break;
00176                                                                 }
00177                                                 }
00178                                 } else {
00179                                                         // <<<<<<<<<<<<<<<<<<<<<<<<<<<  WAVE_FORMAT_PCM   >>>>>>>>>>>>>>>>>>>>>>
00180                                                 odebug << "start recording WAVE_FORMAT_PCM" << oendl;
00181                                                 short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ];
00182                                                 memset( inbuffer, 0, BUFSIZE);
00183                                                 memset( outbuffer, 0, BUFSIZE);
00184 
00185                                                 for(;;) {
00186                                                                 if ( stopped) {
00187                                                                                 odebug << "quickRec:: stopped" << oendl;
00188                                                                                 stopped = true;
00189                                                                                 break;  // stop if playing was set to false
00190                                                                                 return;
00191                                                                 }
00192 
00193                                                                 number = soundDevice->devRead( soundDevice->sd /*filePara.sd*/, (short *)inbuffer, BUFSIZE);
00194 
00195                                                                 if( number <= 0) {
00196                                                                                 perror( "recording error ");
00197                                                                                 odebug << filePara.fileName << oendl;
00198                                                                                 stopped = true;
00199                                                                                 return;
00200                                                                 }
00201 
00202                                                                 bytesWritten = ::write( filePara.fd , inbuffer, number);
00203                                                                 waveform->newSamples( inbuffer, number );
00204 
00205                                                                 if( bytesWritten < 0) {
00206                                                                                 perror("File writing error ");
00207                                                                                 stopped = true;
00208                                                                                 return;
00209                                                                 }
00210 
00211                                                                 total += bytesWritten;
00212 
00213                                                                 filePara.numberSamples = total;
00214 
00215                                                                 if( filePara.SecondsToRecord != 0)
00216                                                                                 timeSlider->setValue( total);
00217                                                                 printf("%d, bytes %d,total %d\r",number,  bytesWritten , total);
00218                                                                 fflush(stdout);
00219 
00220                                                                 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate
00221                                                                                 / (float)2/filePara.channels;
00222                                                                 qApp->processEvents();
00223 
00224                                                                 if( total >= filePara.samplesToRecord) {
00225                                                                                 stopped = true;
00226                                                                                 break;
00227                                                                 }
00228                                                 }
00229                                 } //end main loop
00230 
00231                 } else {
00232 // <<<<<<<<<<<<<<<<<<<<<<<   format = AFMT_U8;
00233                                 unsigned char unsigned_inbuffer[ BUFSIZE ], unsigned_outbuffer[ BUFSIZE ];
00234                                 memset( unsigned_inbuffer, 0, BUFSIZE);
00235                                 memset( unsigned_outbuffer, 0, BUFSIZE);
00236 
00237                                 for(;;) {
00238                                                 if ( stopped) {
00239                                                                 odebug << "quickRec:: stopped" << oendl;
00240                                                                 break;  // stop if playing was set to false
00241                                                 }
00242 
00243                                                 number = ::read( soundDevice->sd /*filePara.sd*/ , unsigned_inbuffer, BUFSIZE);
00244                                                 bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number);
00245             waveform->newSamples( (const short *) unsigned_inbuffer, number );
00246 
00247                                                 if(bytesWritten < 0) {
00248                                                                 stopped = true;
00249                                                                 QMessageBox::message("Note","<p>There was a problem writing to the file</p>");
00250                                                                 perror("File writing error ");
00251                                                                 return;
00252                                                 }
00253 
00254                                                 total += bytesWritten;
00255                                                 filePara.numberSamples = total;
00256                                                         //             printf("%d, bytes %d,total %d \r",number,  bytesWritten , total);
00257                                                         //             fflush(stdout);
00258                                                 if( filePara.SecondsToRecord !=0)
00259                                                                 timeSlider->setValue( total);
00260 
00261                                                 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate;
00262 
00263                                                 qApp->processEvents();
00264                                                 if( total >= filePara.samplesToRecord) {
00265                                                                 stopped = true;
00266                                                                 break;
00267                                                 }
00268                                 } //end main loop
00269                 }
00270                 printf("\n");
00271 } 
00272 
00273 
00274 #ifdef THREADED
00275 void playIt()
00276 #else
00277                 void QtRec::playIt()
00278 #endif
00279 {
00280                 int bytesWritten = 0;
00281                 int number = 0;
00282                 int total = 0;  // Total number of bytes read in so far.
00283                 if( filePara.resolution == 16 ) { //AFMT_S16_LE) {
00284                                 if( filePara.format == WAVE_FORMAT_DVI_ADPCM) {
00285                                                 char abuf[ BUFSIZE / 2 ];
00286                                                 short sbuf[ BUFSIZE ];
00287                                                 short sbuf2[ BUFSIZE * 2 ];
00288                                                 memset( abuf, 0, BUFSIZE / 2);
00289                                                 memset( sbuf, 0, BUFSIZE);
00290                                                 memset( sbuf2, 0, BUFSIZE * 2);
00291 // <<<<<<<<<<<<<<<<<<<<<<<<<<<  WAVE_FORMAT_DVI_ADPCM  >>>>>>>>>>>>>>>>>>>>>>
00292                                                 for(;;) {  // play loop
00293                                                                 if ( stopped) {
00294                                                                                 break;
00295                                                                                 return;
00296                                                                 }// stop if playing was set to false
00297 
00298                                                                 number = ::read( filePara.fd, abuf, BUFSIZE / 2);
00299                                                                 adpcm_decoder( abuf, sbuf, number * 2, &decoder_state);
00300 
00301 //                 for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel
00302 //                     sbuf2[i+1]=sbuf2[i]=sbuf[i];
00303 //                 }
00304                                                                 bytesWritten = write ( soundDevice->sd , sbuf, number * 4);
00305 
00306                                                                 waveform->newSamples( sbuf, number );
00307 
00308                                                                         //          if(filePara.channels==1)
00309                                                                         //              total += bytesWritten/2; //mono
00310                                                                         //          else
00311                                                                 total += bytesWritten;
00312                                                                 filePara.numberSamples = total/4;
00313                                                                 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / 2;
00314 
00315                                                                 timeSlider->setValue( total/4);
00316 //            timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds);
00317 //         if(filePara.numberOfRecordedSeconds>1)
00318 //            timeLabel->setText( timeString+ tr(" seconds"));
00319 //                              printf("playing number %d, bytes %d, total %d\n",number,  bytesWritten, total/4);
00320 //                              fflush(stdout);
00321 
00322                                                                 qApp->processEvents();
00323 
00324                                                                 if( /*total >= filePara.numberSamples || */ bytesWritten == 0) {
00325 //            if( total >= filePara.numberSamples ){//||  secCount > filePara.numberOfRecordedSeconds ) {
00326                                                                                 stopped = true;
00327                                                                                 break;
00328                                                                 }
00329                                                 }
00330                                 } else {
00331                                                         // <<<<<<<<<<<<<<<<<<<<<<<<<<<  WAVE_FORMAT_PCM   >>>>>>>>>>>>>>>>>>>>>>
00332                                                 short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ];
00333                                                 memset( inbuffer, 0, BUFSIZE);
00334                                                 memset( outbuffer, 0, BUFSIZE);
00335 
00336                                                 for(;;) {  // play loop
00337                                                                 if ( stopped) {
00338                                                                                 break;
00339                                                                                 return;
00340                                                                 }
00341 // stop if playing was set to false
00342                                                                 number = ::read( filePara.fd, inbuffer, BUFSIZE);
00343 //                 for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel
00344 //                       //        for (int i=0;i< number ; i++) { //2*i is left channel
00345 //                     outbuffer[i+1]= outbuffer[i]=inbuffer[i];
00346 //                 }
00347                                                                 bytesWritten = ::write( soundDevice->sd, inbuffer, number);
00348                                                                 waveform->newSamples( inbuffer, number);
00349                                                                         //-------------->>>> out to device
00350                                                                         //        total+=bytesWritten;
00351                                                                         //          if(filePara.channels==1)
00352                                                                         //              total += bytesWritten/2; //mono
00353                                                                         //          else
00354                                                                 total += bytesWritten;
00355                                                                 timeSlider->setValue( total);
00356 
00357                                                                 filePara.numberSamples = total;
00358                                                                 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2;
00359 
00360 //             timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds);
00361 //             timeLabel->setText( timeString + tr(" seconds"));
00362 
00363                                                                 qApp->processEvents();
00364 
00365                                                                 if( /*total >= filePara.numberSamples || */ bytesWritten == 0) {
00366                                                                                 owarn << "Jane! Stop this crazy thing!" << oendl;
00367                                                                                 stopped = true;
00368 //                playing = false;
00369                                                                                 break;
00370                                                                 }
00371                                                 }
00372 //             printf("\nplaying number %d, bytes %d, total %d\r",number,  bytesWritten, total);
00373 //             fflush(stdout);
00374                                 } //end loop
00375                 } else {
00377                                 unsigned char unsigned_inbuffer[ BUFSIZE ]; //, unsigned_outbuffer[BUFSIZE];
00378                                 memset( unsigned_inbuffer, 0, BUFSIZE);
00379                                 for(;;) {
00380 // main loop
00381                                                 if (stopped) {
00382                                                                 break;  // stop if playing was set to false
00383                                                                 return;
00384                                                 }
00385                                                 number = ::read( filePara.fd, unsigned_inbuffer, BUFSIZE);
00386 //data = (val >> 8) ^ 0x80;
00387                                                         //          unsigned_outbuffer = (unsigned_inbuffer >> 8) ^ 0x80;
00388                                                 bytesWritten = write ( filePara.sd, unsigned_inbuffer, number);
00389                                                 waveform->newSamples(  (const short *)unsigned_inbuffer, bytesWritten );
00390                                                 total += bytesWritten;
00391 
00392             timeSlider->setValue( total);
00393                                                 filePara.numberSamples = total;
00394 
00395                                                 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate;
00396 //          timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds);
00397 //          timeLabel->setText( timeString + tr(" seconds"));
00398                                                 qApp->processEvents();
00399 
00400                                                 if( /*total >= filePara.numberSamples || */ bytesWritten == 0) {
00401 //         if( total >= filePara.numberSamples ) {
00402                                                                 stopped = true;
00403                                                                 break;
00404                                                 }
00405 //                      printf("Writing number %d, bytes %d, total %d, numberSamples %d\r",number,  bytesWritten , total, filePara.numberSamples);
00406 //                      fflush(stdout);
00407                                 }
00408                 }
00409 }
00410 
00411 
00412 QtRec::QtRec( QWidget* parent,  const char* name, WFlags fl )
00413                                 : QWidget( parent, name, fl )
00414 {
00415                 if ( !name )
00416                                 setName( "OpieRec" );
00417                 init();
00418                 initConfig();
00419                 initConnections();
00420                 renameBox = 0;
00421 
00422 // open sound device to get volumes
00423                 Config hwcfg("OpieRec");
00424                 hwcfg.setGroup("Hardware");
00425 
00426 
00427                 soundDevice = new Device( this, false); //open play
00428 
00429                 getInVol();
00430                 getOutVol();
00431 
00432                 soundDevice->closeDevice( true);
00433                 soundDevice->sd = -1;
00434                 soundDevice = 0;
00435                 wavFile = 0;
00436 //      if( soundDevice) delete soundDevice;
00437                 QTimer::singleShot(100,this, SLOT(initIconView()));
00438 
00439                 if( autoMute)
00440                                 doMute( true);
00441 //              ListView1->setFocus();
00442                 playing = false;
00443 }
00444 
00445 QtRec::~QtRec() {
00446 //   if( soundDevice) delete soundDevice;
00447 
00448 }
00449 
00450 void QtRec::cleanUp() {
00451 
00452                 if( !stopped) {
00453                                 stopped = true;
00454                                 endRecording();
00455                 }
00456 
00457                 ListView1->clear();
00458 
00459                 if( autoMute)
00460                                 doMute(false);
00461 
00462 //      if( wavFile) delete wavFile;
00463 // if(soundDevice) delete soundDevice;
00464 }
00465 
00466 void QtRec::init() {
00467 
00468                 needsStereoOut = false;
00469                 QPixmap image3( ( const char** ) image3_data );
00470                 QPixmap image4( ( const char** ) image4_data );
00471                 QPixmap image6( ( const char** ) image6_data );
00472 
00473                 stopped = true;
00474                 setCaption( tr( "OpieRecord " ));
00475                 QGridLayout *layout = new QGridLayout( this );
00476                 layout->setSpacing( 2);
00477                 layout->setMargin( 2);
00478 
00479                 TabWidget = new QTabWidget( this, "TabWidget" );
00480                 layout->addMultiCellWidget(TabWidget, 0, 7, 0, 8);
00481 //    TabWidget->setTabShape(QTabWidget::Triangular);
00482 
00484                 tab = new QWidget( TabWidget, "tab" );
00485 
00486                 QGridLayout *layout1 = new QGridLayout( tab);
00487                 layout1->setSpacing( 2);
00488                 layout1->setMargin( 2);
00489 
00490                 timeSlider = new QSlider( 0,100,10,0, QSlider::Horizontal, tab, (const char *) "timeSlider" );
00491                 layout1->addMultiCellWidget( timeSlider, 1, 1, 0, 3);
00492 
00493 //              timeLabel = new QLabel( tab, "TimeLabel" );
00494 //              layout1->addMultiCellWidget( timeLabel, 0, 0, 0, 3);
00495 
00496 //              playLabel2 = new QLabel(tab, "PlayLabel2" );
00497 //              playLabel2->setText(tr("Play") );
00498 //              playLabel2->setFixedHeight( 18);
00499 //              layout1->addMultiCellWidget( playLabel2, 0, 0, 4, 4);
00500 
00501                 Stop_PushButton = new QPushButton(  tab, "Stop_PushButton" );
00502                 layout1->addMultiCellWidget( Stop_PushButton, 1, 1, 4, 4);
00503                 Stop_PushButton->setFixedSize( 22, 22);
00504                 Stop_PushButton->setPixmap( image4 );
00505 
00506                 toBeginningButton = new QPushButton(  tab, "Beginning_PushButton" );
00507                 layout1->addMultiCellWidget(toBeginningButton, 1, 1, 5, 5);
00508                 toBeginningButton->setFixedSize( 22, 22);
00509                 toBeginningButton->setPixmap( Opie::Core::OResource::loadPixmap("fastback", Opie::Core::OResource::SmallIcon) );
00510 
00511                 toEndButton = new QPushButton(  tab, "End_PushButton" );
00512                 layout1->addMultiCellWidget( toEndButton, 1, 1, 6, 6);
00513                 toEndButton->setFixedSize( 22, 22);
00514                 toEndButton->setPixmap(  Opie::Core::OResource::loadPixmap( "fastforward", Opie::Core::OResource::SmallIcon )  );
00515 
00516 //              QLabel *recLabel2;
00517 //              recLabel2 = new QLabel( tab, "recLabel2" );
00518 //              recLabel2->setText(tr("Rec"));
00519 //              recLabel2->setFixedHeight( 18);
00520 //              layout1->addMultiCellWidget( recLabel2, 0, 0, 7, 7);
00521 
00522                 Rec_PushButton = new QPushButton( tab, "Rec_PushButton" );
00523                 layout1->addMultiCellWidget(  Rec_PushButton, 1, 1, 7, 7);
00524                 Rec_PushButton->setFixedSize( 22, 22);
00525                 Rec_PushButton->setPixmap( image6 );
00526 
00527                 t = new QTimer( this );
00528                 connect( t, SIGNAL( timeout() ), SLOT( timerBreak() ) );
00529 
00530                 rewindTimer = new QTimer( this );
00531                 connect( rewindTimer, SIGNAL( timeout() ),
00532                                                  this, SLOT( rewindTimerTimeout() ) );
00533 
00534                 forwardTimer = new QTimer( this );
00535                 connect( forwardTimer, SIGNAL( timeout() ),
00536                                                  this, SLOT( forwardTimerTimeout() ) );
00537 
00538                 deleteSoundButton  = new QPushButton( tab, "deleteSoundButton" );
00539                 layout1->addMultiCellWidget( deleteSoundButton, 1, 1, 8, 8);
00540                 deleteSoundButton->setText( tr( "Del" ) );
00541 
00542                 ListView1 = new QListView( tab, "IconView1" );
00543                 layout1->addMultiCellWidget( ListView1, 2, 2, 0, 8);
00544 
00545                 ListView1->addColumn( tr( "Name" ) );
00546                 ListView1->setSorting( 1, false);
00547                 ListView1->addColumn( tr( "Time" ) ); //in seconds
00548                 ListView1->setColumnWidthMode(0, QListView::Maximum);
00549                 ListView1->setColumnAlignment( 1, QListView::AlignCenter);
00550                 ListView1->setAllColumnsShowFocus( true );
00551                 QPEApplication::setStylusOperation( ListView1->viewport(), QPEApplication::RightOnHold);
00552 
00553                 TabWidget->insertTab( tab, tr( "Files" ) );
00554 
00556                 tab_3 = new QWidget( TabWidget, "tab_3" );
00557                 QGridLayout *glayout3 = new QGridLayout( tab_3 );
00558                 glayout3->setSpacing( 2);
00559                 glayout3->setMargin( 2);
00561                 sampleGroup = new QGroupBox( tab_3, "samplegroup" );
00562                 sampleGroup->setTitle( tr( "Sample Rate" ) );
00563                 sampleGroup->setFixedSize( 95,50);
00564 
00565                 sampleRateComboBox = new QComboBox( false, sampleGroup, "SampleRateComboBox" );
00566                 sampleRateComboBox->setGeometry( QRect( 10, 20, 80, 25 ) );
00567                 QString s;
00568                 int z = 0;
00569                 while( deviceSampleRates[z] != -1) {
00570                                 sampleRateComboBox->insertItem( s.setNum( deviceSampleRates[z], 10));
00571                                 z++;
00572                 }
00573 
00574 
00575                 glayout3->addMultiCellWidget(  sampleGroup, 0, 0, 0, 0);
00576 
00577                 sizeGroup= new QGroupBox( tab_3, "sizeGroup" );
00578                 sizeGroup->setTitle( tr( "Limit Size" ) );
00579                 sizeGroup->setFixedSize( 80, 50);
00580 
00581                 sizeLimitCombo = new QComboBox( false, sizeGroup, "sizeLimitCombo" );
00582                 sizeLimitCombo ->setGeometry( QRect( 5, 20, 70, 25 ) );
00583                 sizeLimitCombo->insertItem(tr("Unlimited"));
00584 
00585                 for(int i=1;i<13; i++) {
00586                                 sizeLimitCombo->insertItem( QString::number( i * 5));
00587                 }
00588 
00589 
00590                 glayout3->addMultiCellWidget(  sizeGroup, 0, 0, 1, 1);
00591                 dirGroup = new QGroupBox( tab_3, "dirGroup" );
00592                 dirGroup->setTitle( tr( "File Directory" ) );
00593                 dirGroup->setFixedSize( 130, 50);
00594 
00595                 directoryComboBox = new QComboBox( false, dirGroup, "dirGroup" );
00596                 directoryComboBox->setGeometry( QRect( 10, 15, 115, 25 ) );
00597 
00598                 glayout3->addMultiCellWidget(  dirGroup, 1, 1, 0, 0);
00599 
00600                 bitGroup = new QGroupBox( tab_3, "bitGroup" );
00601                 bitGroup->setTitle( tr( "Bit Depth" ) );
00602                 bitGroup->setFixedSize( 65, 50);
00603 
00604                 bitRateComboBox = new QComboBox( false, bitGroup, "BitRateComboBox" );
00605 
00606                 z = 0;
00607                 while( deviceBitRates[z] != -1) {
00608                                 bitRateComboBox->insertItem( s.setNum( deviceBitRates[z], 10) );
00609                                 z++;
00610                 }
00611 
00612                 bitRateComboBox->setGeometry( QRect( 5, 20, 50, 25 ) );
00613 
00614                 glayout3->addMultiCellWidget(  bitGroup, 1, 1, 1, 1);
00615 
00616                 compressionCheckBox = new QCheckBox ( tr("Wave Compression (smaller files)"), tab_3 );
00617 
00618                 autoMuteCheckBox = new QCheckBox ( tr("Auto Mute"), tab_3 );
00619                 stereoCheckBox = new QCheckBox ( tr("Stereo"), tab_3 );
00620 
00621                 glayout3->addMultiCellWidget( compressionCheckBox, 2, 2, 0, 3);
00622                 glayout3->addMultiCellWidget( autoMuteCheckBox, 3, 3, 0, 0);
00623                 glayout3->addMultiCellWidget( stereoCheckBox, 3, 3, 1, 1);
00624 
00625                 tab_5 = new QWidget( TabWidget, "tab_5" );
00626 
00627                 QHBoxLayout *Layout19a;
00628                 Layout19a = new QHBoxLayout( tab_5);
00629                 Layout19a->setSpacing( 2 );
00630                 Layout19a->setMargin( 0 );
00631 
00632                 Layout15 = new QVBoxLayout( this);
00633                 Layout15->setSpacing( 2 );
00634                 Layout15->setMargin( 0 );
00635 
00636                 Layout15b = new QVBoxLayout( this);
00637                 Layout15b->setSpacing( 2 );
00638                 Layout15b->setMargin( 0 );
00639 
00640                 TextLabel2 = new QLabel( tab_5, "InputLabel" );
00641                 TextLabel2->setText( tr( "In"));
00642                 TextLabel2->setFixedWidth( 35);
00643                 Layout15->addWidget( TextLabel2 );
00644 
00645                 TextLabel3 = new QLabel( tab_5, "OutputLabel" );
00646                 TextLabel3->setText( tr( "Out" ) );
00647                 Layout15b->addWidget( TextLabel3 );
00648 
00649                 InputSlider = new QSlider( -100, 0, 10, 0, QSlider::Vertical, tab_5, (const char *) "InputSlider" );
00650                 InputSlider->setTickmarks( QSlider::Both);
00651                 Layout15->addWidget( InputSlider);
00652 
00653                 OutputSlider = new QSlider( -100,0,10,0, QSlider::Vertical,tab_5,(const char *) "OutputSlider" );
00654                 OutputSlider->setTickmarks( QSlider::Both);
00655 
00656                 Layout15b->addWidget( OutputSlider );
00657 
00658                 outMuteCheckBox = new QCheckBox ( tr("mute"), tab_5 );
00659                 Layout15->addWidget( outMuteCheckBox );
00660 
00661                 inMuteCheckBox = new QCheckBox ( tr("mute"), tab_5 );
00662                 inMuteCheckBox-> setFocusPolicy ( QWidget::NoFocus );
00663                 Layout15b->addWidget( inMuteCheckBox );
00664 
00665 
00666                 Layout19a->addLayout( Layout15 );
00667                 Layout19a->addLayout( Layout15b );
00668 
00669                 fillDirectoryCombo();
00670 
00671                 TabWidget->insertTab( tab_3, tr( "Options" ) );
00672 
00673                 TabWidget->insertTab( tab_5, tr( "Volume" ) );
00674 
00675                 waveform = new Waveform( this, "waveform" );
00676                 waveform->setMinimumSize( QSize( 0, 50 ) );
00677 
00678                 layout->addMultiCellWidget( waveform, 8, 8, 0, 8);
00679                 waveform->setBackgroundColor ( black );
00680 }
00681 
00682 void QtRec::initIconView() {
00683                 ListView1->clear();
00684                 Config cfg("OpieRec");
00685                 cfg.setGroup("Sounds");
00686                 QString temp;
00687                 QPixmap image0( ( const char** ) image0_data );
00688 
00689                 int nFiles = cfg.readNumEntry("NumberofFiles",0);
00690 //    owarn << "init number of files " << nFiles << "" << oendl;
00691 
00692                 for(int i = 1; i <= nFiles; i++) {
00693 
00694                                 QListViewItem * item;
00695                                 QString fileS, mediaLocation, fileDate,  filePath;
00696 
00697                                 temp.sprintf( "%d",i);
00698                                 temp = cfg.readEntry( temp,""); //reads currentFile
00699                                 filePath = cfg.readEntry( temp,""); //currentFileName
00700 
00701                                 QFileInfo info(filePath);
00702                                 fileDate = info.lastModified().toString();
00703 
00704                                 fileS = cfg.readEntry( filePath, "0" );// file length in seconds
00705                                 mediaLocation = getStorage( filePath);
00706                                 if( info.exists()) {
00707 //                                              owarn << "new item " << temp << oendl;
00708                                                 item = new QListViewItem( ListView1, temp,  fileS /*,  mediaLocation, fileDate*/);
00709                                                 item->setPixmap( 0, image0);
00710                                                 if( currentFileName == filePath)
00711                                                                 ListView1->setSelected( item, true);
00712                                 }
00713                 }
00714 }
00715 
00716 void QtRec::initConnections() {
00717                 connect(qApp,SIGNAL(aboutToQuit()),SLOT(cleanUp()));
00718 
00719                 connect(toBeginningButton,SIGNAL(pressed()),this,SLOT(rewindPressed()));
00720                 connect(toBeginningButton,SIGNAL(released()),this,SLOT(rewindReleased()));
00721                 connect(toEndButton,SIGNAL(pressed()),this,SLOT(FastforwardPressed()));
00722                 connect(toEndButton,SIGNAL(released()),this,SLOT(FastforwardReleased()));
00723 
00724                 connect(deleteSoundButton,SIGNAL(released()),this,SLOT(deleteSound()));
00725 
00726                 connect(Stop_PushButton,SIGNAL(released()),this,SLOT(doPlayBtn()));
00727 //              connect(Stop_PushButton,SIGNAL(released()),this,SLOT(doPlayBtn()));
00728 
00729 //              connect(Rec_PushButton,SIGNAL(released()),this,SIGNAL(startRecording()));
00730                 connect(Rec_PushButton,SIGNAL(released()),this,SLOT(newSound()));
00731 
00732                 connect(TabWidget,SIGNAL(currentChanged(QWidget*)),this,SLOT(thisTab(QWidget*)));
00733 
00734                 connect(OutputSlider,SIGNAL(sliderReleased()),this,SLOT(changedOutVolume()));
00735                 connect(InputSlider,SIGNAL(sliderReleased()),this,SLOT(changedInVolume()));
00736 
00737                 connect(sampleRateComboBox,SIGNAL(activated(int)),this,SLOT(changesamplerateCombo(int)));
00738                 connect(bitRateComboBox,SIGNAL(activated(int)),this,SLOT(changebitrateCombo(int)));
00739                 connect(directoryComboBox,SIGNAL(activated(int)),this,SLOT(changeDirCombo(int)));
00740                 connect(sizeLimitCombo,SIGNAL(activated(int)),this,SLOT(changeSizeLimitCombo(int)));
00741 
00742                 connect(stereoCheckBox,SIGNAL(toggled(bool)),this,SLOT(changeStereoCheck(bool)));
00743                 connect(outMuteCheckBox,SIGNAL(toggled(bool)),this,SLOT(doVolMuting(bool)));
00744                 connect(inMuteCheckBox,SIGNAL(toggled(bool)),this,SLOT(doMicMuting(bool)));
00745 
00746                 connect(ListView1,SIGNAL(doubleClicked(QListViewItem*)),this,SLOT(itClick(QListViewItem*)));
00747                 connect(ListView1,SIGNAL(mouseButtonPressed(int,QListViewItem*,const QPoint&,int)),this,SLOT(listPressed(int,QListViewItem*,const QPoint&,int)));
00748 
00749                 connect(timeSlider,SIGNAL(sliderMoved(int)),this,SLOT(changeTimeSlider(int)));
00750                 connect(timeSlider,SIGNAL(sliderPressed()),this,SLOT(timeSliderPressed()));
00751                 connect(timeSlider,SIGNAL(sliderReleased()),this,SLOT(timeSliderReleased()));
00752 
00753                 connect(compressionCheckBox,SIGNAL(toggled(bool)),this,SLOT(compressionSelected(bool)));
00754                 connect(autoMuteCheckBox,SIGNAL(toggled(bool)),this,SLOT(slotAutoMute(bool)));
00755 }
00756 
00757 void QtRec::initConfig() {
00758                 int index, fred, i;
00759                 Config cfg("OpieRec");
00760                 cfg.setGroup("Settings");
00761 
00762                 index = cfg.readNumEntry("samplerate",22050);
00763                 bool ok;
00764 
00765                 for(int ws=0;ws<sampleRateComboBox->count();ws++) {
00766                                 fred = sampleRateComboBox->text(ws).toInt(&ok, 10);
00767                                 if( index == fred) {
00768                                                 filePara.sampleRate  = fred;
00769                                                 sampleRateComboBox->setCurrentItem(ws);
00770                                 }
00771                 }
00772 
00773                 i = cfg.readNumEntry("bitrate",16);
00774                 if(i == 16)
00775                                 bitRateComboBox->setCurrentItem( 1);
00776                 else    if(i == 24)
00777                                 bitRateComboBox->setCurrentItem( 2);
00778                 else    if(i == 32)
00779                                 bitRateComboBox->setCurrentItem( 3);
00780                 else
00781                                 bitRateComboBox->setCurrentItem( 0);
00782 
00783                 filePara.resolution = i;
00784 
00785                 i = cfg.readNumEntry("sizeLimit", 5 );
00786                 QString temp;
00787                 sizeLimitCombo->setCurrentItem((i/5));
00788 
00789                 stereoCheckBox->setChecked( cfg.readBoolEntry("stereo", 1));
00790                 if( stereoCheckBox->isChecked()) {
00791                                 filePara.channels = 2;
00792                 } else {
00793                                 filePara.channels = 1;
00794                 }
00795 
00796                 compressionCheckBox->setChecked( cfg.readBoolEntry("wavCompression",1));
00797                 if( compressionCheckBox->isChecked()) {
00798                                 bitRateComboBox->setCurrentItem(1);
00799                                 bitRateComboBox->setEnabled(false);
00800                                 filePara.resolution=16;
00801                 }
00802 
00803                 autoMuteCheckBox->setChecked( cfg.readBoolEntry("useAutoMute",0));
00804                 if( autoMuteCheckBox->isChecked())
00805                                 slotAutoMute(true);
00806                 else
00807                                 slotAutoMute(false);
00808 
00809                 Config cofg( "qpe");
00810                 cofg.setGroup( "Volume");
00811                 outMuteCheckBox->setChecked( cofg.readBoolEntry( "Mute",0));
00812                 inMuteCheckBox->setChecked( cofg.readBoolEntry( "MicMute",0));
00813 }
00814 
00815 void QtRec::stop() {
00816 //              owarn << "STOP" << oendl;
00817                 setRecordButton(false);
00818 
00819                 if( !recording) {
00820                                 emit stopPlaying();
00821                                 endPlaying();
00822                 } else {
00823                                 emit stopRecording();
00824                                 endRecording();
00825                 }
00826                 timeSlider->setValue(0);
00827 }
00828 
00829 void QtRec::doPlayBtn() {
00830 
00831                 if(!stopped) {
00832 //                              playLabel2->setText(tr("Play"));
00833                                 stop();
00834                 } else {
00835                                 if(ListView1->currentItem() == 0) return;
00836 //                              playLabel2->setText(tr("Stop"));
00837                                 currentFile = ListView1->currentItem()->text(0);
00838                                 start();
00839                 }
00840 }
00841 
00842 void QtRec::start() { //play
00843                 if( stopped) {
00844                                 QPixmap image3( ( const char** ) image3_data );
00845                                 Stop_PushButton->setPixmap( image3 );
00846                                 Stop_PushButton->setDown( true);
00847                                 stopped = false;
00848                                 paused = false;
00849                                 secCount = 1;
00850 
00851                                 if( openPlayFile())
00852                                                 if( setupAudio( false))  //recording is false
00853                                                                 doPlay();
00854                 }
00855 }
00856 
00857 bool QtRec::rec() { //record
00858                 QString timeString;
00859                 timeString.sprintf("%.0f",  0.0);
00860 //              timeLabel->setText( timeString+ " seconds");
00861                 if(!stopped) {
00862                                 monitoring = true;
00863                                 return false;
00864                 } else {
00865                                 secCount = 1;
00866 //                              playLabel2->setText(tr("Stop"));
00867                                 monitoring = false;
00868                                 setRecordButton( true);
00869 
00870                                 if( setupAudio( true))
00871                                                 if(setUpFile())  {
00872                                                                 int fileSize = 0;
00873                                                                 Config cfg("OpieRec");
00874                                                                 cfg.setGroup("Settings");
00875                                                                 filePara.SecondsToRecord = getCurrentSizeLimit();
00876                                                                 int diskSize = checkDiskSpace( (const QString &) wavFile->trackName());
00877 
00878                                                                 if( filePara.SecondsToRecord == 0) {
00879                                                                                 fileSize = diskSize;
00880                                                                 } else if( filePara.format == WAVE_FORMAT_PCM) {
00881 //                odebug << "WAVE_FORMAT_PCM" << oendl;
00882                                                                                 fileSize = (filePara.SecondsToRecord ) * filePara.channels
00883                                                                                                 * filePara.sampleRate * ( filePara.resolution / 8) + 1000;
00884                                                                 } else {
00885 //                odebug << "WAVE_FORMAT_DVI_ADPCM" << oendl;
00886                                                                                 fileSize = ((filePara.SecondsToRecord) * filePara.channels
00887                                                                                                                                 * filePara.sampleRate * ( filePara.resolution / 8) ) / 4 + 250;
00888                                                                 }
00889 
00890                                                                 filePara.samplesToRecord = fileSize;
00891                                                                 odebug << "filesize should be " << filePara.samplesToRecord
00892                                                                                          << ", bits " << filePara.resolution << ", rate " << filePara.sampleRate;
00893                                                                 if( paused) {
00894                                                                                 paused = false;
00895                                                                 }
00896                                                                         //                  else {
00897                                                                 odebug << "Setting timeslider " << filePara.samplesToRecord << "" << oendl;
00898                                                                         //           if(fileSize != 0)
00899                                                                 timeSlider->setRange(0, filePara.samplesToRecord);
00900                                                                         //                  }
00901 
00902                                                                 if( diskSize < fileSize/1024) {
00903                                                                                 QMessageBox::warning(this,
00904                                                                                                                                                                  tr("Low Disk Space"),
00905                                                                                                                                                                  tr("You are running low of\nrecording space\n"
00906                                                                                                                                                                                 "or a card isn't being recognized"));
00907                                                                                 stopped = true; //we need to be stopped
00908                                                                                 stop();
00909                                                                 } else {
00910                                                                                 QString msg;
00911                                                                                 msg.sprintf("%d, %d, %d", filePara.sampleRate, filePara.channels, filePara.resolution);
00912 #ifdef DEV_VERSION
00913                                                                                 setCaption( msg);
00914 #endif
00915                                                                                 filePara.fileName=currentFile.latin1();
00916                                                                                 odebug << "Start recording" << oendl;
00917                                                                                 stopped = false;
00918 
00919 #ifdef THREADED
00920                                                                                 odebug << "Start recording thread" << oendl;
00921                                                                                 pthread_t thread1;
00922                                                                                 pthread_create( &thread1, NULL, (void * (*)(void *))quickRec, NULL/* &*/);
00923 #endif
00924                                                                                 toBeginningButton->setEnabled( false);
00925                                                                                 toEndButton->setEnabled( false);
00926 
00927                                                                                 startTimer(1000);
00928 #ifndef THREADED
00929                                                                                 quickRec();
00930 #endif
00931                                                                 }
00932                                                 } //end setUpFile
00933                 } //end setupAudio
00934                 return true;
00935 }
00936 /*
00937   This happens when a tab is selected*/
00938 void QtRec::thisTab(QWidget* widg) {
00939                 if(widg != NULL) {
00940                                 int index = TabWidget->currentPageIndex();
00941 
00942                                 if(index == 0) { //file page
00943                                 }
00944 
00945                                 if(index == 1) { //control page
00946                                                 fillDirectoryCombo();
00947 //       soundDevice->getOutVol();
00948 //       soundDevice->getInVol();
00949                                 }
00950 
00951                                 if( index==2) { //help page
00952                                 }
00953 
00954                                 qApp->processEvents();
00955                                 update();
00956                 }
00957 }
00958 
00959 void QtRec::getOutVol( ) {
00960                 filePara.outVol = soundDevice->getOutVolume();
00961 //   odebug << "out vol " << filePara.outVol << "" << oendl;
00962                 OutputSlider->setValue( -filePara.outVol);
00963 }
00964 
00965 void QtRec::getInVol() {
00966                 filePara.inVol = soundDevice->getInVolume();
00967 //    odebug << "in vol " << filePara.inVol << "" << oendl;
00968                 InputSlider->setValue( -filePara.inVol);
00969 }
00970 
00971 void QtRec::changedOutVolume() {
00972                 soundDevice->changedOutVolume( -OutputSlider->value());
00973 }
00974 
00975 void QtRec::changedInVolume( ) {
00976                 soundDevice->changedInVolume( -InputSlider->value());
00977 }
00978 
00979 
00980 bool QtRec::setupAudio( bool b) {
00981                 bool ok;
00982                 int  sampleformat, stereo, flags;
00983                 QString dspString, mixerString;
00984 
00985                 filePara.resolution = bitRateComboBox->currentText().toInt( &ok,10);  //16
00986 
00987                 if( !b) {
00988 // we want to play
00989 #ifdef PDAUDIO //ALSA
00990                                 if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) {
00991                                                 sampleformat = SND_PCM_FORMAT_S16;
00992                                                 filePara.resolution = 16;
00993                                 } else if( filePara.resolution == 24 || compressionCheckBox->isChecked() ) {
00994                                                 sampleformat = SND_PCM_FORMAT_S24;
00995                                                 filePara.resolution = 24;
00996                                 } else if( filePara.resolution == 32 || compressionCheckBox->isChecked() ) {
00997                                                 sampleformat = SND_PCM_FORMAT_S32;
00998                                                 filePara.resolution = 32;
00999                                 } else {
01000                                                 sampleformat = SND_PCM_FORMAT_U8;
01001                                                 filePara.resolution = 8;
01002                                 }
01003 #else
01004 // we want to play
01005                                 if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) {
01006                                                 sampleformat = AFMT_S16_LE;
01007                                                 filePara.resolution = 16;
01008                                 } else {
01009                                                 sampleformat = AFMT_U8;
01010                                                 filePara.resolution = 8;
01011                                 }
01012 #endif
01013 
01014                                 stereo = filePara.channels;
01015                                 flags = O_WRONLY;
01016                                 recording = false;
01017                 } else { // we want to record
01018 
01019 #ifdef PDAUDIO //ALSA
01020                                 if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16")
01021                                                 sampleformat = SND_PCM_FORMAT_S16;
01022                                 else if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "24")
01023                                                 sampleformat = SND_PCM_FORMAT_S24;
01024                                 else if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "32")
01025                                                 sampleformat = SND_PCM_FORMAT_S32;
01026                                 else
01027                                                 sampleformat = SND_PCM_FORMAT_U8;
01028 
01029 #else
01030                                 if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16")
01031                                                 sampleformat = AFMT_S16_LE;
01032                                 else
01033                                                 sampleformat = AFMT_U8;
01034 
01035                                 if( !compressionCheckBox->isChecked()) {
01036                                                 filePara.format = WAVE_FORMAT_PCM;
01037 //          odebug << "WAVE_FORMAT_PCM" << oendl;
01038                                 }  else {
01039                                                 filePara.format = WAVE_FORMAT_DVI_ADPCM;
01040                                                 sampleformat = AFMT_S16_LE;
01041 //          odebug << "WAVE_FORMAT_DVI_ADPCM" << oendl;
01042                                 }
01043 #endif
01044 
01045                                 stereo = filePara.channels;
01046 //        filePara.sampleRate = sampleRateComboBox->currentText().toInt( &ok,10);//44100;
01047                                 flags= O_RDWR;
01048 //        flags= O_RDONLY;
01049                                 recording = true;
01050                 }
01051                 
01052                 owarn << "<<<<<<<<<<<<<<<<<<<open dsp " << filePara.sampleRate << " " << filePara.channels << " " << sampleformat << "" << oendl;
01053 //              owarn << "change waveform settings" << oendl;
01054                 waveform->changeSettings( filePara.sampleRate, filePara.channels );
01055 
01056                 soundDevice = new Device( this, b); //open rec
01057 //    soundDevice->openDsp();
01058                 soundDevice->reset();
01059 
01060                 odebug << "device has been made " << soundDevice->sd << "" << oendl;
01061 
01063                 soundDevice->setDeviceFormat( sampleformat);
01064                 soundDevice->setDeviceChannels( filePara.channels);
01065                 soundDevice->setDeviceRate( filePara.sampleRate);
01066                 soundDevice->getDeviceFragSize();
01067 #ifdef QT_QWS_EBX
01068                 int frag = FRAGSIZE;
01069                 soundDevice->setFragSize( frag);
01070                 soundDevice->getDeviceFragSize();
01071 #endif
01072 
01073                 filePara.sd = soundDevice->sd;
01074 
01075                 if ( filePara.sd == -1) {
01076 
01077                                 monitoring = false;
01078                                 stopped = true;
01079                                 update();
01080                                 setCaption( tr( "OpieRecord " )+ QString::number(VERSION) );
01081                                 return false;
01082                 }
01083                 if(autoMute)
01084                                 doMute(false);
01085 
01086                 return true;
01087 }
01088 
01089 
01090 bool QtRec::setUpFile() { //setup file for recording
01091                 wavFile = new WavFile( this, (const QString &)"",
01092                                                                                                          true,
01093                                                                                                          filePara.sampleRate,
01094                                                                                                          filePara.channels,
01095                                                                                                          filePara.resolution,
01096                                                                                                          filePara.format);
01097 
01098                 filePara.fd = wavFile->wavHandle();
01099                 if(filePara.fd == -1) {
01100                                 return false;
01101                 } else {
01102                 }
01103                 return true;
01104 }
01105 
01107 bool QtRec::doPlay() {
01108 
01109                 if( !paused) {
01110                                 total = 0;
01111                                 filePara.numberOfRecordedSeconds = 0;
01112                 } else {
01113                                 paused = false;
01114                                 secCount = (int)filePara.numberOfRecordedSeconds;
01115                 }
01116                 playing = true;
01117                 stopped = false;
01118                 recording = false;
01119 
01120                 QString num;
01121                 odebug << "Play number of samples " << filePara.numberSamples << "" << oendl;
01122 
01123 //   timeSlider->setRange( 0, filePara.numberSamples);
01124 
01125                 timeString.sprintf("%f",  filePara.numberOfRecordedSeconds);
01126 //              timeLabel->setText( timeString+ tr(" seconds"));
01127 
01128                 QString msg;
01129                 msg.sprintf("%d, %d, %d",
01130                                                                 filePara.sampleRate,
01131                                                                 filePara.channels,
01132                                                                 filePara.resolution);
01133 #ifdef DEV_VERSION
01134                 setCaption( msg);
01135 #endif
01136 
01137                 startTimer( 1000);
01138 #ifdef THREADED
01139                 pthread_t thread2;
01140                 pthread_create( &thread2, NULL, (void * (*)(void *))playIt, NULL/* &*/);
01141 #endif
01142 
01143                 toBeginningButton->setEnabled( false);
01144                 toEndButton->setEnabled( false);
01145 #ifndef  THREADED
01146                 playIt();
01147 #endif
01148                 return true;
01149 }
01150 
01151 
01152 void QtRec::changebitrateCombo(int i) {
01153                 Config cfg("OpieRec");
01154                 cfg.setGroup("Settings");
01155                 int bits = 0;
01156                 if( i == 1) { bits = 16; }
01157                 else if( i == 2) { bits = 24; }
01158                 else if( i == 3) { bits = 32; }
01159                 else { bits=8; }
01160                 cfg.writeEntry("bitrate", bits);
01161                 filePara.resolution = bits;
01162                 cfg.write();
01163 }
01164 
01165 void QtRec::changesamplerateCombo(int i) {
01166                 Config cfg("OpieRec");
01167                 cfg.setGroup("Settings");
01168                 int rate=0;
01169                 bool ok;
01170                 rate = sampleRateComboBox->text(i).toInt(&ok, 10);
01171                 cfg.writeEntry( "samplerate",rate);
01172                 filePara.sampleRate=rate;
01173                 odebug << "Change sample rate " << rate << "" << oendl;
01174                 cfg.write();
01175 }
01176 
01177 
01178 void QtRec::changeDirCombo(int index) {
01179                 Config cfg("OpieRec");
01180                 cfg.setGroup("Settings");
01181                 QString sName = directoryComboBox->text(index);
01182 
01183                 StorageInfo storageInfo;
01184                 const QList<FileSystem> &fs = storageInfo.fileSystems();
01185                 QListIterator<FileSystem> it ( fs );
01186                 QString storage;
01187                 for( ; it.current(); ++it ){
01188                                 if( sName == (*it)->name()+" "+  (*it)->path() ||
01189                                                 (*it)->name() == sName ) {
01190                                                 const QString path = (*it)->path();
01191                                                 recDir = path;
01192                                                 cfg.writeEntry("directory", recDir);
01193                                                 odebug << "new rec dir "+recDir << oendl;
01194                                 }
01195                 }
01196                 cfg.write();
01197 }
01198 
01199 
01200 void QtRec::changeSizeLimitCombo(int) {
01201                 Config cfg("OpieRec");
01202                 cfg.setGroup("Settings");
01203                 cfg.writeEntry("sizeLimit", getCurrentSizeLimit() );
01204                 cfg.write();
01205 }
01206 
01207 void QtRec::newSound() {
01208                 if( !rec()) {
01209                                 endRecording();
01210                                 deleteSound();
01211                 }
01212 }
01213 
01214 void QtRec::itClick(QListViewItem *item) {
01215                 currentFile = item->text(0);
01216                 setCaption("OpieRecord  "+currentFile);
01217 }
01218 
01219 void QtRec::deleteSound() {
01220                 Config cfg("OpieRec");
01221                 cfg.setGroup("Sounds");
01222                 if( ListView1->currentItem() == NULL)
01223                                 return;
01224                 QString file = ListView1->currentItem()->text(0);
01225                 QString fileName;
01226                 fileName = cfg.readEntry( file, "");
01227                 QFile f( fileName);
01228                 if( f.exists())
01229                                 if( !f.remove())
01230                                                 QMessageBox::message( tr("Error"), tr("Could not remove file."));
01231 
01232                 int nFiles = cfg.readNumEntry( "NumberofFiles",0);
01233                 bool found = false;
01234                 for(int i=0;i<nFiles+1;i++) {
01235 
01236                                 if( cfg.readEntry( QString::number(i),"").find( file,0,true) != -1) {
01237                                                 found = true;
01238                                                 cfg.writeEntry( QString::number(i), cfg.readEntry( QString::number(i+1),""));
01239                                 }
01240                                 if(found)
01241                                                 cfg.writeEntry( QString::number(i), cfg.readEntry( QString::number(i+1),""));
01242                 }
01243 
01244                 cfg.removeEntry( cfg.readEntry( file));
01245                 cfg.removeEntry( file);
01246                 cfg.writeEntry( "NumberofFiles", nFiles-1);
01247                 cfg.write();
01248 
01249                 ListView1->takeItem( ListView1->currentItem() );
01250                 delete ListView1->currentItem();
01251 
01252                 ListView1->clear();
01253                 ListView1->setSelected( ListView1->firstChild(), true);
01254                 initIconView();
01255                 update();
01256                 setCaption( tr( "OpieRecord " ));
01257 }
01258 
01259 void QtRec::keyPressEvent( QKeyEvent *e) {
01260 
01261                 switch ( e->key() ) {
01262                                         //  case Key_F1:
01263                                         //     if(stopped && !recording)
01264                                         //       newSound();
01265                                         //     else
01266                                         //       stop();
01267                                         //    break;
01268                                         //   case Key_F2: {
01269                                         //     if( !e->isAutoRepeat())
01270                                         //     rewindPressed();
01271                                         //   }
01272                                         //     break;
01273                                         //   case Key_F3: {
01274                                         //     if( !e->isAutoRepeat())
01275                                         //     FastforwardPressed();
01276                                         //   }
01277                                         //     break;
01278 
01280                         case Key_F9: //activity
01281                                         break;
01282                         case Key_F10: //contacts
01283                                         break;
01284                         case Key_F11: //menu
01285                                         break;
01286                         case Key_F12: //home
01287                                         break;
01288                         case Key_F13: //mail
01289                                         break;
01290                         case Key_Space:
01291                                         break;
01292                         case Key_Delete:
01293                                         break;
01294                         case Key_Up:
01295                                                 //    stop();
01296                                         break;
01297                         case Key_Down:
01298                                                 //    newSound();
01299                                         break;
01300                         case Key_Left: {
01301                                         odebug << "rewinding" << oendl;
01302                                         if( !e->isAutoRepeat())
01303                                                         rewindPressed();
01304                         }
01305                                         break;
01306                         case Key_Right: {
01307                                         if( !e->isAutoRepeat())
01308                                                         FastforwardPressed();
01309                         }
01310                                         break;
01311                 }
01312 }
01313 
01314 void  QtRec::keyReleaseEvent( QKeyEvent *e) {
01315                 switch ( e->key() ) {
01316                                         //   case Key_F1:
01317                                         //      if(stopped && !recording)
01318                                         //        newSound();
01319                                         //      else
01320                                         //        stop();
01321                                         //     break;
01322                                         //   case Key_F2:
01323                                         //     rewindReleased();
01324                                         //     break;
01325                                         //   case Key_F3:
01326                                         //     FastforwardReleased();
01327                                         //     break;
01328 
01330                         case Key_F9: //activity
01331                                         break;
01332                         case Key_F10: //contacts
01333                                         break;
01334                         case Key_F11: //menu
01335                                         break;
01336                         case Key_F12: //home
01337                                         if(stopped)
01338                                                         doPlayBtn();
01339                                         else
01340                                                         stop();
01341                                         break;
01342                         case Key_F13: //mail
01343                                         break;
01344                         case Key_Space:
01345                                         if(stopped && !recording)
01346                                                         newSound();
01347                                         else
01348                                                         stop();
01349                                         break;
01350                         case Key_Delete:
01351                                         deleteSound();
01352                                         break;
01353                         case Key_Up:
01354                                                 //      stop();
01355                                         odebug << "Up" << oendl;
01356                                         break;
01357                         case Key_Down:
01358                                                 //      start();
01359                                                 //      odebug << "Down" << oendl;
01360                                                 //    newSound();
01361                                         break;
01362                         case Key_Left:
01363                                         odebug << "Left" << oendl;
01364                                         rewindReleased();
01365                                         break;
01366                         case Key_Right:
01367                                         odebug << "Right" << oendl;
01368                                         FastforwardReleased();
01369                                         break;
01370                 }
01371 }
01372 
01373 void QtRec::endRecording() {
01374                 
01375                 monitoring = false;
01376                 recording = false;
01377                 stopped = true;
01378                 waveform->reset();
01379                 setRecordButton( false);
01380 
01381                 toBeginningButton->setEnabled( true);
01382                 toEndButton->setEnabled( true);
01383 
01384                 killTimers();
01385 
01386                 if(autoMute)
01387                                 doMute( true);
01388 
01389                 soundDevice->closeDevice( true);
01390 
01391                 if( wavFile->track.isOpen()) {
01392                                 wavFile->adjustHeaders( filePara.fd, filePara.numberSamples);
01393                                 filePara.numberSamples = 0;
01394                                 wavFile->closeFile();
01395                                 filePara.fd=0;
01396 
01397                                 if( wavFile->isTempFile()) {
01398 // move tmp file to regular file
01399                                                 QString cmd;
01400                                                 cmd.sprintf("mv "+ wavFile->trackName() + " " + wavFile->currentFileName);
01401                                                 odebug << "moving tmp file to "+currentFileName << oendl;
01402                                                 system( cmd.latin1());
01403                                 }
01404 
01405                                 odebug << "Just moved " + wavFile->currentFileName << oendl;
01406                                 Config cfg("OpieRec");
01407                                 cfg.setGroup("Sounds");
01408 
01409                                 int nFiles = cfg.readNumEntry( "NumberofFiles",0);
01410 
01411                                 currentFile = QFileInfo( wavFile->currentFileName).fileName();
01412                                 currentFile = currentFile.left( currentFile.length() - 4);
01413 
01414                                 cfg.writeEntry( "NumberofFiles", nFiles + 1);
01415                                 cfg.writeEntry( QString::number( nFiles + 1), currentFile);
01416                                 cfg.writeEntry( currentFile, wavFile->currentFileName);
01417 
01418                                 QString time;
01419                                 time.sprintf("%.2f", filePara.numberOfRecordedSeconds);
01420                                 cfg.writeEntry( wavFile->currentFileName, time );
01421                                 odebug << "writing config numberOfRecordedSeconds "+time << oendl;
01422 
01423                                 cfg.write();
01424                                 odebug << "finished recording" << oendl;
01425 //                              timeLabel->setText("");
01426                 }
01427 
01428 //      if(soundDevice) delete soundDevice;
01429 
01430                 timeSlider->setValue(0);
01431                 initIconView();
01432                 selectItemByName( currentFile);
01433                 setCaption( tr( "OpieRecord " ));
01434                 
01435 }
01436 
01437 void QtRec::endPlaying() {
01438                 monitoring = false;
01439                 recording = false;
01440                 playing = false;
01441                 stopped = true;
01442                 waveform->reset();
01443 //   errorStop();
01444     odebug << "end playing" << oendl;
01445                 setRecordButton( false);
01446 
01447                 toBeginningButton->setEnabled( true);
01448                 toEndButton->setEnabled( true);
01449 
01450                 if(autoMute)
01451                                 doMute( true);
01452 
01453                 soundDevice->closeDevice( false);
01454                 soundDevice->sd = -1;
01455                         //  if(soundDevice) delete soundDevice;
01456     odebug << "file and sound device closed" << oendl;
01457 //              timeLabel->setText("");
01458                 total = 0;
01459                 filePara.numberSamples = 0;
01460                 filePara.sd = -1;
01461 //   wavFile->closeFile();
01462                 filePara.fd = 0;
01463 //  if(wavFile) delete wavFile; //this crashes
01464 
01465     odebug << "track closed" << oendl;
01466                 killTimers();
01467 //              owarn << "reset slider" << oendl;
01468                 timeSlider->setValue(0);
01469 
01470 //      if(soundDevice) delete soundDevice;
01471 
01472 }
01473 
01474 bool QtRec::openPlayFile() {
01475                 qWarning("opening file");
01476                 qApp->processEvents();
01477                 if( currentFile.isEmpty()) {
01478                                 QMessageBox::message(tr("Opierec"),tr("Please select file to play"));
01479                                 endPlaying();
01480                                 return false;
01481                 }
01482                 QString currentFileName;
01483                 Config cfg("OpieRec");
01484                 cfg.setGroup("Sounds");
01485                 int nFiles = cfg.readNumEntry( "NumberofFiles", 0);
01486                 for(int i=0;i<nFiles+1;i++) { //look for file
01487                                 if( cfg.readEntry( QString::number(i),"").find( currentFile,0,true) != -1) {
01488                                                 currentFileName = cfg.readEntry( currentFile, "" );
01489                                                 odebug << "opening for play: " + currentFileName << oendl;
01490                                 }
01491                 }
01492                 wavFile = new WavFile(this,
01493                                                                                                         currentFileName,
01494                                                                                                         false);
01495                 filePara.fd = wavFile->wavHandle();
01496                 if(filePara.fd == -1) {
01497                                         //  if(!track.open(IO_ReadOnly)) {
01498                                 QString errorMsg = (QString)strerror(errno);
01499                                 monitoring = false;
01500                                 setCaption( tr( "OpieRecord " ));
01501                                 QMessageBox::message(tr("Note"), tr("Could not open audio file.\n")
01502                                                                                                                  + errorMsg + "\n" + currentFile);
01503                                 return false;
01504                 } else {
01505 
01506                                 filePara.numberSamples = wavFile->getNumberSamples();
01507                                 filePara.format = wavFile->getFormat();
01508                                 filePara.sampleRate = wavFile->getSampleRate();
01509                                 filePara.resolution = wavFile->getResolution();
01510                                 filePara.channels = wavFile->getChannels();
01511                                 timeSlider->setPageStep(1);
01512                                 monitoring = true;
01513 
01514                                 odebug << "file " << filePara.fd << ", samples " << filePara.numberSamples << " " << filePara.sampleRate << "" << oendl;
01515                                 int sec = (int) (( filePara.numberSamples / filePara.sampleRate) / filePara.channels) / ( filePara.channels*( filePara.resolution/8));
01516 
01517 //                              owarn << "seconds " << sec << "" << oendl;
01518 
01519                                 timeSlider->setRange(0, filePara.numberSamples );
01520                 }
01521 
01522                 return true;
01523 }
01524 
01525 void QtRec::listPressed( int mouse, QListViewItem *item, const QPoint &, int ) {
01526                 if(item == NULL )
01527                                 return;
01528                 switch (mouse) {
01529                         case 1: {
01530                                         if( renameBox != 0 ) //tricky
01531                                                         cancelRename();
01532 
01533                                         currentFile = item->text(0);
01534 //                                      setCaption( "OpieRecord  " + currentFile);
01535                         }
01536                                         break;
01537                         case 2:
01538                                         showListMenu(item);
01539                                         ListView1->clearSelection();
01540                                         break;
01541                 };
01542 }
01543 
01544 void QtRec::showListMenu(QListViewItem * item) {
01545                 if(item == NULL)
01546                                 return;
01547                 QPopupMenu *m = new QPopupMenu(this);
01548                 m->insertItem( tr("Play"), this, SLOT( doMenuPlay() ));
01549                 if(Ir::supported())  m->insertItem( tr( "Send with Ir" ), this, SLOT( doBeam() ));
01550                 m->insertItem( tr( "Rename" ), this, SLOT( doRename() ));
01551                         // #if defined (QTOPIA_INTERNAL_FSLP)
01552                         //     m->insertItem( tr( "Properties" ), this, SLOT( doProperties() ));
01553                         // #endif
01554                 m->insertSeparator();
01555                 m->insertItem( tr("Delete"), this, SLOT( deleteSound() ) );
01556                 m->exec( QCursor::pos() );
01557                 qApp->processEvents();
01558 }
01559 
01560 void QtRec::fileBeamFinished( Ir *ir) {
01561                 if(ir)
01562                                 QMessageBox::message( tr("Ir Beam out"), tr("Ir sent.") ,tr("Ok") );
01563 
01564 }
01565 
01566 void QtRec::doBeam() {
01567                 qApp->processEvents();
01568                 if(  ListView1->currentItem() == NULL)
01569                                 return;
01570                 Ir ir;
01571                 if( ir.supported()) {
01572                                 QString file = ListView1->currentItem()->text(0);
01573                                 Config cfg("OpieRec");
01574                                 cfg.setGroup("Sounds");
01575 
01576                                 int nFiles = cfg.readNumEntry("NumberofFiles",0);
01577 
01578                                 for(int i=0;i<nFiles+1;i++) {
01579                                                 if( cfg.readEntry( QString::number( i),"").find( file, 0, true) != -1) {
01580                                                                 QString filePath = cfg.readEntry(file,"");
01581                                                                 Ir *file = new Ir(this, "IR");
01582                                                                 connect( file, SIGNAL( done(Ir*)),
01583                                                                                                  this, SLOT( fileBeamFinished(Ir*)));
01584                                                                 file->send( filePath, "OPieRec audio file\n" + filePath );
01585                                                 }
01586                                 }
01587                 }
01588 }
01589 
01590 void QtRec::doMenuPlay() {
01591                 qApp->processEvents();
01592                 currentFile = ListView1->currentItem()->text(0);
01593 }
01594 
01595 void QtRec::doRename() {
01596                 QRect r = ListView1->itemRect( ListView1->currentItem( ));
01597                 r = QRect( ListView1->viewportToContents( r.topLeft() ), r.size() );
01598                 r.setX( ListView1->contentsX() );
01599                 if ( r.width() > ListView1->visibleWidth() )
01600                                 r.setWidth( ListView1->visibleWidth() );
01601 
01602                 renameBox = new QLineEdit( ListView1->viewport(), "qt_renamebox" );
01603                 renameBox->setFrame(true);
01604 
01605                 renameBox->setText(  ListView1->currentItem()->text(0) );
01606 
01607                 renameBox->selectAll();
01608                 renameBox->installEventFilter( this );
01609                 ListView1->addChild( renameBox, r.x(), r.y() );
01610                 renameBox->resize( r.size() );
01611                 ListView1->viewport()->setFocusProxy( renameBox );
01612                 renameBox->setFocus();
01613                 renameBox->show();
01614 
01615 }
01616 
01617 void QtRec::okRename() {
01618                 odebug << renameBox->text() << oendl;
01619                 QString  filename = renameBox->text();
01620                 cancelRename();
01621 
01622                 if(  ListView1->currentItem() == NULL)
01623                                 return;
01624 
01625                 Config cfg("OpieRec");
01626                 cfg.setGroup("Sounds");
01627 
01628                 QString file = ListView1->currentItem()->text(0);
01629 
01630                 odebug << "filename is  " + filename << oendl;
01631 
01632                 int nFiles = cfg.readNumEntry("NumberofFiles",0);
01633 
01634                 for(int i=0;i<nFiles+1;i++) { //look for file
01635                                 if( cfg.readEntry( QString::number(i),"").find(file,0,true) != -1) {
01636 
01637                                                 QString filePath = cfg.readEntry(file,"");
01638 
01639                                                 cfg.writeEntry( QString::number(i), filename );
01640                                                 cfg.writeEntry( filename, filePath );
01641                                                 cfg.removeEntry( file);
01642                                                 cfg.write();
01643                                 }
01644                 }
01645 
01646                 ListView1->takeItem( ListView1->currentItem() );
01647                 delete ListView1->currentItem();
01648                 ListView1->clear();
01649                 initIconView();
01650                 update();
01651 }
01652 
01653 void QtRec::cancelRename() {
01654                 bool resetFocus = ListView1->viewport()->focusProxy() == renameBox;
01655                 delete renameBox;
01656                 renameBox = 0;
01657                 if ( resetFocus ) {
01658                                 ListView1->viewport()->setFocusProxy( ListView1 );
01659                                 ListView1->setFocus();
01660                 }
01661 }
01662 
01663 bool QtRec::eventFilter( QObject * o, QEvent * e ) {
01664                 if ( o->inherits( "QLineEdit" ) ) {
01665                                 if ( e->type() == QEvent::KeyPress ) {
01666                                                 QKeyEvent *ke = (QKeyEvent*)e;
01667                                                 if ( ke->key() == Key_Return ||
01668                                                                  ke->key() == Key_Enter ) {
01669                                                                 okRename();
01670                                                                 return true;
01671                                                 } else if ( ke->key() == Key_Escape ) {
01672                                                                 cancelRename();
01673                                                                 return true;
01674                                                 }
01675                                 } else if ( e->type() == QEvent::FocusOut ) {
01676                                                 cancelRename();
01677                                                 return true;
01678                                 }
01679                 }
01680                 return QWidget::eventFilter( o, e );
01681 }
01682 
01683 
01684 int QtRec::getCurrentSizeLimit() {
01685                 return  sizeLimitCombo->currentItem() * 5;
01686 }
01687 
01688 void QtRec::timerBreak() {
01689                 endPlaying();
01690 }
01691 
01692 void QtRec::doVolMuting(bool b) {
01693                 Config cfg( "qpe" );
01694                 cfg. setGroup( "Volume" );
01695                 cfg.writeEntry( "Mute",b);
01696                 cfg.write();
01697                 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << b;
01698 }
01699 
01700 void QtRec::doMicMuting(bool b) {
01701                         //  odebug << "mic mute" << oendl;
01702                 Config cfg( "qpe" );
01703                 cfg. setGroup( "Volume" );
01704                 cfg.writeEntry( "MicMute",b);
01705                 cfg.write();
01706                 QCopEnvelope( "QPE/System", "micChange(bool)" ) << b;
01707 }
01708 
01709 void QtRec::compressionSelected(bool b) {
01710                 Config cfg("OpieRec");
01711                 cfg.setGroup("Settings");
01712                 cfg.writeEntry("wavCompression", b);
01713                 cfg.writeEntry("bitrate", 16);
01714                 filePara.resolution = 16;
01715                 cfg.write();
01716 
01717                 if(b) {
01718                                 qWarning("set adpcm");
01719                                 bitRateComboBox->setCurrentItem( 1);
01720                                 bitRateComboBox->setEnabled( false);
01721                                 filePara.resolution = 16;
01722                 } else{
01723                                 bitRateComboBox->setEnabled( true);
01724                 }
01725 }
01726 
01727 long QtRec::checkDiskSpace(const QString &path) {
01728 
01729                 struct statfs fs;
01730 
01731                 if ( !statfs( path.latin1(), &fs ) ) {
01732 
01733                                 int blkSize = fs.f_bsize;
01734                                 int availBlks = fs.f_bavail;
01735 
01736                                 long mult = blkSize / 1024;
01737                                 long div = 1024 / blkSize;
01738 
01739                                 if ( !mult ) mult = 1;
01740                                 if ( !div ) div = 1;
01741 
01742                                 return  availBlks * mult / div;
01743                 }
01744                 return -1;
01745 }
01746 
01747 //   short  f_fstyp;    /* File system type */
01748 //   long  f_bsize;    /* Block size */
01749 //   long  f_frsize;   /* Fragment size */
01750 //   long  f_blocks;   /* Total number of blocks*/
01751 //   long  f_bfree;    /* Count of free blocks */
01752 //   long  f_files;    /* Total number of file nodes */
01753 //   long  f_ffree;    /* Count of free file nodes */
01754 //   char  f_fname[6]; /* Volumename */
01755 //   char  f_fpack[6]; /* Pack name */
01756 
01757 void QtRec::receive( const QCString &msg, const QByteArray & ) {
01758                 odebug << "Voicerecord received message "+msg << oendl;
01759 
01760 }
01761 
01762 
01764 void QtRec::timerEvent( QTimerEvent * ) {
01765 
01766 //    if(!recording)
01767 //       timeSlider->setValue( secCount);
01768 //     else
01769 //        timeSlider->setValue( filePara.numberOfRecordedSeconds);
01770 
01771                 if( stopped && playing) {
01772                                 stop();
01773                 }
01774 
01775                 if( stopped && recording ){
01776                                 stop();
01777                 }
01778 
01779                 if( recording && filePara.SecondsToRecord < secCount && filePara.SecondsToRecord != 0) {
01780                                 stop();
01781                 }
01782 
01783                 odebug << "" << secCount << "" << oendl;
01784                 QString  timeString;
01785 
01786                 timeString.sprintf("%d", secCount);
01787 //              timeLabel->setText( timeString + " seconds");
01788 
01789                 secCount++;
01790 }
01791 
01792 void QtRec::changeTimeSlider(int index) {
01793                 if( ListView1->currentItem() == 0 || !wavFile->track.isOpen()) return;
01794                 odebug << "Slider moved to " << index << "" << oendl;
01795                 paused = true;
01796                 stopped = true;
01797 
01798                 sliderPos=index;
01799 
01800                 QString timeString;
01801                 filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2;
01802                 timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds);
01803                 secCount = (int)filePara.numberOfRecordedSeconds;
01804 //              timeLabel->setText( timeString + tr(" seconds"));
01805 }
01806 
01807 void QtRec::timeSliderPressed() {
01808                 if( ListView1->currentItem() == 0) return;
01809                 odebug << "slider pressed" << oendl;
01810                 paused = true;
01811                 stopped = true;
01812 }
01813 
01814 void QtRec::timeSliderReleased() {
01815                 if( ListView1->currentItem() == 0) return;
01816                 sliderPos = timeSlider->value();
01817 
01818                 odebug << "slider released " << sliderPos << "" << oendl;
01819                 stopped = false;
01820                 int newPos =  lseek( filePara.fd, sliderPos, SEEK_SET);
01821                 total =  newPos*4;
01822                 filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2;
01823 
01824                 doPlay();
01825 }
01826 
01827 void QtRec::rewindPressed() {
01828                 if( ListView1->currentItem() == 0) return;
01829                 if( !wavFile->track.isOpen()) {
01830                                 if( !openPlayFile() )
01831                                                 return;
01832                                 else
01833                                                 if( !setupAudio( false))
01834                                                                 return;
01835                 } else {
01836                                 killTimers();
01837                                 paused = true;
01838                                 stopped = true;
01839                                 rewindTimer->start( 50, false);
01840                 }
01841 }
01842 
01843 void QtRec::rewindTimerTimeout() {
01844                 int  sliderValue = timeSlider->value();
01845                 sliderValue = sliderValue - ( filePara.numberSamples / 100);
01846                         //  if(toBeginningButton->isDown())
01847                 timeSlider->setValue( sliderValue ) ;
01848                 odebug << "" << sliderValue << "" << oendl;
01849                 QString timeString;
01850                 filePara.numberOfRecordedSeconds = (float)sliderValue / (float)filePara.sampleRate * (float)2;
01851                 timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds);
01852 //              timeLabel->setText( timeString+ tr(" seconds"));
01853 }
01854 
01855 void QtRec::rewindReleased() {
01856                 rewindTimer->stop();
01857                 if( wavFile->track.isOpen()) {
01858                                 sliderPos=timeSlider->value();
01859                                 stopped = false;
01860                                 int newPos =  lseek( filePara.fd, sliderPos, SEEK_SET);
01861                                 total =  newPos * 4;
01862                                 odebug << "rewind released " << total << "" << oendl;
01863                                 startTimer( 1000);
01864                                 doPlay();
01865                 }
01866 }
01867 
01868 void QtRec::FastforwardPressed() {
01869                 if( ListView1->currentItem() == 0) return;
01870                 if( !wavFile->track.isOpen())
01871                                 if( !openPlayFile() )
01872                                                 return;
01873                                 else
01874                                                 if( !setupAudio( false))
01875                                                                 return;
01876                 killTimers();
01877 
01878                 paused = true;
01879                 stopped = true;
01880                 forwardTimer->start(50, false);
01881 }
01882 
01883 
01884 void QtRec::forwardTimerTimeout() {
01885                 int sliderValue = timeSlider->value();
01886                 sliderValue = sliderValue + ( filePara.numberSamples / 100);
01887 
01888                         //  if(toEndButton->isDown())
01889                 timeSlider->setValue( sliderValue);
01890 
01891                 QString timeString;
01892                 filePara.numberOfRecordedSeconds = (float)sliderValue / (float)filePara.sampleRate * (float)2;
01893                 timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds);
01894 //              timeLabel->setText( timeString+ tr(" seconds"));
01895 }
01896 
01897 void QtRec::FastforwardReleased() {
01898                 forwardTimer->stop();
01899                 if( wavFile->track.isOpen()) {
01900                                 sliderPos=timeSlider->value();
01901                                 stopped = false;
01902                                 int newPos =  lseek( filePara.fd, sliderPos, SEEK_SET);
01903                                 total =  newPos * 4;
01904                                 filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2;
01905                                 startTimer( 1000);
01906                                 doPlay();
01907                 }
01908 }
01909 
01910 
01911 QString QtRec::getStorage(const QString &fileName) {
01912 
01913                 StorageInfo storageInfo;
01914                 const QList<FileSystem> &fs = storageInfo.fileSystems();
01915                 QListIterator<FileSystem> it ( fs );
01916                 QString storage;
01917                 for( ; it.current(); ++it ){
01918                                 const QString name = ( *it)->name();
01919                                 const QString path = ( *it)->path();
01920                                 const QString disk = ( *it)->disk();
01921                                 if( fileName.find( path,0,true) != -1)
01922                                                 storage = name;
01923                                         //        const QString options = (*it)->options();
01924                                         //        if( name.find( tr("Internal"),0,true) == -1) {
01925                                         //            storageComboBox->insertItem( name +" -> "+disk);
01926                                         //    odebug << name << oendl;
01927                 }
01928                 return storage;
01929                         //      struct mntent *me;
01930                         //  //     if(fileName == "/etc/mtab") {
01931                         //      FILE *mntfp = setmntent( fileName.latin1(), "r" );
01932                         //      if ( mntfp ) {
01933                         //          while ( (me = getmntent( mntfp )) != 0 ) {
01934                         //              QString filesystemType = me->mnt_type;
01935 
01936                         //          }
01937                         //      }
01938                         //      endmntent( mntfp );
01939 }
01940 
01941 void QtRec::setRecordButton(bool b) {
01942 
01943                 if(b) { //about to record or play
01944 
01945                                 Rec_PushButton->setDown( true);
01946                                 QPixmap image3( ( const char** ) image3_data );
01947                                 Stop_PushButton->setPixmap( image3 );
01948                                 if(Stop_PushButton->isDown())
01949                                                 Stop_PushButton->setDown( true);
01950 //                              playLabel2->setText( tr("Stop") );
01951 
01952                 } else { //about to stop
01953 
01954                                 QPixmap image4( ( const char** ) image4_data );
01955                                 Stop_PushButton->setPixmap( image4);
01956                                 if(Stop_PushButton->isDown())
01957                                                 Stop_PushButton->setDown( false);
01958 //                              playLabel2->setText( tr("Play") );
01959                                 if(Rec_PushButton->isDown())
01960                                                 Rec_PushButton->setDown( false);
01961                 }
01962 }
01963 
01964 void QtRec::fillDirectoryCombo() {
01965                 if( directoryComboBox->count() > 0)
01966                                 directoryComboBox->clear();
01967                 int index = 0;
01968                 Config cfg("OpieRec");
01969                 cfg.setGroup("Settings");
01970                 QString dir = cfg.readEntry("directory", "/");
01971                 StorageInfo storageInfo;
01972                 const QList<FileSystem> &fs = storageInfo.fileSystems();
01973                 QListIterator<FileSystem> it ( fs );
01974                 QString storage;
01975                 for( ; it.current(); ++it ){
01976                                 const QString name = ( *it)->name();
01977                                 const QString path = ( *it)->path();
01978                                         //    directoryComboBox->insertItem(name+" "+path);
01979                                 directoryComboBox->insertItem(name);
01980                                 if( path == dir)
01981                                                 directoryComboBox->setCurrentItem( index);
01982                                 index++;
01983                 }
01984 }
01985 
01986 void QtRec::errorStop() {
01987                 stopped = true;
01988                 wavFile->closeFile();
01989                 killTimers();
01990 }
01991 
01992 void QtRec::doMute(bool b) {
01993                 doVolMuting( b);
01994                 doMicMuting( b);
01995 }
01996 
01997 void QtRec::slotAutoMute(bool b) {
01998                 autoMute = b;
01999                 Config cfg("OpieRec");
02000                 cfg.setGroup("Settings");
02001                 cfg.writeEntry("useAutoMute",b);
02002                 doMute( b);
02003                 outMuteCheckBox->setChecked( b);
02004                 inMuteCheckBox->setChecked( b);
02005 }
02006 
02007 void QtRec::selectItemByName(const QString & name) {
02008                 QListViewItemIterator it( ListView1 );
02009                 for ( ; it.current(); ++it )
02010                                 if( name == it.current()->text(0))
02011                                                 ListView1->setCurrentItem(it.current());
02012 }
02013 
02014 
02015 // long findPeak(long input ) {
02016 
02017 // // halfLife = time in seconds for output to decay to half value after an impulse
02018 //    static float output = 0.0;
02019 //    float halfLife = .0025;
02020 //    float vsf = .0025;
02021 //    float scalar = pow( 0.5, 1.0/(halfLife * filePara.sampleRate ));
02022 //    if( input < 0.0 )
02023 //       input = -input;  // Absolute value.
02024 //    if ( input >= output ) {
02025 //       // When we hit a peak, ride the peak to the top.
02026 //       output = input;
02027 //    } else {
02028 // // Exponential decay of output when signal is low.
02029 //       output = output * scalar;
02030 // //
02031 // //   When current gets close to 0.0, set current to 0.0 to prevent FP underflow
02032 // //   which can cause a severe performance degradation due to a flood
02033 // //   of interrupts.
02034 // //
02035 //       if( output < vsf ) output = 0.0;
02036 //    }
02037 
02038 //    return (long) output;
02039 // }
02040 
02041 void QtRec::changeStereoCheck(bool b) {
02042                 Config cfg("OpieRec");
02043                 cfg.setGroup("Settings");
02044                 int ch = 0;
02045                 if ( !b) { ch = 1;}
02046                 else { ch = 2;}
02047                 cfg.writeEntry("stereo", b);
02048                 filePara.channels = ch;
02049 
02050                 cfg.write();
02051 }
02052 
02053 

Generated on Sat Nov 5 16:17:34 2005 for OPIE by  doxygen 1.4.2