-rw-r--r-- | libopie2/opiemm/osoundsystem.cpp | 12 | ||||
-rw-r--r-- | libopie2/opiemm/osoundsystem.h | 13 |
2 files changed, 13 insertions, 12 deletions
diff --git a/libopie2/opiemm/osoundsystem.cpp b/libopie2/opiemm/osoundsystem.cpp index 2956682..6f849cd 100644 --- a/libopie2/opiemm/osoundsystem.cpp +++ b/libopie2/opiemm/osoundsystem.cpp | |||
@@ -1,315 +1,317 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | =. (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | ||
5 | .=l. | 4 | .=l. |
6 | .>+-= | 5 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 12 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 20 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
28 | 27 | ||
29 | */ | 28 | */ |
30 | 29 | ||
31 | #include <opie2/osoundsystem.h> | 30 | #include "osoundsystem.h" |
31 | using namespace Opie::MM; | ||
32 | |||
33 | /* OPIE */ | ||
32 | #include <opie2/odebug.h> | 34 | #include <opie2/odebug.h> |
35 | using namespace Opie::Core; | ||
33 | 36 | ||
37 | /* STD */ | ||
34 | #include <errno.h> | 38 | #include <errno.h> |
35 | #include <fcntl.h> | 39 | #include <fcntl.h> |
36 | #include <string.h> | 40 | #include <string.h> |
37 | #include <sys/ioctl.h> | 41 | #include <sys/ioctl.h> |
38 | #include <sys/types.h> | 42 | #include <sys/types.h> |
39 | #include <sys/soundcard.h> | 43 | #include <sys/soundcard.h> |
40 | #include <sys/stat.h> | 44 | #include <sys/stat.h> |
41 | 45 | ||
42 | static const char* device_label[] = SOUND_DEVICE_LABELS; | 46 | static const char* device_label[] = SOUND_DEVICE_LABELS; |
43 | static int max_device_nr = sizeof device_label / sizeof (const char*); | 47 | static int max_device_nr = sizeof device_label / sizeof (const char*); |
44 | 48 | ||
45 | using namespace Opie::Core; | ||
46 | using namespace Opie::MM; | ||
47 | /*====================================================================================== | 49 | /*====================================================================================== |
48 | * OSoundSystem | 50 | * OSoundSystem |
49 | *======================================================================================*/ | 51 | *======================================================================================*/ |
50 | 52 | ||
51 | OSoundSystem* OSoundSystem::_instance = 0; | 53 | OSoundSystem* OSoundSystem::_instance = 0; |
52 | 54 | ||
53 | OSoundSystem::OSoundSystem() | 55 | OSoundSystem::OSoundSystem() |
54 | { | 56 | { |
55 | odebug << "OSoundSystem::OSoundSystem()" << oendl; | 57 | odebug << "OSoundSystem::OSoundSystem()" << oendl; |
56 | synchronize(); | 58 | synchronize(); |
57 | } | 59 | } |
58 | 60 | ||
59 | void OSoundSystem::synchronize() | 61 | void OSoundSystem::synchronize() |
60 | { | 62 | { |
61 | _interfaces.clear(); | 63 | _interfaces.clear(); |
62 | _interfaces.insert( "soundcard", new OSoundCard( this, "soundcard" ) ); | 64 | _interfaces.insert( "soundcard", new OSoundCard( this, "soundcard" ) ); |
63 | 65 | ||
64 | /* | 66 | /* |
65 | 67 | ||
66 | QString str; | 68 | QString str; |
67 | QFile f( "/dev/sound" ); | 69 | QFile f( "/dev/sound" ); |
68 | bool hasFile = f.open( IO_ReadOnly ); | 70 | bool hasFile = f.open( IO_ReadOnly ); |
69 | if ( !hasFile ) | 71 | if ( !hasFile ) |
70 | { | 72 | { |
71 | odebug << "OSoundSystem: /dev/sound not existing. No sound devices available" << oendl; | 73 | odebug << "OSoundSystem: /dev/sound not existing. No sound devices available" << oendl; |
72 | return; | 74 | return; |
73 | } | 75 | } |
74 | QTextStream s( &f ); | 76 | QTextStream s( &f ); |
75 | s.readLine(); | 77 | s.readLine(); |
76 | s.readLine(); | 78 | s.readLine(); |
77 | while ( !s.atEnd() ) | 79 | while ( !s.atEnd() ) |
78 | { | 80 | { |
79 | s >> str; | 81 | s >> str; |
80 | str.truncate( str.find( ':' ) ); | 82 | str.truncate( str.find( ':' ) ); |
81 | odebug << "OSoundSystem: found interface '" << str << "'" << oendl; | 83 | odebug << "OSoundSystem: found interface '" << str << "'" << oendl; |
82 | OAudioInterface* iface; | 84 | OAudioInterface* iface; |
83 | iface = new OAudioInterface( this, (const char*) str ); | 85 | iface = new OAudioInterface( this, (const char*) str ); |
84 | 86 | ||
85 | _interfaces.insert( str, iface ); | 87 | _interfaces.insert( str, iface ); |
86 | s.readLine(); | 88 | s.readLine(); |
87 | } | 89 | } |
88 | */ | 90 | */ |
89 | } | 91 | } |
90 | 92 | ||
91 | 93 | ||
92 | int OSoundSystem::count() const | 94 | int OSoundSystem::count() const |
93 | { | 95 | { |
94 | return _interfaces.count(); | 96 | return _interfaces.count(); |
95 | } | 97 | } |
96 | 98 | ||
97 | 99 | ||
98 | OSoundCard* OSoundSystem::card( const QString& iface ) const | 100 | OSoundCard* OSoundSystem::card( const QString& iface ) const |
99 | { | 101 | { |
100 | return _interfaces[iface]; | 102 | return _interfaces[iface]; |
101 | } | 103 | } |
102 | 104 | ||
103 | 105 | ||
104 | OSoundSystem* OSoundSystem::instance() | 106 | OSoundSystem* OSoundSystem::instance() |
105 | { | 107 | { |
106 | if ( !_instance ) _instance = new OSoundSystem(); | 108 | if ( !_instance ) _instance = new OSoundSystem(); |
107 | return _instance; | 109 | return _instance; |
108 | } | 110 | } |
109 | 111 | ||
110 | 112 | ||
111 | OSoundSystem::CardIterator OSoundSystem::iterator() const | 113 | OSoundSystem::CardIterator OSoundSystem::iterator() const |
112 | { | 114 | { |
113 | return OSoundSystem::CardIterator( _interfaces ); | 115 | return OSoundSystem::CardIterator( _interfaces ); |
114 | } | 116 | } |
115 | 117 | ||
116 | 118 | ||
117 | /*====================================================================================== | 119 | /*====================================================================================== |
118 | * OSoundCard | 120 | * OSoundCard |
119 | *======================================================================================*/ | 121 | *======================================================================================*/ |
120 | 122 | ||
121 | OSoundCard::OSoundCard( QObject* parent, const char* name ) | 123 | OSoundCard::OSoundCard( QObject* parent, const char* name ) |
122 | :QObject( parent, name ), _audio( 0 ), _mixer( 0 ) | 124 | :QObject( parent, name ), _audio( 0 ), _mixer( 0 ) |
123 | { | 125 | { |
124 | odebug << "OSoundCard::OSoundCard()" << oendl; | 126 | odebug << "OSoundCard::OSoundCard()" << oendl; |
125 | init(); | 127 | init(); |
126 | } | 128 | } |
127 | 129 | ||
128 | 130 | ||
129 | OSoundCard::~OSoundCard() | 131 | OSoundCard::~OSoundCard() |
130 | { | 132 | { |
131 | } | 133 | } |
132 | 134 | ||
133 | 135 | ||
134 | void OSoundCard::init() | 136 | void OSoundCard::init() |
135 | { | 137 | { |
136 | #ifdef QT_QWS_DEVFS | 138 | #ifdef QT_QWS_DEVFS |
137 | _audio = new OAudioInterface( this, "/dev/sound/dsp" ); | 139 | _audio = new OAudioInterface( this, "/dev/sound/dsp" ); |
138 | _mixer = new OMixerInterface( this, "/dev/sound/mixer" ); | 140 | _mixer = new OMixerInterface( this, "/dev/sound/mixer" ); |
139 | #else | 141 | #else |
140 | _audio = new OAudioInterface( this, "/dev/dsp" ); | 142 | _audio = new OAudioInterface( this, "/dev/dsp" ); |
141 | _mixer = new OMixerInterface( this, "/dev/mixer" ); | 143 | _mixer = new OMixerInterface( this, "/dev/mixer" ); |
142 | #endif | 144 | #endif |
143 | } | 145 | } |
144 | 146 | ||
145 | 147 | ||
146 | /*====================================================================================== | 148 | /*====================================================================================== |
147 | * OAudioInterface | 149 | * OAudioInterface |
148 | *======================================================================================*/ | 150 | *======================================================================================*/ |
149 | 151 | ||
150 | OAudioInterface::OAudioInterface( QObject* parent, const char* name ) | 152 | OAudioInterface::OAudioInterface( QObject* parent, const char* name ) |
151 | :QObject( parent, name ), _sfd(0) | 153 | :QObject( parent, name ), _sfd(0) |
152 | { | 154 | { |
153 | odebug << "OAudioInterface::OAudioInterface()" << oendl; | 155 | odebug << "OAudioInterface::OAudioInterface()" << oendl; |
154 | init(); | 156 | init(); |
155 | } | 157 | } |
156 | 158 | ||
157 | 159 | ||
158 | OAudioInterface::~OAudioInterface() | 160 | OAudioInterface::~OAudioInterface() |
159 | { | 161 | { |
160 | } | 162 | } |
161 | 163 | ||
162 | 164 | ||
163 | void OAudioInterface::init() | 165 | void OAudioInterface::init() |
164 | { | 166 | { |
165 | 167 | ||
166 | 168 | ||
167 | } | 169 | } |
168 | 170 | ||
169 | 171 | ||
170 | /*====================================================================================== | 172 | /*====================================================================================== |
171 | * OMixerInterface | 173 | * OMixerInterface |
172 | *======================================================================================*/ | 174 | *======================================================================================*/ |
173 | 175 | ||
174 | OMixerInterface::OMixerInterface( QObject* parent, const char* name ) | 176 | OMixerInterface::OMixerInterface( QObject* parent, const char* name ) |
175 | :QObject( parent, name ), _devmask( 0 ), _recmask( 0 ), _stmask( 0 ) | 177 | :QObject( parent, name ), _devmask( 0 ), _recmask( 0 ), _stmask( 0 ) |
176 | { | 178 | { |
177 | odebug << "OMixerInterface::OMixerInterface()" << oendl; | 179 | odebug << "OMixerInterface::OMixerInterface()" << oendl; |
178 | init(); | 180 | init(); |
179 | } | 181 | } |
180 | 182 | ||
181 | 183 | ||
182 | OMixerInterface::~OMixerInterface() | 184 | OMixerInterface::~OMixerInterface() |
183 | { | 185 | { |
184 | } | 186 | } |
185 | 187 | ||
186 | 188 | ||
187 | void OMixerInterface::init() | 189 | void OMixerInterface::init() |
188 | { | 190 | { |
189 | // open the device | 191 | // open the device |
190 | _fd = ::open( name(), O_RDWR ); | 192 | _fd = ::open( name(), O_RDWR ); |
191 | if ( _fd == -1 ) | 193 | if ( _fd == -1 ) |
192 | { | 194 | { |
193 | owarn << "OMixerInterface::init(): Can't open mixer " << name() << oendl; | 195 | owarn << "OMixerInterface::init(): Can't open mixer " << name() << oendl; |
194 | return; | 196 | return; |
195 | } | 197 | } |
196 | 198 | ||
197 | // construct the device capabilities | 199 | // construct the device capabilities |
198 | if ( ioctl( _fd, SOUND_MIXER_READ_CAPS, &_capmask ) != -1 ) | 200 | if ( ioctl( _fd, SOUND_MIXER_READ_CAPS, &_capmask ) != -1 ) |
199 | { | 201 | { |
200 | odebug << "OMixerInterface::init() - capmask = " << _capmask << oendl; | 202 | odebug << "OMixerInterface::init() - capmask = " << _capmask << oendl; |
201 | } | 203 | } |
202 | if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &_devmask ) != -1 ) | 204 | if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &_devmask ) != -1 ) |
203 | { | 205 | { |
204 | odebug << "OMixerInterface::init() - devmask = " << _devmask << oendl; | 206 | odebug << "OMixerInterface::init() - devmask = " << _devmask << oendl; |
205 | } | 207 | } |
206 | if ( ioctl( _fd, SOUND_MIXER_READ_RECMASK, &_recmask ) != -1 ) | 208 | if ( ioctl( _fd, SOUND_MIXER_READ_RECMASK, &_recmask ) != -1 ) |
207 | { | 209 | { |
208 | odebug << "OMixerInterface::init() - recmask = " << _recmask << oendl; | 210 | odebug << "OMixerInterface::init() - recmask = " << _recmask << oendl; |
209 | } | 211 | } |
210 | if ( ioctl( _fd, SOUND_MIXER_READ_STEREODEVS, &_stmask ) != -1 ) | 212 | if ( ioctl( _fd, SOUND_MIXER_READ_STEREODEVS, &_stmask ) != -1 ) |
211 | { | 213 | { |
212 | odebug << "OMixerInterface::init() - stereomask = " << _stmask << oendl; | 214 | odebug << "OMixerInterface::init() - stereomask = " << _stmask << oendl; |
213 | } | 215 | } |
214 | for ( int i = 0; i < max_device_nr; ++i ) | 216 | for ( int i = 0; i < max_device_nr; ++i ) |
215 | { | 217 | { |
216 | if ( _devmask & ( 1 << i ) ) | 218 | if ( _devmask & ( 1 << i ) ) |
217 | { | 219 | { |
218 | _channels.insert( QString( device_label[i] ).stripWhiteSpace(), i ); | 220 | _channels.insert( QString( device_label[i] ).stripWhiteSpace(), i ); |
219 | odebug << "OMixerInterface::init() - channel '" << device_label[i] << "'" << oendl; | 221 | odebug << "OMixerInterface::init() - channel '" << device_label[i] << "'" << oendl; |
220 | } | 222 | } |
221 | } | 223 | } |
222 | } | 224 | } |
223 | 225 | ||
224 | 226 | ||
225 | QStringList OMixerInterface::allChannels() const | 227 | QStringList OMixerInterface::allChannels() const |
226 | { | 228 | { |
227 | ChannelIterator it = _channels.begin(); | 229 | ChannelIterator it = _channels.begin(); |
228 | QStringList channels; | 230 | QStringList channels; |
229 | while ( it != _channels.end() ) | 231 | while ( it != _channels.end() ) |
230 | { | 232 | { |
231 | channels += it++.key(); | 233 | channels += it++.key(); |
232 | } | 234 | } |
233 | return channels; | 235 | return channels; |
234 | } | 236 | } |
235 | 237 | ||
236 | 238 | ||
237 | QStringList OMixerInterface::recChannels() const | 239 | QStringList OMixerInterface::recChannels() const |
238 | { | 240 | { |
239 | ChannelIterator it = _channels.begin(); | 241 | ChannelIterator it = _channels.begin(); |
240 | QStringList channels; | 242 | QStringList channels; |
241 | while ( it != _channels.end() ) | 243 | while ( it != _channels.end() ) |
242 | { | 244 | { |
243 | if ( _recmask & ( 1 << _channels[it.key()] ) ) channels += it++.key(); | 245 | if ( _recmask & ( 1 << _channels[it.key()] ) ) channels += it++.key(); |
244 | } | 246 | } |
245 | return channels; | 247 | return channels; |
246 | } | 248 | } |
247 | 249 | ||
248 | 250 | ||
249 | QStringList OMixerInterface::playChannels() const | 251 | QStringList OMixerInterface::playChannels() const |
250 | { | 252 | { |
251 | return allChannels(); | 253 | return allChannels(); |
252 | } | 254 | } |
253 | 255 | ||
254 | 256 | ||
255 | bool OMixerInterface::hasMultipleRecording() const | 257 | bool OMixerInterface::hasMultipleRecording() const |
256 | { | 258 | { |
257 | return !( _capmask & SOUND_CAP_EXCL_INPUT ); | 259 | return !( _capmask & SOUND_CAP_EXCL_INPUT ); |
258 | } | 260 | } |
259 | 261 | ||
260 | 262 | ||
261 | bool OMixerInterface::hasChannel( const QString& channel ) const | 263 | bool OMixerInterface::hasChannel( const QString& channel ) const |
262 | { | 264 | { |
263 | return _channels.contains( channel ); | 265 | return _channels.contains( channel ); |
264 | } | 266 | } |
265 | 267 | ||
266 | 268 | ||
267 | bool OMixerInterface::isStereo( const QString& channel ) const | 269 | bool OMixerInterface::isStereo( const QString& channel ) const |
268 | { | 270 | { |
269 | return _channels.contains( channel ) && ( _stmask & ( 1 << _channels[channel] ) ); | 271 | return _channels.contains( channel ) && ( _stmask & ( 1 << _channels[channel] ) ); |
270 | } | 272 | } |
271 | 273 | ||
272 | 274 | ||
273 | bool OMixerInterface::isRecordable( const QString& channel ) const | 275 | bool OMixerInterface::isRecordable( const QString& channel ) const |
274 | { | 276 | { |
275 | return _channels.contains( channel ) && ( _recmask & ( 1 << _channels[channel] ) ); | 277 | return _channels.contains( channel ) && ( _recmask & ( 1 << _channels[channel] ) ); |
276 | } | 278 | } |
277 | 279 | ||
278 | 280 | ||
279 | void OMixerInterface::setVolume( const QString& channel, int left, int right ) | 281 | void OMixerInterface::setVolume( const QString& channel, int left, int right ) |
280 | { | 282 | { |
281 | int volume = left; | 283 | int volume = left; |
282 | volume |= ( right == -1 ) ? left << 8 : right << 8; | 284 | volume |= ( right == -1 ) ? left << 8 : right << 8; |
283 | 285 | ||
284 | if ( _channels.contains( channel ) ) | 286 | if ( _channels.contains( channel ) ) |
285 | { | 287 | { |
286 | int result = ioctl( _fd, MIXER_WRITE( _channels[channel] ), &volume ); | 288 | int result = ioctl( _fd, MIXER_WRITE( _channels[channel] ), &volume ); |
287 | if ( result == -1 ) | 289 | if ( result == -1 ) |
288 | { | 290 | { |
289 | owarn << "Can't set volume: " << strerror( errno ) << oendl; | 291 | owarn << "Can't set volume: " << strerror( errno ) << oendl; |
290 | } | 292 | } |
291 | else | 293 | else |
292 | { | 294 | { |
293 | if ( result & 0xff != left ) | 295 | if ( result & 0xff != left ) |
294 | { | 296 | { |
295 | owarn << "Device adjusted volume from " << left << " to " << (result & 0xff) << oendl; | 297 | owarn << "Device adjusted volume from " << left << " to " << (result & 0xff) << oendl; |
296 | } | 298 | } |
297 | } | 299 | } |
298 | } | 300 | } |
299 | } | 301 | } |
300 | 302 | ||
301 | 303 | ||
302 | int OMixerInterface::volume( const QString& channel ) const | 304 | int OMixerInterface::volume( const QString& channel ) const |
303 | { | 305 | { |
304 | int volume; | 306 | int volume; |
305 | 307 | ||
306 | if ( _channels.contains( channel ) ) | 308 | if ( _channels.contains( channel ) ) |
307 | { | 309 | { |
308 | if ( ioctl( _fd, MIXER_READ( _channels[channel] ), &volume ) == -1 ) | 310 | if ( ioctl( _fd, MIXER_READ( _channels[channel] ), &volume ) == -1 ) |
309 | { | 311 | { |
310 | owarn << "Can't get volume: " << strerror( errno ) << oendl; | 312 | owarn << "Can't get volume: " << strerror( errno ) << oendl; |
311 | } | 313 | } |
312 | else return volume; | 314 | else return volume; |
313 | } | 315 | } |
314 | return -1; | 316 | return -1; |
315 | } | 317 | } |
diff --git a/libopie2/opiemm/osoundsystem.h b/libopie2/opiemm/osoundsystem.h index 5f6fb7a..1e48f5c 100644 --- a/libopie2/opiemm/osoundsystem.h +++ b/libopie2/opiemm/osoundsystem.h | |||
@@ -1,245 +1,244 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | =. (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | ||
5 | .=l. | 4 | .=l. |
6 | .>+-= | 5 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; version 2 of the License. |
12 | ._= =} : or (at your option) any later version. | 11 | ._= =} : |
13 | .%`+i> _;_. | 12 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 20 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
28 | 27 | ||
29 | */ | 28 | */ |
30 | 29 | ||
31 | #ifndef OSOUNDSYSTEM_H | 30 | #ifndef OSOUNDSYSTEM_H |
32 | #define OSOUNDSYSTEM_H | 31 | #define OSOUNDSYSTEM_H |
33 | 32 | ||
34 | #include <qobject.h> | 33 | #include <qobject.h> |
35 | #include <qdict.h> | 34 | #include <qdict.h> |
36 | #include <qmap.h> | 35 | #include <qmap.h> |
37 | 36 | ||
38 | namespace Opie { | 37 | namespace Opie { |
39 | namespace MM { | 38 | namespace MM { |
40 | 39 | ||
41 | class OAudioInterface; | 40 | class OAudioInterface; |
42 | class OMixerInterface; | 41 | class OMixerInterface; |
43 | class OSoundCard; | 42 | class OSoundCard; |
44 | 43 | ||
45 | /*====================================================================================== | 44 | /*====================================================================================== |
46 | * OSoundSystem | 45 | * OSoundSystem |
47 | *======================================================================================*/ | 46 | *======================================================================================*/ |
48 | 47 | ||
49 | /** | 48 | /** |
50 | * @brief A container class for all audio interfaces | 49 | * @brief A container class for the Linux OSS/ALSA audio subsystem |
51 | * | 50 | * |
52 | * This class provides access to all available audio/midi/sequencer interfaces of your computer. | 51 | * This class provides access to all available audio/midi/sequencer interfaces of your device. |
53 | * | 52 | * |
54 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 53 | * @author Michael 'Mickey' Lauer <mickey@Vanille.de> |
55 | */ | 54 | */ |
56 | class OSoundSystem : public QObject | 55 | class OSoundSystem : public QObject |
57 | { | 56 | { |
58 | Q_OBJECT | 57 | Q_OBJECT |
59 | 58 | ||
60 | public: | 59 | public: |
61 | typedef QDict<OSoundCard> CardMap; | 60 | typedef QDict<OSoundCard> CardMap; |
62 | typedef QDictIterator<OSoundCard> CardIterator; | 61 | typedef QDictIterator<OSoundCard> CardIterator; |
63 | 62 | ||
64 | public: | 63 | public: |
65 | /** | 64 | /** |
66 | * @returns the number of available interfaces | 65 | * @returns the number of available interfaces |
67 | */ | 66 | */ |
68 | int count() const; | 67 | int count() const; |
69 | /** | 68 | /** |
70 | * @returns a pointer to the (one and only) @ref OSystem instance. | 69 | * @returns a pointer to the (one and only) @ref OSystem instance. |
71 | */ | 70 | */ |
72 | static OSoundSystem* instance(); | 71 | static OSoundSystem* instance(); |
73 | /** | 72 | /** |
74 | * @returns an iterator usable for iterating through all sound cards. | 73 | * @returns an iterator usable for iterating through all sound cards. |
75 | */ | 74 | */ |
76 | CardIterator iterator() const; | 75 | CardIterator iterator() const; |
77 | /** | 76 | /** |
78 | * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found | 77 | * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found |
79 | * @see OAudioInterface | 78 | * @see OAudioInterface |
80 | */ | 79 | */ |
81 | OSoundCard* card( const QString& interface ) const; | 80 | OSoundCard* card( const QString& interface ) const; |
82 | /** | 81 | /** |
83 | * @internal Rebuild the internal interface database | 82 | * @internal Rebuild the internal interface database |
84 | * @note Sometimes it might be useful to call this from client code, | 83 | * @note Sometimes it might be useful to call this from client code, |
85 | * e.g. after issuing a cardctl insert | 84 | * e.g. after issuing a cardctl insert |
86 | */ | 85 | */ |
87 | void synchronize(); | 86 | void synchronize(); |
88 | 87 | ||
89 | protected: | 88 | protected: |
90 | OSoundSystem(); | 89 | OSoundSystem(); |
91 | 90 | ||
92 | private: | 91 | private: |
93 | static OSoundSystem* _instance; | 92 | static OSoundSystem* _instance; |
94 | CardMap _interfaces; | 93 | CardMap _interfaces; |
95 | class Private; | 94 | class Private; |
96 | Private *d; | 95 | Private *d; |
97 | }; | 96 | }; |
98 | 97 | ||
99 | 98 | ||
100 | /*====================================================================================== | 99 | /*====================================================================================== |
101 | * OSoundCard | 100 | * OSoundCard |
102 | *======================================================================================*/ | 101 | *======================================================================================*/ |
103 | 102 | ||
104 | class OSoundCard : public QObject | 103 | class OSoundCard : public QObject |
105 | { | 104 | { |
106 | Q_OBJECT | 105 | Q_OBJECT |
107 | 106 | ||
108 | public: | 107 | public: |
109 | /** | 108 | /** |
110 | * Constructor. Normally you don't create @ref OSoundCard objects yourself, | 109 | * Constructor. Normally you don't create @ref OSoundCard objects yourself, |
111 | * but access them via @ref OSoundSystem::card(). | 110 | * but access them via @ref OSoundSystem::card(). |
112 | */ | 111 | */ |
113 | OSoundCard( QObject* parent, const char* name ); | 112 | OSoundCard( QObject* parent, const char* name ); |
114 | /** | 113 | /** |
115 | * Destructor. | 114 | * Destructor. |
116 | */ | 115 | */ |
117 | virtual ~OSoundCard(); | 116 | virtual ~OSoundCard(); |
118 | 117 | ||
119 | bool hasMixer() const { return _audio; }; | 118 | bool hasMixer() const { return _audio; }; |
120 | bool hasAudio() const { return _mixer; }; | 119 | bool hasAudio() const { return _mixer; }; |
121 | 120 | ||
122 | OAudioInterface* audio() const { return _audio; }; | 121 | OAudioInterface* audio() const { return _audio; }; |
123 | OMixerInterface* mixer() const { return _mixer; }; | 122 | OMixerInterface* mixer() const { return _mixer; }; |
124 | 123 | ||
125 | protected: | 124 | protected: |
126 | OAudioInterface* _audio; | 125 | OAudioInterface* _audio; |
127 | OMixerInterface* _mixer; | 126 | OMixerInterface* _mixer; |
128 | 127 | ||
129 | private: | 128 | private: |
130 | void init(); | 129 | void init(); |
131 | private: | 130 | private: |
132 | class Private; | 131 | class Private; |
133 | Private *d; | 132 | Private *d; |
134 | }; | 133 | }; |
135 | 134 | ||
136 | /*====================================================================================== | 135 | /*====================================================================================== |
137 | * OAudioInterface | 136 | * OAudioInterface |
138 | *======================================================================================*/ | 137 | *======================================================================================*/ |
139 | 138 | ||
140 | class OAudioInterface : public QObject | 139 | class OAudioInterface : public QObject |
141 | { | 140 | { |
142 | Q_OBJECT | 141 | Q_OBJECT |
143 | 142 | ||
144 | public: | 143 | public: |
145 | /** | 144 | /** |
146 | * Constructor. Normally you don't create @ref OAudioInterface objects yourself, | 145 | * Constructor. Normally you don't create @ref OAudioInterface objects yourself, |
147 | * but access them via the @ref OSoundCard interface. | 146 | * but access them via the @ref OSoundCard interface. |
148 | */ | 147 | */ |
149 | OAudioInterface( QObject* parent, const char* name ); | 148 | OAudioInterface( QObject* parent, const char* name ); |
150 | /** | 149 | /** |
151 | * Destructor. | 150 | * Destructor. |
152 | */ | 151 | */ |
153 | virtual ~OAudioInterface(); | 152 | virtual ~OAudioInterface(); |
154 | 153 | ||
155 | protected: | 154 | protected: |
156 | const int _sfd; | 155 | const int _sfd; |
157 | 156 | ||
158 | private: | 157 | private: |
159 | void init(); | 158 | void init(); |
160 | private: | 159 | private: |
161 | class Private; | 160 | class Private; |
162 | Private *d; | 161 | Private *d; |
163 | }; | 162 | }; |
164 | 163 | ||
165 | 164 | ||
166 | /*====================================================================================== | 165 | /*====================================================================================== |
167 | * OMixerInterface | 166 | * OMixerInterface |
168 | *======================================================================================*/ | 167 | *======================================================================================*/ |
169 | 168 | ||
170 | class OMixerInterface : public QObject | 169 | class OMixerInterface : public QObject |
171 | { | 170 | { |
172 | Q_OBJECT | 171 | Q_OBJECT |
173 | 172 | ||
174 | public: | 173 | public: |
175 | 174 | ||
176 | typedef QMap<QString,int>::ConstIterator ChannelIterator; | 175 | typedef QMap<QString,int>::ConstIterator ChannelIterator; |
177 | 176 | ||
178 | /** | 177 | /** |
179 | * Constructor. Normally you don't create @ref OMixerInterface objects yourself, | 178 | * Constructor. Normally you don't create @ref OMixerInterface objects yourself, |
180 | * but access them via the @ref OSoundCard interface. | 179 | * but access them via the @ref OSoundCard interface. |
181 | */ | 180 | */ |
182 | OMixerInterface( QObject* parent, const char* name ); | 181 | OMixerInterface( QObject* parent, const char* name ); |
183 | /** | 182 | /** |
184 | * Destructor. | 183 | * Destructor. |
185 | */ | 184 | */ |
186 | virtual ~OMixerInterface(); | 185 | virtual ~OMixerInterface(); |
187 | 186 | ||
188 | /** | 187 | /** |
189 | * @returns all available channels. | 188 | * @returns all available channels. |
190 | */ | 189 | */ |
191 | QStringList allChannels() const; | 190 | QStringList allChannels() const; |
192 | /** | 191 | /** |
193 | * @returns recordable channels. | 192 | * @returns recordable channels. |
194 | */ | 193 | */ |
195 | QStringList recChannels() const; | 194 | QStringList recChannels() const; |
196 | /** | 195 | /** |
197 | * @returns playable channels. | 196 | * @returns playable channels. |
198 | */ | 197 | */ |
199 | QStringList playChannels() const; | 198 | QStringList playChannels() const; |
200 | /** | 199 | /** |
201 | * @returns true, if the device features multiple recording sources. | 200 | * @returns true, if the device features multiple recording sources. |
202 | */ | 201 | */ |
203 | bool hasMultipleRecording() const; | 202 | bool hasMultipleRecording() const; |
204 | /** | 203 | /** |
205 | * @returns true, if @a channel exists. | 204 | * @returns true, if @a channel exists. |
206 | */ | 205 | */ |
207 | bool hasChannel( const QString& channel ) const; | 206 | bool hasChannel( const QString& channel ) const; |
208 | /** | 207 | /** |
209 | * @returns true, if @a channel is stereo. | 208 | * @returns true, if @a channel is stereo. |
210 | */ | 209 | */ |
211 | bool isStereo( const QString& channel ) const; | 210 | bool isStereo( const QString& channel ) const; |
212 | /** | 211 | /** |
213 | * @returns tru, if @a channel is a possible recording source. | 212 | * @returns tru, if @a channel is a possible recording source. |
214 | */ | 213 | */ |
215 | bool isRecordable( const QString& channel ) const; | 214 | bool isRecordable( const QString& channel ) const; |
216 | /** | 215 | /** |
217 | * Set the @a left and @a right volumes for @a channel. | 216 | * Set the @a left and @a right volumes for @a channel. |
218 | * If no value for right is given, the value for left is taken for that. | 217 | * If no value for right is given, the value for left is taken for that. |
219 | */ | 218 | */ |
220 | void setVolume( const QString& channel, int left, int right = -1 ); | 219 | void setVolume( const QString& channel, int left, int right = -1 ); |
221 | /** | 220 | /** |
222 | * @returns the volume of @a channel or -1, if the channel doesn't exist. | 221 | * @returns the volume of @a channel or -1, if the channel doesn't exist. |
223 | * @note You might want to use @ref hasChannel() to check if a channel exists. | 222 | * @note You might want to use @ref hasChannel() to check if a channel exists. |
224 | */ | 223 | */ |
225 | int volume( const QString& channel ) const; | 224 | int volume( const QString& channel ) const; |
226 | 225 | ||
227 | protected: | 226 | protected: |
228 | int _fd; | 227 | int _fd; |
229 | int _capmask; | 228 | int _capmask; |
230 | int _devmask; | 229 | int _devmask; |
231 | int _recmask; | 230 | int _recmask; |
232 | int _stmask; | 231 | int _stmask; |
233 | QMap<QString,int> _channels; | 232 | QMap<QString,int> _channels; |
234 | 233 | ||
235 | private: | 234 | private: |
236 | void init(); | 235 | void init(); |
237 | private: | 236 | private: |
238 | class Private; | 237 | class Private; |
239 | Private *d; | 238 | Private *d; |
240 | }; | 239 | }; |
241 | 240 | ||
242 | } | 241 | } |
243 | } | 242 | } |
244 | 243 | ||
245 | #endif // OSOUNDSYSTEM_H | 244 | #endif // OSOUNDSYSTEM_H |