-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 116 |
1 files changed, 60 insertions, 56 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 1ead4dd..835f63a 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -240,65 +240,65 @@ VMemo::VMemo( QWidget *parent, const char *_name ) | |||
240 | recording = FALSE; | 240 | recording = FALSE; |
241 | // } | 241 | // } |
242 | } | 242 | } |
243 | 243 | ||
244 | VMemo::~VMemo() { | 244 | VMemo::~VMemo() { |
245 | } | 245 | } |
246 | 246 | ||
247 | int VMemo::position() | 247 | int VMemo::position() |
248 | { | 248 | { |
249 | return 6; | 249 | return 6; |
250 | } | 250 | } |
251 | 251 | ||
252 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { | 252 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { |
253 | odebug << "Vmemo receive" << oendl; | 253 | odebug << "Vmemo receive" << oendl; |
254 | QDataStream stream( data, IO_ReadOnly ); | 254 | QDataStream stream( data, IO_ReadOnly ); |
255 | 255 | ||
256 | if (msg == "toggleRecord()") { | 256 | if (msg == "toggleRecord()") { |
257 | if (recording) { | 257 | if (recording) { |
258 | fromToggle = TRUE; | 258 | fromToggle = TRUE; |
259 | stopRecording(); | 259 | stopRecording(); |
260 | } else { | 260 | } else { |
261 | fromToggle = TRUE; | 261 | fromToggle = TRUE; |
262 | startRecording(); | 262 | startRecording(); |
263 | } | 263 | } |
264 | } | 264 | } |
265 | } | 265 | } |
266 | 266 | ||
267 | void VMemo::paintEvent( QPaintEvent* ) { | 267 | void VMemo::paintEvent( QPaintEvent* ) { |
268 | QPainter p(this); | 268 | QPainter p(this); |
269 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 269 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
270 | } | 270 | } |
271 | 271 | ||
272 | void VMemo::mousePressEvent( QMouseEvent * me) { | 272 | void VMemo::mousePressEvent( QMouseEvent * /*me*/) { |
273 | /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions | 273 | /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions |
274 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ | 274 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ |
275 | 275 | ||
276 | // if (!systemZaurus && me != NULL) | 276 | // if (!systemZaurus && me != NULL) |
277 | // return; | 277 | // return; |
278 | // } | 278 | // } |
279 | 279 | ||
280 | if(!recording) | 280 | if(!recording) |
281 | startRecording(); | 281 | startRecording(); |
282 | else | 282 | else |
283 | stopRecording(); | 283 | stopRecording(); |
284 | } | 284 | } |
285 | 285 | ||
286 | void VMemo::mouseReleaseEvent( QMouseEvent * ) { | 286 | void VMemo::mouseReleaseEvent( QMouseEvent * ) { |
287 | } | 287 | } |
288 | 288 | ||
289 | bool VMemo::startRecording() { | 289 | bool VMemo::startRecording() { |
290 | Config config( "Vmemo" ); | 290 | Config config( "Vmemo" ); |
291 | config.setGroup( "System" ); | 291 | config.setGroup( "System" ); |
292 | 292 | ||
293 | useAlerts = config.readBoolEntry("Alert",1); | 293 | useAlerts = config.readBoolEntry("Alert",1); |
294 | if(useAlerts) { | 294 | if(useAlerts) { |
295 | 295 | ||
296 | msgLabel = new QLabel( 0, "alertLabel" ); | 296 | msgLabel = new QLabel( 0, "alertLabel" ); |
297 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); | 297 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); |
298 | msgLabel->show(); | 298 | msgLabel->show(); |
299 | } | 299 | } |
300 | 300 | ||
301 | odebug << "Start recording engines" << oendl; | 301 | odebug << "Start recording engines" << oendl; |
302 | recording = TRUE; | 302 | recording = TRUE; |
303 | 303 | ||
304 | if (openDSP() == -1) { | 304 | if (openDSP() == -1) { |
@@ -456,162 +456,166 @@ int VMemo::openWAV(const char *filename) { | |||
456 | wav=track.handle(); | 456 | wav=track.handle(); |
457 | Config vmCfg("Vmemo"); | 457 | Config vmCfg("Vmemo"); |
458 | vmCfg.setGroup("Defaults"); | 458 | vmCfg.setGroup("Defaults"); |
459 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | 459 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); |
460 | 460 | ||
461 | WaveHeader wh; | 461 | WaveHeader wh; |
462 | 462 | ||
463 | wh.main_chunk = RIFF; | 463 | wh.main_chunk = RIFF; |
464 | wh.length=0; | 464 | wh.length=0; |
465 | wh.chunk_type = WAVE; | 465 | wh.chunk_type = WAVE; |
466 | wh.sub_chunk = FMT; | 466 | wh.sub_chunk = FMT; |
467 | wh.sc_len = 16; | 467 | wh.sc_len = 16; |
468 | if(useADPCM) | 468 | if(useADPCM) |
469 | wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; | 469 | wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; |
470 | else | 470 | else |
471 | wh.format = PCM_CODE; | 471 | wh.format = PCM_CODE; |
472 | wh.modus = channels; | 472 | wh.modus = channels; |
473 | wh.sample_fq = speed; | 473 | wh.sample_fq = speed; |
474 | wh.byte_p_sec = speed * channels * resolution/8; | 474 | wh.byte_p_sec = speed * channels * resolution/8; |
475 | wh.byte_p_spl = channels * (resolution / 8); | 475 | wh.byte_p_spl = channels * (resolution / 8); |
476 | wh.bit_p_spl = resolution; | 476 | wh.bit_p_spl = resolution; |
477 | wh.data_chunk = DATA; | 477 | wh.data_chunk = DATA; |
478 | wh.data_length= 0; | 478 | wh.data_length= 0; |
479 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" | 479 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" |
480 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); | 480 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); |
481 | write (wav, &wh, sizeof(WaveHeader)); | 481 | write (wav, &wh, sizeof(WaveHeader)); |
482 | 482 | ||
483 | return 1; | 483 | return 1; |
484 | } | 484 | } |
485 | 485 | ||
486 | bool VMemo::record() { | 486 | bool VMemo::record() { |
487 | length = 0; | 487 | length = 0; |
488 | int result, value; | 488 | int bytesWritten = 0; |
489 | int result = 0; | ||
490 | int value = 0; | ||
489 | QString msg; | 491 | QString msg; |
490 | msg.sprintf("Recording format %d", format); | 492 | msg.sprintf("Recording format %d", format); |
491 | odebug << msg << oendl; | 493 | odebug << msg << oendl; |
492 | Config config("Vmemo"); | 494 | Config config("Vmemo"); |
493 | config.setGroup("Record"); | 495 | config.setGroup("Record"); |
494 | int sRate=config.readNumEntry("SizeLimit", 30); | 496 | int sRate = config.readNumEntry("SizeLimit", 30); |
495 | if(sRate > 0) | 497 | if(sRate > 0) |
496 | t_timer->start( sRate * 1000+1000, TRUE); | 498 | t_timer->start( sRate * 1000+1000, TRUE); |
497 | 499 | ||
498 | // if(systemZaurus) { | ||
499 | // } else { // 16 bit only capabilities | ||
500 | |||
501 | msg.sprintf("Recording format other"); | 500 | msg.sprintf("Recording format other"); |
502 | odebug << msg << oendl; | 501 | odebug << msg << oendl; |
503 | 502 | ||
503 | config.setGroup("Defaults"); | ||
504 | useADPCM = config.readBoolEntry("use_ADPCM", 0); | ||
504 | 505 | ||
505 | int bytesWritten = 0; | 506 | int bufsize = config.readNumEntry("BufferSize",1024); |
506 | 507 | unsigned short sound[bufsize]; //, monoBuffer[bufsize]; | |
507 | Config vmCfg("Vmemo"); | ||
508 | vmCfg.setGroup("Defaults"); | ||
509 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | ||
510 | |||
511 | int bufsize = vmCfg.readNumEntry("BufferSize",1024); | ||
512 | signed short sound[bufsize], monoBuffer[bufsize]; | ||
513 | char abuf[bufsize / 2]; | 508 | char abuf[bufsize / 2]; |
514 | short sbuf[bufsize]; | 509 | short sbuf[bufsize]; |
515 | 510 | ||
516 | while(recording) { | 511 | if(useADPCM) { |
517 | 512 | while(recording) { | |
518 | if(useADPCM) | 513 | result = ::read(dsp, sbuf, bufsize); // adpcm read |
519 | result = ::read(dsp, sbuf, bufsize); // 8192 | 514 | if( result <= 0) { |
520 | else | 515 | perror("recording error "); |
521 | result = ::read(dsp, sound, bufsize); // 8192 | 516 | QMessageBox::message(tr("Note"),tr("error recording")); |
522 | if( result <= 0) { | 517 | recording = FALSE; |
523 | perror("recording error "); | 518 | break; |
524 | // odebug << currentFileName << oendl; | 519 | return FALSE; |
525 | QMessageBox::message(tr("Note"),tr("error recording")); | 520 | } |
526 | recording = FALSE; | 521 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); |
527 | break; | 522 | bytesWritten = ::write(wav, abuf, result/4); // adpcm write |
528 | return FALSE; | 523 | length += bytesWritten; |
529 | } | 524 | |
530 | 525 | if(length < 0) { | |
531 | if(useADPCM) { | 526 | recording = false; |
532 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); | 527 | perror("dev/dsp's is a lookin' messy"); |
533 | bytesWritten = ::write(wav, abuf, result/4); | 528 | QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); |
534 | 529 | break; | |
535 | } else { | 530 | return FALSE; |
536 | // for (int i = 0; i < result; i++) { //since Z is mono do normally | 531 | } |
537 | // monoBuffer[i] = sound[i]; | 532 | // printf("%d\r", length); |
538 | // } | 533 | // fflush(stdout); |
539 | 534 | qApp->processEvents(); | |
540 | length += write(wav, sound, result); | ||
541 | } | ||
542 | length += bytesWritten; | ||
543 | |||
544 | if(length<0) { | ||
545 | recording = false; | ||
546 | perror("dev/dsp's is a lookin' messy"); | ||
547 | QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); | ||
548 | break; | ||
549 | return FALSE; | ||
550 | } | 535 | } |
551 | // odebug << "" << length << "\r" << oendl; | 536 | } else { |
552 | // fflush(stdout); | 537 | while(recording) { |
553 | qApp->processEvents(); | 538 | result = ::read(dsp, sound, bufsize); // read |
554 | } | 539 | if( result <= 0) { |
540 | perror("recording error "); | ||
541 | QMessageBox::message(tr("Note"),tr("error recording")); | ||
542 | recording = FALSE; | ||
543 | break; | ||
544 | return FALSE; | ||
545 | |||
546 | bytesWritten = ::write(wav, sound, result); // write | ||
547 | length += bytesWritten; | ||
548 | |||
549 | if(length < 0) { | ||
550 | recording = false; | ||
551 | perror("dev/dsp's is a lookin' messy"); | ||
552 | QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); | ||
553 | break; | ||
554 | return FALSE; | ||
555 | } | ||
556 | // printf("%d\r", length); | ||
557 | // fflush(stdout); | ||
558 | qApp->processEvents(); | ||
559 | } | ||
560 | } | ||
561 | } | ||
555 | // qDebug("file has length of %d lasting %d seconds", | 562 | // qDebug("file has length of %d lasting %d seconds", |
556 | // length, (( length / speed) / channels) / 2 ); | 563 | // length, (( length / speed) / channels) / 2 ); |
557 | // } | ||
558 | |||
559 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// | ||
560 | 564 | ||
561 | value = length + 36; | 565 | value = length + 36; |
562 | 566 | ||
563 | lseek(wav, 4, SEEK_SET); | 567 | lseek(wav, 4, SEEK_SET); |
564 | write(wav, &value, 4); | 568 | write(wav, &value, 4); |
565 | lseek(wav, 40, SEEK_SET); | 569 | lseek(wav, 40, SEEK_SET); |
566 | 570 | ||
567 | write(wav, &length, 4); | 571 | write(wav, &length, 4); |
568 | 572 | ||
569 | track.close(); | 573 | track.close(); |
570 | odebug << "Track closed" << oendl; | 574 | odebug << "Track closed" << oendl; |
571 | 575 | ||
572 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 576 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
573 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 577 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
574 | 578 | ||
575 | ::close(dsp); | 579 | ::close(dsp); |
576 | 580 | ||
577 | Config cfgO("OpieRec"); | 581 | Config cfgO("OpieRec"); |
578 | cfgO.setGroup("Sounds"); | 582 | cfgO.setGroup("Sounds"); |
579 | 583 | ||
580 | int nFiles = cfgO.readNumEntry( "NumberofFiles",0); | 584 | int nFiles = cfgO.readNumEntry( "NumberofFiles",0); |
581 | 585 | ||
582 | QString currentFileName = fileName; | 586 | QString currentFileName = fileName; |
583 | QString currentFile = "vm_"+ date; | 587 | QString currentFile = "vm_"+ date; |
584 | 588 | ||
585 | float numberOfRecordedSeconds=(float) length / (float)speed * (float)2; | 589 | float numberOfRecordedSeconds = (float) length / (float)speed * (float)2; |
586 | 590 | ||
587 | cfgO.writeEntry( "NumberofFiles", nFiles + 1); | 591 | cfgO.writeEntry( "NumberofFiles", nFiles + 1); |
588 | cfgO.writeEntry( QString::number( nFiles + 1), currentFile); | 592 | cfgO.writeEntry( QString::number( nFiles + 1), currentFile); |
589 | cfgO.writeEntry( currentFile, currentFileName); | 593 | cfgO.writeEntry( currentFile, currentFileName); |
590 | 594 | ||
591 | QString time; | 595 | QString time; |
592 | time.sprintf("%.2f", numberOfRecordedSeconds); | 596 | time.sprintf("%.2f", numberOfRecordedSeconds); |
593 | cfgO.writeEntry( currentFileName, time ); | 597 | cfgO.writeEntry( currentFileName, time ); |
594 | // odebug << "writing config numberOfRecordedSeconds "+time << oendl; | 598 | // odebug << "writing config numberOfRecordedSeconds "+time << oendl; |
595 | 599 | ||
596 | cfgO.write(); | 600 | cfgO.write(); |
597 | 601 | ||
598 | odebug << "done recording "+fileName << oendl; | 602 | odebug << "done recording "+fileName << oendl; |
599 | 603 | ||
600 | Config cfg("qpe"); | 604 | Config cfg("qpe"); |
601 | cfg.setGroup("Volume"); | 605 | cfg.setGroup("Volume"); |
602 | QString foo = cfg.readEntry("Mute","TRUE"); | 606 | QString foo = cfg.readEntry("Mute","TRUE"); |
603 | if(foo.find("TRUE",0,TRUE) != -1) | 607 | if(foo.find("TRUE",0,TRUE) != -1) |
604 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute | 608 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute |
605 | return TRUE; | 609 | return TRUE; |
606 | } | 610 | } |
607 | 611 | ||
608 | int VMemo::setToggleButton(int tog) { | 612 | int VMemo::setToggleButton(int tog) { |
609 | 613 | ||
610 | for( int i=0; i < 10;i++) { | 614 | for( int i=0; i < 10;i++) { |
611 | switch (tog) { | 615 | switch (tog) { |
612 | case 0: | 616 | case 0: |
613 | return -1; | 617 | return -1; |
614 | break; | 618 | break; |
615 | case 1: | 619 | case 1: |
616 | return 0; | 620 | return 0; |
617 | break; | 621 | break; |