-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 577db75..4b398ad 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -177,477 +177,485 @@ static char * vmemo_xpm[] = { | |||
177 | "X c #42444A", | 177 | "X c #42444A", |
178 | "Y c #22282E", | 178 | "Y c #22282E", |
179 | "Z c #B0B2BC", | 179 | "Z c #B0B2BC", |
180 | "` c #898A90", | 180 | "` c #898A90", |
181 | " . c #65656A", | 181 | " . c #65656A", |
182 | ".. c #999AA2", | 182 | ".. c #999AA2", |
183 | "+. c #52535A", | 183 | "+. c #52535A", |
184 | "@. c #151B21", | 184 | "@. c #151B21", |
185 | "#. c #515257", | 185 | "#. c #515257", |
186 | "$. c #B5B5BE", | 186 | "$. c #B5B5BE", |
187 | "%. c #616167", | 187 | "%. c #616167", |
188 | "&. c #1A1D22", | 188 | "&. c #1A1D22", |
189 | "*. c #000713", | 189 | "*. c #000713", |
190 | "=. c #1F1F21", | 190 | "=. c #1F1F21", |
191 | " ", | 191 | " ", |
192 | " . + @ # ", | 192 | " . + @ # ", |
193 | " $ % & * = - ", | 193 | " $ % & * = - ", |
194 | " ; > , ' ) ! ~ ", | 194 | " ; > , ' ) ! ~ ", |
195 | " { ] ^ / ( _ : ", | 195 | " { ] ^ / ( _ : ", |
196 | " < [ } | 1 2 3 ", | 196 | " < [ } | 1 2 3 ", |
197 | " 4 5 6 7 8 9 0 a b c ", | 197 | " 4 5 6 7 8 9 0 a b c ", |
198 | " d e f g h i j 3 k l m n ", | 198 | " d e f g h i j 3 k l m n ", |
199 | " o p q r s t u v w n ", | 199 | " o p q r s t u v w n ", |
200 | " o x y z A B C D E n ", | 200 | " o x y z A B C D E n ", |
201 | " F G H I J K L M N O ", | 201 | " F G H I J K L M N O ", |
202 | " P Q R S T U V W X ", | 202 | " P Q R S T U V W X ", |
203 | " Y Z ` b ...+. ", | 203 | " Y Z ` b ...+. ", |
204 | " @.#.$.%.&. ", | 204 | " @.#.$.%.&. ", |
205 | " *.B =. ", | 205 | " *.B =. ", |
206 | " n n n n n n n n n "}; | 206 | " n n n n n n n n n "}; |
207 | 207 | ||
208 | 208 | ||
209 | VMemo::VMemo( QWidget *parent, const char *_name ) | 209 | VMemo::VMemo( QWidget *parent, const char *_name ) |
210 | : QWidget( parent, _name ) { | 210 | : QWidget( parent, _name ) { |
211 | setFixedHeight( 18 ); | 211 | setFixedHeight( 18 ); |
212 | setFixedWidth( 14 ); | 212 | setFixedWidth( 14 ); |
213 | 213 | ||
214 | recording = FALSE; | 214 | recording = FALSE; |
215 | 215 | ||
216 | t_timer = new QTimer( this ); | 216 | t_timer = new QTimer( this ); |
217 | connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); | 217 | connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); |
218 | 218 | ||
219 | struct utsname name; /* check for embedix kernel running on the zaurus*/ | 219 | struct utsname name; /* check for embedix kernel running on the zaurus*/ |
220 | if (uname(&name) != -1) { | 220 | if (uname(&name) != -1) { |
221 | QString release=name.release; | 221 | QString release=name.release; |
222 | 222 | ||
223 | Config vmCfg("Vmemo"); | 223 | Config vmCfg("Vmemo"); |
224 | vmCfg.setGroup("Defaults"); | 224 | vmCfg.setGroup("Defaults"); |
225 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); | 225 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); |
226 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | 226 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); |
227 | 227 | ||
228 | qDebug("toggleKey %d", toggleKey); | 228 | qDebug("toggleKey %d", toggleKey); |
229 | 229 | ||
230 | if(release.find("embedix",0,TRUE) !=-1) | 230 | if(release.find("embedix",0,TRUE) !=-1) |
231 | systemZaurus=TRUE; | 231 | systemZaurus=TRUE; |
232 | else | 232 | else |
233 | systemZaurus=FALSE; | 233 | systemZaurus=FALSE; |
234 | 234 | ||
235 | myChannel = new QCopChannel( "QPE/VMemo", this ); | 235 | myChannel = new QCopChannel( "QPE/VMemo", this ); |
236 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), | 236 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), |
237 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 237 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
238 | 238 | ||
239 | if( toggleKey != -1 ) { | 239 | if( toggleKey != -1 ) { |
240 | // QPEApplication::grabKeyboard(); | 240 | // QPEApplication::grabKeyboard(); |
241 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); | 241 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); |
242 | // e << 4096; // Key_Escape | 242 | // e << 4096; // Key_Escape |
243 | // e << Key_F5; //4148 | 243 | // e << Key_F5; //4148 |
244 | e << toggleKey; | 244 | e << toggleKey; |
245 | e << QString("QPE/VMemo"); | 245 | e << QString("QPE/VMemo"); |
246 | e << QString("toggleRecord()"); | 246 | e << QString("toggleRecord()"); |
247 | } | 247 | } |
248 | if(toggleKey == 1) | 248 | if(toggleKey == 1) |
249 | usingIcon=TRUE; | 249 | usingIcon=TRUE; |
250 | else | 250 | else |
251 | usingIcon=FALSE; | 251 | usingIcon=FALSE; |
252 | if( vmCfg.readNumEntry("hideIcon",0) == 1) | 252 | if( vmCfg.readNumEntry("hideIcon",0) == 1) |
253 | hide(); | 253 | hide(); |
254 | } | 254 | } |
255 | } | 255 | } |
256 | 256 | ||
257 | VMemo::~VMemo() { | 257 | VMemo::~VMemo() { |
258 | } | 258 | } |
259 | 259 | ||
260 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { | 260 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { |
261 | qDebug("receive"); | 261 | qDebug("receive"); |
262 | QDataStream stream( data, IO_ReadOnly ); | 262 | QDataStream stream( data, IO_ReadOnly ); |
263 | 263 | ||
264 | if (msg == "toggleRecord()") { | 264 | if (msg == "toggleRecord()") { |
265 | 265 | ||
266 | if (recording) { | 266 | if (recording) { |
267 | fromToggle = TRUE; | 267 | fromToggle = TRUE; |
268 | mouseReleaseEvent(NULL); | 268 | mouseReleaseEvent(NULL); |
269 | stopRecording(); | 269 | stopRecording(); |
270 | } else { | 270 | } else { |
271 | fromToggle = TRUE; | 271 | fromToggle = TRUE; |
272 | // mousePressEvent(NULL); | 272 | // mousePressEvent(NULL); |
273 | startRecording(); | 273 | startRecording(); |
274 | } | 274 | } |
275 | } | 275 | } |
276 | } | 276 | } |
277 | 277 | ||
278 | void VMemo::paintEvent( QPaintEvent* ) { | 278 | void VMemo::paintEvent( QPaintEvent* ) { |
279 | QPainter p(this); | 279 | QPainter p(this); |
280 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 280 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
281 | } | 281 | } |
282 | 282 | ||
283 | void VMemo::mousePressEvent( QMouseEvent * me) { | 283 | void VMemo::mousePressEvent( QMouseEvent * me) { |
284 | // just to be safe | 284 | // just to be safe |
285 | if (recording) { | 285 | if (recording) { |
286 | recording = FALSE; | 286 | recording = FALSE; |
287 | return; | 287 | return; |
288 | } | 288 | } |
289 | /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions | 289 | /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions |
290 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ | 290 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ |
291 | if ( me->button() != LeftButton || me != NULL) | 291 | if ( me->button() != LeftButton || me != NULL) |
292 | // if (!systemZaurus && me != NULL) | 292 | // if (!systemZaurus && me != NULL) |
293 | return; | 293 | return; |
294 | 294 | ||
295 | if(!recording) | 295 | if(!recording) |
296 | startRecording(); | 296 | startRecording(); |
297 | else | 297 | else |
298 | stopRecording(); | 298 | stopRecording(); |
299 | } | 299 | } |
300 | 300 | ||
301 | void VMemo::mouseReleaseEvent( QMouseEvent * ) { | 301 | void VMemo::mouseReleaseEvent( QMouseEvent * ) { |
302 | // if(usingIcon && !recording) | 302 | // if(usingIcon && !recording) |
303 | // stopRecording(); | 303 | // stopRecording(); |
304 | } | 304 | } |
305 | 305 | ||
306 | bool VMemo::startRecording() { | 306 | bool VMemo::startRecording() { |
307 | 307 | ||
308 | if ( recording) | 308 | if ( recording) |
309 | return FALSE; | 309 | return FALSE; |
310 | 310 | ||
311 | Config config( "Vmemo" ); | 311 | Config config( "Vmemo" ); |
312 | config.setGroup( "System" ); | 312 | config.setGroup( "System" ); |
313 | 313 | ||
314 | useAlerts = config.readBoolEntry("Alert",1); | 314 | useAlerts = config.readBoolEntry("Alert",1); |
315 | if(useAlerts) { | 315 | if(useAlerts) { |
316 | 316 | ||
317 | msgLabel = new QLabel( 0, "alertLabel" ); | 317 | msgLabel = new QLabel( 0, "alertLabel" ); |
318 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); | 318 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); |
319 | msgLabel->show(); | 319 | msgLabel->show(); |
320 | } | 320 | } |
321 | 321 | ||
322 | // if(useAlerts) | 322 | // if(useAlerts) |
323 | // QMessageBox::message("VMemo","Really Record?");//) ==1) | 323 | // QMessageBox::message("VMemo","Really Record?");//) ==1) |
324 | // return; | 324 | // return; |
325 | // } else { | 325 | // } else { |
326 | // if (!systemZaurus ) | 326 | // if (!systemZaurus ) |
327 | // QSound::play(Resource::findSound("vmemob")); | 327 | // QSound::play(Resource::findSound("vmemob")); |
328 | // } | 328 | // } |
329 | qDebug("Start recording engines"); | 329 | qDebug("Start recording engines"); |
330 | recording = TRUE; | 330 | recording = TRUE; |
331 | 331 | ||
332 | if (openDSP() == -1) { | 332 | if (openDSP() == -1) { |
333 | // QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort"); | 333 | // QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort"); |
334 | // delete msgLabel; | 334 | // delete msgLabel; |
335 | recording = FALSE; | 335 | recording = FALSE; |
336 | msgLabel=0; | 336 | msgLabel=0; |
337 | delete msgLabel; | 337 | delete msgLabel; |
338 | 338 | ||
339 | return FALSE; | 339 | return FALSE; |
340 | } | 340 | } |
341 | 341 | ||
342 | config.setGroup("Defaults"); | 342 | config.setGroup("Defaults"); |
343 | 343 | ||
344 | QDateTime dt = QDateTime::currentDateTime(); | 344 | QDateTime dt = QDateTime::currentDateTime(); |
345 | 345 | ||
346 | QString fName; | 346 | QString fName; |
347 | config.setGroup( "System" ); | 347 | config.setGroup( "System" ); |
348 | fName = QPEApplication::documentDir() ; | 348 | fName = QPEApplication::documentDir() ; |
349 | fileName = config.readEntry("RecLocation", fName); | 349 | fileName = config.readEntry("RecLocation", fName); |
350 | 350 | ||
351 | int s; | 351 | int s; |
352 | s=fileName.find(':'); | 352 | s=fileName.find(':'); |
353 | if(s) | 353 | if(s) |
354 | fileName=fileName.right(fileName.length()-s-2); | 354 | fileName=fileName.right(fileName.length()-s-2); |
355 | qDebug("pathname will be "+fileName); | 355 | qDebug("pathname will be "+fileName); |
356 | 356 | ||
357 | if( fileName.left(1).find('/') == -1) | 357 | if( fileName.left(1).find('/') == -1) |
358 | fileName="/"+fileName; | 358 | fileName="/"+fileName; |
359 | if( fileName.right(1).find('/') == -1) | 359 | if( fileName.right(1).find('/') == -1) |
360 | fileName+="/"; | 360 | fileName+="/"; |
361 | fName = "vm_"+ dt.toString()+ ".wav"; | 361 | fName = "vm_"+ dt.toString()+ ".wav"; |
362 | 362 | ||
363 | fileName+=fName; | 363 | fileName+=fName; |
364 | // No spaces in the filename | 364 | // No spaces in the filename |
365 | fileName.replace(QRegExp("'"),""); | 365 | fileName.replace(QRegExp("'"),""); |
366 | fileName.replace(QRegExp(" "),"_"); | 366 | fileName.replace(QRegExp(" "),"_"); |
367 | fileName.replace(QRegExp(":"),"."); | 367 | fileName.replace(QRegExp(":"),"."); |
368 | fileName.replace(QRegExp(","),""); | 368 | fileName.replace(QRegExp(","),""); |
369 | fileName += ".wav"; | 369 | |
370 | 370 | ||
371 | qDebug("filename is "+fileName); | 371 | qDebug("filename is "+fileName); |
372 | // open tmp file here | 372 | // open tmp file here |
373 | char *pointer; | 373 | char *pointer; |
374 | pointer=tmpnam(NULL); | 374 | pointer=tmpnam(NULL); |
375 | qDebug("Opening tmp file %s",pointer); | 375 | qDebug("Opening tmp file %s",pointer); |
376 | 376 | ||
377 | if(openWAV(pointer ) == -1) { | 377 | if(openWAV(pointer ) == -1) { |
378 | 378 | ||
379 | // if(openWAV(fileName.latin1()) == -1) { | 379 | // if(openWAV(fileName.latin1()) == -1) { |
380 | QString err("Could not open the temp file\n"); | 380 | QString err("Could not open the temp file\n"); |
381 | err += fileName; | 381 | err += fileName; |
382 | QMessageBox::critical(0, "vmemo", err, "Abort"); | 382 | QMessageBox::critical(0, "vmemo", err, "Abort"); |
383 | ::close(dsp); | 383 | ::close(dsp); |
384 | return FALSE; | 384 | return FALSE; |
385 | } | 385 | } |
386 | if( record() ) { | 386 | if( record() ) { |
387 | 387 | ||
388 | QString cmd; | 388 | QString cmd; |
389 | if( fileName.find(".wav",0,TRUE) == -1) | ||
390 | fileName += ".wav"; | ||
391 | |||
389 | cmd.sprintf("mv %s "+fileName, pointer); | 392 | cmd.sprintf("mv %s "+fileName, pointer); |
390 | // move tmp file to regular file here | 393 | // move tmp file to regular file here |
394 | |||
391 | system(cmd.latin1()); | 395 | system(cmd.latin1()); |
392 | 396 | ||
393 | QArray<int> cats(1); | 397 | QArray<int> cats(1); |
394 | cats[0] = config.readNumEntry("Category", 0); | 398 | cats[0] = config.readNumEntry("Category", 0); |
395 | 399 | ||
396 | QString dlName("vm_"); | 400 | QString dlName("vm_"); |
397 | dlName += dt.toString(); | 401 | dlName += dt.toString(); |
398 | DocLnk l; | 402 | DocLnk l; |
399 | l.setFile(fileName); | 403 | l.setFile(fileName); |
400 | l.setName(dlName); | 404 | l.setName(dlName); |
401 | l.setType("audio/x-wav"); | 405 | l.setType("audio/x-wav"); |
402 | l.setCategories(cats); | 406 | l.setCategories(cats); |
403 | l.writeLink(); | 407 | l.writeLink(); |
404 | return TRUE; | 408 | return TRUE; |
405 | } else | 409 | } else |
406 | return FALSE; | 410 | return FALSE; |
407 | 411 | ||
408 | } | 412 | } |
409 | 413 | ||
410 | void VMemo::stopRecording() { | 414 | void VMemo::stopRecording() { |
411 | show(); | 415 | show(); |
412 | qDebug("Stopped recording"); | 416 | qDebug("Stopped recording"); |
413 | recording = FALSE; | 417 | recording = FALSE; |
414 | if(useAlerts) { | 418 | if(useAlerts) { |
415 | msgLabel->close(); | 419 | msgLabel->close(); |
416 | msgLabel=0; | 420 | msgLabel=0; |
417 | delete msgLabel; | 421 | delete msgLabel; |
418 | } | 422 | } |
419 | t_timer->stop(); | 423 | t_timer->stop(); |
420 | Config cfg("Vmemo"); | 424 | Config cfg("Vmemo"); |
421 | cfg.setGroup("Defaults"); | 425 | cfg.setGroup("Defaults"); |
422 | if( cfg.readNumEntry("hideIcon",0) == 1 ) | 426 | if( cfg.readNumEntry("hideIcon",0) == 1 ) |
423 | hide(); | 427 | hide(); |
424 | } | 428 | } |
425 | 429 | ||
426 | int VMemo::openDSP() { | 430 | int VMemo::openDSP() { |
427 | Config cfg("Vmemo"); | 431 | Config cfg("Vmemo"); |
428 | cfg.setGroup("Record"); | 432 | cfg.setGroup("Record"); |
429 | 433 | ||
430 | speed = cfg.readNumEntry("SampleRate", 22050); | 434 | speed = cfg.readNumEntry("SampleRate", 22050); |
431 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 435 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
432 | if (cfg.readNumEntry("SixteenBit", 1)==1) { | 436 | if (cfg.readNumEntry("SixteenBit", 1)==1) { |
433 | format = AFMT_S16_LE; | 437 | format = AFMT_S16_LE; |
434 | resolution = 16; | 438 | resolution = 16; |
435 | } else { | 439 | } else { |
436 | format = AFMT_U8; | 440 | format = AFMT_U8; |
437 | resolution = 8; | 441 | resolution = 8; |
438 | } | 442 | } |
439 | 443 | ||
440 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); | 444 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); |
441 | 445 | ||
442 | if(systemZaurus) { | 446 | if(systemZaurus) { |
443 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 | 447 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 |
444 | channels=1; //zaurus has one input channel | 448 | channels=1; //zaurus has one input channel |
445 | } else { | 449 | } else { |
446 | dsp = open("/dev/dsp", O_RDONLY); | 450 | dsp = open("/dev/dsp", O_RDONLY); |
447 | } | 451 | } |
448 | 452 | ||
449 | if(dsp == -1) { | 453 | if(dsp == -1) { |
450 | perror("open(\"/dev/dsp\")"); | 454 | perror("open(\"/dev/dsp\")"); |
451 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); | 455 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); |
452 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); | 456 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); |
453 | return -1; | 457 | return -1; |
454 | } | 458 | } |
455 | 459 | ||
456 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { | 460 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { |
457 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 461 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
458 | return -1; | 462 | return -1; |
459 | } | 463 | } |
460 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { | 464 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { |
461 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 465 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
462 | return -1; | 466 | return -1; |
463 | } | 467 | } |
464 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { | 468 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { |
465 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 469 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
466 | return -1; | 470 | return -1; |
467 | } | 471 | } |
468 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { | 472 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { |
469 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 473 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); |
470 | return -1; | 474 | return -1; |
471 | } | 475 | } |
472 | 476 | ||
473 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute | 477 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute |
474 | 478 | ||
475 | return 1; | 479 | return 1; |
476 | } | 480 | } |
477 | 481 | ||
478 | int VMemo::openWAV(const char *filename) { | 482 | int VMemo::openWAV(const char *filename) { |
479 | track.setName(filename); | 483 | track.setName(filename); |
480 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { | 484 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { |
481 | errorMsg=filename; | 485 | errorMsg=filename; |
482 | return -1; | 486 | return -1; |
483 | } | 487 | } |
484 | 488 | ||
485 | wav=track.handle(); | 489 | wav=track.handle(); |
490 | Config vmCfg("Vmemo"); | ||
491 | vmCfg.setGroup("Defaults"); | ||
486 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | 492 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); |
487 | 493 | ||
488 | WaveHeader wh; | 494 | WaveHeader wh; |
489 | 495 | ||
490 | wh.main_chunk = RIFF; | 496 | wh.main_chunk = RIFF; |
491 | wh.length=0; | 497 | wh.length=0; |
492 | wh.chunk_type = WAVE; | 498 | wh.chunk_type = WAVE; |
493 | wh.sub_chunk = FMT; | 499 | wh.sub_chunk = FMT; |
494 | wh.sc_len = 16; | 500 | wh.sc_len = 16; |
495 | if(useADPCM) | 501 | if(useADPCM) |
496 | wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; | 502 | wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; |
497 | else | 503 | else |
498 | wh.format = PCM_CODE; | 504 | wh.format = PCM_CODE; |
499 | wh.modus = channels; | 505 | wh.modus = channels; |
500 | wh.sample_fq = speed; | 506 | wh.sample_fq = speed; |
501 | wh.byte_p_sec = speed * channels * resolution/8; | 507 | wh.byte_p_sec = speed * channels * resolution/8; |
502 | wh.byte_p_spl = channels * (resolution / 8); | 508 | wh.byte_p_spl = channels * (resolution / 8); |
503 | wh.bit_p_spl = resolution; | 509 | wh.bit_p_spl = resolution; |
504 | wh.data_chunk = DATA; | 510 | wh.data_chunk = DATA; |
505 | wh.data_length= 0; | 511 | wh.data_length= 0; |
506 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" | 512 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" |
507 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); | 513 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); |
508 | write (wav, &wh, sizeof(WaveHeader)); | 514 | write (wav, &wh, sizeof(WaveHeader)); |
509 | 515 | ||
510 | return 1; | 516 | return 1; |
511 | } | 517 | } |
512 | 518 | ||
513 | bool VMemo::record() { | 519 | bool VMemo::record() { |
514 | 520 | ||
515 | int length=0, result, value; | 521 | int length=0, result, value; |
516 | QString msg; | 522 | QString msg; |
517 | msg.sprintf("Recording format %d", format); | 523 | msg.sprintf("Recording format %d", format); |
518 | qDebug(msg); | 524 | qDebug(msg); |
519 | Config config("Vmemo"); | 525 | Config config("Vmemo"); |
520 | config.setGroup("Record"); | 526 | config.setGroup("Record"); |
521 | int sRate=config.readNumEntry("SizeLimit", 30); | 527 | int sRate=config.readNumEntry("SizeLimit", 30); |
522 | if(sRate > 0) | 528 | if(sRate > 0) |
523 | t_timer->start( sRate * 1000+1000, TRUE); | 529 | t_timer->start( sRate * 1000+1000, TRUE); |
524 | 530 | ||
525 | // if(systemZaurus) { | 531 | // if(systemZaurus) { |
526 | // } else { // 16 bit only capabilities | 532 | // } else { // 16 bit only capabilities |
527 | 533 | ||
528 | msg.sprintf("Recording format other"); | 534 | msg.sprintf("Recording format other"); |
529 | qDebug(msg); | 535 | qDebug(msg); |
530 | 536 | ||
531 | int bufsize=1024; | 537 | int bufsize=1024; |
532 | int bytesWritten=0; | 538 | int bytesWritten=0; |
533 | signed short sound[1024], monoBuffer[1024]; | 539 | signed short sound[1024], monoBuffer[1024]; |
534 | char abuf[bufsize/2]; | 540 | char abuf[bufsize/2]; |
535 | short sbuf[bufsize]; | 541 | short sbuf[bufsize]; |
542 | Config vmCfg("Vmemo"); | ||
543 | vmCfg.setGroup("Defaults"); | ||
536 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | 544 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); |
537 | 545 | ||
538 | while(recording) { | 546 | while(recording) { |
539 | 547 | ||
540 | if(useADPCM) | 548 | if(useADPCM) |
541 | result = read( dsp, sbuf, bufsize); // 8192 | 549 | result = read( dsp, sbuf, bufsize); // 8192 |
542 | else | 550 | else |
543 | result = read(dsp, sound, 1024); // 8192 | 551 | result = read(dsp, sound, 1024); // 8192 |
544 | if( result <= 0) { | 552 | if( result <= 0) { |
545 | perror("recording error "); | 553 | perror("recording error "); |
546 | // qDebug(currentFileName); | 554 | // qDebug(currentFileName); |
547 | QMessageBox::message(tr("Note"),tr("error recording")); | 555 | QMessageBox::message(tr("Note"),tr("error recording")); |
548 | recording=FALSE; | 556 | recording=FALSE; |
549 | break; | 557 | break; |
550 | return FALSE; | 558 | return FALSE; |
551 | } | 559 | } |
552 | 560 | ||
553 | if(useADPCM) { | 561 | if(useADPCM) { |
554 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); | 562 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); |
555 | bytesWritten = ::write(wav, abuf, result/4); | 563 | bytesWritten = ::write(wav, abuf, result/4); |
556 | 564 | ||
557 | } else { | 565 | } else { |
558 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 566 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
559 | monoBuffer[i] = sound[i]; | 567 | monoBuffer[i] = sound[i]; |
560 | } | 568 | } |
561 | 569 | ||
562 | length+=write(wav, monoBuffer, result); | 570 | length+=write(wav, monoBuffer, result); |
563 | } | 571 | } |
564 | length +=bytesWritten; | 572 | length +=bytesWritten; |
565 | 573 | ||
566 | if(length<0) { | 574 | if(length<0) { |
567 | recording=false; | 575 | recording=false; |
568 | perror("dev/dsp's is a lookin' messy"); | 576 | perror("dev/dsp's is a lookin' messy"); |
569 | QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); | 577 | QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); |
570 | break; | 578 | break; |
571 | return FALSE; | 579 | return FALSE; |
572 | } | 580 | } |
573 | // printf("%d\r",length); | 581 | // printf("%d\r",length); |
574 | // fflush(stdout); | 582 | // fflush(stdout); |
575 | qApp->processEvents(); | 583 | qApp->processEvents(); |
576 | } | 584 | } |
577 | // qDebug("file has length of %d lasting %d seconds", | 585 | // qDebug("file has length of %d lasting %d seconds", |
578 | // length, (( length / speed) / channels) / 2 ); | 586 | // length, (( length / speed) / channels) / 2 ); |
579 | // } | 587 | // } |
580 | 588 | ||
581 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// | 589 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// |
582 | 590 | ||
583 | value = length+36; | 591 | value = length+36; |
584 | 592 | ||
585 | lseek(wav, 4, SEEK_SET); | 593 | lseek(wav, 4, SEEK_SET); |
586 | write(wav, &value, 4); | 594 | write(wav, &value, 4); |
587 | lseek(wav, 40, SEEK_SET); | 595 | lseek(wav, 40, SEEK_SET); |
588 | 596 | ||
589 | write(wav, &length, 4); | 597 | write(wav, &length, 4); |
590 | 598 | ||
591 | track.close(); | 599 | track.close(); |
592 | qDebug("Track closed"); | 600 | qDebug("Track closed"); |
593 | 601 | ||
594 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 602 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
595 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 603 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
596 | 604 | ||
597 | ::close(dsp); | 605 | ::close(dsp); |
598 | fileName = fileName.left(fileName.length()-4); | 606 | |
599 | // if(useAlerts) | 607 | // if(useAlerts) |
600 | // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); | 608 | // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); |
601 | qDebug("done recording "+fileName); | 609 | qDebug("done recording "+fileName); |
602 | 610 | ||
603 | // QSound::play(Resource::findSound("vmemoe")); | 611 | // QSound::play(Resource::findSound("vmemoe")); |
604 | 612 | ||
605 | Config cfg("qpe"); | 613 | Config cfg("qpe"); |
606 | cfg.setGroup("Volume"); | 614 | cfg.setGroup("Volume"); |
607 | QString foo = cfg.readEntry("Mute","TRUE"); | 615 | QString foo = cfg.readEntry("Mute","TRUE"); |
608 | if(foo.find("TRUE",0,TRUE) != -1) | 616 | if(foo.find("TRUE",0,TRUE) != -1) |
609 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute | 617 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute |
610 | return TRUE; | 618 | return TRUE; |
611 | } | 619 | } |
612 | 620 | ||
613 | int VMemo::setToggleButton(int tog) { | 621 | int VMemo::setToggleButton(int tog) { |
614 | 622 | ||
615 | for( int i=0; i < 10;i++) { | 623 | for( int i=0; i < 10;i++) { |
616 | switch (tog) { | 624 | switch (tog) { |
617 | case 0: | 625 | case 0: |
618 | return -1; | 626 | return -1; |
619 | break; | 627 | break; |
620 | case 1: | 628 | case 1: |
621 | return 0; | 629 | return 0; |
622 | break; | 630 | break; |
623 | case 2: | 631 | case 2: |
624 | return Key_Escape; | 632 | return Key_Escape; |
625 | break; | 633 | break; |
626 | case 3: | 634 | case 3: |
627 | return Key_Space; | 635 | return Key_Space; |
628 | break; | 636 | break; |
629 | case 4: | 637 | case 4: |
630 | return Key_F12; | 638 | return Key_F12; |
631 | break; | 639 | break; |
632 | case 5: | 640 | case 5: |
633 | return Key_F9; | 641 | return Key_F9; |
634 | break; | 642 | break; |
635 | case 6: | 643 | case 6: |
636 | return Key_F10; | 644 | return Key_F10; |
637 | break; | 645 | break; |
638 | case 7: | 646 | case 7: |
639 | return Key_F11; | 647 | return Key_F11; |
640 | break; | 648 | break; |
641 | case 8: | 649 | case 8: |
642 | return Key_F13; | 650 | return Key_F13; |
643 | break; | 651 | break; |
644 | }; | 652 | }; |
645 | } | 653 | } |
646 | return -1; | 654 | return -1; |
647 | } | 655 | } |
648 | 656 | ||
649 | void VMemo::timerBreak() { | 657 | void VMemo::timerBreak() { |
650 | //stop | 658 | //stop |
651 | stopRecording(); | 659 | stopRecording(); |
652 | QMessageBox::message("Vmemo","Vmemo recording has ended"); | 660 | QMessageBox::message("Vmemo","Vmemo recording has ended"); |
653 | } | 661 | } |