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