summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-05-26 23:41:26 (UTC)
committer llornkcor <llornkcor>2002-05-26 23:41:26 (UTC)
commitff4ab0f08fe935fd781be4caa245cb953e9f68ce (patch) (unidiff)
tree3a20249c724552e4437677dea4e407397afc1610
parentf0d0d53759436686f7f15fcd55a6706b1ecaa1cc (diff)
downloadopie-ff4ab0f08fe935fd781be4caa245cb953e9f68ce.zip
opie-ff4ab0f08fe935fd781be4caa245cb953e9f68ce.tar.gz
opie-ff4ab0f08fe935fd781be4caa245cb953e9f68ce.tar.bz2
changed visual alert to QLabel in the corner while recording, instead of nag screen when stopping recording. made pick-a-key record work
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp78
-rw-r--r--core/applets/vmemo/vmemo.h6
2 files changed, 72 insertions, 12 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index f5d2b20..e327098 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -192,36 +192,38 @@ static char * vmemo_xpm[] = {
192" @.#.$.%.&. ", 192" @.#.$.%.&. ",
193" *.B =. ", 193" *.B =. ",
194" n n n n n n n n n "}; 194" n n n n n n n n n "};
195 195
196 196
197VMemo::VMemo( QWidget *parent, const char *_name ) 197VMemo::VMemo( QWidget *parent, const char *_name )
198 : QWidget( parent, _name ) 198 : QWidget( parent, _name )
199{ 199{
200 setFixedHeight( 18 ); 200 setFixedHeight( 18 );
201 setFixedWidth( 14 ); 201 setFixedWidth( 14 );
202 202
203 recording = FALSE; 203 recording = FALSE;
204 204
205 struct utsname name; /* check for embedix kernel running on the zaurus*/ 205 struct utsname name; /* check for embedix kernel running on the zaurus*/
206 if (uname(&name) != -1) { 206 if (uname(&name) != -1) {
207 QString release=name.release; 207 QString release=name.release;
208 Config vmCfg("VMemo"); 208 Config vmCfg("Vmemo");
209 vmCfg.setGroup("Defaults"); 209 vmCfg.setGroup("Defaults");
210 int toggleKey = vmCfg.readNumEntry("toggleKey", -1); 210 int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1));
211 211
212 qDebug("toggleKey %d", toggleKey);
213
212 if(release.find("embedix",0,TRUE) !=-1) 214 if(release.find("embedix",0,TRUE) !=-1)
213 systemZaurus=TRUE; 215 systemZaurus=TRUE;
214 else 216 else
215 systemZaurus=FALSE; 217 systemZaurus=FALSE;
216 218
217 myChannel = new QCopChannel( "QPE/VMemo", this ); 219 myChannel = new QCopChannel( "QPE/VMemo", this );
218 connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), 220 connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)),
219 this, SLOT(receive(const QCString&, const QByteArray&)) ); 221 this, SLOT(receive(const QCString&, const QByteArray&)) );
220 222
221 if( toggleKey != -1 ) { 223 if( toggleKey != -1 ) {
222 QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); 224 QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)");
223// e << 4096; // Key_Escape 225// e << 4096; // Key_Escape
224// e << Key_F5; //4148 226// e << Key_F5; //4148
225 e << toggleKey; 227 e << toggleKey;
226 e << QString("QPE/VMemo"); 228 e << QString("QPE/VMemo");
227 e << QString("toggleRecord()"); 229 e << QString("toggleRecord()");
@@ -256,47 +258,55 @@ void VMemo::paintEvent( QPaintEvent* )
256} 258}
257 259
258void VMemo::mousePressEvent( QMouseEvent * ) 260void VMemo::mousePressEvent( QMouseEvent * )
259{ 261{
260 startRecording(); 262 startRecording();
261} 263}
262 264
263void VMemo::mouseReleaseEvent( QMouseEvent * ) 265void VMemo::mouseReleaseEvent( QMouseEvent * )
264{ 266{
265 stopRecording(); 267 stopRecording();
266} 268}
267 269
268bool VMemo::startRecording() { 270bool VMemo::startRecording() {
269 271
270 if ( recording) 272 if ( recording)
271 return FALSE;; 273 return FALSE;;
272 Config config( "Vmemo" ); 274
275 Config config( "Vmemo" );
273 config.setGroup( "System" ); 276 config.setGroup( "System" );
277
274 useAlerts = config.readBoolEntry("Alert"); 278 useAlerts = config.readBoolEntry("Alert");
279 if(useAlerts) {
280
281 msgLabel = new QLabel( 0, "alertLabel" );
282 msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>");
283 msgLabel->show();
284 }
275 285
276// if(useAlerts) 286// if(useAlerts)
277// QMessageBox::message("VMemo","Really Record?");//) ==1) 287// QMessageBox::message("VMemo","Really Record?");//) ==1)
278// return; 288// return;
279// } else { 289// } else {
280 if (!systemZaurus ) 290 if (!systemZaurus )
281 QSound::play(Resource::findSound("vmemob")); 291 QSound::play(Resource::findSound("vmemob"));
282// } 292// }
283 qDebug("Start recording"); 293 qDebug("Start recording");
284 recording = TRUE; 294 recording = TRUE;
285 if (openDSP() == -1) { 295 if (openDSP() == -1) {
286 QMessageBox::critical(0, "VMemo", "Could not open dsp device.\n"+errorMsg, "Abort"); 296 QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort");
287 recording = FALSE; 297 recording = FALSE;
288 return FALSE; 298 return FALSE;
289 } 299 }
290 300
291 config.setGroup("Defaults"); 301 config.setGroup("Defaults");
292 302
293 QDateTime dt = QDateTime::currentDateTime(); 303 QDateTime dt = QDateTime::currentDateTime();
294 304
295 QString fName; 305 QString fName;
296 config.setGroup( "System" ); 306 config.setGroup( "System" );
297 fName = QPEApplication::documentDir() ; 307 fName = QPEApplication::documentDir() ;
298 fileName = config.readEntry("RecLocation", fName); 308 fileName = config.readEntry("RecLocation", fName);
299 309
300 int s; 310 int s;
301 s=fileName.find(':'); 311 s=fileName.find(':');
302 if(s) 312 if(s)
@@ -306,55 +316,58 @@ bool VMemo::startRecording() {
306 fileName="/"+fileName; 316 fileName="/"+fileName;
307 if( fileName.right(1).find('/') == -1) 317 if( fileName.right(1).find('/') == -1)
308 fileName+="/"; 318 fileName+="/";
309 fName = "vm_"+ dt.toString()+ ".wav"; 319 fName = "vm_"+ dt.toString()+ ".wav";
310 320
311 fileName+=fName; 321 fileName+=fName;
312 qDebug("filename is "+fileName); 322 qDebug("filename is "+fileName);
313 // No spaces in the filename 323 // No spaces in the filename
314 fileName.replace(QRegExp("'"),""); 324 fileName.replace(QRegExp("'"),"");
315 fileName.replace(QRegExp(" "),"_"); 325 fileName.replace(QRegExp(" "),"_");
316 fileName.replace(QRegExp(":"),"."); 326 fileName.replace(QRegExp(":"),".");
317 fileName.replace(QRegExp(","),""); 327 fileName.replace(QRegExp(","),"");
318 328
319 if(openWAV(fileName.latin1()) == -1) { 329 if(openWAV(fileName.latin1()) == -1) {
320 QString err("Could not open the output file\n"); 330 QString err("Could not open the output file\n");
321 err += fileName; 331 err += fileName;
322 QMessageBox::critical(0, "VMemo", err, "Abort"); 332 QMessageBox::critical(0, "vmemo", err, "Abort");
323 close(dsp); 333 close(dsp);
324 return FALSE; 334 return FALSE;
325 } 335 }
326 336
327 QArray<int> cats(1); 337 QArray<int> cats(1);
328 cats[0] = config.readNumEntry("Category", 0); 338 cats[0] = config.readNumEntry("Category", 0);
329 339
330 QString dlName("vm_"); 340 QString dlName("vm_");
331 dlName += dt.toString(); 341 dlName += dt.toString();
332 DocLnk l; 342 DocLnk l;
333 l.setFile(fileName); 343 l.setFile(fileName);
334 l.setName(dlName); 344 l.setName(dlName);
335 l.setType("audio/x-wav"); 345 l.setType("audio/x-wav");
336 l.setCategories(cats); 346 l.setCategories(cats);
337 l.writeLink(); 347 l.writeLink();
348
338 349
339 record(); 350 record();
340 return TRUE; 351 return TRUE;
341} 352}
342 353
343void VMemo::stopRecording() { 354void VMemo::stopRecording() {
344 recording = FALSE; 355 recording = FALSE;
356 if(useAlerts)
357 if( msgLabel) delete msgLabel;
345} 358}
346 359
347int VMemo::openDSP() 360int VMemo::openDSP()
348{ 361{
349 Config cfg("Vmemo"); 362 Config cfg("Vmemo");
350 cfg.setGroup("Record"); 363 cfg.setGroup("Record");
351 364
352 speed = cfg.readNumEntry("SampleRate", 22050); 365 speed = cfg.readNumEntry("SampleRate", 22050);
353 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) 366 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1)
354 if (cfg.readNumEntry("SixteenBit", 1)==1) { 367 if (cfg.readNumEntry("SixteenBit", 1)==1) {
355 format = AFMT_S16_LE; 368 format = AFMT_S16_LE;
356 resolution = 16; 369 resolution = 16;
357 } else { 370 } else {
358 format = AFMT_U8; 371 format = AFMT_U8;
359 resolution = 8; 372 resolution = 8;
360 } 373 }
@@ -416,56 +429,66 @@ int VMemo::openWAV(const char *filename)
416 wh.sample_fq = speed; 429 wh.sample_fq = speed;
417 wh.byte_p_sec = speed * channels * resolution/8; 430 wh.byte_p_sec = speed * channels * resolution/8;
418 wh.byte_p_spl = channels * (resolution / 8); 431 wh.byte_p_spl = channels * (resolution / 8);
419 wh.bit_p_spl = resolution; 432 wh.bit_p_spl = resolution;
420 wh.data_chunk = DATA; 433 wh.data_chunk = DATA;
421 wh.data_length= 0; 434 wh.data_length= 0;
422 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" 435 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d"
423 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); 436 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl );
424 write (wav, &wh, sizeof(WaveHeader)); 437 write (wav, &wh, sizeof(WaveHeader));
425 438
426 return 1; 439 return 1;
427} 440}
428 441
429void VMemo::record(void) 442void VMemo::record(void)
430{ 443{
431 int length=0, result, value; 444 int length=0, result, value;
432 qDebug("Recording"); 445 QString msg;
446 msg.sprintf("Recording format %d", format);
447 qDebug(msg);
433 448
434 if(systemZaurus) { 449 if(systemZaurus) {
435 signed short sound[512], monoBuffer[512]; 450 signed short sound[512], monoBuffer[512];
436 if(format==AFMT_S16_LE) { 451 if(format==AFMT_S16_LE) {
452
437 while(recording) { 453 while(recording) {
454
438 result = read(dsp, sound, 512); // 8192 455 result = read(dsp, sound, 512); // 8192
439 int j=0; 456 int j=0;
457
440 if(systemZaurus) { 458 if(systemZaurus) {
441 for (int i = 0; i < result; i++) { //since Z is mono do normally 459 for (int i = 0; i < result; i++) { //since Z is mono do normally
442 monoBuffer[i] = sound[i]; 460 monoBuffer[i] = sound[i];
443 } 461 }
462
444 length+=write(wav, monoBuffer, result); 463 length+=write(wav, monoBuffer, result);
464
445 } else { //ipaq /stereo inputs 465 } else { //ipaq /stereo inputs
466
446 for (int i = 0; i < result; i+=2) { 467 for (int i = 0; i < result; i+=2) {
447 monoBuffer[j] = (sound[i]+sound[i+1])/2; 468 monoBuffer[j] = (sound[i]+sound[i+1])/2;
448 j++; 469 j++;
449 } 470 }
471
450 length+=write(wav, monoBuffer, result/2); 472 length+=write(wav, monoBuffer, result/2);
451 } 473 }
474 qApp->processEvents();
452// printf("%d\r",length); 475// printf("%d\r",length);
453// fflush(stdout); 476// fflush(stdout);
454 } 477 }
455 } else { //AFMT_U8 478 } else { //AFMT_U8
456// 8bit unsigned 479// 8bit unsigned
457 unsigned short sound[512], monoBuffer[512]; 480 unsigned short sound[512], monoBuffer[512];
458 while(recording) { 481 while(recording) {
459 result = read(dsp, sound, 512); // 8192 482 result = read(dsp, sound, 512); // 8192
460 int j=0; 483 int j=0;
461 if(systemZaurus) { 484 if(systemZaurus) {
462 for (int i = 0; i < result; i++) { //since Z is mono do normally 485 for (int i = 0; i < result; i++) { //since Z is mono do normally
463 monoBuffer[i] = sound[i]; 486 monoBuffer[i] = sound[i];
464 } 487 }
465 length+=write(wav, monoBuffer, result); 488 length+=write(wav, monoBuffer, result);
466 } else { //ipaq /stereo inputs 489 } else { //ipaq /stereo inputs
467 for (int i = 0; i < result; i+=2) { 490 for (int i = 0; i < result; i+=2) {
468 monoBuffer[j] = (sound[i]+sound[i+1])/2; 491 monoBuffer[j] = (sound[i]+sound[i+1])/2;
469 j++; 492 j++;
470 } 493 }
471 length+=write(wav, monoBuffer, result/2); 494 length+=write(wav, monoBuffer, result/2);
@@ -494,21 +517,56 @@ void VMemo::record(void)
494 // qDebug("file has length of %d lasting %d seconds", 517 // qDebug("file has length of %d lasting %d seconds",
495 // length, (( length / speed) / channels) / 2 ); 518 // length, (( length / speed) / channels) / 2 );
496 // medialplayer states wrong length in secs 519 // medialplayer states wrong length in secs
497 } 520 }
498 521
499 value = length+36; 522 value = length+36;
500 lseek(wav, 4, SEEK_SET); 523 lseek(wav, 4, SEEK_SET);
501 write(wav, &value, 4); 524 write(wav, &value, 4);
502 lseek(wav, 40, SEEK_SET); 525 lseek(wav, 40, SEEK_SET);
503 write(wav, &length, 4); 526 write(wav, &length, 4);
504 track.close(); 527 track.close();
505 528
506 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) 529 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)
507 perror("ioctl(\"SNDCTL_DSP_RESET\")"); 530 perror("ioctl(\"SNDCTL_DSP_RESET\")");
508 ::close(dsp); 531 ::close(dsp);
509 fileName = fileName.left(fileName.length()-4); 532 fileName = fileName.left(fileName.length()-4);
510 if(useAlerts) 533// if(useAlerts)
511 QMessageBox::message("Vmemo"," Done recording\n"+ fileName); 534// QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName);
512 qDebug("done recording "+fileName); 535 qDebug("done recording "+fileName);
513 QSound::play(Resource::findSound("vmemoe")); 536 QSound::play(Resource::findSound("vmemoe"));
514} 537}
538
539int VMemo::setToggleButton(int tog) {
540
541 for( int i=0; i < 10;i++) {
542 switch (tog) {
543 case 0:
544 return -1;
545 break;
546 case 1:
547 return 0;
548 break;
549 case 2:
550 return Key_Escape;
551 break;
552 case 3:
553 return Key_Space;
554 break;
555 case 4:
556 return Key_F12;
557 break;
558 case 5:
559 return Key_F9;
560 break;
561 case 6:
562 return Key_F10;
563 break;
564 case 7:
565 return Key_F11;
566 break;
567 case 8:
568 return Key_F13;
569 break;
570 };
571 }
572}
diff --git a/core/applets/vmemo/vmemo.h b/core/applets/vmemo/vmemo.h
index 701663f..b33ab55 100644
--- a/core/applets/vmemo/vmemo.h
+++ b/core/applets/vmemo/vmemo.h
@@ -4,54 +4,56 @@
4** GNU General Public License version 2 as published by the Free Software 4** GNU General Public License version 2 as published by the Free Software
5** Foundation and appearing in the file LICENSE.GPL included in the 5** Foundation and appearing in the file LICENSE.GPL included in the
6** packaging of this file. 6** packaging of this file.
7** 7**
8** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 8** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
9** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 9** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
10** 10**
11*********************************************************************************************/ 11*********************************************************************************************/
12 12
13/* 13/*
14 * $Id$ 14 * $Id$
15 */ 15 */
16 16
17#ifndef __VMEMO_H__ 17#ifndef __VMEMO_H__
18#define __VMEMO_H__ 18#define __VMEMO_H__
19 19
20
20#include <qwidget.h> 21#include <qwidget.h>
21#include <qpixmap.h> 22#include <qpixmap.h>
22#include <qpe/applnk.h> 23#include <qpe/applnk.h>
23#include <qfile.h> 24#include <qfile.h>
24#include <qpe/qcopenvelope_qws.h> 25#include <qpe/qcopenvelope_qws.h>
26#include <qlabel.h>
25 27
26class VMemo : public QWidget 28class VMemo : public QWidget
27{ 29{
28 Q_OBJECT 30 Q_OBJECT
29public: 31public:
30 VMemo( QWidget *parent, const char *name = NULL); 32 VMemo( QWidget *parent, const char *name = NULL);
31 ~VMemo(); 33 ~VMemo();
32 QFile track; 34 QFile track;
33 QString fileName, errorMsg; 35 QString fileName, errorMsg;
34 36 QLabel* msgLabel;
35public slots: 37public slots:
36 void record(); 38 void record();
37 void mousePressEvent( QMouseEvent * ); 39 void mousePressEvent( QMouseEvent * );
38 void mouseReleaseEvent( QMouseEvent * ); 40 void mouseReleaseEvent( QMouseEvent * );
39 void receive( const QCString &msg, const QByteArray &data ); 41 void receive( const QCString &msg, const QByteArray &data );
40 bool startRecording(); 42 bool startRecording();
41 void stopRecording(); 43 void stopRecording();
42private: 44private:
43 bool useAlerts; 45 bool useAlerts;
44 void paintEvent( QPaintEvent* ); 46 void paintEvent( QPaintEvent* );
45 47 int setToggleButton(int);
46 int openDSP(); 48 int openDSP();
47 int openWAV(const char *filename); 49 int openWAV(const char *filename);
48 bool fromToggle; 50 bool fromToggle;
49 QPixmap vmemoPixmap; 51 QPixmap vmemoPixmap;
50 QCopChannel *myChannel; 52 QCopChannel *myChannel;
51 bool systemZaurus; 53 bool systemZaurus;
52 int dsp, wav, rate, speed, channels, format, resolution; 54 int dsp, wav, rate, speed, channels, format, resolution;
53 bool recording; 55 bool recording;
54}; 56};
55 57
56#endif // __VMEMO_H__ 58#endif // __VMEMO_H__
57 59