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