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