-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 108 |
1 files changed, 56 insertions, 52 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 7dd5b4b..622b1df 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -12,6 +12,10 @@ | |||
12 | // copyright 2002 Jeremy Cowgar <jc@cowgar.com> | 12 | // copyright 2002 Jeremy Cowgar <jc@cowgar.com> |
13 | // copyright 2002 and 2003 L.J.Potter <ljp@llornkcor.com> | 13 | // copyright 2002 and 2003 L.J.Potter <ljp@llornkcor.com> |
14 | 14 | ||
15 | /* OPIE */ | ||
16 | #include <opie2/odebug.h> | ||
17 | using namespace Opie::Core; | ||
18 | |||
15 | extern "C" { | 19 | extern "C" { |
16 | #include "adpcm.h" | 20 | #include "adpcm.h" |
17 | } | 21 | } |
@@ -29,7 +33,7 @@ typedef struct _waveheader { | |||
29 | u_long length; /* filelen */ | 33 | u_long length; /* filelen */ |
30 | u_long chunk_type; /* 'WAVE' */ | 34 | u_long chunk_type; /* 'WAVE' */ |
31 | u_long sub_chunk; /* 'fmt ' */ | 35 | u_long sub_chunk; /* 'fmt ' */ |
32 | u_long sc_len; /* length of sub_chunk, =16 | 36 | u_long sc_len; /* length of sub_chunk, =16 |
33 | (chunckSize) format len */ | 37 | (chunckSize) format len */ |
34 | u_short format; /* should be 1 for PCM-code (formatTag) */ | 38 | u_short format; /* should be 1 for PCM-code (formatTag) */ |
35 | 39 | ||
@@ -198,21 +202,21 @@ VMemo::VMemo( QWidget *parent, const char *_name ) | |||
198 | : QWidget( parent, _name ) { | 202 | : QWidget( parent, _name ) { |
199 | setFixedHeight( 18 ); | 203 | setFixedHeight( 18 ); |
200 | setFixedWidth( 14 ); | 204 | setFixedWidth( 14 ); |
201 | 205 | ||
202 | t_timer = new QTimer( this ); | 206 | t_timer = new QTimer( this ); |
203 | connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); | 207 | connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); |
204 | 208 | ||
205 | Config vmCfg("Vmemo"); | 209 | Config vmCfg("Vmemo"); |
206 | vmCfg.setGroup("Defaults"); | 210 | vmCfg.setGroup("Defaults"); |
207 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); | 211 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); |
208 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | 212 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); |
209 | 213 | ||
210 | qDebug("toggleKey %d", toggleKey); | 214 | odebug << "toggleKey " << toggleKey << "" << oendl; |
211 | if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) | 215 | if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) |
212 | systemZaurus=TRUE; | 216 | systemZaurus=TRUE; |
213 | else | 217 | else |
214 | systemZaurus=FALSE; | 218 | systemZaurus=FALSE; |
215 | 219 | ||
216 | myChannel = new QCopChannel( "QPE/VMemo", this ); | 220 | myChannel = new QCopChannel( "QPE/VMemo", this ); |
217 | connect( myChannel, SIGNAL(received(const QCString&,const QByteArray&)), | 221 | connect( myChannel, SIGNAL(received(const QCString&,const QByteArray&)), |
218 | this, SLOT(receive(const QCString&,const QByteArray&)) ); | 222 | this, SLOT(receive(const QCString&,const QByteArray&)) ); |
@@ -245,7 +249,7 @@ int VMemo::position() | |||
245 | } | 249 | } |
246 | 250 | ||
247 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { | 251 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { |
248 | qDebug("receive"); | 252 | odebug << "receive" << oendl; |
249 | QDataStream stream( data, IO_ReadOnly ); | 253 | QDataStream stream( data, IO_ReadOnly ); |
250 | 254 | ||
251 | if (msg == "toggleRecord()") { | 255 | if (msg == "toggleRecord()") { |
@@ -267,7 +271,7 @@ void VMemo::paintEvent( QPaintEvent* ) { | |||
267 | void VMemo::mousePressEvent( QMouseEvent * me) { | 271 | void VMemo::mousePressEvent( QMouseEvent * me) { |
268 | /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions | 272 | /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions |
269 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ | 273 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ |
270 | 274 | ||
271 | // if (!systemZaurus && me != NULL) | 275 | // if (!systemZaurus && me != NULL) |
272 | // return; | 276 | // return; |
273 | // } | 277 | // } |
@@ -293,14 +297,14 @@ bool VMemo::startRecording() { | |||
293 | msgLabel->show(); | 297 | msgLabel->show(); |
294 | } | 298 | } |
295 | 299 | ||
296 | qDebug("Start recording engines"); | 300 | odebug << "Start recording engines" << oendl; |
297 | recording = TRUE; | 301 | recording = TRUE; |
298 | 302 | ||
299 | if (openDSP() == -1) { | 303 | if (openDSP() == -1) { |
300 | recording = FALSE; | 304 | recording = FALSE; |
301 | return FALSE; | 305 | return FALSE; |
302 | } | 306 | } |
303 | 307 | ||
304 | config.setGroup("Defaults"); | 308 | config.setGroup("Defaults"); |
305 | 309 | ||
306 | date = TimeString::dateString( QDateTime::currentDateTime(),false,true); | 310 | date = TimeString::dateString( QDateTime::currentDateTime(),false,true); |
@@ -318,21 +322,21 @@ bool VMemo::startRecording() { | |||
318 | s=fileName.find(':'); | 322 | s=fileName.find(':'); |
319 | if(s) | 323 | if(s) |
320 | fileName=fileName.right(fileName.length()-s-2); | 324 | fileName=fileName.right(fileName.length()-s-2); |
321 | qDebug("pathname will be "+fileName); | 325 | odebug << "pathname will be "+fileName << oendl; |
322 | 326 | ||
323 | if( fileName.left(1).find('/') == -1) | 327 | if( fileName.left(1).find('/') == -1) |
324 | fileName="/"+fileName; | 328 | fileName="/"+fileName; |
325 | if( fileName.right(1).find('/') == -1) | 329 | if( fileName.right(1).find('/') == -1) |
326 | fileName+="/"; | 330 | fileName+="/"; |
327 | fName = "vm_"+ date+ ".wav"; | 331 | fName = "vm_"+ date+ ".wav"; |
328 | 332 | ||
329 | fileName+=fName; | 333 | fileName+=fName; |
330 | qDebug("filename is "+fileName); | 334 | odebug << "filename is "+fileName << oendl; |
331 | // open tmp file here | 335 | // open tmp file here |
332 | char *pointer; | 336 | char *pointer; |
333 | pointer=tmpnam(NULL); | 337 | pointer=tmpnam(NULL); |
334 | qDebug("Opening tmp file %s",pointer); | 338 | odebug << "Opening tmp file " << pointer << "" << oendl; |
335 | 339 | ||
336 | if(openWAV(pointer ) == -1) { | 340 | if(openWAV(pointer ) == -1) { |
337 | 341 | ||
338 | QString err("Could not open the temp file\n"); | 342 | QString err("Could not open the temp file\n"); |
@@ -349,12 +353,12 @@ bool VMemo::startRecording() { | |||
349 | 353 | ||
350 | cmd.sprintf("mv %s "+fileName, pointer); | 354 | cmd.sprintf("mv %s "+fileName, pointer); |
351 | // move tmp file to regular file here | 355 | // move tmp file to regular file here |
352 | 356 | ||
353 | system(cmd.latin1()); | 357 | system(cmd.latin1()); |
354 | 358 | ||
355 | QArray<int> cats(1); | 359 | QArray<int> cats(1); |
356 | cats[0] = config.readNumEntry("Category", 0); | 360 | cats[0] = config.readNumEntry("Category", 0); |
357 | 361 | ||
358 | QString dlName("vm_"); | 362 | QString dlName("vm_"); |
359 | dlName += date; | 363 | dlName += date; |
360 | DocLnk l; | 364 | DocLnk l; |
@@ -366,12 +370,12 @@ bool VMemo::startRecording() { | |||
366 | return TRUE; | 370 | return TRUE; |
367 | } else | 371 | } else |
368 | return FALSE; | 372 | return FALSE; |
369 | 373 | ||
370 | } | 374 | } |
371 | 375 | ||
372 | void VMemo::stopRecording() { | 376 | void VMemo::stopRecording() { |
373 | show(); | 377 | show(); |
374 | qDebug("Stopped recording"); | 378 | odebug << "Stopped recording" << oendl; |
375 | recording = FALSE; | 379 | recording = FALSE; |
376 | if(useAlerts) { | 380 | if(useAlerts) { |
377 | msgLabel->close(); | 381 | msgLabel->close(); |
@@ -388,7 +392,7 @@ void VMemo::stopRecording() { | |||
388 | int VMemo::openDSP() { | 392 | int VMemo::openDSP() { |
389 | Config cfg("Vmemo"); | 393 | Config cfg("Vmemo"); |
390 | cfg.setGroup("Record"); | 394 | cfg.setGroup("Record"); |
391 | 395 | ||
392 | speed = cfg.readNumEntry("SampleRate", 22050); | 396 | speed = cfg.readNumEntry("SampleRate", 22050); |
393 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 397 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
394 | if (cfg.readNumEntry("SixteenBit", 1)==1) { | 398 | if (cfg.readNumEntry("SixteenBit", 1)==1) { |
@@ -399,7 +403,7 @@ int VMemo::openDSP() { | |||
399 | resolution = 8; | 403 | resolution = 8; |
400 | } | 404 | } |
401 | 405 | ||
402 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); | 406 | odebug << "samplerate: " << speed << ", channels " << channels << ", resolution " << resolution << "" << oendl; |
403 | 407 | ||
404 | if(systemZaurus) { | 408 | if(systemZaurus) { |
405 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 | 409 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 |
@@ -407,18 +411,18 @@ int VMemo::openDSP() { | |||
407 | } else { | 411 | } else { |
408 | dsp = open("/dev/dsp", O_RDONLY); | 412 | dsp = open("/dev/dsp", O_RDONLY); |
409 | } | 413 | } |
410 | 414 | ||
411 | if(dsp == -1) { | 415 | if(dsp == -1) { |
412 | msgLabel->close(); | 416 | msgLabel->close(); |
413 | msgLabel=0; | 417 | msgLabel=0; |
414 | delete msgLabel; | 418 | delete msgLabel; |
415 | 419 | ||
416 | perror("open(\"/dev/dsp\")"); | 420 | perror("open(\"/dev/dsp\")"); |
417 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); | 421 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); |
418 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); | 422 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); |
419 | return -1; | 423 | return -1; |
420 | } | 424 | } |
421 | 425 | ||
422 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { | 426 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { |
423 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 427 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
424 | return -1; | 428 | return -1; |
@@ -437,7 +441,7 @@ int VMemo::openDSP() { | |||
437 | } | 441 | } |
438 | 442 | ||
439 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute | 443 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute |
440 | 444 | ||
441 | return 1; | 445 | return 1; |
442 | } | 446 | } |
443 | 447 | ||
@@ -452,29 +456,29 @@ int VMemo::openWAV(const char *filename) { | |||
452 | Config vmCfg("Vmemo"); | 456 | Config vmCfg("Vmemo"); |
453 | vmCfg.setGroup("Defaults"); | 457 | vmCfg.setGroup("Defaults"); |
454 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | 458 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); |
455 | 459 | ||
456 | WaveHeader wh; | 460 | WaveHeader wh; |
457 | 461 | ||
458 | wh.main_chunk = RIFF; | 462 | wh.main_chunk = RIFF; |
459 | wh.length=0; | 463 | wh.length=0; |
460 | wh.chunk_type = WAVE; | 464 | wh.chunk_type = WAVE; |
461 | wh.sub_chunk = FMT; | 465 | wh.sub_chunk = FMT; |
462 | wh.sc_len = 16; | 466 | wh.sc_len = 16; |
463 | if(useADPCM) | 467 | if(useADPCM) |
464 | wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; | 468 | wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; |
465 | else | 469 | else |
466 | wh.format = PCM_CODE; | 470 | wh.format = PCM_CODE; |
467 | wh.modus = channels; | 471 | wh.modus = channels; |
468 | wh.sample_fq = speed; | 472 | wh.sample_fq = speed; |
469 | wh.byte_p_sec = speed * channels * resolution/8; | 473 | wh.byte_p_sec = speed * channels * resolution/8; |
470 | wh.byte_p_spl = channels * (resolution / 8); | 474 | wh.byte_p_spl = channels * (resolution / 8); |
471 | wh.bit_p_spl = resolution; | 475 | wh.bit_p_spl = resolution; |
472 | wh.data_chunk = DATA; | 476 | wh.data_chunk = DATA; |
473 | wh.data_length= 0; | 477 | wh.data_length= 0; |
474 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" | 478 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" |
475 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); | 479 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); |
476 | write (wav, &wh, sizeof(WaveHeader)); | 480 | write (wav, &wh, sizeof(WaveHeader)); |
477 | 481 | ||
478 | return 1; | 482 | return 1; |
479 | } | 483 | } |
480 | 484 | ||
@@ -483,7 +487,7 @@ bool VMemo::record() { | |||
483 | int result, value; | 487 | int result, value; |
484 | QString msg; | 488 | QString msg; |
485 | msg.sprintf("Recording format %d", format); | 489 | msg.sprintf("Recording format %d", format); |
486 | qDebug(msg); | 490 | odebug << msg << oendl; |
487 | Config config("Vmemo"); | 491 | Config config("Vmemo"); |
488 | config.setGroup("Record"); | 492 | config.setGroup("Record"); |
489 | int sRate=config.readNumEntry("SizeLimit", 30); | 493 | int sRate=config.readNumEntry("SizeLimit", 30); |
@@ -494,7 +498,7 @@ bool VMemo::record() { | |||
494 | // } else { // 16 bit only capabilities | 498 | // } else { // 16 bit only capabilities |
495 | 499 | ||
496 | msg.sprintf("Recording format other"); | 500 | msg.sprintf("Recording format other"); |
497 | qDebug(msg); | 501 | odebug << msg << oendl; |
498 | 502 | ||
499 | int bufsize=1024; | 503 | int bufsize=1024; |
500 | int bytesWritten=0; | 504 | int bytesWritten=0; |
@@ -513,7 +517,7 @@ bool VMemo::record() { | |||
513 | result = read(dsp, sound, 1024); // 8192 | 517 | result = read(dsp, sound, 1024); // 8192 |
514 | if( result <= 0) { | 518 | if( result <= 0) { |
515 | perror("recording error "); | 519 | perror("recording error "); |
516 | // qDebug(currentFileName); | 520 | // odebug << currentFileName << oendl; |
517 | QMessageBox::message(tr("Note"),tr("error recording")); | 521 | QMessageBox::message(tr("Note"),tr("error recording")); |
518 | recording=FALSE; | 522 | recording=FALSE; |
519 | break; | 523 | break; |
@@ -540,7 +544,7 @@ bool VMemo::record() { | |||
540 | break; | 544 | break; |
541 | return FALSE; | 545 | return FALSE; |
542 | } | 546 | } |
543 | // printf("%d\r",length); | 547 | // odebug << "" << length << "\r" << oendl; |
544 | // fflush(stdout); | 548 | // fflush(stdout); |
545 | qApp->processEvents(); | 549 | qApp->processEvents(); |
546 | } | 550 | } |
@@ -559,8 +563,8 @@ bool VMemo::record() { | |||
559 | write(wav, &length, 4); | 563 | write(wav, &length, 4); |
560 | 564 | ||
561 | track.close(); | 565 | track.close(); |
562 | qDebug("Track closed"); | 566 | odebug << "Track closed" << oendl; |
563 | 567 | ||
564 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 568 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
565 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 569 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
566 | 570 | ||
@@ -573,7 +577,7 @@ bool VMemo::record() { | |||
573 | 577 | ||
574 | QString currentFileName = fileName; | 578 | QString currentFileName = fileName; |
575 | QString currentFile = "vm_"+ date; | 579 | QString currentFile = "vm_"+ date; |
576 | 580 | ||
577 | float numberOfRecordedSeconds=(float) length / (float)speed * (float)2; | 581 | float numberOfRecordedSeconds=(float) length / (float)speed * (float)2; |
578 | 582 | ||
579 | cfgO.writeEntry( "NumberofFiles", nFiles + 1); | 583 | cfgO.writeEntry( "NumberofFiles", nFiles + 1); |
@@ -583,11 +587,11 @@ bool VMemo::record() { | |||
583 | QString time; | 587 | QString time; |
584 | time.sprintf("%.2f", numberOfRecordedSeconds); | 588 | time.sprintf("%.2f", numberOfRecordedSeconds); |
585 | cfgO.writeEntry( currentFileName, time ); | 589 | cfgO.writeEntry( currentFileName, time ); |
586 | // qDebug("writing config numberOfRecordedSeconds "+time); | 590 | // odebug << "writing config numberOfRecordedSeconds "+time << oendl; |
587 | 591 | ||
588 | cfgO.write(); | 592 | cfgO.write(); |
589 | 593 | ||
590 | qDebug("done recording "+fileName); | 594 | odebug << "done recording "+fileName << oendl; |
591 | 595 | ||
592 | Config cfg("qpe"); | 596 | Config cfg("qpe"); |
593 | cfg.setGroup("Volume"); | 597 | cfg.setGroup("Volume"); |
@@ -602,32 +606,32 @@ int VMemo::setToggleButton(int tog) { | |||
602 | for( int i=0; i < 10;i++) { | 606 | for( int i=0; i < 10;i++) { |
603 | switch (tog) { | 607 | switch (tog) { |
604 | case 0: | 608 | case 0: |
605 | return -1; | 609 | return -1; |
606 | break; | 610 | break; |
607 | case 1: | 611 | case 1: |
608 | return 0; | 612 | return 0; |
609 | break; | 613 | break; |
610 | case 2: | 614 | case 2: |
611 | return Key_F24; //was Escape | 615 | return Key_F24; //was Escape |
612 | break; | 616 | break; |
613 | case 3: | 617 | case 3: |
614 | return Key_Space; | 618 | return Key_Space; |
615 | break; | 619 | break; |
616 | case 4: | 620 | case 4: |
617 | return Key_F12; | 621 | return Key_F12; |
618 | break; | 622 | break; |
619 | case 5: | 623 | case 5: |
620 | return Key_F9; | 624 | return Key_F9; |
621 | break; | 625 | break; |
622 | case 6: | 626 | case 6: |
623 | return Key_F10; | 627 | return Key_F10; |
624 | break; | 628 | break; |
625 | case 7: | 629 | case 7: |
626 | return Key_F11; | 630 | return Key_F11; |
627 | break; | 631 | break; |
628 | case 8: | 632 | case 8: |
629 | return Key_F13; | 633 | return Key_F13; |
630 | break; | 634 | break; |
631 | }; | 635 | }; |
632 | } | 636 | } |
633 | return -1; | 637 | return -1; |