-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 97 | ||||
-rw-r--r-- | core/applets/vmemo/vmemo.h | 1 |
2 files changed, 33 insertions, 65 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 5ce6fa9..006e0ba 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -125,129 +125,87 @@ static char * vmemo_xpm[] = { | |||
125 | " ;#{]!)", | 125 | " ;#{]!)", |
126 | " ^~/(_)", | 126 | " ^~/(_)", |
127 | " ./:@<[)", | 127 | " ./:@<[)", |
128 | " }. .|]1;;2 ", | 128 | " }. .|]1;;2 ", |
129 | " #-$;^/3&;;4@ ", | 129 | " #-$;^/3&;;4@ ", |
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 | ||
136 | VMemo::VMemo( QWidget *parent, const char *name ) | 136 | VMemo::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(sayHi()), this, SLOT(sayHi()) ); | ||
146 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), | 145 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), |
147 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 146 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
148 | 147 | ||
149 | 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 |
150 | lineo change string, this break | 149 | lineo change string, this break |
151 | */ | 150 | */ |
152 | if (uname(&name) != -1) | 151 | if (uname(&name) != -1) |
153 | { | 152 | { |
154 | QString release=name.release; | 153 | QString release=name.release; |
155 | qWarning("System release: %s\n", name.release); | 154 | qWarning("System release: %s\n", name.release); |
156 | if(release.find("embedix",0,TRUE) !=-1) | 155 | if(release.find("embedix",0,TRUE) !=-1) |
157 | systemZaurus=TRUE; | 156 | systemZaurus=TRUE; |
158 | else | 157 | else |
159 | { | 158 | { |
160 | int fr; | ||
161 | systemZaurus=FALSE; | 159 | systemZaurus=FALSE; |
162 | 160 | ||
163 | if ((fr = fork()) == -1) | 161 | // Register the REC key press. |
164 | { | 162 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); |
165 | qWarning("Fork failed"); | 163 | e << 4096; |
166 | } | 164 | e << QString("QPE/VMemo"); |
167 | else if (fr == 0) | 165 | e << QString("toggleRecord()"); |
168 | { | ||
169 | int key, max; | ||
170 | fd_set fdr; | ||
171 | char buffer[10]; | ||
172 | |||
173 | key = open("/dev/touchscreen/key", O_RDONLY); | ||
174 | if (key == -1) | ||
175 | { | ||
176 | qWarning("Could not open key"); | ||
177 | exit(1); | ||
178 | } | ||
179 | |||
180 | while(1) | ||
181 | { | ||
182 | FD_ZERO(&fdr); | ||
183 | FD_SET(key, &fdr); | ||
184 | max = key; | ||
185 | |||
186 | qWarning("while"); | ||
187 | |||
188 | read(key, buffer, 10); | ||
189 | if(*buffer == (char)129) | ||
190 | { | ||
191 | qWarning("REC = stop"); | ||
192 | QCopEnvelope( "QPE/VMemo", "toggleRecord()"); | ||
193 | QCopEnvelope( "QPE/VMemo", "sayHi()"); | ||
194 | } | ||
195 | else if(*buffer == (char)1) | ||
196 | { | ||
197 | qWarning("REC = start"); | ||
198 | QCopEnvelope( "QPE/VMemo", "toggleRecord()"); | ||
199 | QCopEnvelope( "QPE/VMemo", "sayHi()"); | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | else if(fr) | ||
204 | qWarning("parent: Fork = good"); | ||
205 | } | 166 | } |
206 | } | 167 | } |
207 | qWarning("VMemo done init"); | 168 | qWarning("VMemo done init"); |
208 | } | 169 | } |
209 | 170 | ||
210 | VMemo::~VMemo() | 171 | VMemo::~VMemo() |
211 | { | 172 | { |
212 | } | 173 | } |
213 | 174 | ||
214 | void VMemo::sayHi() | ||
215 | { | ||
216 | qWarning("Hi"); | ||
217 | } | ||
218 | |||
219 | void VMemo::receive( const QCString &msg, const QByteArray &data ) | 175 | void VMemo::receive( const QCString &msg, const QByteArray &data ) |
220 | { | 176 | { |
221 | QDataStream stream( data, IO_ReadOnly ); | 177 | QDataStream stream( data, IO_ReadOnly ); |
222 | qWarning(msg); | 178 | qWarning("VMemo::receive: %s", (const char *)msg); |
223 | if ( msg == "toggleRecord()" ) { | 179 | if (msg == "toggleRecord()") |
224 | qWarning("Hello"); | 180 | { |
225 | } | 181 | if (recording) |
182 | mouseReleaseEvent(NULL); | ||
183 | else | ||
184 | mousePressEvent(NULL); | ||
185 | } | ||
226 | } | 186 | } |
227 | 187 | ||
228 | void VMemo::paintEvent( QPaintEvent* ) | 188 | void VMemo::paintEvent( QPaintEvent* ) |
229 | { | 189 | { |
230 | QPainter p(this); | 190 | QPainter p(this); |
231 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 191 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
232 | } | 192 | } |
233 | 193 | ||
234 | void VMemo::mousePressEvent( QMouseEvent * ) | 194 | void VMemo::mousePressEvent( QMouseEvent * ) |
235 | { | 195 | { |
236 | QCopEnvelope( "QPE/VMemo", "sayHi()"); | ||
237 | |||
238 | // just to be safe | 196 | // just to be safe |
239 | if (recording) | 197 | if (recording) |
240 | { | 198 | { |
241 | recording = FALSE; | 199 | recording = FALSE; |
242 | return; | 200 | return; |
243 | } | 201 | } |
244 | 202 | ||
245 | qWarning("VMemo::mousePress()"); | 203 | qWarning("VMemo::mousePress()"); |
246 | QSound::play(Resource::findSound("vmemob")); | 204 | QSound::play(Resource::findSound("vmemob")); |
247 | 205 | ||
248 | recording = TRUE; | 206 | recording = TRUE; |
249 | qWarning("VMemo::mousePress() -> Starting to record"); | 207 | qWarning("VMemo::mousePress() -> Starting to record"); |
250 | if (openDSP() == -1) | 208 | if (openDSP() == -1) |
251 | { | 209 | { |
252 | // ### Display an error box | 210 | // ### Display an error box |
253 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort"); | 211 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort"); |
@@ -382,53 +340,64 @@ int VMemo::openWAV(const char *filename) | |||
382 | wh.modus = channels; | 340 | wh.modus = channels; |
383 | wh.sample_fq = speed; | 341 | wh.sample_fq = speed; |
384 | wh.byte_p_sec = speed * channels * resolution/8; | 342 | wh.byte_p_sec = speed * channels * resolution/8; |
385 | wh.byte_p_spl = channels * (resolution / 8); | 343 | wh.byte_p_spl = channels * (resolution / 8); |
386 | wh.bit_p_spl = resolution; | 344 | wh.bit_p_spl = resolution; |
387 | wh.data_chunk = DATA; | 345 | wh.data_chunk = DATA; |
388 | wh.data_length= 0; | 346 | wh.data_length= 0; |
389 | // 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" |
390 | // , 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 ); |
391 | write (wav, &wh, sizeof(WaveHeader)); | 349 | write (wav, &wh, sizeof(WaveHeader)); |
392 | 350 | ||
393 | return 1; | 351 | return 1; |
394 | } | 352 | } |
395 | 353 | ||
396 | void VMemo::record(void) | 354 | void VMemo::record(void) |
397 | { | 355 | { |
398 | int length=0, result, value; | 356 | int length=0, result, value; //, i; |
399 | char sound[8192]; | 357 | char sound[512]; //, leftBuffer[256], rightBuffer[256]; |
400 | 358 | ||
401 | qWarning("VMemo::record()"); | 359 | qWarning("VMemo::record()"); |
402 | 360 | ||
403 | while(recording) | 361 | while(recording) |
404 | { | 362 | { |
405 | result = read(dsp, sound, 512); // 8192 | 363 | result = read(dsp, sound, 512); // 8192 |
406 | qApp->processEvents(); | 364 | qApp->processEvents(); |
407 | write(wav, sound, result); | 365 | |
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 | */ | ||
408 | qApp->processEvents(); | 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); | ||
409 | length += result; | 380 | length += result; |
381 | |||
410 | qApp->processEvents(); | 382 | qApp->processEvents(); |
411 | // printf("%d\r",length); | ||
412 | // fflush(stdout); | ||
413 | } | 383 | } |
414 | 384 | ||
415 | qWarning("VMemo::record() -> Done recording"); | 385 | qWarning("VMemo::record() -> Done recording"); |
416 | qWarning("VMemo::record() -> Closing dsp"); | 386 | qWarning("VMemo::record() -> Closing dsp"); |
417 | 387 | ||
418 | value = length+36; | 388 | value = length+36; |
419 | lseek(wav, 4, SEEK_SET); | 389 | lseek(wav, 4, SEEK_SET); |
420 | write(wav, &value, 4); | 390 | write(wav, &value, 4); |
421 | lseek(wav, 40, SEEK_SET); | 391 | lseek(wav, 40, SEEK_SET); |
422 | write(wav, &length, 4); | 392 | write(wav, &length, 4); |
423 | // qDebug("File length %d, samplecount %d", value, length); | ||
424 | track.close(); | 393 | track.close(); |
425 | 394 | ||
426 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 395 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
427 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 396 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
428 | ::close(dsp); | 397 | ::close(dsp); |
429 | 398 | ||
430 | qWarning("VMemo::record() -> playing done recording sound"); | 399 | qWarning("VMemo::record() -> playing done recording sound"); |
431 | QSound::play(Resource::findSound("vmemoe")); | 400 | QSound::play(Resource::findSound("vmemoe")); |
432 | qWarning("VMemo::record() -> terminating"); | 401 | qWarning("VMemo::record() -> terminating"); |
433 | QMessageBox::information(0, "VMemo", "Recording Done", 1); | 402 | QMessageBox::information(0, "VMemo", "Recording Done", 1); |
434 | } | 403 | } |
diff --git a/core/applets/vmemo/vmemo.h b/core/applets/vmemo/vmemo.h index 824309e..d96cd94 100644 --- a/core/applets/vmemo/vmemo.h +++ b/core/applets/vmemo/vmemo.h | |||
@@ -23,33 +23,32 @@ | |||
23 | #include <qfile.h> | 23 | #include <qfile.h> |
24 | #include <qpe/qcopenvelope_qws.h> | 24 | #include <qpe/qcopenvelope_qws.h> |
25 | 25 | ||
26 | class VMemo : public QWidget | 26 | class VMemo : public QWidget |
27 | { | 27 | { |
28 | Q_OBJECT | 28 | Q_OBJECT |
29 | public: | 29 | public: |
30 | VMemo( QWidget *parent, const char *name = NULL); | 30 | VMemo( QWidget *parent, const char *name = NULL); |
31 | ~VMemo(); | 31 | ~VMemo(); |
32 | QFile track; | 32 | QFile track; |
33 | 33 | ||
34 | public slots: | 34 | public slots: |
35 | void record(); | 35 | void record(); |
36 | void mousePressEvent( QMouseEvent * ); | 36 | void mousePressEvent( QMouseEvent * ); |
37 | void mouseReleaseEvent( QMouseEvent * ); | 37 | void mouseReleaseEvent( QMouseEvent * ); |
38 | void receive( const QCString &msg, const QByteArray &data ); | 38 | void receive( const QCString &msg, const QByteArray &data ); |
39 | void sayHi(); | ||
40 | 39 | ||
41 | private: | 40 | private: |
42 | void paintEvent( QPaintEvent* ); | 41 | void paintEvent( QPaintEvent* ); |
43 | 42 | ||
44 | int openDSP(); | 43 | int openDSP(); |
45 | int openWAV(const char *filename); | 44 | int openWAV(const char *filename); |
46 | 45 | ||
47 | QPixmap vmemoPixmap; | 46 | QPixmap vmemoPixmap; |
48 | QCopChannel *myChannel; | 47 | QCopChannel *myChannel; |
49 | bool systemZaurus; | 48 | bool systemZaurus; |
50 | int dsp, wav, rate, speed, channels, format, resolution; | 49 | int dsp, wav, rate, speed, channels, format, resolution; |
51 | bool recording; | 50 | bool recording; |
52 | }; | 51 | }; |
53 | 52 | ||
54 | #endif // __VMEMO_H__ | 53 | #endif // __VMEMO_H__ |
55 | 54 | ||