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