-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 249 |
1 files changed, 154 insertions, 95 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 9c0025d..8875cdf 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -141,25 +141,84 @@ VMemo::VMemo( QWidget *parent, const char *name ) | |||
141 | 141 | ||
142 | recording = FALSE; | 142 | recording = FALSE; |
143 | 143 | ||
144 | myChannel = new QCopChannel( "QPE/VMemo", this ); | ||
145 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), | ||
146 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | ||
147 | |||
144 | 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 |
145 | lineo change string, this break | 149 | lineo change string, this break |
146 | */ | 150 | */ |
147 | if (uname(&name) != -1) | 151 | if (uname(&name) != -1) |
148 | { | 152 | { |
149 | QString release=name.release; | 153 | QString release=name.release; |
150 | qWarning("System release: %s\n", name.release); | 154 | qWarning("System release: %s\n", name.release); |
151 | if(release.find("embedix",0,TRUE) !=-1) | 155 | if(release.find("embedix",0,TRUE) !=-1) |
152 | systemZaurus=TRUE; | 156 | systemZaurus=TRUE; |
153 | else | 157 | else |
154 | systemZaurus=FALSE; | 158 | { |
155 | } | 159 | int fr; |
156 | 160 | systemZaurus=FALSE; | |
161 | |||
162 | if ((fr = fork()) == -1) | ||
163 | { | ||
164 | qWarning("Fork failed"); | ||
165 | } | ||
166 | else if (fr == 0) | ||
167 | { | ||
168 | int key, max; | ||
169 | fd_set fdr; | ||
170 | char buffer[10]; | ||
171 | |||
172 | key = open("/dev/touchscreen/key", O_RDONLY); | ||
173 | if (key == -1) | ||
174 | { | ||
175 | qWarning("Could not open key"); | ||
176 | exit(1); | ||
177 | } | ||
178 | |||
179 | while(1) | ||
180 | { | ||
181 | FD_ZERO(&fdr); | ||
182 | FD_SET(key, &fdr); | ||
183 | max = key; | ||
184 | |||
185 | qWarning("while"); | ||
186 | |||
187 | read(key, buffer, 10); | ||
188 | if(*buffer == (char)129) | ||
189 | { | ||
190 | qWarning("REC = stop"); | ||
191 | QCopEnvelope( "QPE/VMemo", "toggleRecord()"); | ||
192 | activate_signal("toggleRecordNow()"); | ||
193 | } | ||
194 | else if(*buffer == (char)1) | ||
195 | { | ||
196 | qWarning("REC = start"); | ||
197 | QCopEnvelope( "QPE/VMemo", "toggleRecord()"); | ||
198 | activate_signal("toggleRecordNow()"); | ||
199 | } | ||
200 | } | ||
201 | } | ||
202 | else if(fr) | ||
203 | qWarning("parent: Fork = good"); | ||
204 | } | ||
205 | } | ||
206 | qWarning("VMemo done init"); | ||
157 | } | 207 | } |
158 | 208 | ||
159 | VMemo::~VMemo() | 209 | VMemo::~VMemo() |
160 | { | 210 | { |
161 | } | 211 | } |
162 | 212 | ||
213 | void VMemo::receive( const QCString &msg, const QByteArray &data ) | ||
214 | { | ||
215 | QDataStream stream( data, IO_ReadOnly ); | ||
216 | qWarning(msg); | ||
217 | if ( msg == "toggleRecord()" ) { | ||
218 | qWarning("Hello"); | ||
219 | } | ||
220 | } | ||
221 | |||
163 | void VMemo::paintEvent( QPaintEvent* ) | 222 | void VMemo::paintEvent( QPaintEvent* ) |
164 | { | 223 | { |
165 | QPainter p(this); | 224 | QPainter p(this); |
@@ -170,55 +229,55 @@ void VMemo::mousePressEvent( QMouseEvent * ) | |||
170 | { | 229 | { |
171 | // just to be safe | 230 | // just to be safe |
172 | if (recording) | 231 | if (recording) |
173 | { | 232 | { |
174 | recording = FALSE; | 233 | recording = FALSE; |
175 | return; | 234 | return; |
176 | } | 235 | } |
177 | 236 | ||
178 | qWarning("VMemo::mousePress()"); | 237 | qWarning("VMemo::mousePress()"); |
179 | QSound::play(Resource::findSound("vmemob")); | 238 | QSound::play(Resource::findSound("vmemob")); |
180 | 239 | ||
181 | recording = TRUE; | 240 | recording = TRUE; |
182 | qWarning("VMemo::mousePress() -> Starting to record"); | 241 | qWarning("VMemo::mousePress() -> Starting to record"); |
183 | if (openDSP() == -1) | 242 | if (openDSP() == -1) |
184 | { | 243 | { |
185 | // ### Display an error box | 244 | // ### Display an error box |
186 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort"); | 245 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort"); |
187 | recording = FALSE; | 246 | recording = FALSE; |
188 | return; | 247 | return; |
189 | } | 248 | } |
190 | 249 | ||
191 | Config vmCfg("VMemo"); | 250 | Config vmCfg("VMemo"); |
192 | vmCfg.setGroup("Defaults"); | 251 | vmCfg.setGroup("Defaults"); |
193 | 252 | ||
194 | QDateTime dt = QDateTime::currentDateTime(); | 253 | QDateTime dt = QDateTime::currentDateTime(); |
195 | QString fileName; | 254 | QString fileName; |
196 | if(systemZaurus) | 255 | if(systemZaurus) |
197 | fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs | 256 | fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs |
198 | else | 257 | else |
199 | fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); | 258 | fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); |
200 | 259 | ||
201 | fileName += "vm_"; | 260 | fileName += "vm_"; |
202 | fileName += dt.toString(); | 261 | fileName += dt.toString(); |
203 | fileName += ".wav"; | 262 | fileName += ".wav"; |
204 | 263 | ||
205 | // No spaces in the filename | 264 | // No spaces in the filename |
206 | fileName.replace(QRegExp("'"),""); | 265 | fileName.replace(QRegExp("'"),""); |
207 | fileName.replace(QRegExp(" "),"_"); | 266 | fileName.replace(QRegExp(" "),"_"); |
208 | fileName.replace(QRegExp(":"),"."); | 267 | fileName.replace(QRegExp(":"),"."); |
209 | fileName.replace(QRegExp(","),""); | 268 | fileName.replace(QRegExp(","),""); |
210 | 269 | ||
211 | if(openWAV(fileName.latin1()) == -1) | 270 | if(openWAV(fileName.latin1()) == -1) |
212 | { | 271 | { |
213 | // ### Display an error box | 272 | // ### Display an error box |
214 | qWarning("VMemo::mousePress() -> WAV error"); | 273 | qWarning("VMemo::mousePress() -> WAV error"); |
215 | close(dsp); | 274 | close(dsp); |
216 | return; | 275 | return; |
217 | } | 276 | } |
218 | 277 | ||
219 | QArray<int> cats(1); | 278 | QArray<int> cats(1); |
220 | cats[0] = vmCfg.readNumEntry("Category", 0); | 279 | cats[0] = vmCfg.readNumEntry("Category", 0); |
221 | 280 | ||
222 | QString dlName("vm_"); | 281 | QString dlName("vm_"); |
223 | dlName += dt.toString(); | 282 | dlName += dt.toString(); |
224 | DocLnk l; | 283 | DocLnk l; |
@@ -227,7 +286,7 @@ void VMemo::mousePressEvent( QMouseEvent * ) | |||
227 | l.setType("audio/x-wav"); | 286 | l.setType("audio/x-wav"); |
228 | l.setCategories(cats); | 287 | l.setCategories(cats); |
229 | l.writeLink(); | 288 | l.writeLink(); |
230 | 289 | ||
231 | record(); | 290 | record(); |
232 | } | 291 | } |
233 | 292 | ||
@@ -241,54 +300,54 @@ int VMemo::openDSP() | |||
241 | { | 300 | { |
242 | Config cfg("Sound"); | 301 | Config cfg("Sound"); |
243 | cfg.setGroup("Record"); | 302 | cfg.setGroup("Record"); |
244 | 303 | ||
245 | speed = cfg.readNumEntry("SampleRate", 22050); | 304 | speed = cfg.readNumEntry("SampleRate", 22050); |
246 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 305 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
247 | if (cfg.readNumEntry("SixteenBit", 1)==1) | 306 | if (cfg.readNumEntry("SixteenBit", 1)==1) |
248 | { | 307 | { |
249 | format = AFMT_S16_LE; | 308 | format = AFMT_S16_LE; |
250 | resolution = 16; | 309 | resolution = 16; |
251 | } | 310 | } |
252 | else | 311 | else |
253 | { | 312 | { |
254 | format = AFMT_U8; | 313 | format = AFMT_U8; |
255 | resolution = 8; | 314 | resolution = 8; |
256 | } | 315 | } |
257 | 316 | ||
258 | if(systemZaurus) | 317 | if(systemZaurus) |
259 | { | 318 | { |
260 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 | 319 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 |
261 | channels=1; //zaurus has one input channel | 320 | channels=1; //zaurus has one input channel |
262 | } | 321 | } |
263 | else | 322 | else |
264 | dsp = open("/dev/dsp", O_RDWR); | 323 | dsp = open("/dev/dsp", O_RDWR); |
265 | 324 | ||
266 | if(dsp == -1) | 325 | if(dsp == -1) |
267 | { | 326 | { |
268 | perror("open(\"/dev/dsp\")"); | 327 | perror("open(\"/dev/dsp\")"); |
269 | return -1; | 328 | return -1; |
270 | } | 329 | } |
271 | 330 | ||
272 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) | 331 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) |
273 | { | 332 | { |
274 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 333 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
275 | return -1; | 334 | return -1; |
276 | } | 335 | } |
277 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) | 336 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) |
278 | { | 337 | { |
279 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 338 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
280 | return -1; | 339 | return -1; |
281 | } | 340 | } |
282 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) | 341 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) |
283 | { | 342 | { |
284 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 343 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
285 | return -1; | 344 | return -1; |
286 | } | 345 | } |
287 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) | 346 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) |
288 | { | 347 | { |
289 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 348 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); |
290 | return -1; | 349 | return -1; |
291 | } | 350 | } |
292 | 351 | ||
293 | return 1; | 352 | return 1; |
294 | } | 353 | } |
@@ -298,14 +357,14 @@ int VMemo::openWAV(const char *filename) | |||
298 | qDebug("Creating %s ",filename); | 357 | qDebug("Creating %s ",filename); |
299 | track.setName(filename); | 358 | track.setName(filename); |
300 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) | 359 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) |
301 | { | 360 | { |
302 | qDebug("Could not open file"); | 361 | qDebug("Could not open file"); |
303 | return -1; | 362 | return -1; |
304 | } | 363 | } |
305 | wav=track.handle(); | 364 | wav=track.handle(); |
306 | 365 | ||
307 | WaveHeader wh; | 366 | WaveHeader wh; |
308 | 367 | ||
309 | wh.main_chunk = RIFF; | 368 | wh.main_chunk = RIFF; |
310 | wh.length=0; | 369 | wh.length=0; |
311 | wh.chunk_type = WAVE; | 370 | wh.chunk_type = WAVE; |
@@ -319,10 +378,10 @@ int VMemo::openWAV(const char *filename) | |||
319 | wh.bit_p_spl = resolution; | 378 | wh.bit_p_spl = resolution; |
320 | wh.data_chunk = DATA; | 379 | wh.data_chunk = DATA; |
321 | wh.data_length= 0; | 380 | wh.data_length= 0; |
322 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" | 381 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" |
323 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); | 382 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); |
324 | write (wav, &wh, sizeof(WaveHeader)); | 383 | write (wav, &wh, sizeof(WaveHeader)); |
325 | 384 | ||
326 | return 1; | 385 | return 1; |
327 | } | 386 | } |
328 | 387 | ||
@@ -330,36 +389,36 @@ void VMemo::record(void) | |||
330 | { | 389 | { |
331 | int length=0, result, value; | 390 | int length=0, result, value; |
332 | char sound[8192]; | 391 | char sound[8192]; |
333 | 392 | ||
334 | qWarning("VMemo::record()"); | 393 | qWarning("VMemo::record()"); |
335 | 394 | ||
336 | while(recording) | 395 | while(recording) |
337 | { | 396 | { |
338 | result = read(dsp, sound, 512); // 8192 | 397 | result = read(dsp, sound, 512); // 8192 |
339 | qApp->processEvents(); | 398 | qApp->processEvents(); |
340 | write(wav, sound, result); | 399 | write(wav, sound, result); |
341 | qApp->processEvents(); | 400 | qApp->processEvents(); |
342 | length += result; | 401 | length += result; |
343 | qApp->processEvents(); | 402 | qApp->processEvents(); |
344 | // printf("%d\r",length); | 403 | // printf("%d\r",length); |
345 | // fflush(stdout); | 404 | // fflush(stdout); |
346 | } | 405 | } |
347 | 406 | ||
348 | qWarning("VMemo::record() -> Done recording"); | 407 | qWarning("VMemo::record() -> Done recording"); |
349 | qWarning("VMemo::record() -> Closing dsp"); | 408 | qWarning("VMemo::record() -> Closing dsp"); |
350 | 409 | ||
351 | value = length+36; | 410 | value = length+36; |
352 | lseek(wav, 4, SEEK_SET); | 411 | lseek(wav, 4, SEEK_SET); |
353 | write(wav, &value, 4); | 412 | write(wav, &value, 4); |
354 | lseek(wav, 40, SEEK_SET); | 413 | lseek(wav, 40, SEEK_SET); |
355 | write(wav, &length, 4); | 414 | write(wav, &length, 4); |
356 | // qDebug("File length %d, samplecount %d", value, length); | 415 | // qDebug("File length %d, samplecount %d", value, length); |
357 | track.close(); | 416 | track.close(); |
358 | 417 | ||
359 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 418 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
360 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 419 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
361 | ::close(dsp); | 420 | ::close(dsp); |
362 | 421 | ||
363 | qWarning("VMemo::record() -> playing done recording sound"); | 422 | qWarning("VMemo::record() -> playing done recording sound"); |
364 | QSound::play(Resource::findSound("vmemoe")); | 423 | QSound::play(Resource::findSound("vmemoe")); |
365 | qWarning("VMemo::record() -> terminating"); | 424 | qWarning("VMemo::record() -> terminating"); |