author | llornkcor <llornkcor> | 2002-06-23 03:12:26 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-06-23 03:12:26 (UTC) |
commit | f3aa76578638116c92652e37b57075850ee17dd3 (patch) (unidiff) | |
tree | af09f06e462b156ab9c8dc2e7ddfcaf673a74cf7 /core/applets/vmemo/vmemo.cpp | |
parent | 8c65ca19eb339c08fc16752697276b7e80794f2d (diff) | |
download | opie-f3aa76578638116c92652e37b57075850ee17dd3.zip opie-f3aa76578638116c92652e37b57075850ee17dd3.tar.gz opie-f3aa76578638116c92652e37b57075850ee17dd3.tar.bz2 |
error checking
-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 69 |
1 files changed, 57 insertions, 12 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 7021fae..e25a1ab 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -212,33 +212,34 @@ VMemo::VMemo( QWidget *parent, const char *_name ) | |||
212 | qDebug("toggleKey %d", toggleKey); | 212 | qDebug("toggleKey %d", toggleKey); |
213 | 213 | ||
214 | if(release.find("embedix",0,TRUE) !=-1) | 214 | if(release.find("embedix",0,TRUE) !=-1) |
215 | systemZaurus=TRUE; | 215 | systemZaurus=TRUE; |
216 | else | 216 | else |
217 | systemZaurus=FALSE; | 217 | systemZaurus=FALSE; |
218 | 218 | ||
219 | myChannel = new QCopChannel( "QPE/VMemo", this ); | 219 | myChannel = new QCopChannel( "QPE/VMemo", this ); |
220 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), | 220 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), |
221 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 221 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
222 | 222 | ||
223 | if( toggleKey != -1 ) { | 223 | if( toggleKey != -1 ) { |
224 | // QPEApplication::grabKeyboard(); | ||
224 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); | 225 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); |
225 | // e << 4096; // Key_Escape | 226 | // e << 4096; // Key_Escape |
226 | // e << Key_F5; //4148 | 227 | // e << Key_F5; //4148 |
227 | e << toggleKey; | 228 | e << toggleKey; |
228 | e << QString("QPE/VMemo"); | 229 | e << QString("QPE/VMemo"); |
229 | e << QString("toggleRecord()"); | 230 | e << QString("toggleRecord()"); |
230 | } | 231 | } |
231 | if( vmCfg.readNumEntry("hideIcon",0) == 1 || toggleKey > 0) | 232 | // if( vmCfg.readNumEntry("hideIcon",0) == 1 || toggleKey > 0) |
232 | hide(); | 233 | // hide(); |
233 | } | 234 | } |
234 | } | 235 | } |
235 | 236 | ||
236 | VMemo::~VMemo() | 237 | VMemo::~VMemo() |
237 | { | 238 | { |
238 | } | 239 | } |
239 | 240 | ||
240 | void VMemo::receive( const QCString &msg, const QByteArray &data ) | 241 | void VMemo::receive( const QCString &msg, const QByteArray &data ) |
241 | { | 242 | { |
242 | QDataStream stream( data, IO_ReadOnly ); | 243 | QDataStream stream( data, IO_ReadOnly ); |
243 | if (msg == "toggleRecord()") { | 244 | if (msg == "toggleRecord()") { |
244 | if (recording) { | 245 | if (recording) { |
@@ -278,31 +279,33 @@ bool VMemo::startRecording() { | |||
278 | useAlerts = config.readBoolEntry("Alert"); | 279 | useAlerts = config.readBoolEntry("Alert"); |
279 | if(useAlerts) { | 280 | if(useAlerts) { |
280 | 281 | ||
281 | msgLabel = new QLabel( 0, "alertLabel" ); | 282 | msgLabel = new QLabel( 0, "alertLabel" ); |
282 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); | 283 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); |
283 | msgLabel->show(); | 284 | msgLabel->show(); |
284 | } | 285 | } |
285 | 286 | ||
286 | // if(useAlerts) | 287 | // if(useAlerts) |
287 | // QMessageBox::message("VMemo","Really Record?");//) ==1) | 288 | // QMessageBox::message("VMemo","Really Record?");//) ==1) |
288 | // return; | 289 | // return; |
289 | // } else { | 290 | // } else { |
290 | if (!systemZaurus ) | 291 | // if (!systemZaurus ) |
291 | QSound::play(Resource::findSound("vmemob")); | 292 | // QSound::play(Resource::findSound("vmemob")); |
292 | // } | 293 | // } |
293 | qDebug("Start recording"); | 294 | qDebug("Start recording engines"); |
294 | recording = TRUE; | 295 | recording = TRUE; |
296 | |||
295 | if (openDSP() == -1) { | 297 | if (openDSP() == -1) { |
296 | QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort"); | 298 | // QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort"); |
299 | // delete msgLabel; | ||
297 | recording = FALSE; | 300 | recording = FALSE; |
298 | return FALSE; | 301 | return FALSE; |
299 | } | 302 | } |
300 | 303 | ||
301 | config.setGroup("Defaults"); | 304 | config.setGroup("Defaults"); |
302 | 305 | ||
303 | QDateTime dt = QDateTime::currentDateTime(); | 306 | QDateTime dt = QDateTime::currentDateTime(); |
304 | 307 | ||
305 | QString fName; | 308 | QString fName; |
306 | config.setGroup( "System" ); | 309 | config.setGroup( "System" ); |
307 | fName = QPEApplication::documentDir() ; | 310 | fName = QPEApplication::documentDir() ; |
308 | fileName = config.readEntry("RecLocation", fName); | 311 | fileName = config.readEntry("RecLocation", fName); |
@@ -318,45 +321,46 @@ bool VMemo::startRecording() { | |||
318 | fileName+="/"; | 321 | fileName+="/"; |
319 | fName = "vm_"+ dt.toString()+ ".wav"; | 322 | fName = "vm_"+ dt.toString()+ ".wav"; |
320 | 323 | ||
321 | fileName+=fName; | 324 | fileName+=fName; |
322 | qDebug("filename is "+fileName); | 325 | qDebug("filename is "+fileName); |
323 | // No spaces in the filename | 326 | // No spaces in the filename |
324 | fileName.replace(QRegExp("'"),""); | 327 | fileName.replace(QRegExp("'"),""); |
325 | fileName.replace(QRegExp(" "),"_"); | 328 | fileName.replace(QRegExp(" "),"_"); |
326 | fileName.replace(QRegExp(":"),"."); | 329 | fileName.replace(QRegExp(":"),"."); |
327 | fileName.replace(QRegExp(","),""); | 330 | fileName.replace(QRegExp(","),""); |
328 | 331 | ||
329 | if(openWAV(fileName.latin1()) == -1) { | 332 | if(openWAV(fileName.latin1()) == -1) { |
330 | QString err("Could not open the output file\n"); | 333 | // QString err("Could not open the output file\n"); |
331 | err += fileName; | 334 | // err += fileName; |
332 | QMessageBox::critical(0, "vmemo", err, "Abort"); | 335 | // QMessageBox::critical(0, "vmemo", err, "Abort"); |
333 | close(dsp); | 336 | close(dsp); |
334 | return FALSE; | 337 | return FALSE; |
335 | } | 338 | } |
336 | 339 | ||
337 | QArray<int> cats(1); | 340 | QArray<int> cats(1); |
338 | cats[0] = config.readNumEntry("Category", 0); | 341 | cats[0] = config.readNumEntry("Category", 0); |
339 | 342 | ||
340 | QString dlName("vm_"); | 343 | QString dlName("vm_"); |
341 | dlName += dt.toString(); | 344 | dlName += dt.toString(); |
342 | DocLnk l; | 345 | DocLnk l; |
343 | l.setFile(fileName); | 346 | l.setFile(fileName); |
344 | l.setName(dlName); | 347 | l.setName(dlName); |
345 | l.setType("audio/x-wav"); | 348 | l.setType("audio/x-wav"); |
346 | l.setCategories(cats); | 349 | l.setCategories(cats); |
347 | l.writeLink(); | 350 | l.writeLink(); |
348 | 351 | ||
349 | 352 | ||
350 | record(); | 353 | record(); |
354 | // delete msgLabel; | ||
351 | return TRUE; | 355 | return TRUE; |
352 | } | 356 | } |
353 | 357 | ||
354 | void VMemo::stopRecording() { | 358 | void VMemo::stopRecording() { |
355 | recording = FALSE; | 359 | recording = FALSE; |
356 | if(useAlerts) | 360 | if(useAlerts) |
357 | if( msgLabel) delete msgLabel; | 361 | if( msgLabel) delete msgLabel; |
358 | } | 362 | } |
359 | 363 | ||
360 | int VMemo::openDSP() | 364 | int VMemo::openDSP() |
361 | { | 365 | { |
362 | Config cfg("Vmemo"); | 366 | Config cfg("Vmemo"); |
@@ -375,24 +379,25 @@ int VMemo::openDSP() | |||
375 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); | 379 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); |
376 | 380 | ||
377 | if(systemZaurus) { | 381 | if(systemZaurus) { |
378 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 | 382 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 |
379 | channels=1; //zaurus has one input channel | 383 | channels=1; //zaurus has one input channel |
380 | } else { | 384 | } else { |
381 | dsp = open("/dev/dsp", O_RDWR); | 385 | dsp = open("/dev/dsp", O_RDWR); |
382 | } | 386 | } |
383 | 387 | ||
384 | if(dsp == -1) { | 388 | if(dsp == -1) { |
385 | perror("open(\"/dev/dsp\")"); | 389 | perror("open(\"/dev/dsp\")"); |
386 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); | 390 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); |
391 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); | ||
387 | return -1; | 392 | return -1; |
388 | } | 393 | } |
389 | 394 | ||
390 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { | 395 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { |
391 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 396 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
392 | return -1; | 397 | return -1; |
393 | } | 398 | } |
394 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { | 399 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { |
395 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 400 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
396 | return -1; | 401 | return -1; |
397 | } | 402 | } |
398 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { | 403 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { |
@@ -438,105 +443,145 @@ int VMemo::openWAV(const char *filename) | |||
438 | 443 | ||
439 | return 1; | 444 | return 1; |
440 | } | 445 | } |
441 | 446 | ||
442 | void VMemo::record(void) | 447 | void VMemo::record(void) |
443 | { | 448 | { |
444 | int length=0, result, value; | 449 | int length=0, result, value; |
445 | QString msg; | 450 | QString msg; |
446 | msg.sprintf("Recording format %d", format); | 451 | msg.sprintf("Recording format %d", format); |
447 | qDebug(msg); | 452 | qDebug(msg); |
448 | 453 | ||
449 | if(systemZaurus) { | 454 | if(systemZaurus) { |
455 | |||
456 | msg.sprintf("Recording format zaurus"); | ||
457 | qDebug(msg); | ||
450 | signed short sound[512], monoBuffer[512]; | 458 | signed short sound[512], monoBuffer[512]; |
459 | |||
451 | if(format==AFMT_S16_LE) { | 460 | if(format==AFMT_S16_LE) { |
452 | 461 | ||
453 | while(recording) { | 462 | while(recording) { |
454 | 463 | ||
455 | result = read(dsp, sound, 512); // 8192 | 464 | result = read(dsp, sound, 512); // 8192 |
456 | int j=0; | 465 | int j=0; |
457 | 466 | ||
458 | if(systemZaurus) { | 467 | if(systemZaurus) { |
459 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 468 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
460 | monoBuffer[i] = sound[i]; | 469 | monoBuffer[i] = sound[i]; |
461 | } | 470 | } |
462 | 471 | ||
463 | length+=write(wav, monoBuffer, result); | 472 | length+=write(wav, monoBuffer, result); |
473 | if(length<0) | ||
474 | recording=false; | ||
464 | 475 | ||
465 | } else { //ipaq /stereo inputs | 476 | } else { //ipaq /stereo inputs |
466 | 477 | ||
478 | |||
467 | for (int i = 0; i < result; i+=2) { | 479 | for (int i = 0; i < result; i+=2) { |
468 | monoBuffer[j] = (sound[i]+sound[i+1])/2; | 480 | / monoBuffer[j] = sound[i]; |
481 | // monoBuffer[j] = (sound[i]+sound[i+1])/2; | ||
482 | |||
469 | j++; | 483 | j++; |
470 | } | 484 | } |
471 | 485 | ||
472 | length+=write(wav, monoBuffer, result/2); | 486 | length+=write(wav, monoBuffer, result); |
487 | if(length<0) | ||
488 | recording=false; | ||
489 | // length+=write(wav, monoBuffer, result/2); | ||
473 | } | 490 | } |
474 | qApp->processEvents(); | 491 | qApp->processEvents(); |
475 | // printf("%d\r",length); | 492 | // printf("%d\r",length); |
476 | // fflush(stdout); | 493 | // fflush(stdout); |
477 | } | 494 | } |
495 | |||
478 | } else { //AFMT_U8 | 496 | } else { //AFMT_U8 |
479 | // 8bit unsigned | 497 | // 8bit unsigned |
480 | unsigned short sound[512], monoBuffer[512]; | 498 | unsigned short sound[512], monoBuffer[512]; |
481 | while(recording) { | 499 | while(recording) { |
482 | result = read(dsp, sound, 512); // 8192 | 500 | result = read(dsp, sound, 512); // 8192 |
483 | int j=0; | 501 | int j=0; |
502 | |||
484 | if(systemZaurus) { | 503 | if(systemZaurus) { |
504 | |||
485 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 505 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
486 | monoBuffer[i] = sound[i]; | 506 | monoBuffer[i] = sound[i]; |
487 | } | 507 | } |
508 | |||
488 | length+=write(wav, monoBuffer, result); | 509 | length+=write(wav, monoBuffer, result); |
510 | |||
489 | } else { //ipaq /stereo inputs | 511 | } else { //ipaq /stereo inputs |
512 | |||
490 | for (int i = 0; i < result; i+=2) { | 513 | for (int i = 0; i < result; i+=2) { |
491 | monoBuffer[j] = (sound[i]+sound[i+1])/2; | 514 | monoBuffer[j] = (sound[i]+sound[i+1])/2; |
492 | j++; | 515 | j++; |
493 | } | 516 | } |
517 | |||
494 | length+=write(wav, monoBuffer, result/2); | 518 | length+=write(wav, monoBuffer, result/2); |
519 | |||
520 | if(length<0) | ||
521 | recording=false; | ||
522 | |||
495 | } | 523 | } |
496 | length += result; | 524 | length += result; |
497 | // printf("%d\r",length); | 525 | // printf("%d\r",length); |
498 | // fflush(stdout); | 526 | // fflush(stdout); |
499 | } | 527 | } |
500 | 528 | ||
501 | qApp->processEvents(); | 529 | qApp->processEvents(); |
502 | } | 530 | } |
503 | 531 | ||
504 | } else { // this is specific for ipaqs that do not have 8 bit capabilities | 532 | } else { // this is specific for ipaqs that do not have 8 bit capabilities |
505 | 533 | ||
534 | msg.sprintf("Recording format other"); | ||
535 | qDebug(msg); | ||
536 | |||
506 | signed short sound[512], monoBuffer[512]; | 537 | signed short sound[512], monoBuffer[512]; |
507 | 538 | ||
508 | while(recording) { | 539 | while(recording) { |
540 | |||
509 | result = read(dsp, sound, 512); // 8192 | 541 | result = read(dsp, sound, 512); // 8192 |
542 | |||
510 | write(wav, sound, result); | 543 | write(wav, sound, result); |
511 | length += result; | 544 | length += result; |
545 | if(length<0) { | ||
512 | 546 | ||
513 | qApp->processEvents(); | 547 | recording=false; |
548 | perror("dev/dsp's is a lookin' messy"); | ||
549 | QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); | ||
514 | } | 550 | } |
515 | // printf("%d\r",length); | 551 | // printf("%d\r",length); |
516 | // fflush(stdout); | 552 | // fflush(stdout); |
553 | qApp->processEvents(); | ||
554 | } | ||
517 | // qDebug("file has length of %d lasting %d seconds", | 555 | // qDebug("file has length of %d lasting %d seconds", |
518 | // length, (( length / speed) / channels) / 2 ); | 556 | // length, (( length / speed) / channels) / 2 ); |
519 | // medialplayer states wrong length in secs | 557 | // medialplayer states wrong length in secs |
520 | } | 558 | } |
521 | 559 | ||
560 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// | ||
561 | |||
522 | value = length+36; | 562 | value = length+36; |
563 | |||
523 | lseek(wav, 4, SEEK_SET); | 564 | lseek(wav, 4, SEEK_SET); |
524 | write(wav, &value, 4); | 565 | write(wav, &value, 4); |
525 | lseek(wav, 40, SEEK_SET); | 566 | lseek(wav, 40, SEEK_SET); |
567 | |||
526 | write(wav, &length, 4); | 568 | write(wav, &length, 4); |
569 | |||
527 | track.close(); | 570 | track.close(); |
571 | qDebug("Tracvk closed"); | ||
528 | 572 | ||
529 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 573 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
530 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 574 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
575 | |||
531 | ::close(dsp); | 576 | ::close(dsp); |
532 | fileName = fileName.left(fileName.length()-4); | 577 | fileName = fileName.left(fileName.length()-4); |
533 | // if(useAlerts) | 578 | // if(useAlerts) |
534 | // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); | 579 | // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); |
535 | qDebug("done recording "+fileName); | 580 | qDebug("done recording "+fileName); |
536 | QSound::play(Resource::findSound("vmemoe")); | 581 | QSound::play(Resource::findSound("vmemoe")); |
537 | } | 582 | } |
538 | 583 | ||
539 | int VMemo::setToggleButton(int tog) { | 584 | int VMemo::setToggleButton(int tog) { |
540 | 585 | ||
541 | for( int i=0; i < 10;i++) { | 586 | for( int i=0; i < 10;i++) { |
542 | switch (tog) { | 587 | switch (tog) { |