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