author | llornkcor <llornkcor> | 2002-06-23 13:46:45 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-06-23 13:46:45 (UTC) |
commit | 6563867791664113808d1b287510ca52b5f840e0 (patch) (unidiff) | |
tree | 643d1a90c0df95095b721b2f4c50af6627eec1a1 | |
parent | f9c5bf03ae5a89ef5cda69e37cc2732f4e4f2808 (diff) | |
download | opie-6563867791664113808d1b287510ca52b5f840e0.zip opie-6563867791664113808d1b287510ca52b5f840e0.tar.gz opie-6563867791664113808d1b287510ca52b5f840e0.tar.bz2 |
automute and unmute
-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 106 |
1 files changed, 59 insertions, 47 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 10a947e..b29ee62 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -1,617 +1,629 @@ | |||
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 | // copyright 2002 Jeremy Cowgar <jc@cowgar.com> | 12 | // copyright 2002 Jeremy Cowgar <jc@cowgar.com> |
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 | 26 | ||
27 | #include <string.h> | 27 | #include <string.h> |
28 | #include <stdlib.h> | 28 | #include <stdlib.h> |
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 | #include "vmemo.h" | 59 | #include "vmemo.h" |
60 | 60 | ||
61 | #include <qpe/qpeapplication.h> | 61 | #include <qpe/qpeapplication.h> |
62 | #include <qpe/resource.h> | 62 | #include <qpe/resource.h> |
63 | #include <qpe/config.h> | 63 | #include <qpe/config.h> |
64 | 64 | ||
65 | #include <qpainter.h> | 65 | #include <qpainter.h> |
66 | #include <qdatetime.h> | 66 | #include <qdatetime.h> |
67 | #include <qregexp.h> | 67 | #include <qregexp.h> |
68 | #include <qsound.h> | 68 | #include <qsound.h> |
69 | #include <qfile.h> | 69 | #include <qfile.h> |
70 | #include <qmessagebox.h> | 70 | #include <qmessagebox.h> |
71 | 71 | ||
72 | int seq = 0; | 72 | int seq = 0; |
73 | 73 | ||
74 | /* XPM */ | 74 | /* XPM */ |
75 | static char * vmemo_xpm[] = { | 75 | static char * vmemo_xpm[] = { |
76 | "16 16 102 2", | 76 | "16 16 102 2", |
77 | " c None", | 77 | " c None", |
78 | ". c #60636A", | 78 | ". c #60636A", |
79 | "+ c #6E6E72", | 79 | "+ c #6E6E72", |
80 | "@ c #68696E", | 80 | "@ c #68696E", |
81 | "# c #4D525C", | 81 | "# c #4D525C", |
82 | "$ c #6B6C70", | 82 | "$ c #6B6C70", |
83 | "% c #E3E3E8", | 83 | "% c #E3E3E8", |
84 | "& c #EEEEF2", | 84 | "& c #EEEEF2", |
85 | "* c #EAEAEF", | 85 | "* c #EAEAEF", |
86 | "= c #CACAD0", | 86 | "= c #CACAD0", |
87 | "- c #474A51", | 87 | "- c #474A51", |
88 | "; c #171819", | 88 | "; c #171819", |
89 | "> c #9B9B9F", | 89 | "> c #9B9B9F", |
90 | ", c #EBEBF0", | 90 | ", c #EBEBF0", |
91 | "' c #F4F4F7", | 91 | "' c #F4F4F7", |
92 | ") c #F1F1F5", | 92 | ") c #F1F1F5", |
93 | "! c #DEDEE4", | 93 | "! c #DEDEE4", |
94 | "~ c #57575C", | 94 | "~ c #57575C", |
95 | "{ c #010101", | 95 | "{ c #010101", |
96 | "] c #A2A2A6", | 96 | "] c #A2A2A6", |
97 | "^ c #747477", | 97 | "^ c #747477", |
98 | "/ c #B5B5B8", | 98 | "/ c #B5B5B8", |
99 | "( c #AEAEB2", | 99 | "( c #AEAEB2", |
100 | "_ c #69696D", | 100 | "_ c #69696D", |
101 | ": c #525256", | 101 | ": c #525256", |
102 | "< c #181C24", | 102 | "< c #181C24", |
103 | "[ c #97979B", | 103 | "[ c #97979B", |
104 | "} c #A7A7AC", | 104 | "} c #A7A7AC", |
105 | "| c #B0B0B4", | 105 | "| c #B0B0B4", |
106 | "1 c #C8C8D1", | 106 | "1 c #C8C8D1", |
107 | "2 c #75757B", | 107 | "2 c #75757B", |
108 | "3 c #46464A", | 108 | "3 c #46464A", |
109 | "4 c #494A4F", | 109 | "4 c #494A4F", |
110 | "5 c #323234", | 110 | "5 c #323234", |
111 | "6 c #909095", | 111 | "6 c #909095", |
112 | "7 c #39393B", | 112 | "7 c #39393B", |
113 | "8 c #757578", | 113 | "8 c #757578", |
114 | "9 c #87878E", | 114 | "9 c #87878E", |
115 | "0 c #222224", | 115 | "0 c #222224", |
116 | "a c #414144", | 116 | "a c #414144", |
117 | "b c #6A6A6E", | 117 | "b c #6A6A6E", |
118 | "c c #020C16", | 118 | "c c #020C16", |
119 | "d c #6B6B6F", | 119 | "d c #6B6B6F", |
120 | "e c #68686D", | 120 | "e c #68686D", |
121 | "f c #5B5B60", | 121 | "f c #5B5B60", |
122 | "g c #8A8A8F", | 122 | "g c #8A8A8F", |
123 | "h c #6B6B6E", | 123 | "h c #6B6B6E", |
124 | "i c #ADADB2", | 124 | "i c #ADADB2", |
125 | "j c #828289", | 125 | "j c #828289", |
126 | "k c #3E3E41", | 126 | "k c #3E3E41", |
127 | "l c #CFCFD7", | 127 | "l c #CFCFD7", |
128 | "m c #4C4C50", | 128 | "m c #4C4C50", |
129 | "n c #000000", | 129 | "n c #000000", |
130 | "o c #66666A", | 130 | "o c #66666A", |
131 | "p c #505054", | 131 | "p c #505054", |
132 | "q c #838388", | 132 | "q c #838388", |
133 | "r c #A1A1A7", | 133 | "r c #A1A1A7", |
134 | "s c #A9A9AE", | 134 | "s c #A9A9AE", |
135 | "t c #A8A8B0", | 135 | "t c #A8A8B0", |
136 | "u c #5E5E63", | 136 | "u c #5E5E63", |
137 | "v c #3A3A3E", | 137 | "v c #3A3A3E", |
138 | "w c #BDBDC6", | 138 | "w c #BDBDC6", |
139 | "x c #59595E", | 139 | "x c #59595E", |
140 | "y c #76767C", | 140 | "y c #76767C", |
141 | "z c #373738", | 141 | "z c #373738", |
142 | "A c #717174", | 142 | "A c #717174", |
143 | "B c #727278", | 143 | "B c #727278", |
144 | "C c #1C1C1E", | 144 | "C c #1C1C1E", |
145 | "D c #3C3C3F", | 145 | "D c #3C3C3F", |
146 | "E c #ADADB6", | 146 | "E c #ADADB6", |
147 | "F c #54555A", | 147 | "F c #54555A", |
148 | "G c #8B8C94", | 148 | "G c #8B8C94", |
149 | "H c #5A5A5F", | 149 | "H c #5A5A5F", |
150 | "I c #BBBBC3", | 150 | "I c #BBBBC3", |
151 | "J c #C4C4CB", | 151 | "J c #C4C4CB", |
152 | "K c #909098", | 152 | "K c #909098", |
153 | "L c #737379", | 153 | "L c #737379", |
154 | "M c #343437", | 154 | "M c #343437", |
155 | "N c #8F8F98", | 155 | "N c #8F8F98", |
156 | "O c #000407", | 156 | "O c #000407", |
157 | "P c #2D3137", | 157 | "P c #2D3137", |
158 | "Q c #B0B1BC", | 158 | "Q c #B0B1BC", |
159 | "R c #3B3C40", | 159 | "R c #3B3C40", |
160 | "S c #6E6E74", | 160 | "S c #6E6E74", |
161 | "T c #95959C", | 161 | "T c #95959C", |
162 | "U c #74747A", | 162 | "U c #74747A", |
163 | "V c #1D1D1E", | 163 | "V c #1D1D1E", |
164 | "W c #91929A", | 164 | "W c #91929A", |
165 | "X c #42444A", | 165 | "X c #42444A", |
166 | "Y c #22282E", | 166 | "Y c #22282E", |
167 | "Z c #B0B2BC", | 167 | "Z c #B0B2BC", |
168 | "` c #898A90", | 168 | "` c #898A90", |
169 | " . c #65656A", | 169 | " . c #65656A", |
170 | ".. c #999AA2", | 170 | ".. c #999AA2", |
171 | "+. c #52535A", | 171 | "+. c #52535A", |
172 | "@. c #151B21", | 172 | "@. c #151B21", |
173 | "#. c #515257", | 173 | "#. c #515257", |
174 | "$. c #B5B5BE", | 174 | "$. c #B5B5BE", |
175 | "%. c #616167", | 175 | "%. c #616167", |
176 | "&. c #1A1D22", | 176 | "&. c #1A1D22", |
177 | "*. c #000713", | 177 | "*. c #000713", |
178 | "=. c #1F1F21", | 178 | "=. c #1F1F21", |
179 | " ", | 179 | " ", |
180 | " . + @ # ", | 180 | " . + @ # ", |
181 | " $ % & * = - ", | 181 | " $ % & * = - ", |
182 | " ; > , ' ) ! ~ ", | 182 | " ; > , ' ) ! ~ ", |
183 | " { ] ^ / ( _ : ", | 183 | " { ] ^ / ( _ : ", |
184 | " < [ } | 1 2 3 ", | 184 | " < [ } | 1 2 3 ", |
185 | " 4 5 6 7 8 9 0 a b c ", | 185 | " 4 5 6 7 8 9 0 a b c ", |
186 | " d e f g h i j 3 k l m n ", | 186 | " d e f g h i j 3 k l m n ", |
187 | " o p q r s t u v w n ", | 187 | " o p q r s t u v w n ", |
188 | " o x y z A B C D E n ", | 188 | " o x y z A B C D E n ", |
189 | " F G H I J K L M N O ", | 189 | " F G H I J K L M N O ", |
190 | " P Q R S T U V W X ", | 190 | " P Q R S T U V W X ", |
191 | " Y Z ` b ...+. ", | 191 | " Y Z ` b ...+. ", |
192 | " @.#.$.%.&. ", | 192 | " @.#.$.%.&. ", |
193 | " *.B =. ", | 193 | " *.B =. ", |
194 | " n n n n n n n n n "}; | 194 | " n n n n n n n n n "}; |
195 | 195 | ||
196 | 196 | ||
197 | VMemo::VMemo( QWidget *parent, const char *_name ) | 197 | VMemo::VMemo( QWidget *parent, const char *_name ) |
198 | : QWidget( parent, _name ) | 198 | : QWidget( parent, _name ) |
199 | { | 199 | { |
200 | setFixedHeight( 18 ); | 200 | setFixedHeight( 18 ); |
201 | setFixedWidth( 14 ); | 201 | setFixedWidth( 14 ); |
202 | 202 | ||
203 | recording = FALSE; | 203 | recording = FALSE; |
204 | 204 | ||
205 | struct utsname name; /* check for embedix kernel running on the zaurus*/ | 205 | struct utsname name; /* check for embedix kernel running on the zaurus*/ |
206 | if (uname(&name) != -1) { | 206 | if (uname(&name) != -1) { |
207 | QString release=name.release; | 207 | QString release=name.release; |
208 | Config vmCfg("Vmemo"); | 208 | Config vmCfg("Vmemo"); |
209 | vmCfg.setGroup("Defaults"); | 209 | vmCfg.setGroup("Defaults"); |
210 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); | 210 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); |
211 | 211 | ||
212 | qDebug("toggleKey %d", toggleKey); | 212 | qDebug("toggleKey %d", toggleKey); |
213 | 213 | ||
214 | if(release.find("embedix",0,TRUE) !=-1) | 214 | if(release.find("embedix",0,TRUE) !=-1) |
215 | systemZaurus=TRUE; | 215 | systemZaurus=TRUE; |
216 | else | 216 | else |
217 | systemZaurus=FALSE; | 217 | systemZaurus=FALSE; |
218 | 218 | ||
219 | myChannel = new QCopChannel( "QPE/VMemo", this ); | 219 | myChannel = new QCopChannel( "QPE/VMemo", this ); |
220 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), | 220 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), |
221 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 221 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
222 | 222 | ||
223 | if( toggleKey != -1 ) { | 223 | if( toggleKey != -1 ) { |
224 | // QPEApplication::grabKeyboard(); | 224 | // QPEApplication::grabKeyboard(); |
225 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); | 225 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); |
226 | // e << 4096; // Key_Escape | 226 | // e << 4096; // Key_Escape |
227 | // e << Key_F5; //4148 | 227 | // e << Key_F5; //4148 |
228 | e << toggleKey; | 228 | e << toggleKey; |
229 | e << QString("QPE/VMemo"); | 229 | e << QString("QPE/VMemo"); |
230 | e << QString("toggleRecord()"); | 230 | e << QString("toggleRecord()"); |
231 | } | 231 | } |
232 | // if( vmCfg.readNumEntry("hideIcon",0) == 1 || toggleKey > 0) | 232 | // if( vmCfg.readNumEntry("hideIcon",0) == 1 || toggleKey > 0) |
233 | // hide(); | 233 | // hide(); |
234 | } | 234 | } |
235 | } | 235 | } |
236 | 236 | ||
237 | VMemo::~VMemo() | 237 | VMemo::~VMemo() |
238 | { | 238 | { |
239 | } | 239 | } |
240 | 240 | ||
241 | void VMemo::receive( const QCString &msg, const QByteArray &data ) | 241 | void VMemo::receive( const QCString &msg, const QByteArray &data ) |
242 | { | 242 | { |
243 | QDataStream stream( data, IO_ReadOnly ); | 243 | QDataStream stream( data, IO_ReadOnly ); |
244 | if (msg == "toggleRecord()") { | 244 | if (msg == "toggleRecord()") { |
245 | if (recording) { | 245 | if (recording) { |
246 | fromToggle = TRUE; | 246 | fromToggle = TRUE; |
247 | stopRecording(); | 247 | stopRecording(); |
248 | } else { | 248 | } else { |
249 | fromToggle = TRUE; | 249 | fromToggle = TRUE; |
250 | startRecording(); | 250 | startRecording(); |
251 | } | 251 | } |
252 | } | 252 | } |
253 | } | 253 | } |
254 | 254 | ||
255 | void VMemo::paintEvent( QPaintEvent* ) | 255 | void VMemo::paintEvent( QPaintEvent* ) |
256 | { | 256 | { |
257 | QPainter p(this); | 257 | QPainter p(this); |
258 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 258 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
259 | } | 259 | } |
260 | 260 | ||
261 | void VMemo::mousePressEvent( QMouseEvent * ) | 261 | void VMemo::mousePressEvent( QMouseEvent * ) |
262 | { | 262 | { |
263 | startRecording(); | 263 | startRecording(); |
264 | } | 264 | } |
265 | 265 | ||
266 | void VMemo::mouseReleaseEvent( QMouseEvent * ) | 266 | void VMemo::mouseReleaseEvent( QMouseEvent * ) |
267 | { | 267 | { |
268 | stopRecording(); | 268 | stopRecording(); |
269 | } | 269 | } |
270 | 270 | ||
271 | bool VMemo::startRecording() { | 271 | bool VMemo::startRecording() { |
272 | 272 | ||
273 | if ( recording) | 273 | if ( recording) |
274 | return FALSE;; | 274 | return FALSE;; |
275 | 275 | ||
276 | Config config( "Vmemo" ); | 276 | Config config( "Vmemo" ); |
277 | config.setGroup( "System" ); | 277 | config.setGroup( "System" ); |
278 | 278 | ||
279 | useAlerts = config.readBoolEntry("Alert"); | 279 | useAlerts = config.readBoolEntry("Alert"); |
280 | if(useAlerts) { | 280 | if(useAlerts) { |
281 | 281 | ||
282 | msgLabel = new QLabel( 0, "alertLabel" ); | 282 | msgLabel = new QLabel( 0, "alertLabel" ); |
283 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); | 283 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); |
284 | msgLabel->show(); | 284 | msgLabel->show(); |
285 | } | 285 | } |
286 | 286 | ||
287 | // if(useAlerts) | 287 | // if(useAlerts) |
288 | // QMessageBox::message("VMemo","Really Record?");//) ==1) | 288 | // QMessageBox::message("VMemo","Really Record?");//) ==1) |
289 | // return; | 289 | // return; |
290 | // } else { | 290 | // } else { |
291 | // if (!systemZaurus ) | 291 | // if (!systemZaurus ) |
292 | // QSound::play(Resource::findSound("vmemob")); | 292 | // QSound::play(Resource::findSound("vmemob")); |
293 | // } | 293 | // } |
294 | qDebug("Start recording engines"); | 294 | qDebug("Start recording engines"); |
295 | recording = TRUE; | 295 | recording = TRUE; |
296 | 296 | ||
297 | if (openDSP() == -1) { | 297 | if (openDSP() == -1) { |
298 | // QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort"); | 298 | // QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort"); |
299 | // delete msgLabel; | 299 | // delete msgLabel; |
300 | recording = FALSE; | 300 | recording = FALSE; |
301 | return FALSE; | 301 | return FALSE; |
302 | } | 302 | } |
303 | 303 | ||
304 | config.setGroup("Defaults"); | 304 | config.setGroup("Defaults"); |
305 | 305 | ||
306 | QDateTime dt = QDateTime::currentDateTime(); | 306 | QDateTime dt = QDateTime::currentDateTime(); |
307 | 307 | ||
308 | QString fName; | 308 | QString fName; |
309 | config.setGroup( "System" ); | 309 | config.setGroup( "System" ); |
310 | fName = QPEApplication::documentDir() ; | 310 | fName = QPEApplication::documentDir() ; |
311 | fileName = config.readEntry("RecLocation", fName); | 311 | fileName = config.readEntry("RecLocation", fName); |
312 | 312 | ||
313 | int s; | 313 | int s; |
314 | s=fileName.find(':'); | 314 | s=fileName.find(':'); |
315 | if(s) | 315 | if(s) |
316 | fileName=fileName.right(fileName.length()-s-2); | 316 | fileName=fileName.right(fileName.length()-s-2); |
317 | qDebug("filename will be "+fileName); | 317 | qDebug("filename will be "+fileName); |
318 | if( fileName.left(1).find('/') == -1) | 318 | if( fileName.left(1).find('/') == -1) |
319 | fileName="/"+fileName; | 319 | fileName="/"+fileName; |
320 | if( fileName.right(1).find('/') == -1) | 320 | if( fileName.right(1).find('/') == -1) |
321 | fileName+="/"; | 321 | fileName+="/"; |
322 | fName = "vm_"+ dt.toString()+ ".wav"; | 322 | fName = "vm_"+ dt.toString()+ ".wav"; |
323 | 323 | ||
324 | fileName+=fName; | 324 | fileName+=fName; |
325 | qDebug("filename is "+fileName); | 325 | qDebug("filename is "+fileName); |
326 | // No spaces in the filename | 326 | // No spaces in the filename |
327 | fileName.replace(QRegExp("'"),""); | 327 | fileName.replace(QRegExp("'"),""); |
328 | fileName.replace(QRegExp(" "),"_"); | 328 | fileName.replace(QRegExp(" "),"_"); |
329 | fileName.replace(QRegExp(":"),"."); | 329 | fileName.replace(QRegExp(":"),"."); |
330 | fileName.replace(QRegExp(","),""); | 330 | fileName.replace(QRegExp(","),""); |
331 | 331 | ||
332 | if(openWAV(fileName.latin1()) == -1) { | 332 | if(openWAV(fileName.latin1()) == -1) { |
333 | // QString err("Could not open the output file\n"); | 333 | // QString err("Could not open the output file\n"); |
334 | // err += fileName; | 334 | // err += fileName; |
335 | // QMessageBox::critical(0, "vmemo", err, "Abort"); | 335 | // QMessageBox::critical(0, "vmemo", err, "Abort"); |
336 | close(dsp); | 336 | close(dsp); |
337 | return FALSE; | 337 | return FALSE; |
338 | } | 338 | } |
339 | 339 | ||
340 | QArray<int> cats(1); | 340 | QArray<int> cats(1); |
341 | cats[0] = config.readNumEntry("Category", 0); | 341 | cats[0] = config.readNumEntry("Category", 0); |
342 | 342 | ||
343 | QString dlName("vm_"); | 343 | QString dlName("vm_"); |
344 | dlName += dt.toString(); | 344 | dlName += dt.toString(); |
345 | DocLnk l; | 345 | DocLnk l; |
346 | l.setFile(fileName); | 346 | l.setFile(fileName); |
347 | l.setName(dlName); | 347 | l.setName(dlName); |
348 | l.setType("audio/x-wav"); | 348 | l.setType("audio/x-wav"); |
349 | l.setCategories(cats); | 349 | l.setCategories(cats); |
350 | l.writeLink(); | 350 | l.writeLink(); |
351 | 351 | ||
352 | 352 | ||
353 | record(); | 353 | record(); |
354 | // delete msgLabel; | 354 | // delete msgLabel; |
355 | return TRUE; | 355 | return TRUE; |
356 | } | 356 | } |
357 | 357 | ||
358 | void VMemo::stopRecording() { | 358 | void VMemo::stopRecording() { |
359 | recording = FALSE; | 359 | recording = FALSE; |
360 | if(useAlerts) | 360 | if(useAlerts) |
361 | if( msgLabel) delete msgLabel; | 361 | if( msgLabel) delete msgLabel; |
362 | } | 362 | } |
363 | 363 | ||
364 | int VMemo::openDSP() | 364 | int VMemo::openDSP() |
365 | { | 365 | { |
366 | Config cfg("Vmemo"); | 366 | Config cfg("Vmemo"); |
367 | cfg.setGroup("Record"); | 367 | cfg.setGroup("Record"); |
368 | 368 | ||
369 | speed = cfg.readNumEntry("SampleRate", 22050); | 369 | speed = cfg.readNumEntry("SampleRate", 22050); |
370 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 370 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
371 | if (cfg.readNumEntry("SixteenBit", 1)==1) { | 371 | if (cfg.readNumEntry("SixteenBit", 1)==1) { |
372 | format = AFMT_S16_LE; | 372 | format = AFMT_S16_LE; |
373 | resolution = 16; | 373 | resolution = 16; |
374 | } else { | 374 | } else { |
375 | format = AFMT_U8; | 375 | format = AFMT_U8; |
376 | resolution = 8; | 376 | resolution = 8; |
377 | } | 377 | } |
378 | 378 | ||
379 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); | 379 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); |
380 | 380 | ||
381 | if(systemZaurus) { | 381 | if(systemZaurus) { |
382 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 | 382 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 |
383 | channels=1; //zaurus has one input channel | 383 | channels=1; //zaurus has one input channel |
384 | } else { | 384 | } else { |
385 | dsp = open("/dev/dsp", O_RDWR); | 385 | dsp = open("/dev/dsp", O_RDWR); |
386 | } | 386 | } |
387 | 387 | ||
388 | if(dsp == -1) { | 388 | if(dsp == -1) { |
389 | perror("open(\"/dev/dsp\")"); | 389 | perror("open(\"/dev/dsp\")"); |
390 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); | 390 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); |
391 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); | 391 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); |
392 | return -1; | 392 | return -1; |
393 | } | 393 | } |
394 | 394 | ||
395 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { | 395 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { |
396 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 396 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
397 | return -1; | 397 | return -1; |
398 | } | 398 | } |
399 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { | 399 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { |
400 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 400 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
401 | return -1; | 401 | return -1; |
402 | } | 402 | } |
403 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { | 403 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { |
404 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 404 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
405 | return -1; | 405 | return -1; |
406 | } | 406 | } |
407 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { | 407 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { |
408 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 408 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); |
409 | return -1; | 409 | return -1; |
410 | } | 410 | } |
411 | |||
412 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute | ||
411 | 413 | ||
412 | return 1; | 414 | return 1; |
413 | } | 415 | } |
414 | 416 | ||
415 | int VMemo::openWAV(const char *filename) | 417 | int VMemo::openWAV(const char *filename) |
416 | { | 418 | { |
417 | track.setName(filename); | 419 | track.setName(filename); |
418 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { | 420 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { |
419 | errorMsg=filename; | 421 | errorMsg=filename; |
420 | return -1; | 422 | return -1; |
421 | } | 423 | } |
422 | 424 | ||
423 | wav=track.handle(); | 425 | wav=track.handle(); |
424 | 426 | ||
425 | WaveHeader wh; | 427 | WaveHeader wh; |
426 | 428 | ||
427 | wh.main_chunk = RIFF; | 429 | wh.main_chunk = RIFF; |
428 | wh.length=0; | 430 | wh.length=0; |
429 | wh.chunk_type = WAVE; | 431 | wh.chunk_type = WAVE; |
430 | wh.sub_chunk = FMT; | 432 | wh.sub_chunk = FMT; |
431 | wh.sc_len = 16; | 433 | wh.sc_len = 16; |
432 | wh.format = PCM_CODE; | 434 | wh.format = PCM_CODE; |
433 | wh.modus = channels; | 435 | wh.modus = channels; |
434 | wh.sample_fq = speed; | 436 | wh.sample_fq = speed; |
435 | wh.byte_p_sec = speed * channels * resolution/8; | 437 | wh.byte_p_sec = speed * channels * resolution/8; |
436 | wh.byte_p_spl = channels * (resolution / 8); | 438 | wh.byte_p_spl = channels * (resolution / 8); |
437 | wh.bit_p_spl = resolution; | 439 | wh.bit_p_spl = resolution; |
438 | wh.data_chunk = DATA; | 440 | wh.data_chunk = DATA; |
439 | wh.data_length= 0; | 441 | wh.data_length= 0; |
440 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" | 442 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" |
441 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); | 443 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); |
442 | write (wav, &wh, sizeof(WaveHeader)); | 444 | write (wav, &wh, sizeof(WaveHeader)); |
443 | 445 | ||
444 | return 1; | 446 | return 1; |
445 | } | 447 | } |
446 | 448 | ||
447 | void VMemo::record(void) | 449 | void VMemo::record(void) |
448 | { | 450 | { |
449 | int length=0, result, value; | 451 | int length=0, result, value; |
450 | QString msg; | 452 | QString msg; |
451 | msg.sprintf("Recording format %d", format); | 453 | msg.sprintf("Recording format %d", format); |
452 | qDebug(msg); | 454 | qDebug(msg); |
453 | 455 | ||
454 | if(systemZaurus) { | 456 | if(systemZaurus) { |
455 | 457 | ||
456 | msg.sprintf("Recording format zaurus"); | 458 | msg.sprintf("Recording format zaurus"); |
457 | qDebug(msg); | 459 | qDebug(msg); |
458 | signed short sound[512], monoBuffer[512]; | 460 | signed short sound[512], monoBuffer[512]; |
459 | 461 | ||
460 | if(format==AFMT_S16_LE) { | 462 | if(format==AFMT_S16_LE) { |
461 | 463 | ||
464 | |||
465 | |||
462 | while(recording) { | 466 | while(recording) { |
463 | 467 | ||
464 | result = read(dsp, sound, 512); // 8192 | 468 | result = read(dsp, sound, 512); // 8192 |
465 | int j=0; | 469 | int j=0; |
466 | 470 | ||
467 | if(systemZaurus) { | 471 | // if(systemZaurus) { |
468 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 472 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
469 | monoBuffer[i] = sound[i]; | 473 | monoBuffer[i] = sound[i]; |
470 | } | 474 | } |
471 | 475 | ||
472 | length+=write(wav, monoBuffer, result); | 476 | length+=write(wav, monoBuffer, result); |
473 | if(length<0) | 477 | if(length<0) |
474 | recording=false; | 478 | recording=false; |
475 | 479 | ||
476 | } else { //ipaq /stereo inputs | 480 | // } else { //ipaq /stereo inputs |
477 | 481 | ||
478 | 482 | ||
479 | for (int i = 0; i < result; i+=2) { | 483 | // for (int i = 0; i < result; i+=2) { |
480 | monoBuffer[j] = sound[i]; | 484 | // monoBuffer[j] = sound[i]; |
481 | // monoBuffer[j] = (sound[i]+sound[i+1])/2; | 485 | // // monoBuffer[j] = (sound[i]+sound[i+1])/2; |
482 | 486 | ||
483 | j++; | 487 | // j++; |
484 | } | 488 | // } |
485 | 489 | ||
486 | length+=write(wav, monoBuffer, result); | 490 | // length+=write(wav, monoBuffer, result); |
487 | if(length<0) | 491 | // if(length<0) |
488 | recording=false; | 492 | // recording=false; |
489 | // length+=write(wav, monoBuffer, result/2); | 493 | // // length+=write(wav, monoBuffer, result/2); |
490 | } | 494 | // } |
491 | qApp->processEvents(); | 495 | qApp->processEvents(); |
492 | // printf("%d\r",length); | 496 | // printf("%d\r",length); |
493 | // fflush(stdout); | 497 | // fflush(stdout); |
494 | } | 498 | } |
495 | 499 | ||
496 | } else { //AFMT_U8 | 500 | } else { //AFMT_U8 |
497 | // 8bit unsigned | 501 | // 8bit unsigned |
498 | unsigned short sound[512], monoBuffer[512]; | 502 | unsigned short sound[512], monoBuffer[512]; |
499 | while(recording) { | 503 | while(recording) { |
500 | result = read(dsp, sound, 512); // 8192 | 504 | result = read(dsp, sound, 512); // 8192 |
501 | int j=0; | 505 | int j=0; |
502 | 506 | ||
503 | if(systemZaurus) { | 507 | // if(systemZaurus) { |
504 | 508 | ||
505 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 509 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
506 | monoBuffer[i] = sound[i]; | 510 | monoBuffer[i] = sound[i]; |
507 | } | 511 | } |
508 | 512 | ||
509 | length+=write(wav, monoBuffer, result); | 513 | length+=write(wav, monoBuffer, result); |
510 | 514 | ||
511 | } else { //ipaq /stereo inputs | 515 | // } else { //ipaq /stereo inputs |
512 | 516 | ||
513 | for (int i = 0; i < result; i+=2) { | 517 | // for (int i = 0; i < result; i+=2) { |
514 | monoBuffer[j] = (sound[i]+sound[i+1])/2; | 518 | // monoBuffer[j] = (sound[i]+sound[i+1])/2; |
515 | j++; | 519 | // j++; |
516 | } | 520 | // } |
517 | 521 | ||
518 | length+=write(wav, monoBuffer, result/2); | 522 | // length+=write(wav, monoBuffer, result/2); |
519 | 523 | ||
520 | if(length<0) | 524 | // if(length<0) |
521 | recording=false; | 525 | // recording=false; |
522 | 526 | ||
523 | } | 527 | // } |
524 | length += result; | 528 | length += result; |
525 | // printf("%d\r",length); | 529 | // printf("%d\r",length); |
526 | // fflush(stdout); | 530 | // fflush(stdout); |
527 | } | 531 | } |
528 | 532 | ||
529 | qApp->processEvents(); | 533 | qApp->processEvents(); |
530 | } | 534 | } |
531 | 535 | ||
532 | } else { // this is specific for ipaqs that do not have 8 bit capabilities | 536 | } else { // 16 bit only capabilities |
533 | 537 | ||
534 | msg.sprintf("Recording format other"); | 538 | |
535 | qDebug(msg); | 539 | msg.sprintf("Recording format other"); |
540 | qDebug(msg); | ||
536 | 541 | ||
537 | signed short sound[512], monoBuffer[512]; | 542 | signed short sound[512], monoBuffer[512]; |
538 | 543 | ||
539 | while(recording) { | 544 | while(recording) { |
540 | 545 | ||
541 | result = read(dsp, sound, 512); // 8192 | 546 | result = read(dsp, sound, 512); // 8192 |
542 | 547 | ||
543 | write(wav, sound, result); | 548 | write(wav, sound, result); |
544 | length += result; | 549 | length += result; |
545 | if(length<0) { | 550 | if(length<0) { |
546 | 551 | ||
547 | recording=false; | 552 | recording=false; |
548 | perror("dev/dsp's is a lookin' messy"); | 553 | perror("dev/dsp's is a lookin' messy"); |
549 | QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); | 554 | QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); |
550 | } | 555 | } |
551 | // printf("%d\r",length); | 556 | // printf("%d\r",length); |
552 | // fflush(stdout); | 557 | // fflush(stdout); |
553 | qApp->processEvents(); | 558 | qApp->processEvents(); |
554 | } | 559 | } |
555 | // qDebug("file has length of %d lasting %d seconds", | 560 | // qDebug("file has length of %d lasting %d seconds", |
556 | // length, (( length / speed) / channels) / 2 ); | 561 | // length, (( length / speed) / channels) / 2 ); |
557 | // medialplayer states wrong length in secs | 562 | // medialplayer states wrong length in secs |
558 | } | 563 | } |
559 | 564 | ||
560 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// | 565 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// |
561 | 566 | ||
562 | value = length+36; | 567 | value = length+36; |
563 | 568 | ||
564 | lseek(wav, 4, SEEK_SET); | 569 | lseek(wav, 4, SEEK_SET); |
565 | write(wav, &value, 4); | 570 | write(wav, &value, 4); |
566 | lseek(wav, 40, SEEK_SET); | 571 | lseek(wav, 40, SEEK_SET); |
567 | 572 | ||
568 | write(wav, &length, 4); | 573 | write(wav, &length, 4); |
569 | 574 | ||
570 | track.close(); | 575 | track.close(); |
571 | qDebug("Tracvk closed"); | 576 | qDebug("Tracvk closed"); |
572 | 577 | ||
573 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 578 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
574 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 579 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
575 | 580 | ||
576 | ::close(dsp); | 581 | ::close(dsp); |
577 | fileName = fileName.left(fileName.length()-4); | 582 | fileName = fileName.left(fileName.length()-4); |
578 | // if(useAlerts) | 583 | // if(useAlerts) |
579 | // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); | 584 | // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); |
580 | qDebug("done recording "+fileName); | 585 | qDebug("done recording "+fileName); |
581 | QSound::play(Resource::findSound("vmemoe")); | 586 | QSound::play(Resource::findSound("vmemoe")); |
587 | |||
588 | Config cfg("qpe"); | ||
589 | cfg.setGroup("Volume"); | ||
590 | QString foo = cfg.readEntry("Mute","TRUE"); | ||
591 | if(foo.find("TRUE",0,TRUE) != -1) | ||
592 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute | ||
593 | |||
582 | } | 594 | } |
583 | 595 | ||
584 | int VMemo::setToggleButton(int tog) { | 596 | int VMemo::setToggleButton(int tog) { |
585 | 597 | ||
586 | for( int i=0; i < 10;i++) { | 598 | for( int i=0; i < 10;i++) { |
587 | switch (tog) { | 599 | switch (tog) { |
588 | case 0: | 600 | case 0: |
589 | return -1; | 601 | return -1; |
590 | break; | 602 | break; |
591 | case 1: | 603 | case 1: |
592 | return 0; | 604 | return 0; |
593 | break; | 605 | break; |
594 | case 2: | 606 | case 2: |
595 | return Key_Escape; | 607 | return Key_Escape; |
596 | break; | 608 | break; |
597 | case 3: | 609 | case 3: |
598 | return Key_Space; | 610 | return Key_Space; |
599 | break; | 611 | break; |
600 | case 4: | 612 | case 4: |
601 | return Key_F12; | 613 | return Key_F12; |
602 | break; | 614 | break; |
603 | case 5: | 615 | case 5: |
604 | return Key_F9; | 616 | return Key_F9; |
605 | break; | 617 | break; |
606 | case 6: | 618 | case 6: |
607 | return Key_F10; | 619 | return Key_F10; |
608 | break; | 620 | break; |
609 | case 7: | 621 | case 7: |
610 | return Key_F11; | 622 | return Key_F11; |
611 | break; | 623 | break; |
612 | case 8: | 624 | case 8: |
613 | return Key_F13; | 625 | return Key_F13; |
614 | break; | 626 | break; |
615 | }; | 627 | }; |
616 | } | 628 | } |
617 | } | 629 | } |