-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 70 | ||||
-rw-r--r-- | core/applets/vmemo/vmemo.h | 5 |
2 files changed, 42 insertions, 33 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 7af3d8b..6ec4583 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -1,82 +1,78 @@ | |||
1 | /************************************************************************************ | 1 | /************************************************************************************ |
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 | // 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 | // copyright 2002 and 2003 L.J.Potter <ljp@llornkcor.com> |
17 | |||
17 | extern "C" { | 18 | extern "C" { |
18 | #include "adpcm.h" | 19 | #include "adpcm.h" |
19 | } | 20 | } |
20 | 21 | ||
21 | #include <sys/utsname.h> | ||
22 | #include <sys/time.h> | ||
23 | #include <sys/types.h> | ||
24 | #include <unistd.h> | 22 | #include <unistd.h> |
25 | #include <stdio.h> | 23 | #include <stdio.h> |
26 | #include <sys/stat.h> | ||
27 | #include <fcntl.h> | 24 | #include <fcntl.h> |
28 | #include <sys/ioctl.h> | 25 | #include <sys/ioctl.h> |
29 | #include <linux/soundcard.h> | 26 | #include <linux/soundcard.h> |
30 | 27 | ||
31 | #include <string.h> | ||
32 | #include <stdlib.h> | ||
33 | #include <errno.h> | 28 | #include <errno.h> |
34 | 29 | ||
30 | |||
35 | typedef struct _waveheader { | 31 | typedef struct _waveheader { |
36 | u_long main_chunk; /* 'RIFF' */ | 32 | u_long main_chunk; /* 'RIFF' */ |
37 | u_long length; /* filelen */ | 33 | u_long length; /* filelen */ |
38 | u_long chunk_type; /* 'WAVE' */ | 34 | u_long chunk_type; /* 'WAVE' */ |
39 | u_long sub_chunk; /* 'fmt ' */ | 35 | u_long sub_chunk; /* 'fmt ' */ |
40 | u_long sc_len; /* length of sub_chunk, =16 | 36 | u_long sc_len; /* length of sub_chunk, =16 |
41 | (chunckSize) format len */ | 37 | (chunckSize) format len */ |
42 | u_short format; /* should be 1 for PCM-code (formatTag) */ | 38 | u_short format; /* should be 1 for PCM-code (formatTag) */ |
43 | 39 | ||
44 | u_short modus; /* 1 Mono, 2 Stereo (channels) */ | 40 | u_short modus; /* 1 Mono, 2 Stereo (channels) */ |
45 | u_long sample_fq; /* samples per second (samplesPerSecond) */ | 41 | u_long sample_fq; /* samples per second (samplesPerSecond) */ |
46 | u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ | 42 | u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ |
47 | u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ | 43 | u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ |
48 | u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ | 44 | u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ |
49 | 45 | ||
50 | u_long data_chunk; /* 'data' */ | 46 | u_long data_chunk; /* 'data' */ |
51 | 47 | ||
52 | u_long data_length;/* samplecount */ | 48 | u_long data_length;/* samplecount */ |
53 | } WaveHeader; | 49 | } WaveHeader; |
54 | 50 | ||
55 | #define RIFF 0x46464952 | 51 | #define RIFF 0x46464952 |
56 | #define WAVE 0x45564157 | 52 | #define WAVE 0x45564157 |
57 | #define FMT 0x20746D66 | 53 | #define FMT 0x20746D66 |
58 | #define DATA 0x61746164 | 54 | #define DATA 0x61746164 |
59 | #define PCM_CODE 1 | 55 | #define PCM_CODE 1 |
60 | #define WAVE_MONO 1 | 56 | #define WAVE_MONO 1 |
61 | #define WAVE_STEREO 2 | 57 | #define WAVE_STEREO 2 |
62 | 58 | ||
63 | struct adpcm_state encoder_state; | 59 | struct adpcm_state encoder_state; |
64 | //struct adpcm_state decoder_state; | 60 | //struct adpcm_state decoder_state; |
65 | 61 | ||
66 | #define WAVE_FORMAT_DVI_ADPCM (0x0011) | 62 | #define WAVE_FORMAT_DVI_ADPCM (0x0011) |
67 | #define WAVE_FORMAT_PCM (0x0001) | 63 | #define WAVE_FORMAT_PCM (0x0001) |
68 | 64 | ||
69 | 65 | ||
70 | #include "vmemo.h" | 66 | #include "vmemo.h" |
71 | 67 | ||
72 | #include <qpe/qpeapplication.h> | 68 | #include <qpe/qpeapplication.h> |
73 | #include <qpe/config.h> | 69 | #include <qpe/config.h> |
74 | 70 | ||
75 | #include <qpainter.h> | 71 | #include <qpainter.h> |
76 | #include <qmessagebox.h> | 72 | #include <qmessagebox.h> |
77 | 73 | ||
78 | int seq = 0; | 74 | int seq = 0; |
79 | 75 | ||
80 | /* XPM */ | 76 | /* XPM */ |
81 | static char * vmemo_xpm[] = { | 77 | static char * vmemo_xpm[] = { |
82 | "16 16 102 2", | 78 | "16 16 102 2", |
@@ -163,255 +159,246 @@ static char * vmemo_xpm[] = { | |||
163 | "P c #2D3137", | 159 | "P c #2D3137", |
164 | "Q c #B0B1BC", | 160 | "Q c #B0B1BC", |
165 | "R c #3B3C40", | 161 | "R c #3B3C40", |
166 | "S c #6E6E74", | 162 | "S c #6E6E74", |
167 | "T c #95959C", | 163 | "T c #95959C", |
168 | "U c #74747A", | 164 | "U c #74747A", |
169 | "V c #1D1D1E", | 165 | "V c #1D1D1E", |
170 | "W c #91929A", | 166 | "W c #91929A", |
171 | "X c #42444A", | 167 | "X c #42444A", |
172 | "Y c #22282E", | 168 | "Y c #22282E", |
173 | "Z c #B0B2BC", | 169 | "Z c #B0B2BC", |
174 | "` c #898A90", | 170 | "` c #898A90", |
175 | " . c #65656A", | 171 | " . c #65656A", |
176 | ".. c #999AA2", | 172 | ".. c #999AA2", |
177 | "+. c #52535A", | 173 | "+. c #52535A", |
178 | "@. c #151B21", | 174 | "@. c #151B21", |
179 | "#. c #515257", | 175 | "#. c #515257", |
180 | "$. c #B5B5BE", | 176 | "$. c #B5B5BE", |
181 | "%. c #616167", | 177 | "%. c #616167", |
182 | "&. c #1A1D22", | 178 | "&. c #1A1D22", |
183 | "*. c #000713", | 179 | "*. c #000713", |
184 | "=. c #1F1F21", | 180 | "=. c #1F1F21", |
185 | " ", | 181 | " ", |
186 | " . + @ # ", | 182 | " . + @ # ", |
187 | " $ % & * = - ", | 183 | " $ % & * = - ", |
188 | " ; > , ' ) ! ~ ", | 184 | " ; > , ' ) ! ~ ", |
189 | " { ] ^ / ( _ : ", | 185 | " { ] ^ / ( _ : ", |
190 | " < [ } | 1 2 3 ", | 186 | " < [ } | 1 2 3 ", |
191 | " 4 5 6 7 8 9 0 a b c ", | 187 | " 4 5 6 7 8 9 0 a b c ", |
192 | " d e f g h i j 3 k l m n ", | 188 | " d e f g h i j 3 k l m n ", |
193 | " o p q r s t u v w n ", | 189 | " o p q r s t u v w n ", |
194 | " o x y z A B C D E n ", | 190 | " o x y z A B C D E n ", |
195 | " F G H I J K L M N O ", | 191 | " F G H I J K L M N O ", |
196 | " P Q R S T U V W X ", | 192 | " P Q R S T U V W X ", |
197 | " Y Z ` b ...+. ", | 193 | " Y Z ` b ...+. ", |
198 | " @.#.$.%.&. ", | 194 | " @.#.$.%.&. ", |
199 | " *.B =. ", | 195 | " *.B =. ", |
200 | " n n n n n n n n n "}; | 196 | " n n n n n n n n n "}; |
201 | 197 | ||
202 | 198 | ||
203 | VMemo::VMemo( QWidget *parent, const char *_name ) | 199 | VMemo::VMemo( QWidget *parent, const char *_name ) |
204 | : QWidget( parent, _name ) { | 200 | : QWidget( parent, _name ) { |
205 | setFixedHeight( 18 ); | 201 | setFixedHeight( 18 ); |
206 | setFixedWidth( 14 ); | 202 | setFixedWidth( 14 ); |
207 | 203 | ||
208 | t_timer = new QTimer( this ); | 204 | t_timer = new QTimer( this ); |
209 | connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); | 205 | connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); |
210 | 206 | ||
211 | struct utsname name; /* check for embedix kernel running on the zaurus*/ | ||
212 | if (uname(&name) != -1) { | ||
213 | QString release=name.release; | ||
214 | |||
215 | Config vmCfg("Vmemo"); | 207 | Config vmCfg("Vmemo"); |
216 | vmCfg.setGroup("Defaults"); | 208 | vmCfg.setGroup("Defaults"); |
217 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); | 209 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); |
218 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | 210 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); |
219 | 211 | ||
220 | qDebug("toggleKey %d", toggleKey); | 212 | qDebug("toggleKey %d", toggleKey); |
221 | 213 | if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) | |
222 | if(release.find("embedix",0,TRUE) !=-1) | 214 | systemZaurus=TRUE; |
223 | systemZaurus=TRUE; | ||
224 | else | 215 | else |
225 | systemZaurus=FALSE; | 216 | systemZaurus=FALSE; |
226 | 217 | ||
227 | myChannel = new QCopChannel( "QPE/VMemo", this ); | 218 | myChannel = new QCopChannel( "QPE/VMemo", this ); |
228 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), | 219 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), |
229 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 220 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
230 | 221 | ||
231 | if( toggleKey != -1 ) { | 222 | if( toggleKey != -1 ) { |
232 | // keyRegister(key, channel, message) | 223 | // keyRegister(key, channel, message) |
233 | QCopEnvelope e("QPE/Launcher", "keyRegister(int,QCString,QCString)"); | 224 | QCopEnvelope e("QPE/Launcher", "keyRegister(int,QCString,QCString)"); |
234 | // e << 4096; // Key_Escape | 225 | // e << 4096; // Key_Escape |
235 | // e << Key_F5; //4148 | 226 | // e << Key_F5; //4148 |
236 | e << toggleKey; | 227 | e << toggleKey; |
237 | e << QString("QPE/VMemo"); | 228 | e << QString("QPE/VMemo"); |
238 | e << QString("toggleRecord()"); | 229 | e << QString("toggleRecord()"); |
239 | } | 230 | } |
240 | if(toggleKey == 1) | 231 | if(toggleKey == 1) |
241 | usingIcon=TRUE; | 232 | usingIcon=TRUE; |
242 | else | 233 | else |
243 | usingIcon=FALSE; | 234 | usingIcon=FALSE; |
244 | if( vmCfg.readNumEntry("hideIcon",0) == 1) | 235 | if( vmCfg.readNumEntry("hideIcon",0) == 1) |
245 | hide(); | 236 | hide(); |
246 | recording = FALSE; | 237 | recording = FALSE; |
247 | } | 238 | // } |
248 | } | 239 | } |
249 | 240 | ||
250 | VMemo::~VMemo() { | 241 | VMemo::~VMemo() { |
251 | } | 242 | } |
252 | 243 | ||
253 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { | 244 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { |
254 | qDebug("receive"); | 245 | qDebug("receive"); |
255 | QDataStream stream( data, IO_ReadOnly ); | 246 | QDataStream stream( data, IO_ReadOnly ); |
256 | 247 | ||
257 | if (msg == "toggleRecord()") { | 248 | if (msg == "toggleRecord()") { |
258 | if (recording) { | 249 | if (recording) { |
259 | fromToggle = TRUE; | 250 | fromToggle = TRUE; |
260 | stopRecording(); | 251 | stopRecording(); |
261 | } else { | 252 | } else { |
262 | fromToggle = TRUE; | 253 | fromToggle = TRUE; |
263 | startRecording(); | 254 | startRecording(); |
264 | } | 255 | } |
265 | } | 256 | } |
266 | } | 257 | } |
267 | 258 | ||
268 | void VMemo::paintEvent( QPaintEvent* ) { | 259 | void VMemo::paintEvent( QPaintEvent* ) { |
269 | QPainter p(this); | 260 | QPainter p(this); |
270 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 261 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
271 | } | 262 | } |
272 | 263 | ||
273 | void VMemo::mousePressEvent( QMouseEvent * me) { | 264 | void VMemo::mousePressEvent( QMouseEvent * me) { |
274 | /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions | 265 | /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions |
275 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ | 266 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ |
276 | 267 | ||
277 | // if (!systemZaurus && me != NULL) | 268 | // if (!systemZaurus && me != NULL) |
278 | // return; | 269 | // return; |
279 | // } | 270 | // } |
280 | 271 | ||
281 | if(!recording) | 272 | if(!recording) |
282 | startRecording(); | 273 | startRecording(); |
283 | else | 274 | else |
284 | stopRecording(); | 275 | stopRecording(); |
285 | } | 276 | } |
286 | 277 | ||
287 | void VMemo::mouseReleaseEvent( QMouseEvent * ) { | 278 | void VMemo::mouseReleaseEvent( QMouseEvent * ) { |
288 | } | 279 | } |
289 | 280 | ||
290 | bool VMemo::startRecording() { | 281 | bool VMemo::startRecording() { |
291 | Config config( "Vmemo" ); | 282 | Config config( "Vmemo" ); |
292 | config.setGroup( "System" ); | 283 | config.setGroup( "System" ); |
293 | 284 | ||
294 | useAlerts = config.readBoolEntry("Alert",1); | 285 | useAlerts = config.readBoolEntry("Alert",1); |
295 | if(useAlerts) { | 286 | if(useAlerts) { |
296 | 287 | ||
297 | msgLabel = new QLabel( 0, "alertLabel" ); | 288 | msgLabel = new QLabel( 0, "alertLabel" ); |
298 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); | 289 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); |
299 | msgLabel->show(); | 290 | msgLabel->show(); |
300 | } | 291 | } |
301 | 292 | ||
302 | qDebug("Start recording engines"); | 293 | qDebug("Start recording engines"); |
303 | recording = TRUE; | 294 | recording = TRUE; |
304 | 295 | ||
305 | if (openDSP() == -1) { | 296 | if (openDSP() == -1) { |
306 | recording = FALSE; | 297 | recording = FALSE; |
307 | return FALSE; | 298 | return FALSE; |
308 | } | 299 | } |
309 | 300 | ||
310 | config.setGroup("Defaults"); | 301 | config.setGroup("Defaults"); |
311 | 302 | ||
312 | QDateTime dt = QDateTime::currentDateTime(); | 303 | date = TimeString::dateString( QDateTime::currentDateTime(),false,true); |
304 | date.replace(QRegExp("'"),""); | ||
305 | date.replace(QRegExp(" "),"_"); | ||
306 | date.replace(QRegExp(":"),"."); | ||
307 | date.replace(QRegExp(","),""); | ||
313 | 308 | ||
314 | QString fName; | 309 | QString fName; |
315 | config.setGroup( "System" ); | 310 | config.setGroup( "System" ); |
316 | fName = QPEApplication::documentDir() ; | 311 | fName = QPEApplication::documentDir() ; |
317 | fileName = config.readEntry("RecLocation", fName); | 312 | fileName = config.readEntry("RecLocation", fName); |
318 | 313 | ||
319 | int s; | 314 | int s; |
320 | s=fileName.find(':'); | 315 | s=fileName.find(':'); |
321 | if(s) | 316 | if(s) |
322 | fileName=fileName.right(fileName.length()-s-2); | 317 | fileName=fileName.right(fileName.length()-s-2); |
323 | qDebug("pathname will be "+fileName); | 318 | qDebug("pathname will be "+fileName); |
324 | 319 | ||
325 | if( fileName.left(1).find('/') == -1) | 320 | if( fileName.left(1).find('/') == -1) |
326 | fileName="/"+fileName; | 321 | fileName="/"+fileName; |
327 | if( fileName.right(1).find('/') == -1) | 322 | if( fileName.right(1).find('/') == -1) |
328 | fileName+="/"; | 323 | fileName+="/"; |
329 | fName = "vm_"+ dt.toString()+ ".wav"; | 324 | fName = "vm_"+ date+ ".wav"; |
330 | 325 | ||
331 | fileName+=fName; | 326 | fileName+=fName; |
332 | // No spaces in the filename | ||
333 | fileName.replace(QRegExp("'"),""); | ||
334 | fileName.replace(QRegExp(" "),"_"); | ||
335 | fileName.replace(QRegExp(":"),"."); | ||
336 | fileName.replace(QRegExp(","),""); | ||
337 | |||
338 | |||
339 | qDebug("filename is "+fileName); | 327 | qDebug("filename is "+fileName); |
340 | // open tmp file here | 328 | // open tmp file here |
341 | char *pointer; | 329 | char *pointer; |
342 | pointer=tmpnam(NULL); | 330 | pointer=tmpnam(NULL); |
343 | qDebug("Opening tmp file %s",pointer); | 331 | qDebug("Opening tmp file %s",pointer); |
344 | 332 | ||
345 | if(openWAV(pointer ) == -1) { | 333 | if(openWAV(pointer ) == -1) { |
346 | 334 | ||
347 | // if(openWAV(fileName.latin1()) == -1) { | ||
348 | QString err("Could not open the temp file\n"); | 335 | QString err("Could not open the temp file\n"); |
349 | err += fileName; | 336 | err += fileName; |
350 | QMessageBox::critical(0, "vmemo", err, "Abort"); | 337 | QMessageBox::critical(0, "vmemo", err, "Abort"); |
351 | ::close(dsp); | 338 | ::close(dsp); |
352 | return FALSE; | 339 | return FALSE; |
353 | } | 340 | } |
354 | if( record() ) { | 341 | if( record() ) { |
355 | 342 | ||
356 | QString cmd; | 343 | QString cmd; |
357 | if( fileName.find(".wav",0,TRUE) == -1) | 344 | if( fileName.find(".wav",0,TRUE) == -1) |
358 | fileName += ".wav"; | 345 | fileName += ".wav"; |
359 | 346 | ||
360 | cmd.sprintf("mv %s "+fileName, pointer); | 347 | cmd.sprintf("mv %s "+fileName, pointer); |
361 | // move tmp file to regular file here | 348 | // move tmp file to regular file here |
362 | 349 | ||
363 | system(cmd.latin1()); | 350 | system(cmd.latin1()); |
364 | 351 | ||
365 | QArray<int> cats(1); | 352 | QArray<int> cats(1); |
366 | cats[0] = config.readNumEntry("Category", 0); | 353 | cats[0] = config.readNumEntry("Category", 0); |
367 | 354 | ||
368 | QString dlName("vm_"); | 355 | QString dlName("vm_"); |
369 | dlName += dt.toString(); | 356 | dlName += date; |
370 | DocLnk l; | 357 | DocLnk l; |
371 | l.setFile(fileName); | 358 | l.setFile(fileName); |
372 | l.setName(dlName); | 359 | l.setName(dlName); |
373 | l.setType("audio/x-wav"); | 360 | l.setType("audio/x-wav"); |
374 | l.setCategories(cats); | 361 | l.setCategories(cats); |
375 | l.writeLink(); | 362 | l.writeLink(); |
376 | return TRUE; | 363 | return TRUE; |
377 | } else | 364 | } else |
378 | return FALSE; | 365 | return FALSE; |
379 | 366 | ||
380 | } | 367 | } |
381 | 368 | ||
382 | void VMemo::stopRecording() { | 369 | void VMemo::stopRecording() { |
383 | show(); | 370 | show(); |
384 | qDebug("Stopped recording"); | 371 | qDebug("Stopped recording"); |
385 | recording = FALSE; | 372 | recording = FALSE; |
386 | if(useAlerts) { | 373 | if(useAlerts) { |
387 | msgLabel->close(); | 374 | msgLabel->close(); |
388 | msgLabel=0; | 375 | msgLabel=0; |
389 | delete msgLabel; | 376 | delete msgLabel; |
390 | } | 377 | } |
391 | t_timer->stop(); | 378 | t_timer->stop(); |
392 | Config cfg("Vmemo"); | 379 | Config cfg("Vmemo"); |
393 | cfg.setGroup("Defaults"); | 380 | cfg.setGroup("Defaults"); |
394 | if( cfg.readNumEntry("hideIcon",0) == 1 ) | 381 | if( cfg.readNumEntry("hideIcon",0) == 1 ) |
395 | hide(); | 382 | hide(); |
396 | } | 383 | } |
397 | 384 | ||
398 | int VMemo::openDSP() { | 385 | int VMemo::openDSP() { |
399 | Config cfg("Vmemo"); | 386 | Config cfg("Vmemo"); |
400 | cfg.setGroup("Record"); | 387 | cfg.setGroup("Record"); |
401 | 388 | ||
402 | speed = cfg.readNumEntry("SampleRate", 22050); | 389 | speed = cfg.readNumEntry("SampleRate", 22050); |
403 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 390 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
404 | if (cfg.readNumEntry("SixteenBit", 1)==1) { | 391 | if (cfg.readNumEntry("SixteenBit", 1)==1) { |
405 | format = AFMT_S16_LE; | 392 | format = AFMT_S16_LE; |
406 | resolution = 16; | 393 | resolution = 16; |
407 | } else { | 394 | } else { |
408 | format = AFMT_U8; | 395 | format = AFMT_U8; |
409 | resolution = 8; | 396 | resolution = 8; |
410 | } | 397 | } |
411 | 398 | ||
412 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); | 399 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); |
413 | 400 | ||
414 | if(systemZaurus) { | 401 | if(systemZaurus) { |
415 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 | 402 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 |
416 | channels=1; //zaurus has one input channel | 403 | channels=1; //zaurus has one input channel |
417 | } else { | 404 | } else { |
@@ -444,184 +431,205 @@ int VMemo::openDSP() { | |||
444 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { | 431 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { |
445 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 432 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); |
446 | return -1; | 433 | return -1; |
447 | } | 434 | } |
448 | 435 | ||
449 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute | 436 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute |
450 | 437 | ||
451 | return 1; | 438 | return 1; |
452 | } | 439 | } |
453 | 440 | ||
454 | int VMemo::openWAV(const char *filename) { | 441 | int VMemo::openWAV(const char *filename) { |
455 | track.setName(filename); | 442 | track.setName(filename); |
456 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { | 443 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { |
457 | errorMsg=filename; | 444 | errorMsg=filename; |
458 | return -1; | 445 | return -1; |
459 | } | 446 | } |
460 | 447 | ||
461 | wav=track.handle(); | 448 | wav=track.handle(); |
462 | Config vmCfg("Vmemo"); | 449 | Config vmCfg("Vmemo"); |
463 | vmCfg.setGroup("Defaults"); | 450 | vmCfg.setGroup("Defaults"); |
464 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | 451 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); |
465 | 452 | ||
466 | WaveHeader wh; | 453 | WaveHeader wh; |
467 | 454 | ||
468 | wh.main_chunk = RIFF; | 455 | wh.main_chunk = RIFF; |
469 | wh.length=0; | 456 | wh.length=0; |
470 | wh.chunk_type = WAVE; | 457 | wh.chunk_type = WAVE; |
471 | wh.sub_chunk = FMT; | 458 | wh.sub_chunk = FMT; |
472 | wh.sc_len = 16; | 459 | wh.sc_len = 16; |
473 | if(useADPCM) | 460 | if(useADPCM) |
474 | wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; | 461 | wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; |
475 | else | 462 | else |
476 | wh.format = PCM_CODE; | 463 | wh.format = PCM_CODE; |
477 | wh.modus = channels; | 464 | wh.modus = channels; |
478 | wh.sample_fq = speed; | 465 | wh.sample_fq = speed; |
479 | wh.byte_p_sec = speed * channels * resolution/8; | 466 | wh.byte_p_sec = speed * channels * resolution/8; |
480 | wh.byte_p_spl = channels * (resolution / 8); | 467 | wh.byte_p_spl = channels * (resolution / 8); |
481 | wh.bit_p_spl = resolution; | 468 | wh.bit_p_spl = resolution; |
482 | wh.data_chunk = DATA; | 469 | wh.data_chunk = DATA; |
483 | wh.data_length= 0; | 470 | wh.data_length= 0; |
484 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" | 471 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" |
485 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); | 472 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); |
486 | write (wav, &wh, sizeof(WaveHeader)); | 473 | write (wav, &wh, sizeof(WaveHeader)); |
487 | 474 | ||
488 | return 1; | 475 | return 1; |
489 | } | 476 | } |
490 | 477 | ||
491 | bool VMemo::record() { | 478 | bool VMemo::record() { |
492 | 479 | length=0; | |
493 | int length=0, result, value; | 480 | int result, value; |
494 | QString msg; | 481 | QString msg; |
495 | msg.sprintf("Recording format %d", format); | 482 | msg.sprintf("Recording format %d", format); |
496 | qDebug(msg); | 483 | qDebug(msg); |
497 | Config config("Vmemo"); | 484 | Config config("Vmemo"); |
498 | config.setGroup("Record"); | 485 | config.setGroup("Record"); |
499 | int sRate=config.readNumEntry("SizeLimit", 30); | 486 | int sRate=config.readNumEntry("SizeLimit", 30); |
500 | if(sRate > 0) | 487 | if(sRate > 0) |
501 | t_timer->start( sRate * 1000+1000, TRUE); | 488 | t_timer->start( sRate * 1000+1000, TRUE); |
502 | 489 | ||
503 | // if(systemZaurus) { | 490 | // if(systemZaurus) { |
504 | // } else { // 16 bit only capabilities | 491 | // } else { // 16 bit only capabilities |
505 | 492 | ||
506 | msg.sprintf("Recording format other"); | 493 | msg.sprintf("Recording format other"); |
507 | qDebug(msg); | 494 | qDebug(msg); |
508 | 495 | ||
509 | int bufsize=1024; | 496 | int bufsize=1024; |
510 | int bytesWritten=0; | 497 | int bytesWritten=0; |
511 | signed short sound[1024], monoBuffer[1024]; | 498 | signed short sound[1024], monoBuffer[1024]; |
512 | char abuf[bufsize/2]; | 499 | char abuf[bufsize/2]; |
513 | short sbuf[bufsize]; | 500 | short sbuf[bufsize]; |
514 | Config vmCfg("Vmemo"); | 501 | Config vmCfg("Vmemo"); |
515 | vmCfg.setGroup("Defaults"); | 502 | vmCfg.setGroup("Defaults"); |
516 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | 503 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); |
517 | 504 | ||
518 | while(recording) { | 505 | while(recording) { |
519 | 506 | ||
520 | if(useADPCM) | 507 | if(useADPCM) |
521 | result = read( dsp, sbuf, bufsize); // 8192 | 508 | result = read( dsp, sbuf, bufsize); // 8192 |
522 | else | 509 | else |
523 | result = read(dsp, sound, 1024); // 8192 | 510 | result = read(dsp, sound, 1024); // 8192 |
524 | if( result <= 0) { | 511 | if( result <= 0) { |
525 | perror("recording error "); | 512 | perror("recording error "); |
526 | // qDebug(currentFileName); | 513 | // qDebug(currentFileName); |
527 | QMessageBox::message(tr("Note"),tr("error recording")); | 514 | QMessageBox::message(tr("Note"),tr("error recording")); |
528 | recording=FALSE; | 515 | recording=FALSE; |
529 | break; | 516 | break; |
530 | return FALSE; | 517 | return FALSE; |
531 | } | 518 | } |
532 | 519 | ||
533 | if(useADPCM) { | 520 | if(useADPCM) { |
534 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); | 521 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); |
535 | bytesWritten = ::write(wav, abuf, result/4); | 522 | bytesWritten = ::write(wav, abuf, result/4); |
536 | 523 | ||
537 | } else { | 524 | } else { |
538 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 525 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
539 | monoBuffer[i] = sound[i]; | 526 | monoBuffer[i] = sound[i]; |
540 | } | 527 | } |
541 | 528 | ||
542 | length+=write(wav, monoBuffer, result); | 529 | length+=write(wav, monoBuffer, result); |
543 | } | 530 | } |
544 | length +=bytesWritten; | 531 | length +=bytesWritten; |
545 | 532 | ||
546 | if(length<0) { | 533 | if(length<0) { |
547 | recording=false; | 534 | recording=false; |
548 | perror("dev/dsp's is a lookin' messy"); | 535 | perror("dev/dsp's is a lookin' messy"); |
549 | QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); | 536 | QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); |
550 | break; | 537 | break; |
551 | return FALSE; | 538 | return FALSE; |
552 | } | 539 | } |
553 | // printf("%d\r",length); | 540 | // printf("%d\r",length); |
554 | // fflush(stdout); | 541 | // fflush(stdout); |
555 | qApp->processEvents(); | 542 | qApp->processEvents(); |
556 | } | 543 | } |
557 | // qDebug("file has length of %d lasting %d seconds", | 544 | // qDebug("file has length of %d lasting %d seconds", |
558 | // length, (( length / speed) / channels) / 2 ); | 545 | // length, (( length / speed) / channels) / 2 ); |
559 | // } | 546 | // } |
560 | 547 | ||
561 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// | 548 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// |
562 | 549 | ||
563 | value = length+36; | 550 | value = length+36; |
564 | 551 | ||
565 | lseek(wav, 4, SEEK_SET); | 552 | lseek(wav, 4, SEEK_SET); |
566 | write(wav, &value, 4); | 553 | write(wav, &value, 4); |
567 | lseek(wav, 40, SEEK_SET); | 554 | lseek(wav, 40, SEEK_SET); |
568 | 555 | ||
569 | write(wav, &length, 4); | 556 | write(wav, &length, 4); |
570 | 557 | ||
571 | track.close(); | 558 | track.close(); |
572 | qDebug("Track closed"); | 559 | qDebug("Track closed"); |
573 | 560 | ||
574 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 561 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
575 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 562 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
576 | 563 | ||
577 | ::close(dsp); | 564 | ::close(dsp); |
578 | 565 | ||
579 | qDebug("done recording "+fileName); | 566 | Config cfgO("OpieRec"); |
567 | cfgO.setGroup("Sounds"); | ||
568 | |||
569 | int nFiles = cfgO.readNumEntry( "NumberofFiles",0); | ||
570 | |||
571 | QString currentFileName = fileName; | ||
572 | QString currentFile = "vm_"+ date; | ||
573 | |||
574 | float numberOfRecordedSeconds=(float) length / (float)speed * (float)2; | ||
575 | |||
576 | cfgO.writeEntry( "NumberofFiles", nFiles + 1); | ||
577 | cfgO.writeEntry( QString::number( nFiles + 1), currentFile); | ||
578 | cfgO.writeEntry( currentFile, currentFileName); | ||
579 | |||
580 | QString time; | ||
581 | time.sprintf("%.2f", numberOfRecordedSeconds); | ||
582 | cfgO.writeEntry( currentFileName, time ); | ||
583 | // qDebug("writing config numberOfRecordedSeconds "+time); | ||
584 | |||
585 | cfgO.write(); | ||
586 | |||
587 | qDebug("done recording "+fileName); | ||
580 | 588 | ||
581 | Config cfg("qpe"); | 589 | Config cfg("qpe"); |
582 | cfg.setGroup("Volume"); | 590 | cfg.setGroup("Volume"); |
583 | QString foo = cfg.readEntry("Mute","TRUE"); | 591 | QString foo = cfg.readEntry("Mute","TRUE"); |
584 | if(foo.find("TRUE",0,TRUE) != -1) | 592 | if(foo.find("TRUE",0,TRUE) != -1) |
585 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute | 593 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute |
586 | return TRUE; | 594 | return TRUE; |
587 | } | 595 | } |
588 | 596 | ||
589 | int VMemo::setToggleButton(int tog) { | 597 | int VMemo::setToggleButton(int tog) { |
590 | 598 | ||
591 | for( int i=0; i < 10;i++) { | 599 | for( int i=0; i < 10;i++) { |
592 | switch (tog) { | 600 | switch (tog) { |
593 | case 0: | 601 | case 0: |
594 | return -1; | 602 | return -1; |
595 | break; | 603 | break; |
596 | case 1: | 604 | case 1: |
597 | return 0; | 605 | return 0; |
598 | break; | 606 | break; |
599 | case 2: | 607 | case 2: |
600 | return Key_F24; //was Escape | 608 | return Key_F24; //was Escape |
601 | break; | 609 | break; |
602 | case 3: | 610 | case 3: |
603 | return Key_Space; | 611 | return Key_Space; |
604 | break; | 612 | break; |
605 | case 4: | 613 | case 4: |
606 | return Key_F12; | 614 | return Key_F12; |
607 | break; | 615 | break; |
608 | case 5: | 616 | case 5: |
609 | return Key_F9; | 617 | return Key_F9; |
610 | break; | 618 | break; |
611 | case 6: | 619 | case 6: |
612 | return Key_F10; | 620 | return Key_F10; |
613 | break; | 621 | break; |
614 | case 7: | 622 | case 7: |
615 | return Key_F11; | 623 | return Key_F11; |
616 | break; | 624 | break; |
617 | case 8: | 625 | case 8: |
618 | return Key_F13; | 626 | return Key_F13; |
619 | break; | 627 | break; |
620 | }; | 628 | }; |
621 | } | 629 | } |
622 | return -1; | 630 | return -1; |
623 | } | 631 | } |
624 | 632 | ||
625 | void VMemo::timerBreak() { | 633 | void VMemo::timerBreak() { |
626 | //stop | 634 | //stop |
627 | stopRecording(); | 635 | stopRecording(); |
diff --git a/core/applets/vmemo/vmemo.h b/core/applets/vmemo/vmemo.h index 9ee08ff..31d0a25 100644 --- a/core/applets/vmemo/vmemo.h +++ b/core/applets/vmemo/vmemo.h | |||
@@ -1,63 +1,64 @@ | |||
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 | 20 | ||
21 | #include <qwidget.h> | 21 | #include <qwidget.h> |
22 | #include <qpixmap.h> | 22 | #include <qpixmap.h> |
23 | #include <qpe/applnk.h> | 23 | #include <qpe/applnk.h> |
24 | #include <qfile.h> | 24 | #include <qfile.h> |
25 | #include <qpe/qcopenvelope_qws.h> | 25 | #include <qpe/qcopenvelope_qws.h> |
26 | #include <qlabel.h> | 26 | #include <qlabel.h> |
27 | #include <qtimer.h> | 27 | #include <qtimer.h> |
28 | 28 | ||
29 | class VMemo : public QWidget | 29 | class VMemo : public QWidget |
30 | { | 30 | { |
31 | Q_OBJECT | 31 | Q_OBJECT |
32 | public: | 32 | public: |
33 | VMemo( QWidget *parent, const char *name = NULL); | 33 | VMemo( QWidget *parent, const char *name = NULL); |
34 | ~VMemo(); | 34 | ~VMemo(); |
35 | QFile track; | 35 | QFile track; |
36 | QString fileName, errorMsg; | 36 | int length; |
37 | QString fileName, errorMsg, date; | ||
37 | QLabel* msgLabel; | 38 | QLabel* msgLabel; |
38 | QTimer *t_timer; | 39 | QTimer *t_timer; |
39 | bool usingIcon, useADPCM; | 40 | bool usingIcon, useADPCM; |
40 | public slots: | 41 | public slots: |
41 | bool record(); | 42 | bool record(); |
42 | void mousePressEvent( QMouseEvent * ); | 43 | void mousePressEvent( QMouseEvent * ); |
43 | void mouseReleaseEvent( QMouseEvent * ); | 44 | void mouseReleaseEvent( QMouseEvent * ); |
44 | void receive( const QCString &msg, const QByteArray &data ); | 45 | void receive( const QCString &msg, const QByteArray &data ); |
45 | bool startRecording(); | 46 | bool startRecording(); |
46 | void stopRecording(); | 47 | void stopRecording(); |
47 | void timerBreak(); | 48 | void timerBreak(); |
48 | private: | 49 | private: |
49 | bool useAlerts; | 50 | bool useAlerts; |
50 | void paintEvent( QPaintEvent* ); | 51 | void paintEvent( QPaintEvent* ); |
51 | int setToggleButton(int); | 52 | int setToggleButton(int); |
52 | int openDSP(); | 53 | int openDSP(); |
53 | int openWAV(const char *filename); | 54 | int openWAV(const char *filename); |
54 | bool fromToggle; | 55 | bool fromToggle; |
55 | QPixmap vmemoPixmap; | 56 | QPixmap vmemoPixmap; |
56 | QCopChannel *myChannel; | 57 | QCopChannel *myChannel; |
57 | bool systemZaurus; | 58 | bool systemZaurus; |
58 | int dsp, wav, rate, speed, channels, format, resolution; | 59 | int dsp, wav, rate, speed, channels, format, resolution; |
59 | bool recording; | 60 | bool recording; |
60 | }; | 61 | }; |
61 | 62 | ||
62 | #endif // __VMEMO_H__ | 63 | #endif // __VMEMO_H__ |
63 | 64 | ||