summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2005-02-18 07:36:37 (UTC)
committer llornkcor <llornkcor>2005-02-18 07:36:37 (UTC)
commit436a26541402c85a24eaf9ffb3ab2e866631000c (patch) (unidiff)
treec78780fa2a6a461e58646b71edb09fdd717f35ad
parentfc9d9892b0798f2f0b27f2a9c60e72ff27178b8a (diff)
downloadopie-436a26541402c85a24eaf9ffb3ab2e866631000c.zip
opie-436a26541402c85a24eaf9ffb3ab2e866631000c.tar.gz
opie-436a26541402c85a24eaf9ffb3ab2e866631000c.tar.bz2
fix icon showing. add filename to visual.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp317
1 files changed, 154 insertions, 163 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index d5808b7..8ba1eb7 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -118,554 +118,545 @@ static char * vmemo_xpm[] = {
118 "0 c #222224", 118 "0 c #222224",
119 "a c #414144", 119 "a c #414144",
120 "b c #6A6A6E", 120 "b c #6A6A6E",
121 "c c #020C16", 121 "c c #020C16",
122 "d c #6B6B6F", 122 "d c #6B6B6F",
123 "e c #68686D", 123 "e c #68686D",
124 "f c #5B5B60", 124 "f c #5B5B60",
125 "g c #8A8A8F", 125 "g c #8A8A8F",
126 "h c #6B6B6E", 126 "h c #6B6B6E",
127 "i c #ADADB2", 127 "i c #ADADB2",
128 "j c #828289", 128 "j c #828289",
129 "k c #3E3E41", 129 "k c #3E3E41",
130 "l c #CFCFD7", 130 "l c #CFCFD7",
131 "m c #4C4C50", 131 "m c #4C4C50",
132 "n c #000000", 132 "n c #000000",
133 "o c #66666A", 133 "o c #66666A",
134 "p c #505054", 134 "p c #505054",
135 "q c #838388", 135 "q c #838388",
136 "r c #A1A1A7", 136 "r c #A1A1A7",
137 "s c #A9A9AE", 137 "s c #A9A9AE",
138 "t c #A8A8B0", 138 "t c #A8A8B0",
139 "u c #5E5E63", 139 "u c #5E5E63",
140 "v c #3A3A3E", 140 "v c #3A3A3E",
141 "w c #BDBDC6", 141 "w c #BDBDC6",
142 "x c #59595E", 142 "x c #59595E",
143 "y c #76767C", 143 "y c #76767C",
144 "z c #373738", 144 "z c #373738",
145 "A c #717174", 145 "A c #717174",
146 "B c #727278", 146 "B c #727278",
147 "C c #1C1C1E", 147 "C c #1C1C1E",
148 "D c #3C3C3F", 148 "D c #3C3C3F",
149 "E c #ADADB6", 149 "E c #ADADB6",
150 "F c #54555A", 150 "F c #54555A",
151 "G c #8B8C94", 151 "G c #8B8C94",
152 "H c #5A5A5F", 152 "H c #5A5A5F",
153 "I c #BBBBC3", 153 "I c #BBBBC3",
154 "J c #C4C4CB", 154 "J c #C4C4CB",
155 "K c #909098", 155 "K c #909098",
156 "L c #737379", 156 "L c #737379",
157 "M c #343437", 157 "M c #343437",
158 "N c #8F8F98", 158 "N c #8F8F98",
159 "O c #000407", 159 "O c #000407",
160 "P c #2D3137", 160 "P c #2D3137",
161 "Q c #B0B1BC", 161 "Q c #B0B1BC",
162 "R c #3B3C40", 162 "R c #3B3C40",
163 "S c #6E6E74", 163 "S c #6E6E74",
164 "T c #95959C", 164 "T c #95959C",
165 "U c #74747A", 165 "U c #74747A",
166 "V c #1D1D1E", 166 "V c #1D1D1E",
167 "W c #91929A", 167 "W c #91929A",
168 "X c #42444A", 168 "X c #42444A",
169 "Y c #22282E", 169 "Y c #22282E",
170 "Z c #B0B2BC", 170 "Z c #B0B2BC",
171 "` c #898A90", 171 "` c #898A90",
172 " . c #65656A", 172 " . c #65656A",
173 ".. c #999AA2", 173 ".. c #999AA2",
174 "+. c #52535A", 174 "+. c #52535A",
175 "@. c #151B21", 175 "@. c #151B21",
176 "#. c #515257", 176 "#. c #515257",
177 "$. c #B5B5BE", 177 "$. c #B5B5BE",
178 "%. c #616167", 178 "%. c #616167",
179 "&. c #1A1D22", 179 "&. c #1A1D22",
180 "*. c #000713", 180 "*. c #000713",
181 "=. c #1F1F21", 181 "=. c #1F1F21",
182 " ", 182 " ",
183 " . + @ # ", 183 " . + @ # ",
184 " $ % & * = - ", 184 " $ % & * = - ",
185 " ; > , ' ) ! ~ ", 185 " ; > , ' ) ! ~ ",
186 " { ] ^ / ( _ : ", 186 " { ] ^ / ( _ : ",
187 " < [ } | 1 2 3 ", 187 " < [ } | 1 2 3 ",
188 " 4 5 6 7 8 9 0 a b c ", 188 " 4 5 6 7 8 9 0 a b c ",
189 " d e f g h i j 3 k l m n ", 189 " d e f g h i j 3 k l m n ",
190 " o p q r s t u v w n ", 190 " o p q r s t u v w n ",
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
200using namespace Opie::Ui; 200using namespace Opie::Ui;
201VMemo::VMemo( QWidget *parent, const char *_name ) 201VMemo::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 owarn <<"VMemo toggleKey" << toggleKey << oendl;
215 215
216// if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) 216 systemZaurus = false;
217// systemZaurus=TRUE;
218// else
219 systemZaurus = FALSE;
220 217
221// myChannel = new QCopChannel( "QPE/VMemo", this );
222 myChannel = new QCopChannel( "QPE/VMemo", this ); 218 myChannel = new QCopChannel( "QPE/VMemo", this );
223 219
224 connect( myChannel, SIGNAL(received(const QCString&,const QByteArray&)), 220 connect( myChannel, SIGNAL(received(const QCString&,const QByteArray&)),
225 this, SLOT(receive(const QCString&,const QByteArray&)) ); 221 this, SLOT(receive(const QCString&,const QByteArray&)) );
226 222
227 223
228 if( toggleKey != -1 ) { 224 if( toggleKey != -1 ) {
229 odebug << "Register key " << toggleKey << "" << oendl; 225 owarn << "Register key " << toggleKey << "" << oendl;
230 QCopEnvelope e("QPE/Launcher", "keyRegister(int,QCString,QCString)"); 226
227 QCopEnvelope e("QPE/Launcher", "keyRegister(int,QCString,QCString)");
231 // e << 4096; // Key_Escape 228 // e << 4096; // Key_Escape
232 // e << Key_F5; //4148 229 // e << Key_F5; //4148
233 e << toggleKey; 230 e << toggleKey;
234 e << QCString("QPE/VMemo"); 231 e << QCString("QPE/VMemo");
235 e << QCString("toggleRecord()"); 232 e << QCString("toggleRecord()");
236 } 233 }
237 if(toggleKey == 1) 234 if(toggleKey == 0)
238 usingIcon = TRUE; 235 usingIcon = true;
239 else 236 else
240 usingIcon = FALSE; 237 usingIcon = false;
241// if( vmCfg.readNumEntry("hideIcon",0) == 1)
242 if (!usingIcon) 238 if (!usingIcon)
243 hide(); 239 hide();
244 recording = FALSE; 240 recording = false;
245 // }
246} 241}
247 242
248VMemo::~VMemo() { 243VMemo::~VMemo() {
249} 244}
250 245
251int VMemo::position() 246int VMemo::position()
252{ 247{
253 return 6; 248 return 1;
254} 249}
255 250
256void VMemo::receive( const QCString &msg, const QByteArray &data ) { 251void VMemo::receive( const QCString &msg, const QByteArray &data ) {
257 QDataStream stream( data, IO_ReadOnly ); 252 QDataStream stream( data, IO_ReadOnly );
258 253
259 if (msg == "toggleRecord()") { 254 if (msg == "toggleRecord()") {
260 if (recording) { 255 if (recording) {
261 fromToggle = TRUE; 256 fromToggle = true;
262 stopRecording(); 257 stopRecording();
263 } else { 258 } else {
264 fromToggle = TRUE; 259 fromToggle = true;
265 startRecording(); 260 startRecording();
266 } 261 }
267 } 262 }
268} 263}
269 264
270void VMemo::paintEvent( QPaintEvent* ) { 265void VMemo::paintEvent( QPaintEvent* ) {
271 QPainter p(this); 266 QPainter p(this);
272 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); 267 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm );
273} 268}
274 269
275void VMemo::mousePressEvent( QMouseEvent * /*me*/) { 270void VMemo::mousePressEvent( QMouseEvent * /*me*/) {
276 /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions
277 mousePressEvent and mouseReleaseEvent with a NULL parameter. */
278
279// if (!systemZaurus && me != NULL)
280// return;
281// }
282 271
283 if(!recording) 272 if(!recording) {
284 startRecording(); 273 if(!startRecording() ){
285 else 274 QMessageBox::critical(0, "vmemo", "Abort Recording", "Abort Recording");
286 stopRecording(); 275 }
276 } else {
277 stopRecording();
278 }
287} 279}
288 280
289void VMemo::mouseReleaseEvent( QMouseEvent * ) { 281void VMemo::mouseReleaseEvent( QMouseEvent * ) {
290} 282}
291 283
292bool VMemo::startRecording() { 284bool VMemo::startRecording() {
293 Config config( "Vmemo" ); 285 Config config( "Vmemo" );
294 config.setGroup( "System" ); 286 config.setGroup( "System" );
295 287
296 useAlerts = config.readBoolEntry("Alert",1);
297 if(useAlerts) {
298
299 msgLabel = new QLabel( 0, "alertLabel" );
300 msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>");
301 msgLabel->show();
302 }
303 288
304 odebug << "Start recording engines" << oendl; 289 odebug << "Start recording engines" << oendl;
305 recording = TRUE; 290 recording = true;
306 291
307 if (openDSP() == -1) { 292 if (openDSP() == -1) {
308 recording = FALSE; 293 recording = false;
309 return FALSE; 294 return false;
310 } 295 }
311 296
312 config.setGroup("Defaults"); 297 config.setGroup("Defaults");
313 298
314 date = TimeString::dateString( QDateTime::currentDateTime(),false,true); 299 date = TimeString::dateString( QDateTime::currentDateTime(),false,true);
315 date.replace(QRegExp("'"),""); 300 date.replace(QRegExp("'"),"");
316 date.replace(QRegExp(" "),"_"); 301 date.replace(QRegExp(" "),"_");
317 date.replace(QRegExp(":"),"-"); 302 date.replace(QRegExp(":"),"-");
318 date.replace(QRegExp(","),""); 303 date.replace(QRegExp(","),"");
319 304
320 QString fName; 305 QString fName;
321 config.setGroup( "System" ); 306 config.setGroup( "System" );
322 fName = QPEApplication::documentDir() ; 307 fName = QPEApplication::documentDir() ;
323 fileName = config.readEntry("RecLocation", fName); 308 fileName = config.readEntry("RecLocation", fName);
324 309
325 int s; 310 int s;
326 s=fileName.find(':'); 311 s=fileName.find(':');
327 if(s) 312 if(s)
328 fileName=fileName.right(fileName.length()-s-2); 313 fileName=fileName.right(fileName.length()-s-2);
329 odebug << "pathname will be "+fileName << oendl; 314 odebug << "pathname will be "+fileName << oendl;
330 315
331 if( fileName.left(1).find('/') == -1) 316 if( fileName.left(1).find('/') == -1)
332 fileName="/"+fileName; 317 fileName="/"+fileName;
333 if( fileName.right(1).find('/') == -1) 318 if( fileName.right(1).find('/') == -1)
334 fileName+="/"; 319 fileName+="/";
335 fName = "vm_"+ date + ".wav"; 320 fName = "vm_"+ date + ".wav";
336 321
337 fileName+=fName; 322 fileName += fName;
338 odebug << "filename is " + fileName << oendl; 323 odebug << "filename is " + fileName << oendl;
324
325 useAlerts = config.readBoolEntry("Alert",1);
326 if(useAlerts) {
327 msgLabel = new QLabel( 0, "alertLabel" );
328 msgLabel->setText( tr("<B><P><font size=+2>VMemo-Recording</font></B><p>%1</p>").arg("vm_"+ date));
329 msgLabel->show();
330 }
331
339// open tmp file here 332// open tmp file here
340 char *pointer; 333 char *pointer;
341 pointer=tmpnam(NULL); 334 pointer=tmpnam(NULL);
342 odebug << "Opening tmp file " << pointer << "" << oendl; 335 odebug << "Opening tmp file " << pointer << "" << oendl;
343 336
344 if(openWAV(pointer ) == -1) { 337 if(openWAV(pointer ) == -1) {
345 338
346 QString err("Could not open the temp file\n"); 339 QString err("Could not open the temp file\n");
347 err += fileName; 340 err += fileName;
348 QMessageBox::critical(0, "vmemo", err, "Abort"); 341 QMessageBox::critical(0, "vmemo", err, "Abort");
349 ::close(dsp); 342 ::close(dsp);
350 return FALSE; 343 return false;
351 } 344 }
352 if( record() ) { 345 if( record() ) {
353 346
354 QString cmd; 347 QString cmd;
355 if( fileName.find(".wav",0,TRUE) == -1) 348 if( fileName.find(".wav",0,true) == -1)
356 fileName += ".wav"; 349 fileName += ".wav";
357 350
358 cmd.sprintf("mv %s "+fileName, pointer); 351 cmd.sprintf("mv %s "+fileName, pointer);
359// move tmp file to regular file here 352// move tmp file to regular file here
360 353
361 system(cmd.latin1()); 354 system(cmd.latin1());
362 355
363 QArray<int> cats(1); 356 QArray<int> cats(1);
364 cats[0] = config.readNumEntry("Category", 0); 357 cats[0] = config.readNumEntry("Category", 0);
365 358
366 QString dlName("vm_"); 359 QString dlName("vm_");
367 dlName += date; 360 dlName += date;
368 DocLnk l; 361 DocLnk l;
369 l.setFile(fileName); 362 l.setFile(fileName);
370 l.setName(dlName); 363 l.setName(dlName);
371 l.setType("audio/x-wav"); 364 l.setType("audio/x-wav");
372 l.setCategories(cats); 365 l.setCategories(cats);
373 l.writeLink(); 366 l.writeLink();
374 return TRUE; 367 return true;
375 } else 368 } else
376 return FALSE; 369 return false;
377 370
378} 371}
379 372
380void VMemo::stopRecording() { 373void VMemo::stopRecording() {
381// show(); 374// show();
382 odebug << "Stopped recording" << oendl; 375 odebug << "Stopped recording" << oendl;
383 recording = FALSE; 376 recording = false;
384 if(useAlerts) { 377 if(useAlerts) {
385 msgLabel->close(); 378 msgLabel->close();
386 msgLabel=0; 379 msgLabel=0;
387 delete msgLabel; 380 delete msgLabel;
388 } 381 }
389 t_timer->stop(); 382 t_timer->stop();
390 Config cfg("Vmemo"); 383 Config cfg("Vmemo");
391 cfg.setGroup("Defaults"); 384 cfg.setGroup("Defaults");
392// if( cfg.readNumEntry("hideIcon",0) == 1 ) 385// if( cfg.readNumEntry("hideIcon",0) == 1 )
393// hide(); 386// hide();
394} 387}
395 388
396int VMemo::openDSP() { 389int VMemo::openDSP() {
397 Config cfg("Vmemo"); 390 Config cfg("Vmemo");
398 cfg.setGroup("Record"); 391 cfg.setGroup("Record");
399 392
400 speed = cfg.readNumEntry("SampleRate", 22050); 393 speed = cfg.readNumEntry("SampleRate", 22050);
401 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) 394 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1)
402 if (cfg.readNumEntry("SixteenBit", 1)==1) { 395 if (cfg.readNumEntry("SixteenBit", 1)==1) {
403 format = AFMT_S16_LE; 396 format = AFMT_S16_LE;
404 resolution = 16; 397 resolution = 16;
405 } else { 398 } else {
406 format = AFMT_U8; 399 format = AFMT_U8;
407 resolution = 8; 400 resolution = 8;
408 } 401 }
409 402
410 odebug << "samplerate: " << speed << ", channels " << channels << ", resolution " << resolution << "" << oendl; 403 odebug << "samplerate: " << speed << ", channels " << channels << ", resolution " << resolution << "" << oendl;
411 404
412 if(systemZaurus) { 405 if(systemZaurus) {
413 dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 406 dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1
414 channels=1; //zaurus has one input channel 407 channels=1; //zaurus has one input channel
415 } else { 408 } else {
416#ifdef QT_QWS_DEVFS 409#ifdef QT_QWS_DEVFS
417 dsp = open("/dev/sound/dsp", O_RDONLY); 410 dsp = open("/dev/sound/dsp", O_RDONLY);
418#else 411#else
419 dsp = open("/dev/dsp", O_RDONLY); 412 dsp = open("/dev/dsp", O_RDONLY);
420#endif 413#endif
421 } 414 }
422 415
423 if (dsp == -1) { 416 if (dsp == -1) {
424 msgLabel->close(); 417 msgLabel->close();
425 msgLabel=0; 418 msgLabel=0;
426 delete msgLabel; 419 delete msgLabel;
427 420
428 perror("open(\"/dev/dsp\")"); 421 perror("open(\"/dev/dsp\")");
429 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); 422 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno);
430 QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); 423 QMessageBox::critical(0, "vmemo", errorMsg, "Abort");
431 return -1; 424 return -1;
432 } 425 }
433 426
434 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { 427 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) {
435 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 428 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
436 return -1; 429// return -1;
437 } 430 }
438 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { 431 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) {
439 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 432 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
440 return -1; 433// return -1;
441 } 434 }
442 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { 435 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) {
443 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 436 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
444 return -1; 437// return -1;
445 } 438 }
446 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { 439 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) {
447 perror("ioctl(\"SOUND_PCM_READ_RATE\")"); 440 perror("ioctl(\"SOUND_PCM_READ_RATE\")");
448 return -1; 441// return -1;
449 } 442 }
450 443
451 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute 444 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; //mute
452 445
453 return 1; 446 return 1;
454} 447}
455 448
456int VMemo::openWAV(const char *filename) { 449int VMemo::openWAV(const char *filename) {
457 track.setName(filename); 450 track.setName(filename);
458 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { 451 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) {
459 errorMsg=filename; 452 errorMsg=filename;
460 return -1; 453 return -1;
461 } 454 }
462 455
463 wav=track.handle(); 456 wav=track.handle();
464 Config vmCfg("Vmemo"); 457 Config vmCfg("Vmemo");
465 vmCfg.setGroup("Defaults"); 458 vmCfg.setGroup("Defaults");
466 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); 459 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0);
467 460
468 WaveHeader wh; 461 WaveHeader wh;
469 462
470 wh.main_chunk = RIFF; 463 wh.main_chunk = RIFF;
471 wh.length=0; 464 wh.length=0;
472 wh.chunk_type = WAVE; 465 wh.chunk_type = WAVE;
473 wh.sub_chunk = FMT; 466 wh.sub_chunk = FMT;
474 wh.sc_len = 16; 467 wh.sc_len = 16;
475 if(useADPCM) 468 if(useADPCM)
476 wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; 469 wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE;
477 else 470 else
478 wh.format = PCM_CODE; 471 wh.format = PCM_CODE;
479 wh.modus = channels; 472 wh.modus = channels;
480 wh.sample_fq = speed; 473 wh.sample_fq = speed;
481 wh.byte_p_sec = speed * channels * resolution/8; 474 wh.byte_p_sec = speed * channels * resolution/8;
482 wh.byte_p_spl = channels * (resolution / 8); 475 wh.byte_p_spl = channels * (resolution / 8);
483 wh.bit_p_spl = resolution; 476 wh.bit_p_spl = resolution;
484 wh.data_chunk = DATA; 477 wh.data_chunk = DATA;
485 wh.data_length= 0; 478 wh.data_length= 0;
486 // odebug << "Write header channels " << wh.modus << ", speed " << wh.sample_fq << ", b/s " 479 // odebug << "Write header channels " << wh.modus << ", speed " << wh.sample_fq << ", b/s "
487 // << wh.byte_p_sec << ", blockalign " << wh.byte_p_spl << ", bitrate " << wh.bit_p_spl << oendl; 480 // << wh.byte_p_sec << ", blockalign " << wh.byte_p_spl << ", bitrate " << wh.bit_p_spl << oendl;
488 write (wav, &wh, sizeof(WaveHeader)); 481 write (wav, &wh, sizeof(WaveHeader));
489 482
490 return 1; 483 return 1;
491} 484}
492 485
493bool VMemo::record() { 486bool VMemo::record() {
494 length = 0; 487 length = 0;
495 int bytesWritten = 0; 488 int bytesWritten = 0;
496 int result = 0; 489 int result = 0;
497 int value = 0; 490 int value = 0;
498 491
499 QString msg; 492 QString msg;
500 msg.sprintf("Recording format %d", format); 493 msg.sprintf("Recording format %d", format);
501 odebug << msg << oendl; 494 odebug << msg << oendl;
502 495
503 Config config("Vmemo"); 496 Config config("Vmemo");
504 config.setGroup("Record"); 497 config.setGroup("Record");
505 int sRate = config.readNumEntry("SizeLimit", 30); 498 int sRate = config.readNumEntry("SizeLimit", 30);
506 odebug << "VMEMO rate" << sRate << oendl; 499 odebug << "VMEMO rate" << sRate << oendl;
507 500
508 if(sRate > 0) { 501 if(sRate > 0) {
509 t_timer->start( sRate * 1000+1000, TRUE); 502 t_timer->start( sRate * 1000+1000, true);
510 } 503 }
511 504
512 msg.sprintf("Recording format other"); 505 msg.sprintf("Recording format other");
513 odebug << msg << oendl; 506 odebug << msg << oendl;
514 507
515 config.setGroup("Defaults"); 508 config.setGroup("Defaults");
516 useADPCM = config.readBoolEntry("use_ADPCM", 0); 509 useADPCM = config.readBoolEntry("use_ADPCM", 0);
517 510
518 int bufsize = config.readNumEntry("BufferSize",1024); 511 int bufsize = config.readNumEntry("BufferSize",1024);
519 unsigned short sound[bufsize]; //, monoBuffer[bufsize]; 512 unsigned short sound[bufsize]; //, monoBuffer[bufsize];
520 char abuf[bufsize / 2]; 513 char abuf[bufsize / 2];
521 short sbuf[bufsize]; 514 short sbuf[bufsize];
522 odebug << "ready to record"<< oendl; 515 odebug << "ready to record"<< oendl;
523 if(useADPCM) { 516 if(useADPCM) {
524 odebug << "usr ADPCM" << oendl; 517 odebug << "usr ADPCM" << oendl;
525 518
526 while(recording) { 519 while(recording) {
527 result = ::read(dsp, sbuf, bufsize); // adpcm read 520 result = ::read(dsp, sbuf, bufsize); // adpcm read
528 if( result <= 0) { 521 if( result <= 0) {
529 perror("recording error "); 522 perror("recording error ");
530 QMessageBox::message(tr("Note"),tr("error recording")); 523 QMessageBox::message(tr("Note"),tr("error recording"));
531 recording = FALSE; 524 recording = false;
532 break; 525 break;
533 return FALSE; 526 return false;
534 } 527 }
535 adpcm_coder( sbuf, abuf, result/2, &encoder_state); 528 adpcm_coder( sbuf, abuf, result/2, &encoder_state);
536 bytesWritten = ::write(wav, abuf, result/4); // adpcm write 529 bytesWritten = ::write(wav, abuf, result/4); // adpcm write
537 length += bytesWritten; 530 length += bytesWritten;
538 531
539 if(length < 0) { 532 if(length < 0) {
540 recording = false; 533 recording = false;
541 perror("dev/dsp's is a lookin' messy"); 534 perror("dev/dsp's is a lookin' messy");
542 QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); 535 QMessageBox::message("Vmemo","Error writing to file\n"+ fileName);
543 break; 536 break;
544 return FALSE; 537 return false;
545 } 538 }
546 printf("%d\r", length); 539 printf("%d\r", length);
547 fflush(stdout); 540 fflush(stdout);
548 qApp->processEvents(); 541 qApp->processEvents();
549 } 542 }
550 } else { 543 } else {
551 odebug << "use regular wav" << oendl; 544 odebug << "use regular wav" << oendl;
552 while(recording) { 545 while(recording) {
553 result = ::read(dsp, sound, bufsize); // read 546 result = ::read(dsp, sound, bufsize); // read
554 if( result <= 0) { 547 if( result <= 0) {
555 perror("recording error "); 548 perror("recording error ");
556 QMessageBox::message(tr("Note"),tr("error recording")); 549 QMessageBox::message(tr("Note"),tr("error recording"));
557 recording = FALSE; 550 recording = false;
558 break; 551 break;
559 return FALSE; 552 return false;
560 } 553 }
561 554
562 bytesWritten = ::write(wav, sound, result); // write 555 bytesWritten = ::write(wav, sound, result); // write
563 length += bytesWritten; 556 length += bytesWritten;
564 557
565 if(length < 0) { 558 if(length < 0) {
566 recording = false; 559 recording = false;
567 perror("dev/dsp's is a lookin' messy"); 560 perror("dev/dsp's is a lookin' messy");
568 QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); 561 QMessageBox::message("Vmemo","Error writing to file\n"+ fileName);
569 break; 562 break;
570 return FALSE; 563 return false;
571 } 564 }
572// printf("%d\r", length); 565// printf("%d\r", length);
573// fflush(stdout); 566// fflush(stdout);
574 qApp->processEvents(); 567 qApp->processEvents();
575 } 568 }
576 // odebug << "result is " << result << oendl; 569 }
577 } 570 owarn << "file has length of " << length << " lasting " << (( length / speed) / channels) / 2 << " seconds" << oendl;
578 odebug << "file has length of " << length << " lasting " << (( length / speed) / channels) / 2 << " seconds" << oendl; 571
579 572 value = length + 36;
580 value = length + 36; 573
581 574 lseek(wav, 4, SEEK_SET);
582 lseek(wav, 4, SEEK_SET); 575 write(wav, &value, 4);
583 write(wav, &value, 4); 576 lseek(wav, 40, SEEK_SET);
584 lseek(wav, 40, SEEK_SET); 577
585 578 write(wav, &length, 4);
586 write(wav, &length, 4); 579
587 580 track.close();
588 track.close(); 581
589 odebug << "Track closed" << oendl; 582 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)
590 583 perror("ioctl(\"SNDCTL_DSP_RESET\")");
591 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) 584
592 perror("ioctl(\"SNDCTL_DSP_RESET\")"); 585 ::close(dsp);
593 586
594 ::close(dsp); 587 Config cfgO("OpieRec");
595 588 cfgO.setGroup("Sounds");
596 Config cfgO("OpieRec"); 589
597 cfgO.setGroup("Sounds"); 590 int nFiles = cfgO.readNumEntry( "NumberofFiles",0);
598 591
599 int nFiles = cfgO.readNumEntry( "NumberofFiles",0); 592 QString currentFileName = fileName;
600 593 QString currentFile = "vm_"+ date;
601 QString currentFileName = fileName; 594
602 QString currentFile = "vm_"+ date; 595 float numberOfRecordedSeconds = (float) length / (float)speed * (float)2;
603 596
604 float numberOfRecordedSeconds = (float) length / (float)speed * (float)2; 597 cfgO.writeEntry( "NumberofFiles", nFiles + 1);
605 598 cfgO.writeEntry( QString::number( nFiles + 1), currentFile);
606 cfgO.writeEntry( "NumberofFiles", nFiles + 1); 599 cfgO.writeEntry( currentFile, currentFileName);
607 cfgO.writeEntry( QString::number( nFiles + 1), currentFile); 600
608 cfgO.writeEntry( currentFile, currentFileName); 601 QString time;
609 602 time.sprintf("%.2f", numberOfRecordedSeconds);
610 QString time; 603 cfgO.writeEntry( currentFileName, time );
611 time.sprintf("%.2f", numberOfRecordedSeconds);
612 cfgO.writeEntry( currentFileName, time );
613 // odebug << "writing config numberOfRecordedSeconds "+time << oendl; 604 // odebug << "writing config numberOfRecordedSeconds "+time << oendl;
614 605
615 cfgO.write(); 606 cfgO.write();
616 607
617 odebug << "done recording "+fileName << oendl; 608 odebug << "done recording "+fileName << oendl;
618 609
619 Config cfg("qpe"); 610 Config cfg("qpe");
620 cfg.setGroup("Volume"); 611 cfg.setGroup("Volume");
621 QString foo = cfg.readEntry("Mute","TRUE"); 612 QString foo = cfg.readEntry("Mute","true");
622 if(foo.find("TRUE",0,TRUE) != -1) 613 if(foo.find("true",0,true) != -1)
623 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute 614 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << true; //mute
624 return TRUE; 615 return true;
625} 616}
626 617
627int VMemo::setToggleButton(int tog) { 618int VMemo::setToggleButton(int tog) {
628 619
629 for( int i=0; i < 10;i++) { 620 for( int i=0; i < 10;i++) {
630 switch (tog) { 621 switch (tog) {
631 case 0: 622 case 0:
632 return -1; 623 return -1;
633 break; 624 break;
634 case 1: 625 case 1:
635 return 0; 626 return 0;
636 break; 627 break;
637 case 2: 628 case 2:
638 return Key_F24; //was Escape 629 return Key_F24; //was Escape
639 break; 630 break;
640 case 3: 631 case 3:
641 return Key_Space; 632 return Key_Space;
642 break; 633 break;
643 case 4: 634 case 4:
644 return Key_F12; 635 return Key_F12;
645 break; 636 break;
646 case 5: 637 case 5:
647 return Key_F9; 638 return Key_F9;
648 break; 639 break;
649 case 6: 640 case 6:
650 return Key_F10; 641 return Key_F10;
651 break; 642 break;
652 case 7: 643 case 7:
653 return Key_F11; 644 return Key_F11;
654 break; 645 break;
655 case 8: 646 case 8:
656 return Key_F13; 647 return Key_F13;
657 break; 648 break;
658 }; 649 };
659 } 650 }
660 return -1; 651 return -1;
661} 652}
662 653
663void VMemo::timerBreak() { 654void VMemo::timerBreak() {
664 //stop 655 //stop
665 stopRecording(); 656 stopRecording();
666 QMessageBox::message("Vmemo","Vmemo recording has ended"); 657 QMessageBox::message("Vmemo","Vmemo recording has ended");
667} 658}
668 659
669 660
670//EXPORT_OPIE_APPLET_v1( VMemo ) 661EXPORT_OPIE_APPLET_v1( VMemo )
671 662