author | llornkcor <llornkcor> | 2002-04-20 14:19:26 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-04-20 14:19:26 (UTC) |
commit | 90c114cefd8d8675fa3992b5049d01a14eb7712c (patch) (unidiff) | |
tree | 779366706fbabc90e5efcd88e54c6e7c6f7e6bfd | |
parent | 0850b6d2e7908e66c8a14eb3e7fafcc63e0b800c (diff) | |
download | opie-90c114cefd8d8675fa3992b5049d01a14eb7712c.zip opie-90c114cefd8d8675fa3992b5049d01a14eb7712c.tar.gz opie-90c114cefd8d8675fa3992b5049d01a14eb7712c.tar.bz2 |
more informative error messages
-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 116 | ||||
-rw-r--r-- | core/applets/vmemo/vmemo.h | 1 |
2 files changed, 70 insertions, 47 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 4d4d598..4c55dc7 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -1,498 +1,520 @@ | |||
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 | 12 | ||
13 | /* | 13 | /* |
14 | * $Id$ | 14 | * $Id$ |
15 | */ | 15 | */ |
16 | // Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com> | 16 | // Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com> |
17 | #include <sys/utsname.h> | 17 | #include <sys/utsname.h> |
18 | #include <sys/time.h> | 18 | #include <sys/time.h> |
19 | #include <sys/types.h> | 19 | #include <sys/types.h> |
20 | #include <unistd.h> | 20 | #include <unistd.h> |
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <sys/stat.h> | 22 | #include <sys/stat.h> |
23 | #include <fcntl.h> | 23 | #include <fcntl.h> |
24 | #include <sys/ioctl.h> | 24 | #include <sys/ioctl.h> |
25 | #include <linux/soundcard.h> | 25 | #include <linux/soundcard.h> |
26 | #include <string.h> | 26 | #include <string.h> |
27 | #include <stdlib.h> | 27 | #include <stdlib.h> |
28 | #include <errno.h> | ||
29 | #include <string.h> | ||
28 | 30 | ||
29 | typedef struct _waveheader { | 31 | typedef struct _waveheader { |
30 | u_long main_chunk; /* 'RIFF' */ | 32 | u_long main_chunk; /* 'RIFF' */ |
31 | u_long length; /* filelen */ | 33 | u_long length; /* filelen */ |
32 | u_long chunk_type; /* 'WAVE' */ | 34 | u_long chunk_type; /* 'WAVE' */ |
33 | u_long sub_chunk; /* 'fmt ' */ | 35 | u_long sub_chunk; /* 'fmt ' */ |
34 | u_long sc_len; /* length of sub_chunk, =16 | 36 | u_long sc_len; /* length of sub_chunk, =16 |
35 | (chunckSize) format len */ | 37 | (chunckSize) format len */ |
36 | u_short format; /* should be 1 for PCM-code (formatTag) */ | 38 | u_short format; /* should be 1 for PCM-code (formatTag) */ |
37 | 39 | ||
38 | u_short modus; /* 1 Mono, 2 Stereo (channels) */ | 40 | u_short modus; /* 1 Mono, 2 Stereo (channels) */ |
39 | u_long sample_fq; /* samples per second (samplesPerSecond) */ | 41 | u_long sample_fq; /* samples per second (samplesPerSecond) */ |
40 | u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ | 42 | u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ |
41 | u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ | 43 | u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ |
42 | u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ | 44 | u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ |
43 | 45 | ||
44 | u_long data_chunk; /* 'data' */ | 46 | u_long data_chunk; /* 'data' */ |
45 | 47 | ||
46 | u_long data_length;/* samplecount */ | 48 | u_long data_length;/* samplecount */ |
47 | } WaveHeader; | 49 | } WaveHeader; |
48 | 50 | ||
49 | #define RIFF 0x46464952 | 51 | #define RIFF 0x46464952 |
50 | #define WAVE 0x45564157 | 52 | #define WAVE 0x45564157 |
51 | #define FMT 0x20746D66 | 53 | #define FMT 0x20746D66 |
52 | #define DATA 0x61746164 | 54 | #define DATA 0x61746164 |
53 | #define PCM_CODE 1 | 55 | #define PCM_CODE 1 |
54 | #define WAVE_MONO 1 | 56 | #define WAVE_MONO 1 |
55 | #define WAVE_STEREO 2 | 57 | #define WAVE_STEREO 2 |
56 | 58 | ||
57 | #include "vmemo.h" | 59 | #include "vmemo.h" |
58 | 60 | ||
59 | #include <qpe/qpeapplication.h> | 61 | #include <qpe/qpeapplication.h> |
60 | #include <qpe/resource.h> | 62 | #include <qpe/resource.h> |
61 | #include <qpe/config.h> | 63 | #include <qpe/config.h> |
62 | 64 | ||
63 | #include <qpainter.h> | 65 | #include <qpainter.h> |
64 | #include <qdatetime.h> | 66 | #include <qdatetime.h> |
65 | #include <qsound.h> | 67 | #include <qsound.h> |
66 | #include <qfile.h> | 68 | #include <qfile.h> |
67 | #include <qmessagebox.h> | 69 | #include <qmessagebox.h> |
68 | 70 | ||
69 | int seq = 0; | 71 | int seq = 0; |
70 | 72 | ||
71 | /* XPM */ | 73 | /* XPM */ |
72 | static char * vmemo_xpm[] = { | 74 | static char * vmemo_xpm[] = { |
73 | "16 16 102 2", | 75 | "16 16 102 2", |
74 | " c None", | 76 | " c None", |
75 | ". c #60636A", | 77 | ". c #60636A", |
76 | "+ c #6E6E72", | 78 | "+ c #6E6E72", |
77 | "@ c #68696E", | 79 | "@ c #68696E", |
78 | "# c #4D525C", | 80 | "# c #4D525C", |
79 | "$ c #6B6C70", | 81 | "$ c #6B6C70", |
80 | "% c #E3E3E8", | 82 | "% c #E3E3E8", |
81 | "& c #EEEEF2", | 83 | "& c #EEEEF2", |
82 | "* c #EAEAEF", | 84 | "* c #EAEAEF", |
83 | "= c #CACAD0", | 85 | "= c #CACAD0", |
84 | "- c #474A51", | 86 | "- c #474A51", |
85 | "; c #171819", | 87 | "; c #171819", |
86 | "> c #9B9B9F", | 88 | "> c #9B9B9F", |
87 | ", c #EBEBF0", | 89 | ", c #EBEBF0", |
88 | "' c #F4F4F7", | 90 | "' c #F4F4F7", |
89 | ") c #F1F1F5", | 91 | ") c #F1F1F5", |
90 | "! c #DEDEE4", | 92 | "! c #DEDEE4", |
91 | "~ c #57575C", | 93 | "~ c #57575C", |
92 | "{ c #010101", | 94 | "{ c #010101", |
93 | "] c #A2A2A6", | 95 | "] c #A2A2A6", |
94 | "^ c #747477", | 96 | "^ c #747477", |
95 | "/ c #B5B5B8", | 97 | "/ c #B5B5B8", |
96 | "( c #AEAEB2", | 98 | "( c #AEAEB2", |
97 | "_ c #69696D", | 99 | "_ c #69696D", |
98 | ": c #525256", | 100 | ": c #525256", |
99 | "< c #181C24", | 101 | "< c #181C24", |
100 | "[ c #97979B", | 102 | "[ c #97979B", |
101 | "} c #A7A7AC", | 103 | "} c #A7A7AC", |
102 | "| c #B0B0B4", | 104 | "| c #B0B0B4", |
103 | "1 c #C8C8D1", | 105 | "1 c #C8C8D1", |
104 | "2 c #75757B", | 106 | "2 c #75757B", |
105 | "3 c #46464A", | 107 | "3 c #46464A", |
106 | "4 c #494A4F", | 108 | "4 c #494A4F", |
107 | "5 c #323234", | 109 | "5 c #323234", |
108 | "6 c #909095", | 110 | "6 c #909095", |
109 | "7 c #39393B", | 111 | "7 c #39393B", |
110 | "8 c #757578", | 112 | "8 c #757578", |
111 | "9 c #87878E", | 113 | "9 c #87878E", |
112 | "0 c #222224", | 114 | "0 c #222224", |
113 | "a c #414144", | 115 | "a c #414144", |
114 | "b c #6A6A6E", | 116 | "b c #6A6A6E", |
115 | "c c #020C16", | 117 | "c c #020C16", |
116 | "d c #6B6B6F", | 118 | "d c #6B6B6F", |
117 | "e c #68686D", | 119 | "e c #68686D", |
118 | "f c #5B5B60", | 120 | "f c #5B5B60", |
119 | "g c #8A8A8F", | 121 | "g c #8A8A8F", |
120 | "h c #6B6B6E", | 122 | "h c #6B6B6E", |
121 | "i c #ADADB2", | 123 | "i c #ADADB2", |
122 | "j c #828289", | 124 | "j c #828289", |
123 | "k c #3E3E41", | 125 | "k c #3E3E41", |
124 | "l c #CFCFD7", | 126 | "l c #CFCFD7", |
125 | "m c #4C4C50", | 127 | "m c #4C4C50", |
126 | "n c #000000", | 128 | "n c #000000", |
127 | "o c #66666A", | 129 | "o c #66666A", |
128 | "p c #505054", | 130 | "p c #505054", |
129 | "q c #838388", | 131 | "q c #838388", |
130 | "r c #A1A1A7", | 132 | "r c #A1A1A7", |
131 | "s c #A9A9AE", | 133 | "s c #A9A9AE", |
132 | "t c #A8A8B0", | 134 | "t c #A8A8B0", |
133 | "u c #5E5E63", | 135 | "u c #5E5E63", |
134 | "v c #3A3A3E", | 136 | "v c #3A3A3E", |
135 | "w c #BDBDC6", | 137 | "w c #BDBDC6", |
136 | "x c #59595E", | 138 | "x c #59595E", |
137 | "y c #76767C", | 139 | "y c #76767C", |
138 | "z c #373738", | 140 | "z c #373738", |
139 | "A c #717174", | 141 | "A c #717174", |
140 | "B c #727278", | 142 | "B c #727278", |
141 | "C c #1C1C1E", | 143 | "C c #1C1C1E", |
142 | "D c #3C3C3F", | 144 | "D c #3C3C3F", |
143 | "E c #ADADB6", | 145 | "E c #ADADB6", |
144 | "F c #54555A", | 146 | "F c #54555A", |
145 | "G c #8B8C94", | 147 | "G c #8B8C94", |
146 | "H c #5A5A5F", | 148 | "H c #5A5A5F", |
147 | "I c #BBBBC3", | 149 | "I c #BBBBC3", |
148 | "J c #C4C4CB", | 150 | "J c #C4C4CB", |
149 | "K c #909098", | 151 | "K c #909098", |
150 | "L c #737379", | 152 | "L c #737379", |
151 | "M c #343437", | 153 | "M c #343437", |
152 | "N c #8F8F98", | 154 | "N c #8F8F98", |
153 | "O c #000407", | 155 | "O c #000407", |
154 | "P c #2D3137", | 156 | "P c #2D3137", |
155 | "Q c #B0B1BC", | 157 | "Q c #B0B1BC", |
156 | "R c #3B3C40", | 158 | "R c #3B3C40", |
157 | "S c #6E6E74", | 159 | "S c #6E6E74", |
158 | "T c #95959C", | 160 | "T c #95959C", |
159 | "U c #74747A", | 161 | "U c #74747A", |
160 | "V c #1D1D1E", | 162 | "V c #1D1D1E", |
161 | "W c #91929A", | 163 | "W c #91929A", |
162 | "X c #42444A", | 164 | "X c #42444A", |
163 | "Y c #22282E", | 165 | "Y c #22282E", |
164 | "Z c #B0B2BC", | 166 | "Z c #B0B2BC", |
165 | "` c #898A90", | 167 | "` c #898A90", |
166 | " . c #65656A", | 168 | " . c #65656A", |
167 | ".. c #999AA2", | 169 | ".. c #999AA2", |
168 | "+. c #52535A", | 170 | "+. c #52535A", |
169 | "@. c #151B21", | 171 | "@. c #151B21", |
170 | "#. c #515257", | 172 | "#. c #515257", |
171 | "$. c #B5B5BE", | 173 | "$. c #B5B5BE", |
172 | "%. c #616167", | 174 | "%. c #616167", |
173 | "&. c #1A1D22", | 175 | "&. c #1A1D22", |
174 | "*. c #000713", | 176 | "*. c #000713", |
175 | "=. c #1F1F21", | 177 | "=. c #1F1F21", |
176 | " ", | 178 | " ", |
177 | " . + @ # ", | 179 | " . + @ # ", |
178 | " $ % & * = - ", | 180 | " $ % & * = - ", |
179 | " ; > , ' ) ! ~ ", | 181 | " ; > , ' ) ! ~ ", |
180 | " { ] ^ / ( _ : ", | 182 | " { ] ^ / ( _ : ", |
181 | " < [ } | 1 2 3 ", | 183 | " < [ } | 1 2 3 ", |
182 | " 4 5 6 7 8 9 0 a b c ", | 184 | " 4 5 6 7 8 9 0 a b c ", |
183 | " d e f g h i j 3 k l m n ", | 185 | " d e f g h i j 3 k l m n ", |
184 | " o p q r s t u v w n ", | 186 | " o p q r s t u v w n ", |
185 | " o x y z A B C D E n ", | 187 | " o x y z A B C D E n ", |
186 | " F G H I J K L M N O ", | 188 | " F G H I J K L M N O ", |
187 | " P Q R S T U V W X ", | 189 | " P Q R S T U V W X ", |
188 | " Y Z ` b ...+. ", | 190 | " Y Z ` b ...+. ", |
189 | " @.#.$.%.&. ", | 191 | " @.#.$.%.&. ", |
190 | " *.B =. ", | 192 | " *.B =. ", |
191 | " n n n n n n n n n "}; | 193 | " n n n n n n n n n "}; |
192 | 194 | ||
193 | 195 | ||
194 | VMemo::VMemo( QWidget *parent, const char *_name ) | 196 | VMemo::VMemo( QWidget *parent, const char *_name ) |
195 | : QWidget( parent, _name ) | 197 | : QWidget( parent, _name ) |
196 | { | 198 | { |
197 | setFixedHeight( 18 ); | 199 | setFixedHeight( 18 ); |
198 | setFixedWidth( 14 ); | 200 | setFixedWidth( 14 ); |
199 | 201 | ||
200 | recording = FALSE; | 202 | recording = FALSE; |
201 | 203 | ||
202 | struct utsname name; /* check for embedix kernel running on the zaurus*/ | 204 | struct utsname name; /* check for embedix kernel running on the zaurus*/ |
203 | if (uname(&name) != -1) { | 205 | if (uname(&name) != -1) { |
204 | QString release=name.release; | 206 | QString release=name.release; |
205 | if(release.find("embedix",0,TRUE) !=-1) | 207 | if(release.find("embedix",0,TRUE) !=-1) |
206 | systemZaurus=TRUE; | 208 | systemZaurus=TRUE; |
207 | else { | 209 | else { |
208 | systemZaurus=FALSE; | 210 | systemZaurus=FALSE; |
209 | myChannel = new QCopChannel( "QPE/VMemo", this ); | 211 | myChannel = new QCopChannel( "QPE/VMemo", this ); |
210 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), | 212 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), |
211 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 213 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
212 | 214 | ||
213 | // // Register the REC key press, for ipaq only | 215 | // // Register the REC key press, for ipaq only |
214 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); | 216 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); |
215 | e << 4096; | 217 | e << 4096; |
216 | e << QString("QPE/VMemo"); | 218 | e << QString("QPE/VMemo"); |
217 | e << QString("toggleRecord()"); | 219 | e << QString("toggleRecord()"); |
218 | } | 220 | } |
219 | } | 221 | } |
220 | } | 222 | } |
221 | 223 | ||
222 | VMemo::~VMemo() | 224 | VMemo::~VMemo() |
223 | { | 225 | { |
224 | } | 226 | } |
225 | 227 | ||
226 | void VMemo::receive( const QCString &msg, const QByteArray &data ) | 228 | void VMemo::receive( const QCString &msg, const QByteArray &data ) |
227 | { | 229 | { |
228 | QDataStream stream( data, IO_ReadOnly ); | 230 | QDataStream stream( data, IO_ReadOnly ); |
229 | if (msg == "toggleRecord()") { | 231 | if (msg == "toggleRecord()") { |
230 | if (recording) | 232 | if (recording) |
231 | mouseReleaseEvent(NULL); | 233 | mouseReleaseEvent(NULL); |
232 | else | 234 | else |
233 | mousePressEvent(NULL); | 235 | mousePressEvent(NULL); |
234 | } | 236 | } |
235 | } | 237 | } |
236 | 238 | ||
237 | void VMemo::paintEvent( QPaintEvent* ) | 239 | void VMemo::paintEvent( QPaintEvent* ) |
238 | { | 240 | { |
239 | QPainter p(this); | 241 | QPainter p(this); |
240 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 242 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
241 | } | 243 | } |
242 | 244 | ||
243 | void VMemo::mousePressEvent( QMouseEvent *me ) | 245 | void VMemo::mousePressEvent( QMouseEvent *me ) |
244 | { | 246 | { |
245 | // just to be safe | 247 | // just to be safe |
246 | if (recording) { | 248 | if (recording) { |
247 | recording = FALSE; | 249 | recording = FALSE; |
248 | return; | 250 | return; |
249 | } | 251 | } |
250 | 252 | ||
251 | /* | 253 | /* |
252 | No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions | 254 | No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions |
253 | mousePressEvent and mouseReleaseEvent with a NULL parameter. | 255 | mousePressEvent and mouseReleaseEvent with a NULL parameter. |
254 | */ | 256 | */ |
255 | if (!systemZaurus && me != NULL) | 257 | if (!systemZaurus && me != NULL) |
256 | return; | 258 | return; |
257 | 259 | ||
258 | // Config config( "Sound" ); | 260 | Config config( "Sound" ); |
259 | // config.setGroup( "System" ); | 261 | config.setGroup( "System" ); |
260 | // useAlerts = config.readBoolEntry("Alert"); | 262 | useAlerts = config.readBoolEntry("Alert"); |
261 | 263 | ||
262 | // if(useAlerts) { | 264 | // if(useAlerts) |
263 | // if( QMessageBox::warning(this,"VMemo","Really Record?","Yes","No",0,0,1) ==1) | 265 | // QMessageBox::message("VMemo","Really Record?");//) ==1) |
264 | // return; | 266 | // return; |
265 | // } else { | 267 | // } else { |
266 | QSound::play(Resource::findSound("vmemob")); | 268 | QSound::play(Resource::findSound("vmemob")); |
267 | // } | 269 | // } |
268 | qDebug("Start recording"); | 270 | qDebug("Start recording"); |
269 | recording = TRUE; | 271 | recording = TRUE; |
270 | if (openDSP() == -1) { | 272 | if (openDSP() == -1) { |
271 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort"); | 273 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.\n"+errorMsg, "Abort"); |
272 | recording = FALSE; | 274 | recording = FALSE; |
273 | return; | 275 | return; |
274 | } | 276 | } |
275 | 277 | ||
276 | Config vmCfg("VMemo"); | 278 | Config vmCfg("VMemo"); |
277 | vmCfg.setGroup("Defaults"); | 279 | vmCfg.setGroup("Defaults"); |
278 | 280 | ||
279 | QDateTime dt = QDateTime::currentDateTime(); | 281 | QDateTime dt = QDateTime::currentDateTime(); |
280 | QString fileName; | ||
281 | 282 | ||
282 | if(systemZaurus) | 283 | QString fName; |
283 | fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs | 284 | Config cfg( "Sound" ); |
284 | else | 285 | cfg.setGroup( "System" ); |
285 | fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); | 286 | fileName = cfg.readEntry("RecLocation",QPEApplication::documentDir() ); |
286 | 287 | ||
287 | fileName += "vm_"; | 288 | int s; |
288 | fileName += dt.toString(); | 289 | s=fileName.find(':'); |
289 | fileName += ".wav"; | 290 | if(s) |
291 | fileName=fileName.right(fileName.length()-s-2)+"/"; | ||
292 | |||
293 | // if( !fileName.right(1).find('/') == -1) | ||
294 | // fileName+="/audio/"; | ||
295 | // else | ||
296 | // fileName+="audio/"; | ||
297 | |||
298 | // if(systemZaurus) | ||
299 | // fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs | ||
300 | // else | ||
301 | // fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); | ||
290 | 302 | ||
303 | fName = "vm_"+ dt.toString()+ ".wav"; | ||
304 | fileName+=fName; | ||
305 | qDebug("filename is "+fileName); | ||
291 | // No spaces in the filename | 306 | // No spaces in the filename |
292 | fileName.replace(QRegExp("'"),""); | 307 | fileName.replace(QRegExp("'"),""); |
293 | fileName.replace(QRegExp(" "),"_"); | 308 | fileName.replace(QRegExp(" "),"_"); |
294 | fileName.replace(QRegExp(":"),"."); | 309 | fileName.replace(QRegExp(":"),"."); |
295 | fileName.replace(QRegExp(","),""); | 310 | fileName.replace(QRegExp(","),""); |
296 | 311 | ||
297 | if(openWAV(fileName.latin1()) == -1) { | 312 | if(openWAV(fileName.latin1()) == -1) { |
298 | QString err("Could not open the output file: "); | 313 | QString err("Could not open the output file\n"); |
299 | err += fileName; | 314 | err += fileName; |
300 | |||
301 | QMessageBox::critical(0, "VMemo", err, "Abort"); | 315 | QMessageBox::critical(0, "VMemo", err, "Abort"); |
302 | close(dsp); | 316 | close(dsp); |
303 | return; | 317 | return; |
304 | } | 318 | } |
305 | 319 | ||
306 | QArray<int> cats(1); | 320 | QArray<int> cats(1); |
307 | cats[0] = vmCfg.readNumEntry("Category", 0); | 321 | cats[0] = vmCfg.readNumEntry("Category", 0); |
308 | 322 | ||
309 | QString dlName("vm_"); | 323 | QString dlName("vm_"); |
310 | dlName += dt.toString(); | 324 | dlName += dt.toString(); |
311 | DocLnk l; | 325 | DocLnk l; |
312 | l.setFile(fileName); | 326 | l.setFile(fileName); |
313 | l.setName(dlName); | 327 | l.setName(dlName); |
314 | l.setType("audio/x-wav"); | 328 | l.setType("audio/x-wav"); |
315 | l.setCategories(cats); | 329 | l.setCategories(cats); |
316 | l.writeLink(); | 330 | l.writeLink(); |
317 | 331 | ||
318 | record(); | 332 | record(); |
319 | } | 333 | } |
320 | 334 | ||
321 | void VMemo::mouseReleaseEvent( QMouseEvent * ) | 335 | void VMemo::mouseReleaseEvent( QMouseEvent * ) |
322 | { | 336 | { |
323 | recording = FALSE; | 337 | recording = FALSE; |
324 | } | 338 | } |
325 | 339 | ||
326 | int VMemo::openDSP() | 340 | int VMemo::openDSP() |
327 | { | 341 | { |
328 | Config cfg("Sound"); | 342 | Config cfg("Sound"); |
329 | cfg.setGroup("Record"); | 343 | cfg.setGroup("Record"); |
330 | 344 | ||
331 | speed = cfg.readNumEntry("SampleRate", 22050); | 345 | speed = cfg.readNumEntry("SampleRate", 22050); |
332 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 346 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
333 | if (cfg.readNumEntry("SixteenBit", 1)==1) { | 347 | if (cfg.readNumEntry("SixteenBit", 1)==1) { |
334 | format = AFMT_S16_LE; | 348 | format = AFMT_S16_LE; |
335 | resolution = 16; | 349 | resolution = 16; |
336 | } else { | 350 | } else { |
337 | format = AFMT_S8; | 351 | format = AFMT_U8; |
338 | resolution = 8; | 352 | resolution = 8; |
339 | } | 353 | } |
340 | 354 | ||
355 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); | ||
341 | 356 | ||
342 | if(systemZaurus) { | 357 | if(systemZaurus) { |
343 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 | 358 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 |
344 | channels=1; //zaurus has one input channel | 359 | channels=1; //zaurus has one input channel |
345 | } else { | 360 | } else { |
346 | dsp = open("/dev/dsp", O_RDWR); | 361 | dsp = open("/dev/dsp", O_RDWR); |
347 | } | 362 | } |
348 | 363 | ||
349 | if(dsp == -1) { | 364 | if(dsp == -1) { |
350 | perror("open(\"/dev/dsp\")"); | 365 | perror("open(\"/dev/dsp\")"); |
366 | |||
367 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); | ||
351 | return -1; | 368 | return -1; |
352 | } | 369 | } |
353 | 370 | ||
354 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { | 371 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { |
355 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 372 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
373 | errorMsg="ioctl(\"SNDCTL_DSP_SETFMT\")\n%d\n"+(QString)strerror(errno),format; | ||
356 | return -1; | 374 | return -1; |
357 | } | 375 | } |
358 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { | 376 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { |
359 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 377 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
378 | errorMsg="ioctl(\"SNDCTL_DSP_CHANNELS\")\n%d\n"+(QString)strerror(errno),channels; | ||
360 | return -1; | 379 | return -1; |
361 | } | 380 | } |
362 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { | 381 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { |
363 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 382 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
383 | errorMsg="ioctl(\"SNDCTL_DSP_SPEED\")\n%d\n"+(QString)strerror(errno),speed; | ||
364 | return -1; | 384 | return -1; |
365 | } | 385 | } |
366 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { | 386 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { |
367 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 387 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); |
388 | errorMsg="ioctl(\"SOUND_PCM_READ_RATE\")\n%d\n"+(QString)strerror(errno),rate; | ||
368 | return -1; | 389 | return -1; |
369 | } | 390 | } |
370 | 391 | ||
371 | return 1; | 392 | return 1; |
372 | } | 393 | } |
373 | 394 | ||
374 | int VMemo::openWAV(const char *filename) | 395 | int VMemo::openWAV(const char *filename) |
375 | { | 396 | { |
376 | track.setName(filename); | 397 | track.setName(filename); |
377 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) | 398 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { |
399 | errorMsg=filename; | ||
378 | return -1; | 400 | return -1; |
401 | } | ||
379 | 402 | ||
380 | wav=track.handle(); | 403 | wav=track.handle(); |
381 | 404 | ||
382 | WaveHeader wh; | 405 | WaveHeader wh; |
383 | 406 | ||
384 | wh.main_chunk = RIFF; | 407 | wh.main_chunk = RIFF; |
385 | wh.length=0; | 408 | wh.length=0; |
386 | wh.chunk_type = WAVE; | 409 | wh.chunk_type = WAVE; |
387 | wh.sub_chunk = FMT; | 410 | wh.sub_chunk = FMT; |
388 | wh.sc_len = 16; | 411 | wh.sc_len = 16; |
389 | wh.format = PCM_CODE; | 412 | wh.format = PCM_CODE; |
390 | wh.modus = channels; | 413 | wh.modus = channels; |
391 | wh.sample_fq = speed; | 414 | wh.sample_fq = speed; |
392 | wh.byte_p_sec = speed * channels * resolution/8; | 415 | wh.byte_p_sec = speed * channels * resolution/8; |
393 | wh.byte_p_spl = channels * (resolution / 8); | 416 | wh.byte_p_spl = channels * (resolution / 8); |
394 | wh.bit_p_spl = resolution; | 417 | wh.bit_p_spl = resolution; |
395 | wh.data_chunk = DATA; | 418 | wh.data_chunk = DATA; |
396 | wh.data_length= 0; | 419 | wh.data_length= 0; |
397 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" | 420 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" |
398 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); | 421 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); |
399 | write (wav, &wh, sizeof(WaveHeader)); | 422 | write (wav, &wh, sizeof(WaveHeader)); |
400 | 423 | ||
401 | return 1; | 424 | return 1; |
402 | } | 425 | } |
403 | 426 | ||
404 | void VMemo::record(void) | 427 | void VMemo::record(void) |
405 | { | 428 | { |
406 | int length=0, result, value; | 429 | int length=0, result, value; |
407 | qDebug("Recording"); | 430 | qDebug("Recording"); |
408 | 431 | ||
409 | if(systemZaurus) { | 432 | if(systemZaurus) { |
410 | signed short sound[512], monoBuffer[512]; | 433 | signed short sound[512], monoBuffer[512]; |
411 | if(format==AFMT_S16_LE) { | 434 | if(format==AFMT_S16_LE) { |
412 | while(recording) { | 435 | while(recording) { |
413 | result = read(dsp, sound, 512); // 8192 | 436 | result = read(dsp, sound, 512); // 8192 |
414 | qApp->processEvents(); | 437 | qApp->processEvents(); |
415 | int j=0; | 438 | int j=0; |
416 | if(systemZaurus) { | 439 | if(systemZaurus) { |
417 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 440 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
418 | monoBuffer[i] = sound[i]; | 441 | monoBuffer[i] = sound[i]; |
419 | } | 442 | } |
420 | qApp->processEvents(); | 443 | qApp->processEvents(); |
421 | length+=write(wav, monoBuffer, result); | 444 | length+=write(wav, monoBuffer, result); |
422 | } else { //ipaq /stereo inputs | 445 | } else { //ipaq /stereo inputs |
423 | for (int i = 0; i < result; i+=2) { | 446 | for (int i = 0; i < result; i+=2) { |
424 | monoBuffer[j] = (sound[i]+sound[i+1])/2; | 447 | monoBuffer[j] = (sound[i]+sound[i+1])/2; |
425 | j++; | 448 | j++; |
426 | } | 449 | } |
427 | qApp->processEvents(); | 450 | qApp->processEvents(); |
428 | length+=write(wav, monoBuffer, result/2); | 451 | length+=write(wav, monoBuffer, result/2); |
429 | } | 452 | } |
430 | printf("%d\r",length); | 453 | printf("%d\r",length); |
431 | fflush(stdout); | 454 | fflush(stdout); |
432 | } | 455 | } |
433 | } else { //AFMT_S8 | 456 | } else { //AFMT_U8 |
434 | // 8bit unsigned | 457 | // 8bit unsigned |
435 | unsigned short sound[512], monoBuffer[512]; | 458 | unsigned short sound[512], monoBuffer[512]; |
436 | while(recording) { | 459 | while(recording) { |
437 | result = read(dsp, sound, 512); // 8192 | 460 | result = read(dsp, sound, 512); // 8192 |
438 | qApp->processEvents(); | 461 | qApp->processEvents(); |
439 | int j=0; | 462 | int j=0; |
440 | if(systemZaurus) { | 463 | if(systemZaurus) { |
441 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 464 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
442 | monoBuffer[i] = sound[i]; | 465 | monoBuffer[i] = sound[i]; |
443 | } | 466 | } |
444 | qApp->processEvents(); | 467 | qApp->processEvents(); |
445 | length+=write(wav, monoBuffer, result); | 468 | length+=write(wav, monoBuffer, result); |
446 | } else { //ipaq /stereo inputs | 469 | } else { //ipaq /stereo inputs |
447 | for (int i = 0; i < result; i+=2) { | 470 | for (int i = 0; i < result; i+=2) { |
448 | monoBuffer[j] = (sound[i]+sound[i+1])/2; | 471 | monoBuffer[j] = (sound[i]+sound[i+1])/2; |
449 | j++; | 472 | j++; |
450 | } | 473 | } |
451 | qApp->processEvents(); | 474 | qApp->processEvents(); |
452 | length+=write(wav, monoBuffer, result/2); | 475 | length+=write(wav, monoBuffer, result/2); |
453 | } | 476 | } |
454 | length += result; | 477 | length += result; |
455 | printf("%d\r",length); | 478 | printf("%d\r",length); |
456 | fflush(stdout); | 479 | fflush(stdout); |
457 | 480 | ||
458 | qApp->processEvents(); | 481 | qApp->processEvents(); |
459 | } | 482 | } |
460 | 483 | ||
461 | qApp->processEvents(); | 484 | qApp->processEvents(); |
462 | } | 485 | } |
463 | 486 | ||
464 | } else { | 487 | } else { |
465 | 488 | ||
466 | signed short sound[512], monoBuffer[512]; | 489 | signed short sound[512], monoBuffer[512]; |
467 | 490 | ||
468 | while(recording) { | 491 | while(recording) { |
469 | result = read(dsp, sound, 512); // 8192 | 492 | result = read(dsp, sound, 512); // 8192 |
470 | qApp->processEvents(); | 493 | qApp->processEvents(); |
471 | 494 | ||
472 | write(wav, sound, result); | 495 | write(wav, sound, result); |
473 | length += result; | 496 | length += result; |
474 | 497 | ||
475 | qApp->processEvents(); | 498 | qApp->processEvents(); |
476 | } | 499 | } |
477 | printf("%d\r",length); | 500 | printf("%d\r",length); |
478 | fflush(stdout); | 501 | fflush(stdout); |
479 | // qDebug("file has length of %d lasting %d seconds", | 502 | // qDebug("file has length of %d lasting %d seconds", |
480 | // length, (( length / speed) / channels) / 2 ); | 503 | // length, (( length / speed) / channels) / 2 ); |
481 | // medialplayer states wrong length in secs | 504 | // medialplayer states wrong length in secs |
482 | } | 505 | } |
483 | 506 | ||
484 | value = length+36; | 507 | value = length+36; |
485 | lseek(wav, 4, SEEK_SET); | 508 | lseek(wav, 4, SEEK_SET); |
486 | write(wav, &value, 4); | 509 | write(wav, &value, 4); |
487 | lseek(wav, 40, SEEK_SET); | 510 | lseek(wav, 40, SEEK_SET); |
488 | write(wav, &length, 4); | 511 | write(wav, &length, 4); |
489 | track.close(); | 512 | track.close(); |
490 | 513 | ||
491 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 514 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
492 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 515 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
493 | ::close(dsp); | 516 | ::close(dsp); |
494 | // if(useAlerts) | 517 | if(useAlerts) |
495 | // QMessageBox::message("Vmemo"," Done recording"); | 518 | QMessageBox::message("Vmemo"," Done recording\n"+ fileName); |
496 | // else | 519 | QSound::play(Resource::findSound("vmemoe")); |
497 | QSound::play(Resource::findSound("vmemoe")); | ||
498 | } | 520 | } |
diff --git a/core/applets/vmemo/vmemo.h b/core/applets/vmemo/vmemo.h index f30476f..3972877 100644 --- a/core/applets/vmemo/vmemo.h +++ b/core/applets/vmemo/vmemo.h | |||
@@ -1,55 +1,56 @@ | |||
1 | /**************************************************************************************94x78** | 1 | /**************************************************************************************94x78** |
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 | 12 | ||
13 | /* | 13 | /* |
14 | * $Id$ | 14 | * $Id$ |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #ifndef __VMEMO_H__ | 17 | #ifndef __VMEMO_H__ |
18 | #define __VMEMO_H__ | 18 | #define __VMEMO_H__ |
19 | 19 | ||
20 | #include <qwidget.h> | 20 | #include <qwidget.h> |
21 | #include <qpixmap.h> | 21 | #include <qpixmap.h> |
22 | #include <qpe/applnk.h> | 22 | #include <qpe/applnk.h> |
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 | QString fileName, errorMsg; | ||
33 | 34 | ||
34 | public slots: | 35 | public slots: |
35 | void record(); | 36 | void record(); |
36 | void mousePressEvent( QMouseEvent * ); | 37 | void mousePressEvent( QMouseEvent * ); |
37 | void mouseReleaseEvent( QMouseEvent * ); | 38 | void mouseReleaseEvent( QMouseEvent * ); |
38 | void receive( const QCString &msg, const QByteArray &data ); | 39 | void receive( const QCString &msg, const QByteArray &data ); |
39 | 40 | ||
40 | private: | 41 | private: |
41 | bool useAlerts; | 42 | bool useAlerts; |
42 | void paintEvent( QPaintEvent* ); | 43 | void paintEvent( QPaintEvent* ); |
43 | 44 | ||
44 | int openDSP(); | 45 | int openDSP(); |
45 | int openWAV(const char *filename); | 46 | int openWAV(const char *filename); |
46 | 47 | ||
47 | QPixmap vmemoPixmap; | 48 | QPixmap vmemoPixmap; |
48 | QCopChannel *myChannel; | 49 | QCopChannel *myChannel; |
49 | bool systemZaurus; | 50 | bool systemZaurus; |
50 | int dsp, wav, rate, speed, channels, format, resolution; | 51 | int dsp, wav, rate, speed, channels, format, resolution; |
51 | bool recording; | 52 | bool recording; |
52 | }; | 53 | }; |
53 | 54 | ||
54 | #endif // __VMEMO_H__ | 55 | #endif // __VMEMO_H__ |
55 | 56 | ||