-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 178 |
1 files changed, 91 insertions, 87 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 622b1df..1ead4dd 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -23,626 +23,630 @@ extern "C" { | |||
23 | #include <unistd.h> | 23 | #include <unistd.h> |
24 | #include <stdio.h> | 24 | #include <stdio.h> |
25 | #include <fcntl.h> | 25 | #include <fcntl.h> |
26 | #include <sys/ioctl.h> | 26 | #include <sys/ioctl.h> |
27 | #include <linux/soundcard.h> | 27 | #include <linux/soundcard.h> |
28 | 28 | ||
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 | if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) | 215 | |
216 | systemZaurus=TRUE; | 216 | // if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) |
217 | else | 217 | // systemZaurus=TRUE; |
218 | systemZaurus=FALSE; | 218 | // else |
219 | systemZaurus = FALSE; | ||
219 | 220 | ||
220 | myChannel = new QCopChannel( "QPE/VMemo", this ); | 221 | myChannel = new QCopChannel( "QPE/VMemo", this ); |
221 | connect( myChannel, SIGNAL(received(const QCString&,const QByteArray&)), | 222 | connect( myChannel, SIGNAL(received(const QCString&,const QByteArray&)), |
222 | this, SLOT(receive(const QCString&,const QByteArray&)) ); | 223 | this, SLOT(receive(const QCString&,const QByteArray&)) ); |
223 | 224 | ||
224 | if( toggleKey != -1 ) { | 225 | if( toggleKey != -1 ) { |
225 | // keyRegister(key, channel, message) | 226 | qDebug("Register key %d", toggleKey); |
226 | QCopEnvelope e("QPE/Launcher", "keyRegister(int,QCString,QCString)"); | 227 | QCopEnvelope e("QPE/Launcher", "keyRegister(int,QCString,QCString)"); |
227 | // e << 4096; // Key_Escape | 228 | // e << 4096; // Key_Escape |
228 | // e << Key_F5; //4148 | 229 | // e << Key_F5; //4148 |
229 | e << toggleKey; | 230 | e << toggleKey; |
230 | e << QString("QPE/VMemo"); | 231 | e << QString("QPE/VMemo"); |
231 | e << QString("toggleRecord()"); | 232 | e << QString("toggleRecord()"); |
232 | } | 233 | } |
233 | if(toggleKey == 1) | 234 | if(toggleKey == 1) |
234 | usingIcon=TRUE; | 235 | usingIcon = TRUE; |
235 | else | 236 | else |
236 | usingIcon=FALSE; | 237 | usingIcon = FALSE; |
237 | if( vmCfg.readNumEntry("hideIcon",0) == 1) | 238 | // if( vmCfg.readNumEntry("hideIcon",0) == 1) |
238 | hide(); | 239 | // hide(); |
239 | recording = FALSE; | 240 | recording = FALSE; |
240 | // } | 241 | // } |
241 | } | 242 | } |
242 | 243 | ||
243 | VMemo::~VMemo() { | 244 | VMemo::~VMemo() { |
244 | } | 245 | } |
245 | 246 | ||
246 | int VMemo::position() | 247 | int VMemo::position() |
247 | { | 248 | { |
248 | return 6; | 249 | return 6; |
249 | } | 250 | } |
250 | 251 | ||
251 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { | 252 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { |
252 | odebug << "receive" << oendl; | 253 | odebug << "Vmemo receive" << oendl; |
253 | QDataStream stream( data, IO_ReadOnly ); | 254 | QDataStream stream( data, IO_ReadOnly ); |
254 | 255 | ||
255 | if (msg == "toggleRecord()") { | 256 | if (msg == "toggleRecord()") { |
256 | if (recording) { | 257 | if (recording) { |
257 | fromToggle = TRUE; | 258 | fromToggle = TRUE; |
258 | stopRecording(); | 259 | stopRecording(); |
259 | } else { | 260 | } else { |
260 | fromToggle = TRUE; | 261 | fromToggle = TRUE; |
261 | startRecording(); | 262 | startRecording(); |
262 | } | 263 | } |
263 | } | 264 | } |
264 | } | 265 | } |
265 | 266 | ||
266 | void VMemo::paintEvent( QPaintEvent* ) { | 267 | void VMemo::paintEvent( QPaintEvent* ) { |
267 | QPainter p(this); | 268 | QPainter p(this); |
268 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 269 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
269 | } | 270 | } |
270 | 271 | ||
271 | void VMemo::mousePressEvent( QMouseEvent * me) { | 272 | void VMemo::mousePressEvent( QMouseEvent * me) { |
272 | /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions | 273 | /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions |
273 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ | 274 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ |
274 | 275 | ||
275 | // if (!systemZaurus && me != NULL) | 276 | // if (!systemZaurus && me != NULL) |
276 | // return; | 277 | // return; |
277 | // } | 278 | // } |
278 | 279 | ||
279 | if(!recording) | 280 | if(!recording) |
280 | startRecording(); | 281 | startRecording(); |
281 | else | 282 | else |
282 | stopRecording(); | 283 | stopRecording(); |
283 | } | 284 | } |
284 | 285 | ||
285 | void VMemo::mouseReleaseEvent( QMouseEvent * ) { | 286 | void VMemo::mouseReleaseEvent( QMouseEvent * ) { |
286 | } | 287 | } |
287 | 288 | ||
288 | bool VMemo::startRecording() { | 289 | bool VMemo::startRecording() { |
289 | Config config( "Vmemo" ); | 290 | Config config( "Vmemo" ); |
290 | config.setGroup( "System" ); | 291 | config.setGroup( "System" ); |
291 | 292 | ||
292 | useAlerts = config.readBoolEntry("Alert",1); | 293 | useAlerts = config.readBoolEntry("Alert",1); |
293 | if(useAlerts) { | 294 | if(useAlerts) { |
294 | 295 | ||
295 | msgLabel = new QLabel( 0, "alertLabel" ); | 296 | msgLabel = new QLabel( 0, "alertLabel" ); |
296 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); | 297 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); |
297 | msgLabel->show(); | 298 | msgLabel->show(); |
298 | } | 299 | } |
299 | 300 | ||
300 | odebug << "Start recording engines" << oendl; | 301 | odebug << "Start recording engines" << oendl; |
301 | recording = TRUE; | 302 | recording = TRUE; |
302 | 303 | ||
303 | if (openDSP() == -1) { | 304 | if (openDSP() == -1) { |
304 | recording = FALSE; | 305 | recording = FALSE; |
305 | return FALSE; | 306 | return FALSE; |
306 | } | 307 | } |
307 | 308 | ||
308 | config.setGroup("Defaults"); | 309 | config.setGroup("Defaults"); |
309 | 310 | ||
310 | date = TimeString::dateString( QDateTime::currentDateTime(),false,true); | 311 | date = TimeString::dateString( QDateTime::currentDateTime(),false,true); |
311 | date.replace(QRegExp("'"),""); | 312 | date.replace(QRegExp("'"),""); |
312 | date.replace(QRegExp(" "),"_"); | 313 | date.replace(QRegExp(" "),"_"); |
313 | date.replace(QRegExp(":"),"."); | 314 | date.replace(QRegExp(":"),"."); |
314 | date.replace(QRegExp(","),""); | 315 | date.replace(QRegExp(","),""); |
315 | 316 | ||
316 | QString fName; | 317 | QString fName; |
317 | config.setGroup( "System" ); | 318 | config.setGroup( "System" ); |
318 | fName = QPEApplication::documentDir() ; | 319 | fName = QPEApplication::documentDir() ; |
319 | fileName = config.readEntry("RecLocation", fName); | 320 | fileName = config.readEntry("RecLocation", fName); |
320 | 321 | ||
321 | int s; | 322 | int s; |
322 | s=fileName.find(':'); | 323 | s=fileName.find(':'); |
323 | if(s) | 324 | if(s) |
324 | fileName=fileName.right(fileName.length()-s-2); | 325 | fileName=fileName.right(fileName.length()-s-2); |
325 | odebug << "pathname will be "+fileName << oendl; | 326 | odebug << "pathname will be "+fileName << oendl; |
326 | 327 | ||
327 | if( fileName.left(1).find('/') == -1) | 328 | if( fileName.left(1).find('/') == -1) |
328 | fileName="/"+fileName; | 329 | fileName="/"+fileName; |
329 | if( fileName.right(1).find('/') == -1) | 330 | if( fileName.right(1).find('/') == -1) |
330 | fileName+="/"; | 331 | fileName+="/"; |
331 | fName = "vm_"+ date+ ".wav"; | 332 | fName = "vm_"+ date + ".wav"; |
332 | 333 | ||
333 | fileName+=fName; | 334 | fileName+=fName; |
334 | odebug << "filename is "+fileName << oendl; | 335 | odebug << "filename is " + fileName << oendl; |
335 | // open tmp file here | 336 | // open tmp file here |
336 | char *pointer; | 337 | char *pointer; |
337 | pointer=tmpnam(NULL); | 338 | pointer=tmpnam(NULL); |
338 | odebug << "Opening tmp file " << pointer << "" << oendl; | 339 | odebug << "Opening tmp file " << pointer << "" << oendl; |
339 | 340 | ||
340 | if(openWAV(pointer ) == -1) { | 341 | if(openWAV(pointer ) == -1) { |
341 | 342 | ||
342 | QString err("Could not open the temp file\n"); | 343 | QString err("Could not open the temp file\n"); |
343 | err += fileName; | 344 | err += fileName; |
344 | QMessageBox::critical(0, "vmemo", err, "Abort"); | 345 | QMessageBox::critical(0, "vmemo", err, "Abort"); |
345 | ::close(dsp); | 346 | ::close(dsp); |
346 | return FALSE; | 347 | return FALSE; |
347 | } | 348 | } |
348 | if( record() ) { | 349 | if( record() ) { |
349 | 350 | ||
350 | QString cmd; | 351 | QString cmd; |
351 | if( fileName.find(".wav",0,TRUE) == -1) | 352 | if( fileName.find(".wav",0,TRUE) == -1) |
352 | fileName += ".wav"; | 353 | fileName += ".wav"; |
353 | 354 | ||
354 | cmd.sprintf("mv %s "+fileName, pointer); | 355 | cmd.sprintf("mv %s "+fileName, pointer); |
355 | // move tmp file to regular file here | 356 | // move tmp file to regular file here |
356 | 357 | ||
357 | system(cmd.latin1()); | 358 | system(cmd.latin1()); |
358 | 359 | ||
359 | QArray<int> cats(1); | 360 | QArray<int> cats(1); |
360 | cats[0] = config.readNumEntry("Category", 0); | 361 | cats[0] = config.readNumEntry("Category", 0); |
361 | 362 | ||
362 | QString dlName("vm_"); | 363 | QString dlName("vm_"); |
363 | dlName += date; | 364 | dlName += date; |
364 | DocLnk l; | 365 | DocLnk l; |
365 | l.setFile(fileName); | 366 | l.setFile(fileName); |
366 | l.setName(dlName); | 367 | l.setName(dlName); |
367 | l.setType("audio/x-wav"); | 368 | l.setType("audio/x-wav"); |
368 | l.setCategories(cats); | 369 | l.setCategories(cats); |
369 | l.writeLink(); | 370 | l.writeLink(); |
370 | return TRUE; | 371 | return TRUE; |
371 | } else | 372 | } else |
372 | return FALSE; | 373 | return FALSE; |
373 | 374 | ||
374 | } | 375 | } |
375 | 376 | ||
376 | void VMemo::stopRecording() { | 377 | void VMemo::stopRecording() { |
377 | show(); | 378 | show(); |
378 | odebug << "Stopped recording" << oendl; | 379 | odebug << "Stopped recording" << oendl; |
379 | recording = FALSE; | 380 | recording = FALSE; |
380 | if(useAlerts) { | 381 | if(useAlerts) { |
381 | msgLabel->close(); | 382 | msgLabel->close(); |
382 | msgLabel=0; | 383 | msgLabel=0; |
383 | delete msgLabel; | 384 | delete msgLabel; |
384 | } | 385 | } |
385 | t_timer->stop(); | 386 | t_timer->stop(); |
386 | Config cfg("Vmemo"); | 387 | Config cfg("Vmemo"); |
387 | cfg.setGroup("Defaults"); | 388 | cfg.setGroup("Defaults"); |
388 | if( cfg.readNumEntry("hideIcon",0) == 1 ) | 389 | // if( cfg.readNumEntry("hideIcon",0) == 1 ) |
389 | hide(); | 390 | // hide(); |
390 | } | 391 | } |
391 | 392 | ||
392 | int VMemo::openDSP() { | 393 | int VMemo::openDSP() { |
393 | Config cfg("Vmemo"); | 394 | Config cfg("Vmemo"); |
394 | cfg.setGroup("Record"); | 395 | cfg.setGroup("Record"); |
395 | 396 | ||
396 | speed = cfg.readNumEntry("SampleRate", 22050); | 397 | speed = cfg.readNumEntry("SampleRate", 22050); |
397 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 398 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
398 | if (cfg.readNumEntry("SixteenBit", 1)==1) { | 399 | if (cfg.readNumEntry("SixteenBit", 1)==1) { |
399 | format = AFMT_S16_LE; | 400 | format = AFMT_S16_LE; |
400 | resolution = 16; | 401 | resolution = 16; |
401 | } else { | 402 | } else { |
402 | format = AFMT_U8; | 403 | format = AFMT_U8; |
403 | resolution = 8; | 404 | resolution = 8; |
404 | } | 405 | } |
405 | 406 | ||
406 | odebug << "samplerate: " << speed << ", channels " << channels << ", resolution " << resolution << "" << oendl; | 407 | odebug << "samplerate: " << speed << ", channels " << channels << ", resolution " << resolution << "" << oendl; |
407 | 408 | ||
408 | if(systemZaurus) { | 409 | if(systemZaurus) { |
409 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 | 410 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 |
410 | channels=1; //zaurus has one input channel | 411 | channels=1; //zaurus has one input channel |
411 | } else { | 412 | } else { |
412 | dsp = open("/dev/dsp", O_RDONLY); | 413 | dsp = open("/dev/dsp", O_RDONLY); |
413 | } | 414 | } |
414 | 415 | ||
415 | if(dsp == -1) { | 416 | if(dsp == -1) { |
416 | msgLabel->close(); | 417 | msgLabel->close(); |
417 | msgLabel=0; | 418 | msgLabel=0; |
418 | delete msgLabel; | 419 | delete msgLabel; |
419 | 420 | ||
420 | perror("open(\"/dev/dsp\")"); | 421 | perror("open(\"/dev/dsp\")"); |
421 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); | 422 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); |
422 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); | 423 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); |
423 | return -1; | 424 | return -1; |
424 | } | 425 | } |
425 | 426 | ||
426 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { | 427 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { |
427 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 428 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
428 | return -1; | 429 | return -1; |
429 | } | 430 | } |
430 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { | 431 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { |
431 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 432 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
432 | return -1; | 433 | return -1; |
433 | } | 434 | } |
434 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { | 435 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { |
435 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 436 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
436 | return -1; | 437 | return -1; |
437 | } | 438 | } |
438 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { | 439 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { |
439 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 440 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); |
440 | return -1; | 441 | return -1; |
441 | } | 442 | } |
442 | 443 | ||
443 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute | 444 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute |
444 | 445 | ||
445 | return 1; | 446 | return 1; |
446 | } | 447 | } |
447 | 448 | ||
448 | int VMemo::openWAV(const char *filename) { | 449 | int VMemo::openWAV(const char *filename) { |
449 | track.setName(filename); | 450 | track.setName(filename); |
450 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { | 451 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { |
451 | errorMsg=filename; | 452 | errorMsg=filename; |
452 | return -1; | 453 | return -1; |
453 | } | 454 | } |
454 | 455 | ||
455 | wav=track.handle(); | 456 | wav=track.handle(); |
456 | Config vmCfg("Vmemo"); | 457 | Config vmCfg("Vmemo"); |
457 | vmCfg.setGroup("Defaults"); | 458 | vmCfg.setGroup("Defaults"); |
458 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | 459 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); |
459 | 460 | ||
460 | WaveHeader wh; | 461 | WaveHeader wh; |
461 | 462 | ||
462 | wh.main_chunk = RIFF; | 463 | wh.main_chunk = RIFF; |
463 | wh.length=0; | 464 | wh.length=0; |
464 | wh.chunk_type = WAVE; | 465 | wh.chunk_type = WAVE; |
465 | wh.sub_chunk = FMT; | 466 | wh.sub_chunk = FMT; |
466 | wh.sc_len = 16; | 467 | wh.sc_len = 16; |
467 | if(useADPCM) | 468 | if(useADPCM) |
468 | wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; | 469 | wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; |
469 | else | 470 | else |
470 | wh.format = PCM_CODE; | 471 | wh.format = PCM_CODE; |
471 | wh.modus = channels; | 472 | wh.modus = channels; |
472 | wh.sample_fq = speed; | 473 | wh.sample_fq = speed; |
473 | wh.byte_p_sec = speed * channels * resolution/8; | 474 | wh.byte_p_sec = speed * channels * resolution/8; |
474 | wh.byte_p_spl = channels * (resolution / 8); | 475 | wh.byte_p_spl = channels * (resolution / 8); |
475 | wh.bit_p_spl = resolution; | 476 | wh.bit_p_spl = resolution; |
476 | wh.data_chunk = DATA; | 477 | wh.data_chunk = DATA; |
477 | wh.data_length= 0; | 478 | wh.data_length= 0; |
478 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" | 479 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" |
479 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); | 480 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); |
480 | write (wav, &wh, sizeof(WaveHeader)); | 481 | write (wav, &wh, sizeof(WaveHeader)); |
481 | 482 | ||
482 | return 1; | 483 | return 1; |
483 | } | 484 | } |
484 | 485 | ||
485 | bool VMemo::record() { | 486 | bool VMemo::record() { |
486 | length=0; | 487 | length = 0; |
487 | int result, value; | 488 | int result, value; |
488 | QString msg; | 489 | QString msg; |
489 | msg.sprintf("Recording format %d", format); | 490 | msg.sprintf("Recording format %d", format); |
490 | odebug << msg << oendl; | 491 | odebug << msg << oendl; |
491 | Config config("Vmemo"); | 492 | Config config("Vmemo"); |
492 | config.setGroup("Record"); | 493 | config.setGroup("Record"); |
493 | int sRate=config.readNumEntry("SizeLimit", 30); | 494 | int sRate=config.readNumEntry("SizeLimit", 30); |
494 | if(sRate > 0) | 495 | if(sRate > 0) |
495 | t_timer->start( sRate * 1000+1000, TRUE); | 496 | t_timer->start( sRate * 1000+1000, TRUE); |
496 | 497 | ||
497 | // if(systemZaurus) { | 498 | // if(systemZaurus) { |
498 | // } else { // 16 bit only capabilities | 499 | // } else { // 16 bit only capabilities |
499 | 500 | ||
500 | msg.sprintf("Recording format other"); | 501 | msg.sprintf("Recording format other"); |
501 | odebug << msg << oendl; | 502 | odebug << msg << oendl; |
502 | 503 | ||
503 | int bufsize=1024; | 504 | |
504 | int bytesWritten=0; | 505 | int bytesWritten = 0; |
505 | signed short sound[1024], monoBuffer[1024]; | 506 | |
506 | char abuf[bufsize/2]; | ||
507 | short sbuf[bufsize]; | ||
508 | Config vmCfg("Vmemo"); | 507 | Config vmCfg("Vmemo"); |
509 | vmCfg.setGroup("Defaults"); | 508 | vmCfg.setGroup("Defaults"); |
510 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | 509 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); |
511 | 510 | ||
511 | int bufsize = vmCfg.readNumEntry("BufferSize",1024); | ||
512 | signed short sound[bufsize], monoBuffer[bufsize]; | ||
513 | char abuf[bufsize / 2]; | ||
514 | short sbuf[bufsize]; | ||
515 | |||
512 | while(recording) { | 516 | while(recording) { |
513 | 517 | ||
514 | if(useADPCM) | 518 | if(useADPCM) |
515 | result = read( dsp, sbuf, bufsize); // 8192 | 519 | result = ::read(dsp, sbuf, bufsize); // 8192 |
516 | else | 520 | else |
517 | result = read(dsp, sound, 1024); // 8192 | 521 | result = ::read(dsp, sound, bufsize); // 8192 |
518 | if( result <= 0) { | 522 | if( result <= 0) { |
519 | perror("recording error "); | 523 | perror("recording error "); |
520 | // odebug << currentFileName << oendl; | 524 | // odebug << currentFileName << oendl; |
521 | QMessageBox::message(tr("Note"),tr("error recording")); | 525 | QMessageBox::message(tr("Note"),tr("error recording")); |
522 | recording=FALSE; | 526 | recording = FALSE; |
523 | break; | 527 | break; |
524 | return FALSE; | 528 | return FALSE; |
525 | } | 529 | } |
526 | 530 | ||
527 | if(useADPCM) { | 531 | if(useADPCM) { |
528 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); | 532 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); |
529 | bytesWritten = ::write(wav, abuf, result/4); | 533 | bytesWritten = ::write(wav, abuf, result/4); |
530 | 534 | ||
531 | } else { | 535 | } else { |
532 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 536 | // for (int i = 0; i < result; i++) { //since Z is mono do normally |
533 | monoBuffer[i] = sound[i]; | 537 | // monoBuffer[i] = sound[i]; |
534 | } | 538 | // } |
535 | 539 | ||
536 | length+=write(wav, monoBuffer, result); | 540 | length += write(wav, sound, result); |
537 | } | 541 | } |
538 | length +=bytesWritten; | 542 | length += bytesWritten; |
539 | 543 | ||
540 | if(length<0) { | 544 | if(length<0) { |
541 | recording=false; | 545 | recording = false; |
542 | perror("dev/dsp's is a lookin' messy"); | 546 | perror("dev/dsp's is a lookin' messy"); |
543 | QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); | 547 | QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); |
544 | break; | 548 | break; |
545 | return FALSE; | 549 | return FALSE; |
546 | } | 550 | } |
547 | // odebug << "" << length << "\r" << oendl; | 551 | // odebug << "" << length << "\r" << oendl; |
548 | // fflush(stdout); | 552 | // fflush(stdout); |
549 | qApp->processEvents(); | 553 | qApp->processEvents(); |
550 | } | 554 | } |
551 | // qDebug("file has length of %d lasting %d seconds", | 555 | // qDebug("file has length of %d lasting %d seconds", |
552 | // length, (( length / speed) / channels) / 2 ); | 556 | // length, (( length / speed) / channels) / 2 ); |
553 | // } | 557 | // } |
554 | 558 | ||
555 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// | 559 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// |
556 | 560 | ||
557 | value = length+36; | 561 | value = length + 36; |
558 | 562 | ||
559 | lseek(wav, 4, SEEK_SET); | 563 | lseek(wav, 4, SEEK_SET); |
560 | write(wav, &value, 4); | 564 | write(wav, &value, 4); |
561 | lseek(wav, 40, SEEK_SET); | 565 | lseek(wav, 40, SEEK_SET); |
562 | 566 | ||
563 | write(wav, &length, 4); | 567 | write(wav, &length, 4); |
564 | 568 | ||
565 | track.close(); | 569 | track.close(); |
566 | odebug << "Track closed" << oendl; | 570 | odebug << "Track closed" << oendl; |
567 | 571 | ||
568 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 572 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
569 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 573 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
570 | 574 | ||
571 | ::close(dsp); | 575 | ::close(dsp); |
572 | 576 | ||
573 | Config cfgO("OpieRec"); | 577 | Config cfgO("OpieRec"); |
574 | cfgO.setGroup("Sounds"); | 578 | cfgO.setGroup("Sounds"); |
575 | 579 | ||
576 | int nFiles = cfgO.readNumEntry( "NumberofFiles",0); | 580 | int nFiles = cfgO.readNumEntry( "NumberofFiles",0); |
577 | 581 | ||
578 | QString currentFileName = fileName; | 582 | QString currentFileName = fileName; |
579 | QString currentFile = "vm_"+ date; | 583 | QString currentFile = "vm_"+ date; |
580 | 584 | ||
581 | float numberOfRecordedSeconds=(float) length / (float)speed * (float)2; | 585 | float numberOfRecordedSeconds=(float) length / (float)speed * (float)2; |
582 | 586 | ||
583 | cfgO.writeEntry( "NumberofFiles", nFiles + 1); | 587 | cfgO.writeEntry( "NumberofFiles", nFiles + 1); |
584 | cfgO.writeEntry( QString::number( nFiles + 1), currentFile); | 588 | cfgO.writeEntry( QString::number( nFiles + 1), currentFile); |
585 | cfgO.writeEntry( currentFile, currentFileName); | 589 | cfgO.writeEntry( currentFile, currentFileName); |
586 | 590 | ||
587 | QString time; | 591 | QString time; |
588 | time.sprintf("%.2f", numberOfRecordedSeconds); | 592 | time.sprintf("%.2f", numberOfRecordedSeconds); |
589 | cfgO.writeEntry( currentFileName, time ); | 593 | cfgO.writeEntry( currentFileName, time ); |
590 | // odebug << "writing config numberOfRecordedSeconds "+time << oendl; | 594 | // odebug << "writing config numberOfRecordedSeconds "+time << oendl; |
591 | 595 | ||
592 | cfgO.write(); | 596 | cfgO.write(); |
593 | 597 | ||
594 | odebug << "done recording "+fileName << oendl; | 598 | odebug << "done recording "+fileName << oendl; |
595 | 599 | ||
596 | Config cfg("qpe"); | 600 | Config cfg("qpe"); |
597 | cfg.setGroup("Volume"); | 601 | cfg.setGroup("Volume"); |
598 | QString foo = cfg.readEntry("Mute","TRUE"); | 602 | QString foo = cfg.readEntry("Mute","TRUE"); |
599 | if(foo.find("TRUE",0,TRUE) != -1) | 603 | if(foo.find("TRUE",0,TRUE) != -1) |
600 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute | 604 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute |
601 | return TRUE; | 605 | return TRUE; |
602 | } | 606 | } |
603 | 607 | ||
604 | int VMemo::setToggleButton(int tog) { | 608 | int VMemo::setToggleButton(int tog) { |
605 | 609 | ||
606 | for( int i=0; i < 10;i++) { | 610 | for( int i=0; i < 10;i++) { |
607 | switch (tog) { | 611 | switch (tog) { |
608 | case 0: | 612 | case 0: |
609 | return -1; | 613 | return -1; |
610 | break; | 614 | break; |
611 | case 1: | 615 | case 1: |
612 | return 0; | 616 | return 0; |
613 | break; | 617 | break; |
614 | case 2: | 618 | case 2: |
615 | return Key_F24; //was Escape | 619 | return Key_F24; //was Escape |
616 | break; | 620 | break; |
617 | case 3: | 621 | case 3: |
618 | return Key_Space; | 622 | return Key_Space; |
619 | break; | 623 | break; |
620 | case 4: | 624 | case 4: |
621 | return Key_F12; | 625 | return Key_F12; |
622 | break; | 626 | break; |
623 | case 5: | 627 | case 5: |
624 | return Key_F9; | 628 | return Key_F9; |
625 | break; | 629 | break; |
626 | case 6: | 630 | case 6: |
627 | return Key_F10; | 631 | return Key_F10; |
628 | break; | 632 | break; |
629 | case 7: | 633 | case 7: |
630 | return Key_F11; | 634 | return Key_F11; |
631 | break; | 635 | break; |
632 | case 8: | 636 | case 8: |
633 | return Key_F13; | 637 | return Key_F13; |
634 | break; | 638 | break; |
635 | }; | 639 | }; |
636 | } | 640 | } |
637 | return -1; | 641 | return -1; |
638 | } | 642 | } |
639 | 643 | ||
640 | void VMemo::timerBreak() { | 644 | void VMemo::timerBreak() { |
641 | //stop | 645 | //stop |
642 | stopRecording(); | 646 | stopRecording(); |
643 | QMessageBox::message("Vmemo","Vmemo recording has ended"); | 647 | QMessageBox::message("Vmemo","Vmemo recording has ended"); |
644 | } | 648 | } |
645 | 649 | ||
646 | 650 | ||
647 | EXPORT_OPIE_APPLET_v1( VMemo ) | 651 | EXPORT_OPIE_APPLET_v1( VMemo ) |
648 | 652 | ||