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