summaryrefslogtreecommitdiff
authorjeremy <jeremy>2002-02-19 20:44:24 (UTC)
committer jeremy <jeremy>2002-02-19 20:44:24 (UTC)
commit4532d74ad882dc3c14cf1c42931e5cedf31cba05 (patch) (unidiff)
tree728e3e2c0924f9e11bc9e0f27eb974589ca37e2b
parent3ed313993ab9fa0f6a8c8ca2b2fe0f5c8cf39dc6 (diff)
downloadopie-4532d74ad882dc3c14cf1c42931e5cedf31cba05.zip
opie-4532d74ad882dc3c14cf1c42931e5cedf31cba05.tar.gz
opie-4532d74ad882dc3c14cf1c42931e5cedf31cba05.tar.bz2
Temporarly disabled the mousePress and Release events on the iPAQ only due
to the sticky keyboard problem.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp71
1 files changed, 25 insertions, 46 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index aa23ba7..48dd193 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -130,156 +130,159 @@ static char * vmemo_xpm[] = {
130".$;;#5:67;89 ", 130".$;;#5:67;89 ",
131":%;0%&ab;8. ", 131":%;0%&ab;8. ",
132"@cd%e!fg49 ", 132"@cd%e!fg49 ",
133" h0,!_;2@ ", 133" h0,!_;2@ ",
134" ))))) "}; 134" ))))) "};
135 135
136VMemo::VMemo( QWidget *parent, const char *name ) 136VMemo::VMemo( QWidget *parent, const char *name )
137 : QWidget( parent, name ) 137 : QWidget( parent, name )
138{ 138{
139 setFixedHeight( 18 ); 139 setFixedHeight( 18 );
140 setFixedWidth( 14 ); 140 setFixedWidth( 14 );
141 141
142 recording = FALSE; 142 recording = FALSE;
143 143
144 myChannel = new QCopChannel( "QPE/VMemo", this ); 144 myChannel = new QCopChannel( "QPE/VMemo", this );
145 connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), 145 connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)),
146 this, SLOT(receive(const QCString&, const QByteArray&)) ); 146 this, SLOT(receive(const QCString&, const QByteArray&)) );
147 147
148 struct utsname name; /* check for embedix kernel running on the zaurus, if 148 struct utsname name; /* check for embedix kernel running on the zaurus, if
149 lineo change string, this break 149 lineo change string, this break
150 */ 150 */
151 if (uname(&name) != -1) 151 if (uname(&name) != -1)
152 { 152 {
153 QString release=name.release; 153 QString release=name.release;
154 qWarning("System release: %s\n", name.release);
155 if(release.find("embedix",0,TRUE) !=-1) 154 if(release.find("embedix",0,TRUE) !=-1)
156 systemZaurus=TRUE; 155 systemZaurus=TRUE;
157 else 156 else
158 { 157 {
159 systemZaurus=FALSE; 158 systemZaurus=FALSE;
160 159
161 // Register the REC key press. 160 // Register the REC key press.
162 QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); 161 QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)");
163 e << 4096; 162 e << 4096;
164 e << QString("QPE/VMemo"); 163 e << QString("QPE/VMemo");
165 e << QString("toggleRecord()"); 164 e << QString("toggleRecord()");
166 } 165 }
167 } 166 }
168 qWarning("VMemo done init");
169} 167}
170 168
171VMemo::~VMemo() 169VMemo::~VMemo()
172{ 170{
173} 171}
174 172
175void VMemo::receive( const QCString &msg, const QByteArray &data ) 173void VMemo::receive( const QCString &msg, const QByteArray &data )
176{ 174{
177 QDataStream stream( data, IO_ReadOnly ); 175 QDataStream stream( data, IO_ReadOnly );
178 qWarning("VMemo::receive: %s", (const char *)msg); 176 if (msg == "toggleRecord()")
179 if (msg == "toggleRecord()") 177 {
180 { 178 if (recording)
181 if (recording) 179 mouseReleaseEvent(NULL);
182 mouseReleaseEvent(NULL); 180 else
183 else 181 mousePressEvent(NULL);
184 mousePressEvent(NULL); 182 }
185 }
186} 183}
187 184
188void VMemo::paintEvent( QPaintEvent* ) 185void VMemo::paintEvent( QPaintEvent* )
189{ 186{
190 QPainter p(this); 187 QPainter p(this);
191 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); 188 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm );
192} 189}
193 190
194void VMemo::mousePressEvent( QMouseEvent * ) 191void VMemo::mousePressEvent( QMouseEvent *me )
195{ 192{
196 // just to be safe 193 // just to be safe
197 if (recording) 194 if (recording)
198 { 195 {
199 recording = FALSE; 196 recording = FALSE;
200 return; 197 return;
201 } 198 }
199
200 /*
201 No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions
202 mousePressEvent and mouseReleaseEvent with a NULL parameter.
203 */
204 if (!systemZaurus && me != NULL)
205 return;
202 206
203 qWarning("VMemo::mousePress()");
204 QSound::play(Resource::findSound("vmemob")); 207 QSound::play(Resource::findSound("vmemob"));
205 208
206 recording = TRUE; 209 recording = TRUE;
207 qWarning("VMemo::mousePress() -> Starting to record");
208 if (openDSP() == -1) 210 if (openDSP() == -1)
209 { 211 {
210 // ### Display an error box
211 QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort"); 212 QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort");
212 recording = FALSE; 213 recording = FALSE;
213 return; 214 return;
214 } 215 }
215 216
216 Config vmCfg("VMemo"); 217 Config vmCfg("VMemo");
217 vmCfg.setGroup("Defaults"); 218 vmCfg.setGroup("Defaults");
218 219
219 QDateTime dt = QDateTime::currentDateTime(); 220 QDateTime dt = QDateTime::currentDateTime();
220 QString fileName; 221 QString fileName;
222
221 if(systemZaurus) 223 if(systemZaurus)
222 fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs 224 fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs
223 else 225 else
224 fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); 226 fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/");
225 227
226 fileName += "vm_"; 228 fileName += "vm_";
227 fileName += dt.toString(); 229 fileName += dt.toString();
228 fileName += ".wav"; 230 fileName += ".wav";
229 231
230 // No spaces in the filename 232 // No spaces in the filename
231 fileName.replace(QRegExp("'"),""); 233 fileName.replace(QRegExp("'"),"");
232 fileName.replace(QRegExp(" "),"_"); 234 fileName.replace(QRegExp(" "),"_");
233 fileName.replace(QRegExp(":"),"."); 235 fileName.replace(QRegExp(":"),".");
234 fileName.replace(QRegExp(","),""); 236 fileName.replace(QRegExp(","),"");
235 237
236 if(openWAV(fileName.latin1()) == -1) 238 if(openWAV(fileName.latin1()) == -1)
237 { 239 {
238 // ### Display an error box 240 QString err("Could not open the output file: ");
239 qWarning("VMemo::mousePress() -> WAV error"); 241 err += fileName;
242
243 QMessageBox::critical(0, "VMemo", err, "Abort");
240 close(dsp); 244 close(dsp);
241 return; 245 return;
242 } 246 }
243 247
244 QArray<int> cats(1); 248 QArray<int> cats(1);
245 cats[0] = vmCfg.readNumEntry("Category", 0); 249 cats[0] = vmCfg.readNumEntry("Category", 0);
246 250
247 QString dlName("vm_"); 251 QString dlName("vm_");
248 dlName += dt.toString(); 252 dlName += dt.toString();
249 DocLnk l; 253 DocLnk l;
250 l.setFile(fileName); 254 l.setFile(fileName);
251 l.setName(dlName); 255 l.setName(dlName);
252 l.setType("audio/x-wav"); 256 l.setType("audio/x-wav");
253 l.setCategories(cats); 257 l.setCategories(cats);
254 l.writeLink(); 258 l.writeLink();
255 259
256 record(); 260 record();
257} 261}
258 262
259void VMemo::mouseReleaseEvent( QMouseEvent * ) 263void VMemo::mouseReleaseEvent( QMouseEvent * )
260{ 264{
261 qWarning("VMemo::mouseRelese() -> Done recording");
262 recording = FALSE; 265 recording = FALSE;
263} 266}
264 267
265int VMemo::openDSP() 268int VMemo::openDSP()
266{ 269{
267 Config cfg("Sound"); 270 Config cfg("Sound");
268 cfg.setGroup("Record"); 271 cfg.setGroup("Record");
269 272
270 speed = cfg.readNumEntry("SampleRate", 22050); 273 speed = cfg.readNumEntry("SampleRate", 22050);
271 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) 274 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1)
272 if (cfg.readNumEntry("SixteenBit", 1)==1) 275 if (cfg.readNumEntry("SixteenBit", 1)==1)
273 { 276 {
274 format = AFMT_S16_LE; 277 format = AFMT_S16_LE;
275 resolution = 16; 278 resolution = 16;
276 } 279 }
277 else 280 else
278 { 281 {
279 format = AFMT_U8; 282 format = AFMT_U8;
280 resolution = 8; 283 resolution = 8;
281 } 284 }
282 285
283 if(systemZaurus) 286 if(systemZaurus)
284 { 287 {
285 dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 288 dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1
@@ -299,105 +302,81 @@ int VMemo::openDSP()
299 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 302 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
300 return -1; 303 return -1;
301 } 304 }
302 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) 305 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1)
303 { 306 {
304 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 307 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
305 return -1; 308 return -1;
306 } 309 }
307 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) 310 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1)
308 { 311 {
309 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 312 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
310 return -1; 313 return -1;
311 } 314 }
312 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) 315 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1)
313 { 316 {
314 perror("ioctl(\"SOUND_PCM_READ_RATE\")"); 317 perror("ioctl(\"SOUND_PCM_READ_RATE\")");
315 return -1; 318 return -1;
316 } 319 }
317 320
318 return 1; 321 return 1;
319} 322}
320 323
321int VMemo::openWAV(const char *filename) 324int VMemo::openWAV(const char *filename)
322{ 325{
323 qDebug("Creating %s ",filename);
324 track.setName(filename); 326 track.setName(filename);
325 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) 327 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw))
326 {
327 qDebug("Could not open file");
328 return -1; 328 return -1;
329 } 329
330 wav=track.handle(); 330 wav=track.handle();
331 331
332 WaveHeader wh; 332 WaveHeader wh;
333 333
334 wh.main_chunk = RIFF; 334 wh.main_chunk = RIFF;
335 wh.length=0; 335 wh.length=0;
336 wh.chunk_type = WAVE; 336 wh.chunk_type = WAVE;
337 wh.sub_chunk = FMT; 337 wh.sub_chunk = FMT;
338 wh.sc_len = 16; 338 wh.sc_len = 16;
339 wh.format = PCM_CODE; 339 wh.format = PCM_CODE;
340 wh.modus = channels; 340 wh.modus = channels;
341 wh.sample_fq = speed; 341 wh.sample_fq = speed;
342 wh.byte_p_sec = speed * channels * resolution/8; 342 wh.byte_p_sec = speed * channels * resolution/8;
343 wh.byte_p_spl = channels * (resolution / 8); 343 wh.byte_p_spl = channels * (resolution / 8);
344 wh.bit_p_spl = resolution; 344 wh.bit_p_spl = resolution;
345 wh.data_chunk = DATA; 345 wh.data_chunk = DATA;
346 wh.data_length= 0; 346 wh.data_length= 0;
347 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" 347 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d"
348 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); 348 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl );
349 write (wav, &wh, sizeof(WaveHeader)); 349 write (wav, &wh, sizeof(WaveHeader));
350 350
351 return 1; 351 return 1;
352} 352}
353 353
354void VMemo::record(void) 354void VMemo::record(void)
355{ 355{
356 int length=0, result, value; //, i; 356 int length=0, result, value;
357 char sound[512]; //, leftBuffer[256], rightBuffer[256]; 357 char sound[512];
358
359 qWarning("VMemo::record()");
360 358
361 while(recording) 359 while(recording)
362 { 360 {
363 result = read(dsp, sound, 512); // 8192 361 result = read(dsp, sound, 512); // 8192
364 qApp->processEvents(); 362 qApp->processEvents();
365 363
366 /* attempt to write only one channel...didnt work.
367 for (i = 0; i < result; i++) {
368 leftBuffer[i] = sound[2*i];
369 rightBuffer[i] = sound[2*i+1];
370 }
371 */
372 qApp->processEvents();
373
374 /* needed to only write one channel. comment out above "write/length" code.
375 write(wav, leftBuffer, result / 2);
376 length += result/2;
377 */
378
379 write(wav, sound, result); 364 write(wav, sound, result);
380 length += result; 365 length += result;
381 366
382 qApp->processEvents(); 367 qApp->processEvents();
383 } 368 }
384 369
385 qWarning("VMemo::record() -> Done recording");
386 qWarning("VMemo::record() -> Closing dsp");
387
388 value = length+36; 370 value = length+36;
389 lseek(wav, 4, SEEK_SET); 371 lseek(wav, 4, SEEK_SET);
390 write(wav, &value, 4); 372 write(wav, &value, 4);
391 lseek(wav, 40, SEEK_SET); 373 lseek(wav, 40, SEEK_SET);
392 write(wav, &length, 4); 374 write(wav, &length, 4);
393 track.close(); 375 track.close();
394 376
395 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) 377 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)
396 perror("ioctl(\"SNDCTL_DSP_RESET\")"); 378 perror("ioctl(\"SNDCTL_DSP_RESET\")");
397 ::close(dsp); 379 ::close(dsp);
398 380
399 qWarning("VMemo::record() -> playing done recording sound");
400 QSound::play(Resource::findSound("vmemoe")); 381 QSound::play(Resource::findSound("vmemoe"));
401 qWarning("VMemo::record() -> terminating");
402 //QMessageBox::information(0, "VMemo", "Recording Done", 1);
403} 382}