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