summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp116
-rw-r--r--core/applets/vmemo/vmemo.h5
2 files changed, 63 insertions, 58 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index e14d532..7e91ef0 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -8,508 +8,512 @@
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// copyright 2002 Jeremy Cowgar <jc@cowgar.com> 12// copyright 2002 Jeremy Cowgar <jc@cowgar.com>
13/* 13/*
14 * $Id$ 14 * $Id$
15 */ 15 */
16// Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com> 16// Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com>
17#include <sys/utsname.h> 17#include <sys/utsname.h>
18#include <sys/time.h> 18#include <sys/time.h>
19#include <sys/types.h> 19#include <sys/types.h>
20#include <unistd.h> 20#include <unistd.h>
21#include <stdio.h> 21#include <stdio.h>
22#include <sys/stat.h> 22#include <sys/stat.h>
23#include <fcntl.h> 23#include <fcntl.h>
24#include <sys/ioctl.h> 24#include <sys/ioctl.h>
25#include <linux/soundcard.h> 25#include <linux/soundcard.h>
26 26
27#include <string.h> 27#include <string.h>
28#include <stdlib.h> 28#include <stdlib.h>
29#include <errno.h> 29#include <errno.h>
30 30
31typedef struct _waveheader { 31typedef struct _waveheader {
32 u_long main_chunk; /* 'RIFF' */ 32 u_long main_chunk; /* 'RIFF' */
33 u_long length; /* filelen */ 33 u_long length; /* filelen */
34 u_long chunk_type; /* 'WAVE' */ 34 u_long chunk_type; /* 'WAVE' */
35 u_long sub_chunk; /* 'fmt ' */ 35 u_long sub_chunk; /* 'fmt ' */
36 u_long sc_len; /* length of sub_chunk, =16 36 u_long sc_len; /* length of sub_chunk, =16
37 (chunckSize) format len */ 37 (chunckSize) format len */
38 u_short format; /* should be 1 for PCM-code (formatTag) */ 38 u_short format; /* should be 1 for PCM-code (formatTag) */
39 39
40 u_short modus; /* 1 Mono, 2 Stereo (channels) */ 40 u_short modus; /* 1 Mono, 2 Stereo (channels) */
41 u_long sample_fq; /* samples per second (samplesPerSecond) */ 41 u_long sample_fq; /* samples per second (samplesPerSecond) */
42 u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ 42 u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */
43 u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ 43 u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */
44 u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ 44 u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */
45 45
46 u_long data_chunk; /* 'data' */ 46 u_long data_chunk; /* 'data' */
47 47
48 u_long data_length;/* samplecount */ 48 u_long data_length;/* samplecount */
49} WaveHeader; 49} WaveHeader;
50 50
51#define RIFF 0x46464952 51#define RIFF 0x46464952
52#define WAVE 0x45564157 52#define WAVE 0x45564157
53#define FMT 0x20746D66 53#define FMT 0x20746D66
54#define DATA 0x61746164 54#define DATA 0x61746164
55#define PCM_CODE 1 55#define PCM_CODE 1
56#define WAVE_MONO 1 56#define WAVE_MONO 1
57#define WAVE_STEREO 2 57#define WAVE_STEREO 2
58 58
59#include "vmemo.h" 59#include "vmemo.h"
60 60
61#include <qpe/qpeapplication.h> 61#include <qpe/qpeapplication.h>
62#include <qpe/resource.h> 62#include <qpe/resource.h>
63#include <qpe/config.h> 63#include <qpe/config.h>
64 64
65#include <qpainter.h> 65#include <qpainter.h>
66#include <qdatetime.h> 66#include <qdatetime.h>
67#include <qregexp.h> 67#include <qregexp.h>
68#include <qsound.h> 68#include <qsound.h>
69#include <qfile.h> 69#include <qfile.h>
70#include <qmessagebox.h> 70#include <qmessagebox.h>
71 71
72int seq = 0; 72int seq = 0;
73 73
74/* XPM */ 74/* XPM */
75static char * vmemo_xpm[] = { 75static char * vmemo_xpm[] = {
76"16 16 102 2", 76"16 16 102 2",
77" c None", 77" c None",
78". c #60636A", 78". c #60636A",
79"+ c #6E6E72", 79"+ c #6E6E72",
80"@ c #68696E", 80"@ c #68696E",
81"# c #4D525C", 81"# c #4D525C",
82"$ c #6B6C70", 82"$ c #6B6C70",
83"% c #E3E3E8", 83"% c #E3E3E8",
84"& c #EEEEF2", 84"& c #EEEEF2",
85"* c #EAEAEF", 85"* c #EAEAEF",
86"= c #CACAD0", 86"= c #CACAD0",
87"- c #474A51", 87"- c #474A51",
88"; c #171819", 88"; c #171819",
89"> c #9B9B9F", 89"> c #9B9B9F",
90", c #EBEBF0", 90", c #EBEBF0",
91"' c #F4F4F7", 91"' c #F4F4F7",
92") c #F1F1F5", 92") c #F1F1F5",
93"! c #DEDEE4", 93"! c #DEDEE4",
94"~ c #57575C", 94"~ c #57575C",
95"{ c #010101", 95"{ c #010101",
96"] c #A2A2A6", 96"] c #A2A2A6",
97"^ c #747477", 97"^ c #747477",
98"/ c #B5B5B8", 98"/ c #B5B5B8",
99"( c #AEAEB2", 99"( c #AEAEB2",
100"_ c #69696D", 100"_ c #69696D",
101": c #525256", 101": c #525256",
102"< c #181C24", 102"< c #181C24",
103"[ c #97979B", 103"[ c #97979B",
104"} c #A7A7AC", 104"} c #A7A7AC",
105"| c #B0B0B4", 105"| c #B0B0B4",
106"1 c #C8C8D1", 106"1 c #C8C8D1",
107"2 c #75757B", 107"2 c #75757B",
108"3 c #46464A", 108"3 c #46464A",
109"4 c #494A4F", 109"4 c #494A4F",
110"5 c #323234", 110"5 c #323234",
111"6 c #909095", 111"6 c #909095",
112"7 c #39393B", 112"7 c #39393B",
113"8 c #757578", 113"8 c #757578",
114"9 c #87878E", 114"9 c #87878E",
115"0 c #222224", 115"0 c #222224",
116"a c #414144", 116"a c #414144",
117"b c #6A6A6E", 117"b c #6A6A6E",
118"c c #020C16", 118"c c #020C16",
119"d c #6B6B6F", 119"d c #6B6B6F",
120"e c #68686D", 120"e c #68686D",
121"f c #5B5B60", 121"f c #5B5B60",
122"g c #8A8A8F", 122"g c #8A8A8F",
123"h c #6B6B6E", 123"h c #6B6B6E",
124"i c #ADADB2", 124"i c #ADADB2",
125"j c #828289", 125"j c #828289",
126"k c #3E3E41", 126"k c #3E3E41",
127"l c #CFCFD7", 127"l c #CFCFD7",
128"m c #4C4C50", 128"m c #4C4C50",
129"n c #000000", 129"n c #000000",
130"o c #66666A", 130"o c #66666A",
131"p c #505054", 131"p c #505054",
132"q c #838388", 132"q c #838388",
133"r c #A1A1A7", 133"r c #A1A1A7",
134"s c #A9A9AE", 134"s c #A9A9AE",
135"t c #A8A8B0", 135"t c #A8A8B0",
136"u c #5E5E63", 136"u c #5E5E63",
137"v c #3A3A3E", 137"v c #3A3A3E",
138"w c #BDBDC6", 138"w c #BDBDC6",
139"x c #59595E", 139"x c #59595E",
140"y c #76767C", 140"y c #76767C",
141"z c #373738", 141"z c #373738",
142"A c #717174", 142"A c #717174",
143"B c #727278", 143"B c #727278",
144"C c #1C1C1E", 144"C c #1C1C1E",
145"D c #3C3C3F", 145"D c #3C3C3F",
146"E c #ADADB6", 146"E c #ADADB6",
147"F c #54555A", 147"F c #54555A",
148"G c #8B8C94", 148"G c #8B8C94",
149"H c #5A5A5F", 149"H c #5A5A5F",
150"I c #BBBBC3", 150"I c #BBBBC3",
151"J c #C4C4CB", 151"J c #C4C4CB",
152"K c #909098", 152"K c #909098",
153"L c #737379", 153"L c #737379",
154"M c #343437", 154"M c #343437",
155"N c #8F8F98", 155"N c #8F8F98",
156"O c #000407", 156"O c #000407",
157"P c #2D3137", 157"P c #2D3137",
158"Q c #B0B1BC", 158"Q c #B0B1BC",
159"R c #3B3C40", 159"R c #3B3C40",
160"S c #6E6E74", 160"S c #6E6E74",
161"T c #95959C", 161"T c #95959C",
162"U c #74747A", 162"U c #74747A",
163"V c #1D1D1E", 163"V c #1D1D1E",
164"W c #91929A", 164"W c #91929A",
165"X c #42444A", 165"X c #42444A",
166"Y c #22282E", 166"Y c #22282E",
167"Z c #B0B2BC", 167"Z c #B0B2BC",
168"` c #898A90", 168"` c #898A90",
169" . c #65656A", 169" . c #65656A",
170".. c #999AA2", 170".. c #999AA2",
171"+. c #52535A", 171"+. c #52535A",
172"@. c #151B21", 172"@. c #151B21",
173"#. c #515257", 173"#. c #515257",
174"$. c #B5B5BE", 174"$. c #B5B5BE",
175"%. c #616167", 175"%. c #616167",
176"&. c #1A1D22", 176"&. c #1A1D22",
177"*. c #000713", 177"*. c #000713",
178"=. c #1F1F21", 178"=. c #1F1F21",
179" ", 179" ",
180" . + @ # ", 180" . + @ # ",
181" $ % & * = - ", 181" $ % & * = - ",
182" ; > , ' ) ! ~ ", 182" ; > , ' ) ! ~ ",
183" { ] ^ / ( _ : ", 183" { ] ^ / ( _ : ",
184" < [ } | 1 2 3 ", 184" < [ } | 1 2 3 ",
185" 4 5 6 7 8 9 0 a b c ", 185" 4 5 6 7 8 9 0 a b c ",
186" d e f g h i j 3 k l m n ", 186" d e f g h i j 3 k l m n ",
187" o p q r s t u v w n ", 187" o p q r s t u v w n ",
188" o x y z A B C D E n ", 188" o x y z A B C D E n ",
189" F G H I J K L M N O ", 189" F G H I J K L M N O ",
190" P Q R S T U V W X ", 190" P Q R S T U V W X ",
191" Y Z ` b ...+. ", 191" Y Z ` b ...+. ",
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 if(release.find("embedix",0,TRUE) !=-1) 208 Config vmCfg("VMemo");
209 systemZaurus=TRUE; 209 vmCfg.setGroup("Defaults");
210 else { 210
211 systemZaurus=FALSE; 211 if(release.find("embedix",0,TRUE) !=-1) {
212 myChannel = new QCopChannel( "QPE/VMemo", this ); 212 int toggleKey = vmCfg.readNumEntry("toggleKey", -1);
213 connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), 213 systemZaurus=TRUE;
214 this, SLOT(receive(const QCString&, const QByteArray&)) ); 214 } else {
215 215 int toggleKey = vmCfg.readNumEntry("toggleKey", 4096);
216// // Register the REC key press, for ipaq only 216//default key for ipaq record button is Key_Escape = 4096
217 QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); 217 systemZaurus=FALSE;
218 e << 4096; 218 }
219 e << QString("QPE/VMemo"); 219
220 e << QString("toggleRecord()"); 220 myChannel = new QCopChannel( "QPE/VMemo", this );
221 } 221 connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)),
222 } 222 this, SLOT(receive(const QCString&, const QByteArray&)) );
223
224 if( toggleKey != -1 ) {
225 QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)");
226// e << 4096; // Key_Escape
227// e << Key_F5; //4148
228 e << toggleKey;
229 e << QString("QPE/VMemo");
230 e << QString("toggleRecord()");
231 }
232 }
223} 233}
224 234
225VMemo::~VMemo() 235VMemo::~VMemo()
226{ 236{
227} 237}
228 238
229void VMemo::receive( const QCString &msg, const QByteArray &data ) 239void VMemo::receive( const QCString &msg, const QByteArray &data )
230{ 240{
231 QDataStream stream( data, IO_ReadOnly ); 241 QDataStream stream( data, IO_ReadOnly );
232 if (msg == "toggleRecord()") { 242 if (msg == "toggleRecord()") {
233 if (recording) 243 if (recording) {
234 mouseReleaseEvent(NULL); 244 fromToggle = TRUE;
235 else 245 stopRecording();
236 mousePressEvent(NULL); 246 } else {
237 } 247 fromToggle = TRUE;
248 startRecording();
249 }
250 }
238} 251}
239 252
240void VMemo::paintEvent( QPaintEvent* ) 253void VMemo::paintEvent( QPaintEvent* )
241{ 254{
242 QPainter p(this); 255 QPainter p(this);
243 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); 256 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm );
244} 257}
245 258
246void VMemo::mousePressEvent( QMouseEvent *me ) 259void VMemo::mousePressEvent( QMouseEvent * )
247{ 260{
248 // just to be safe 261 startRecording();
249 if (recording) { 262}
250 recording = FALSE; 263
251 return; 264void VMemo::mouseReleaseEvent( QMouseEvent * )
252 } 265{
266 stopRecording();
267}
268
269bool VMemo::startRecording() {
253 270
254 /* 271 if ( recording)
255 No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions 272 return FALSE;;
256 mousePressEvent and mouseReleaseEvent with a NULL parameter.
257 */
258// #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
259// if (!systemZaurus )
260// return;
261// #endif
262
263 Config config( "Sound" ); 273 Config config( "Sound" );
264 config.setGroup( "System" ); 274 config.setGroup( "System" );
265 useAlerts = config.readBoolEntry("Alert"); 275 useAlerts = config.readBoolEntry("Alert");
266 276
267// if(useAlerts) 277// if(useAlerts)
268// QMessageBox::message("VMemo","Really Record?");//) ==1) 278// QMessageBox::message("VMemo","Really Record?");//) ==1)
269// return; 279// return;
270// } else { 280// } else {
271 if (!systemZaurus ) 281 if (!systemZaurus )
272 QSound::play(Resource::findSound("vmemob")); 282 QSound::play(Resource::findSound("vmemob"));
273// } 283// }
274 qDebug("Start recording"); 284 qDebug("Start recording");
275 recording = TRUE; 285 recording = TRUE;
276 if (openDSP() == -1) { 286 if (openDSP() == -1) {
277 QMessageBox::critical(0, "VMemo", "Could not open dsp device.\n"+errorMsg, "Abort"); 287 QMessageBox::critical(0, "VMemo", "Could not open dsp device.\n"+errorMsg, "Abort");
278 recording = FALSE; 288 recording = FALSE;
279 return; 289 return FALSE;
280 } 290 }
281 291
282 Config vmCfg("VMemo"); 292 Config vmCfg("VMemo");
283 vmCfg.setGroup("Defaults"); 293 vmCfg.setGroup("Defaults");
284 294
285 QDateTime dt = QDateTime::currentDateTime(); 295 QDateTime dt = QDateTime::currentDateTime();
286 296
287 QString fName; 297 QString fName;
288 Config cfg( "Sound" ); 298 Config cfg( "Sound" );
289 cfg.setGroup( "System" ); 299 cfg.setGroup( "System" );
290 fName = QPEApplication::documentDir() ; 300 fName = QPEApplication::documentDir() ;
291 fileName = cfg.readEntry("RecLocation", fName); 301 fileName = cfg.readEntry("RecLocation", fName);
292 302
293 int s; 303 int s;
294 s=fileName.find(':'); 304 s=fileName.find(':');
295 if(s) 305 if(s)
296 fileName=fileName.right(fileName.length()-s-2); 306 fileName=fileName.right(fileName.length()-s-2);
297 qDebug("filename will be "+fileName); 307 qDebug("filename will be "+fileName);
298 if( fileName.right(1).find('/') == -1) 308 if( fileName.right(1).find('/') == -1)
299 fileName+="/"; 309 fileName+="/";
300
301// if(systemZaurus)
302// fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs
303// else
304// fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/");
305
306 fName = "vm_"+ dt.toString()+ ".wav"; 310 fName = "vm_"+ dt.toString()+ ".wav";
307 311
308 fileName+=fName; 312 fileName+=fName;
309 qDebug("filename is "+fileName); 313 qDebug("filename is "+fileName);
310 // No spaces in the filename 314 // No spaces in the filename
311 fileName.replace(QRegExp("'"),""); 315 fileName.replace(QRegExp("'"),"");
312 fileName.replace(QRegExp(" "),"_"); 316 fileName.replace(QRegExp(" "),"_");
313 fileName.replace(QRegExp(":"),"."); 317 fileName.replace(QRegExp(":"),".");
314 fileName.replace(QRegExp(","),""); 318 fileName.replace(QRegExp(","),"");
315 319
316 if(openWAV(fileName.latin1()) == -1) { 320 if(openWAV(fileName.latin1()) == -1) {
317 QString err("Could not open the output file\n"); 321 QString err("Could not open the output file\n");
318 err += fileName; 322 err += fileName;
319 QMessageBox::critical(0, "VMemo", err, "Abort"); 323 QMessageBox::critical(0, "VMemo", err, "Abort");
320 close(dsp); 324 close(dsp);
321 return; 325 return FALSE;
322 } 326 }
323 327
324 QArray<int> cats(1); 328 QArray<int> cats(1);
325 cats[0] = vmCfg.readNumEntry("Category", 0); 329 cats[0] = vmCfg.readNumEntry("Category", 0);
326 330
327 QString dlName("vm_"); 331 QString dlName("vm_");
328 dlName += dt.toString(); 332 dlName += dt.toString();
329 DocLnk l; 333 DocLnk l;
330 l.setFile(fileName); 334 l.setFile(fileName);
331 l.setName(dlName); 335 l.setName(dlName);
332 l.setType("audio/x-wav"); 336 l.setType("audio/x-wav");
333 l.setCategories(cats); 337 l.setCategories(cats);
334 l.writeLink(); 338 l.writeLink();
335 339
336 record(); 340 record();
341 return TRUE;
337} 342}
338 343
339void VMemo::mouseReleaseEvent( QMouseEvent * ) 344void VMemo::stopRecording() {
340{
341 recording = FALSE; 345 recording = FALSE;
342} 346}
343 347
344int VMemo::openDSP() 348int VMemo::openDSP()
345{ 349{
346 Config cfg("Sound"); 350 Config cfg("Sound");
347 cfg.setGroup("Record"); 351 cfg.setGroup("Record");
348 352
349 speed = cfg.readNumEntry("SampleRate", 22050); 353 speed = cfg.readNumEntry("SampleRate", 22050);
350 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) 354 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1)
351 if (cfg.readNumEntry("SixteenBit", 1)==1) { 355 if (cfg.readNumEntry("SixteenBit", 1)==1) {
352 format = AFMT_S16_LE; 356 format = AFMT_S16_LE;
353 resolution = 16; 357 resolution = 16;
354 } else { 358 } else {
355 format = AFMT_U8; 359 format = AFMT_U8;
356 resolution = 8; 360 resolution = 8;
357 } 361 }
358 362
359 qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); 363 qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution);
360 364
361 if(systemZaurus) { 365 if(systemZaurus) {
362 dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 366 dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1
363 channels=1; //zaurus has one input channel 367 channels=1; //zaurus has one input channel
364 } else { 368 } else {
365 dsp = open("/dev/dsp", O_RDWR); 369 dsp = open("/dev/dsp", O_RDWR);
366 } 370 }
367 371
368 if(dsp == -1) { 372 if(dsp == -1) {
369 perror("open(\"/dev/dsp\")"); 373 perror("open(\"/dev/dsp\")");
370 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); 374 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno);
371 return -1; 375 return -1;
372 } 376 }
373 377
374 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { 378 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) {
375 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 379 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
376 errorMsg="ioctl(\"SNDCTL_DSP_SETFMT\")\n%d\n"+(QString)strerror(errno),format; 380 errorMsg="ioctl(\"SNDCTL_DSP_SETFMT\")\n%d\n"+(QString)strerror(errno),format;
377 return -1; 381 return -1;
378 } 382 }
379 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { 383 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) {
380 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 384 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
381 errorMsg="ioctl(\"SNDCTL_DSP_CHANNELS\")\n%d\n"+(QString)strerror(errno),channels; 385 errorMsg="ioctl(\"SNDCTL_DSP_CHANNELS\")\n%d\n"+(QString)strerror(errno),channels;
382 return -1; 386 return -1;
383 } 387 }
384 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { 388 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) {
385 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 389 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
386 errorMsg="ioctl(\"SNDCTL_DSP_SPEED\")\n%d\n"+(QString)strerror(errno),speed; 390 errorMsg="ioctl(\"SNDCTL_DSP_SPEED\")\n%d\n"+(QString)strerror(errno),speed;
387 return -1; 391 return -1;
388 } 392 }
389 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { 393 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) {
390 perror("ioctl(\"SOUND_PCM_READ_RATE\")"); 394 perror("ioctl(\"SOUND_PCM_READ_RATE\")");
391 errorMsg="ioctl(\"SOUND_PCM_READ_RATE\")\n%d\n"+(QString)strerror(errno),rate; 395 errorMsg="ioctl(\"SOUND_PCM_READ_RATE\")\n%d\n"+(QString)strerror(errno),rate;
392 return -1; 396 return -1;
393 } 397 }
394 398
395 return 1; 399 return 1;
396} 400}
397 401
398int VMemo::openWAV(const char *filename) 402int VMemo::openWAV(const char *filename)
399{ 403{
400 track.setName(filename); 404 track.setName(filename);
401 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { 405 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) {
402 errorMsg=filename; 406 errorMsg=filename;
403 return -1; 407 return -1;
404 } 408 }
405 409
406 wav=track.handle(); 410 wav=track.handle();
407 411
408 WaveHeader wh; 412 WaveHeader wh;
409 413
410 wh.main_chunk = RIFF; 414 wh.main_chunk = RIFF;
411 wh.length=0; 415 wh.length=0;
412 wh.chunk_type = WAVE; 416 wh.chunk_type = WAVE;
413 wh.sub_chunk = FMT; 417 wh.sub_chunk = FMT;
414 wh.sc_len = 16; 418 wh.sc_len = 16;
415 wh.format = PCM_CODE; 419 wh.format = PCM_CODE;
416 wh.modus = channels; 420 wh.modus = channels;
417 wh.sample_fq = speed; 421 wh.sample_fq = speed;
418 wh.byte_p_sec = speed * channels * resolution/8; 422 wh.byte_p_sec = speed * channels * resolution/8;
419 wh.byte_p_spl = channels * (resolution / 8); 423 wh.byte_p_spl = channels * (resolution / 8);
420 wh.bit_p_spl = resolution; 424 wh.bit_p_spl = resolution;
421 wh.data_chunk = DATA; 425 wh.data_chunk = DATA;
422 wh.data_length= 0; 426 wh.data_length= 0;
423 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" 427 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d"
424 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); 428 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl );
425 write (wav, &wh, sizeof(WaveHeader)); 429 write (wav, &wh, sizeof(WaveHeader));
426 430
427 return 1; 431 return 1;
428} 432}
429 433
430void VMemo::record(void) 434void VMemo::record(void)
431{ 435{
432 int length=0, result, value; 436 int length=0, result, value;
433 qDebug("Recording"); 437 qDebug("Recording");
434 438
435 if(systemZaurus) { 439 if(systemZaurus) {
436 signed short sound[512], monoBuffer[512]; 440 signed short sound[512], monoBuffer[512];
437 if(format==AFMT_S16_LE) { 441 if(format==AFMT_S16_LE) {
438 while(recording) { 442 while(recording) {
439 result = read(dsp, sound, 512); // 8192 443 result = read(dsp, sound, 512); // 8192
440 int j=0; 444 int j=0;
441 if(systemZaurus) { 445 if(systemZaurus) {
442 for (int i = 0; i < result; i++) { //since Z is mono do normally 446 for (int i = 0; i < result; i++) { //since Z is mono do normally
443 monoBuffer[i] = sound[i]; 447 monoBuffer[i] = sound[i];
444 } 448 }
445 length+=write(wav, monoBuffer, result); 449 length+=write(wav, monoBuffer, result);
446 } else { //ipaq /stereo inputs 450 } else { //ipaq /stereo inputs
447 for (int i = 0; i < result; i+=2) { 451 for (int i = 0; i < result; i+=2) {
448 monoBuffer[j] = (sound[i]+sound[i+1])/2; 452 monoBuffer[j] = (sound[i]+sound[i+1])/2;
449 j++; 453 j++;
450 } 454 }
451 length+=write(wav, monoBuffer, result/2); 455 length+=write(wav, monoBuffer, result/2);
452 } 456 }
453// printf("%d\r",length); 457// printf("%d\r",length);
454// fflush(stdout); 458// fflush(stdout);
455 } 459 }
456 } else { //AFMT_U8 460 } else { //AFMT_U8
457// 8bit unsigned 461// 8bit unsigned
458 unsigned short sound[512], monoBuffer[512]; 462 unsigned short sound[512], monoBuffer[512];
459 while(recording) { 463 while(recording) {
460 result = read(dsp, sound, 512); // 8192 464 result = read(dsp, sound, 512); // 8192
461 int j=0; 465 int j=0;
462 if(systemZaurus) { 466 if(systemZaurus) {
463 for (int i = 0; i < result; i++) { //since Z is mono do normally 467 for (int i = 0; i < result; i++) { //since Z is mono do normally
464 monoBuffer[i] = sound[i]; 468 monoBuffer[i] = sound[i];
465 } 469 }
466 length+=write(wav, monoBuffer, result); 470 length+=write(wav, monoBuffer, result);
467 } else { //ipaq /stereo inputs 471 } else { //ipaq /stereo inputs
468 for (int i = 0; i < result; i+=2) { 472 for (int i = 0; i < result; i+=2) {
469 monoBuffer[j] = (sound[i]+sound[i+1])/2; 473 monoBuffer[j] = (sound[i]+sound[i+1])/2;
470 j++; 474 j++;
471 } 475 }
472 length+=write(wav, monoBuffer, result/2); 476 length+=write(wav, monoBuffer, result/2);
473 } 477 }
474 length += result; 478 length += result;
475// printf("%d\r",length); 479// printf("%d\r",length);
476// fflush(stdout); 480// fflush(stdout);
477 } 481 }
478 482
479 qApp->processEvents(); 483 qApp->processEvents();
480 } 484 }
481 485
482 } else { 486 } else { // this is specific for ipaqs that do not have 8 bit capabilities
483 487
484 signed short sound[512], monoBuffer[512]; 488 signed short sound[512], monoBuffer[512];
485 489
486 while(recording) { 490 while(recording) {
487 result = read(dsp, sound, 512); // 8192 491 result = read(dsp, sound, 512); // 8192
488 write(wav, sound, result); 492 write(wav, sound, result);
489 length += result; 493 length += result;
490 494
491 qApp->processEvents(); 495 qApp->processEvents();
492 } 496 }
493// printf("%d\r",length); 497// printf("%d\r",length);
494// fflush(stdout); 498// fflush(stdout);
495 // qDebug("file has length of %d lasting %d seconds", 499 // qDebug("file has length of %d lasting %d seconds",
496 // length, (( length / speed) / channels) / 2 ); 500 // length, (( length / speed) / channels) / 2 );
497 // medialplayer states wrong length in secs 501 // medialplayer states wrong length in secs
498 } 502 }
499 503
500 value = length+36; 504 value = length+36;
501 lseek(wav, 4, SEEK_SET); 505 lseek(wav, 4, SEEK_SET);
502 write(wav, &value, 4); 506 write(wav, &value, 4);
503 lseek(wav, 40, SEEK_SET); 507 lseek(wav, 40, SEEK_SET);
504 write(wav, &length, 4); 508 write(wav, &length, 4);
505 track.close(); 509 track.close();
506 510
507 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) 511 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)
508 perror("ioctl(\"SNDCTL_DSP_RESET\")"); 512 perror("ioctl(\"SNDCTL_DSP_RESET\")");
509 ::close(dsp); 513 ::close(dsp);
510 fileName = fileName.left(fileName.length()-4); 514 fileName = fileName.left(fileName.length()-4);
511 if(useAlerts) 515 if(useAlerts)
512 QMessageBox::message("Vmemo"," Done recording\n"+ fileName); 516 QMessageBox::message("Vmemo"," Done recording\n"+ fileName);
513 qDebug("done recording "+fileName); 517 qDebug("done recording "+fileName);
514 QSound::play(Resource::findSound("vmemoe")); 518 QSound::play(Resource::findSound("vmemoe"));
515} 519}
diff --git a/core/applets/vmemo/vmemo.h b/core/applets/vmemo/vmemo.h
index 3972877..701663f 100644
--- a/core/applets/vmemo/vmemo.h
+++ b/core/applets/vmemo/vmemo.h
@@ -1,56 +1,57 @@
1/**************************************************************************************94x78** 1/**************************************************************************************94x78**
2** 2**
3** This file may be distributed and/or modified under the terms of the 3** This file may be distributed and/or modified under the terms of the
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#include <qwidget.h> 20#include <qwidget.h>
21#include <qpixmap.h> 21#include <qpixmap.h>
22#include <qpe/applnk.h> 22#include <qpe/applnk.h>
23#include <qfile.h> 23#include <qfile.h>
24#include <qpe/qcopenvelope_qws.h> 24#include <qpe/qcopenvelope_qws.h>
25 25
26class VMemo : public QWidget 26class VMemo : public QWidget
27{ 27{
28 Q_OBJECT 28 Q_OBJECT
29public: 29public:
30 VMemo( QWidget *parent, const char *name = NULL); 30 VMemo( QWidget *parent, const char *name = NULL);
31 ~VMemo(); 31 ~VMemo();
32 QFile track; 32 QFile track;
33 QString fileName, errorMsg; 33 QString fileName, errorMsg;
34 34
35public slots: 35public slots:
36 void record(); 36 void record();
37 void mousePressEvent( QMouseEvent * ); 37 void mousePressEvent( QMouseEvent * );
38 void mouseReleaseEvent( QMouseEvent * ); 38 void mouseReleaseEvent( QMouseEvent * );
39 void receive( const QCString &msg, const QByteArray &data ); 39 void receive( const QCString &msg, const QByteArray &data );
40 40 bool startRecording();
41 void stopRecording();
41private: 42private:
42 bool useAlerts; 43 bool useAlerts;
43 void paintEvent( QPaintEvent* ); 44 void paintEvent( QPaintEvent* );
44 45
45 int openDSP(); 46 int openDSP();
46 int openWAV(const char *filename); 47 int openWAV(const char *filename);
47 48 bool fromToggle;
48 QPixmap vmemoPixmap; 49 QPixmap vmemoPixmap;
49 QCopChannel *myChannel; 50 QCopChannel *myChannel;
50 bool systemZaurus; 51 bool systemZaurus;
51 int dsp, wav, rate, speed, channels, format, resolution; 52 int dsp, wav, rate, speed, channels, format, resolution;
52 bool recording; 53 bool recording;
53}; 54};
54 55
55#endif // __VMEMO_H__ 56#endif // __VMEMO_H__
56 57