-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 622b1df..1ead4dd 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -191,86 +191,87 @@ static char * vmemo_xpm[] = { | |||
191 | " o x y z A B C D E n ", | 191 | " o x y z A B C D E n ", |
192 | " F G H I J K L M N O ", | 192 | " F G H I J K L M N O ", |
193 | " P Q R S T U V W X ", | 193 | " P Q R S T U V W X ", |
194 | " Y Z ` b ...+. ", | 194 | " Y Z ` b ...+. ", |
195 | " @.#.$.%.&. ", | 195 | " @.#.$.%.&. ", |
196 | " *.B =. ", | 196 | " *.B =. ", |
197 | " n n n n n n n n n "}; | 197 | " n n n n n n n n n "}; |
198 | 198 | ||
199 | 199 | ||
200 | using namespace Opie::Ui; | 200 | using namespace Opie::Ui; |
201 | VMemo::VMemo( QWidget *parent, const char *_name ) | 201 | VMemo::VMemo( QWidget *parent, const char *_name ) |
202 | : QWidget( parent, _name ) { | 202 | : QWidget( parent, _name ) { |
203 | setFixedHeight( 18 ); | 203 | setFixedHeight( 18 ); |
204 | setFixedWidth( 14 ); | 204 | setFixedWidth( 14 ); |
205 | 205 | ||
206 | t_timer = new QTimer( this ); | 206 | t_timer = new QTimer( this ); |
207 | connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); | 207 | connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); |
208 | 208 | ||
209 | Config vmCfg("Vmemo"); | 209 | Config vmCfg("Vmemo"); |
210 | vmCfg.setGroup("Defaults"); | 210 | vmCfg.setGroup("Defaults"); |
211 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); | 211 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); |
212 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | 212 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); |
213 | 213 | ||
214 | odebug << "toggleKey " << toggleKey << "" << oendl; | 214 | odebug << "toggleKey " << toggleKey << "" << oendl; |
215 | if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) | 215 | |
216 | systemZaurus=TRUE; | 216 | // if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) |
217 | else | 217 | // systemZaurus=TRUE; |
218 | // else | ||
218 | systemZaurus=FALSE; | 219 | systemZaurus=FALSE; |
219 | 220 | ||
220 | myChannel = new QCopChannel( "QPE/VMemo", this ); | 221 | myChannel = new QCopChannel( "QPE/VMemo", this ); |
221 | connect( myChannel, SIGNAL(received(const QCString&,const QByteArray&)), | 222 | connect( myChannel, SIGNAL(received(const QCString&,const QByteArray&)), |
222 | this, SLOT(receive(const QCString&,const QByteArray&)) ); | 223 | this, SLOT(receive(const QCString&,const QByteArray&)) ); |
223 | 224 | ||
224 | if( toggleKey != -1 ) { | 225 | if( toggleKey != -1 ) { |
225 | // keyRegister(key, channel, message) | 226 | qDebug("Register key %d", toggleKey); |
226 | QCopEnvelope e("QPE/Launcher", "keyRegister(int,QCString,QCString)"); | 227 | QCopEnvelope e("QPE/Launcher", "keyRegister(int,QCString,QCString)"); |
227 | // e << 4096; // Key_Escape | 228 | // e << 4096; // Key_Escape |
228 | // e << Key_F5; //4148 | 229 | // e << Key_F5; //4148 |
229 | e << toggleKey; | 230 | e << toggleKey; |
230 | e << QString("QPE/VMemo"); | 231 | e << QString("QPE/VMemo"); |
231 | e << QString("toggleRecord()"); | 232 | e << QString("toggleRecord()"); |
232 | } | 233 | } |
233 | if(toggleKey == 1) | 234 | if(toggleKey == 1) |
234 | usingIcon=TRUE; | 235 | usingIcon=TRUE; |
235 | else | 236 | else |
236 | usingIcon=FALSE; | 237 | usingIcon=FALSE; |
237 | if( vmCfg.readNumEntry("hideIcon",0) == 1) | 238 | // if( vmCfg.readNumEntry("hideIcon",0) == 1) |
238 | hide(); | 239 | // hide(); |
239 | recording = FALSE; | 240 | recording = FALSE; |
240 | // } | 241 | // } |
241 | } | 242 | } |
242 | 243 | ||
243 | VMemo::~VMemo() { | 244 | VMemo::~VMemo() { |
244 | } | 245 | } |
245 | 246 | ||
246 | int VMemo::position() | 247 | int VMemo::position() |
247 | { | 248 | { |
248 | return 6; | 249 | return 6; |
249 | } | 250 | } |
250 | 251 | ||
251 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { | 252 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { |
252 | odebug << "receive" << oendl; | 253 | odebug << "Vmemo receive" << oendl; |
253 | QDataStream stream( data, IO_ReadOnly ); | 254 | QDataStream stream( data, IO_ReadOnly ); |
254 | 255 | ||
255 | if (msg == "toggleRecord()") { | 256 | if (msg == "toggleRecord()") { |
256 | if (recording) { | 257 | if (recording) { |
257 | fromToggle = TRUE; | 258 | fromToggle = TRUE; |
258 | stopRecording(); | 259 | stopRecording(); |
259 | } else { | 260 | } else { |
260 | fromToggle = TRUE; | 261 | fromToggle = TRUE; |
261 | startRecording(); | 262 | startRecording(); |
262 | } | 263 | } |
263 | } | 264 | } |
264 | } | 265 | } |
265 | 266 | ||
266 | void VMemo::paintEvent( QPaintEvent* ) { | 267 | void VMemo::paintEvent( QPaintEvent* ) { |
267 | QPainter p(this); | 268 | QPainter p(this); |
268 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 269 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
269 | } | 270 | } |
270 | 271 | ||
271 | void VMemo::mousePressEvent( QMouseEvent * me) { | 272 | void VMemo::mousePressEvent( QMouseEvent * me) { |
272 | /* 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 |
273 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ | 274 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ |
274 | 275 | ||
275 | // if (!systemZaurus && me != NULL) | 276 | // if (!systemZaurus && me != NULL) |
276 | // return; | 277 | // return; |
@@ -364,50 +365,50 @@ bool VMemo::startRecording() { | |||
364 | DocLnk l; | 365 | DocLnk l; |
365 | l.setFile(fileName); | 366 | l.setFile(fileName); |
366 | l.setName(dlName); | 367 | l.setName(dlName); |
367 | l.setType("audio/x-wav"); | 368 | l.setType("audio/x-wav"); |
368 | l.setCategories(cats); | 369 | l.setCategories(cats); |
369 | l.writeLink(); | 370 | l.writeLink(); |
370 | return TRUE; | 371 | return TRUE; |
371 | } else | 372 | } else |
372 | return FALSE; | 373 | return FALSE; |
373 | 374 | ||
374 | } | 375 | } |
375 | 376 | ||
376 | void VMemo::stopRecording() { | 377 | void VMemo::stopRecording() { |
377 | show(); | 378 | show(); |
378 | odebug << "Stopped recording" << oendl; | 379 | odebug << "Stopped recording" << oendl; |
379 | recording = FALSE; | 380 | recording = FALSE; |
380 | if(useAlerts) { | 381 | if(useAlerts) { |
381 | msgLabel->close(); | 382 | msgLabel->close(); |
382 | msgLabel=0; | 383 | msgLabel=0; |
383 | delete msgLabel; | 384 | delete msgLabel; |
384 | } | 385 | } |
385 | t_timer->stop(); | 386 | t_timer->stop(); |
386 | Config cfg("Vmemo"); | 387 | Config cfg("Vmemo"); |
387 | cfg.setGroup("Defaults"); | 388 | cfg.setGroup("Defaults"); |
388 | if( cfg.readNumEntry("hideIcon",0) == 1 ) | 389 | // if( cfg.readNumEntry("hideIcon",0) == 1 ) |
389 | hide(); | 390 | // hide(); |
390 | } | 391 | } |
391 | 392 | ||
392 | int VMemo::openDSP() { | 393 | int VMemo::openDSP() { |
393 | Config cfg("Vmemo"); | 394 | Config cfg("Vmemo"); |
394 | cfg.setGroup("Record"); | 395 | cfg.setGroup("Record"); |
395 | 396 | ||
396 | speed = cfg.readNumEntry("SampleRate", 22050); | 397 | speed = cfg.readNumEntry("SampleRate", 22050); |
397 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 398 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
398 | if (cfg.readNumEntry("SixteenBit", 1)==1) { | 399 | if (cfg.readNumEntry("SixteenBit", 1)==1) { |
399 | format = AFMT_S16_LE; | 400 | format = AFMT_S16_LE; |
400 | resolution = 16; | 401 | resolution = 16; |
401 | } else { | 402 | } else { |
402 | format = AFMT_U8; | 403 | format = AFMT_U8; |
403 | resolution = 8; | 404 | resolution = 8; |
404 | } | 405 | } |
405 | 406 | ||
406 | odebug << "samplerate: " << speed << ", channels " << channels << ", resolution " << resolution << "" << oendl; | 407 | odebug << "samplerate: " << speed << ", channels " << channels << ", resolution " << resolution << "" << oendl; |
407 | 408 | ||
408 | if(systemZaurus) { | 409 | if(systemZaurus) { |
409 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 | 410 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 |
410 | channels=1; //zaurus has one input channel | 411 | channels=1; //zaurus has one input channel |
411 | } else { | 412 | } else { |
412 | dsp = open("/dev/dsp", O_RDONLY); | 413 | dsp = open("/dev/dsp", O_RDONLY); |
413 | } | 414 | } |
@@ -479,82 +480,85 @@ int VMemo::openWAV(const char *filename) { | |||
479 | // , 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 ); |
480 | write (wav, &wh, sizeof(WaveHeader)); | 481 | write (wav, &wh, sizeof(WaveHeader)); |
481 | 482 | ||
482 | return 1; | 483 | return 1; |
483 | } | 484 | } |
484 | 485 | ||
485 | bool VMemo::record() { | 486 | bool VMemo::record() { |
486 | length=0; | 487 | length=0; |
487 | int result, value; | 488 | int result, value; |
488 | QString msg; | 489 | QString msg; |
489 | msg.sprintf("Recording format %d", format); | 490 | msg.sprintf("Recording format %d", format); |
490 | odebug << msg << oendl; | 491 | odebug << msg << oendl; |
491 | Config config("Vmemo"); | 492 | Config config("Vmemo"); |
492 | config.setGroup("Record"); | 493 | config.setGroup("Record"); |
493 | int sRate=config.readNumEntry("SizeLimit", 30); | 494 | int sRate=config.readNumEntry("SizeLimit", 30); |
494 | if(sRate > 0) | 495 | if(sRate > 0) |
495 | t_timer->start( sRate * 1000+1000, TRUE); | 496 | t_timer->start( sRate * 1000+1000, TRUE); |
496 | 497 | ||
497 | // if(systemZaurus) { | 498 | // if(systemZaurus) { |
498 | // } else { // 16 bit only capabilities | 499 | // } else { // 16 bit only capabilities |
499 | 500 | ||
500 | msg.sprintf("Recording format other"); | 501 | msg.sprintf("Recording format other"); |
501 | odebug << msg << oendl; | 502 | odebug << msg << oendl; |
502 | 503 | ||
503 | int bufsize=1024; | 504 | |
504 | int bytesWritten=0; | 505 | int bytesWritten=0; |
505 | signed short sound[1024], monoBuffer[1024]; | 506 | |
506 | char abuf[bufsize/2]; | ||
507 | short sbuf[bufsize]; | ||
508 | Config vmCfg("Vmemo"); | 507 | Config vmCfg("Vmemo"); |
509 | vmCfg.setGroup("Defaults"); | 508 | vmCfg.setGroup("Defaults"); |
510 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | 509 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); |
511 | 510 | ||
511 | int bufsize = vmCfg.readNumEntry("BufferSize",1024); | ||
512 | signed short sound[bufsize], monoBuffer[bufsize]; | ||
513 | char abuf[bufsize / 2]; | ||
514 | short sbuf[bufsize]; | ||
515 | |||
512 | while(recording) { | 516 | while(recording) { |
513 | 517 | ||
514 | if(useADPCM) | 518 | if(useADPCM) |
515 | result = read( dsp, sbuf, bufsize); // 8192 | 519 | result = ::read(dsp, sbuf, bufsize); // 8192 |
516 | else | 520 | else |
517 | result = read(dsp, sound, 1024); // 8192 | 521 | result = ::read(dsp, sound, bufsize); // 8192 |
518 | if( result <= 0) { | 522 | if( result <= 0) { |
519 | perror("recording error "); | 523 | perror("recording error "); |
520 | // odebug << currentFileName << oendl; | 524 | // odebug << currentFileName << oendl; |
521 | QMessageBox::message(tr("Note"),tr("error recording")); | 525 | QMessageBox::message(tr("Note"),tr("error recording")); |
522 | recording=FALSE; | 526 | recording=FALSE; |
523 | break; | 527 | break; |
524 | return FALSE; | 528 | return FALSE; |
525 | } | 529 | } |
526 | 530 | ||
527 | if(useADPCM) { | 531 | if(useADPCM) { |
528 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); | 532 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); |
529 | bytesWritten = ::write(wav, abuf, result/4); | 533 | bytesWritten = ::write(wav, abuf, result/4); |
530 | 534 | ||
531 | } else { | 535 | } else { |
532 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 536 | // for (int i = 0; i < result; i++) { //since Z is mono do normally |
533 | monoBuffer[i] = sound[i]; | 537 | // monoBuffer[i] = sound[i]; |
534 | } | 538 | // } |
535 | 539 | ||
536 | length+=write(wav, monoBuffer, result); | 540 | length += write(wav, sound, result); |
537 | } | 541 | } |
538 | length +=bytesWritten; | 542 | length +=bytesWritten; |
539 | 543 | ||
540 | if(length<0) { | 544 | if(length<0) { |
541 | recording=false; | 545 | recording=false; |
542 | perror("dev/dsp's is a lookin' messy"); | 546 | perror("dev/dsp's is a lookin' messy"); |
543 | QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); | 547 | QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); |
544 | break; | 548 | break; |
545 | return FALSE; | 549 | return FALSE; |
546 | } | 550 | } |
547 | // odebug << "" << length << "\r" << oendl; | 551 | // odebug << "" << length << "\r" << oendl; |
548 | // fflush(stdout); | 552 | // fflush(stdout); |
549 | qApp->processEvents(); | 553 | qApp->processEvents(); |
550 | } | 554 | } |
551 | // qDebug("file has length of %d lasting %d seconds", | 555 | // qDebug("file has length of %d lasting %d seconds", |
552 | // length, (( length / speed) / channels) / 2 ); | 556 | // length, (( length / speed) / channels) / 2 ); |
553 | // } | 557 | // } |
554 | 558 | ||
555 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// | 559 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// |
556 | 560 | ||
557 | value = length+36; | 561 | value = length+36; |
558 | 562 | ||
559 | lseek(wav, 4, SEEK_SET); | 563 | lseek(wav, 4, SEEK_SET); |
560 | write(wav, &value, 4); | 564 | write(wav, &value, 4); |