summaryrefslogtreecommitdiff
path: root/libopie2/opiemm/osoundsystem.h
blob: 1e48f5cb8a2d454cbf82f770e36b6f7f32106c9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
                             This file is part of the Opie Project
              =.             (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
            .=l.
           .>+-=
 _;:,     .>    :=|.         This program is free software; you can
.> <`_,   >  .   <=          redistribute it and/or  modify it under
:`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
.="- .-=="i,     .._         License as published by the Free Software
 - .   .-<_>     .<>         Foundation; version 2 of the License.
     ._= =}       :
    .%`+i>       _;_.
    .i_,=:_.      -<s.       This program is distributed in the hope that
     +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
    : ..    .:,     . . .    without even the implied warranty of
    =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ;      Library General Public License for more
++=   -.     .`     .:       details.
 :     =  ...= . :.=-
 -.   .:....=;==+<;          You should have received a copy of the GNU
  -_. . .   )=.  =           Library General Public License along with
    --        :-=`           this library; see the file COPYING.LIB.
                             If not, write to the Free Software Foundation,
                             Inc., 59 Temple Place - Suite 330,
                             Boston, MA 02111-1307, USA.

*/

#ifndef OSOUNDSYSTEM_H
#define OSOUNDSYSTEM_H

#include <qobject.h>
#include <qdict.h>
#include <qmap.h>

namespace Opie {
namespace MM {

class OAudioInterface;
class OMixerInterface;
class OSoundCard;

/*======================================================================================
 * OSoundSystem
 *======================================================================================*/

/**
 * @brief A container class for the Linux OSS/ALSA audio subsystem
 *
 * This class provides access to all available audio/midi/sequencer interfaces of your device.
 *
 * @author Michael 'Mickey' Lauer <mickey@Vanille.de>
 */
class OSoundSystem : public QObject
{
  Q_OBJECT

  public:
    typedef QDict<OSoundCard> CardMap;
    typedef QDictIterator<OSoundCard> CardIterator;

  public:
    /**
     * @returns the number of available interfaces
     */
    int count() const;
    /**
     * @returns a pointer to the (one and only) @ref OSystem instance.
     */
    static OSoundSystem* instance();
    /**
     * @returns an iterator usable for iterating through all sound cards.
     */
    CardIterator iterator() const;
    /**
     * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found
     * @see OAudioInterface
     */
    OSoundCard* card( const QString& interface ) const;
    /**
     * @internal Rebuild the internal interface database
     * @note Sometimes it might be useful to call this from client code,
     * e.g. after issuing a cardctl insert
     */
    void synchronize();

  protected:
    OSoundSystem();

  private:
    static OSoundSystem* _instance;
    CardMap _interfaces;
    class Private;
    Private *d;
};


/*======================================================================================
 * OSoundCard
 *======================================================================================*/

class OSoundCard : public QObject
{
  Q_OBJECT

  public:
    /**
     * Constructor. Normally you don't create @ref OSoundCard objects yourself,
     * but access them via @ref OSoundSystem::card().
     */
    OSoundCard( QObject* parent, const char* name );
    /**
     * Destructor.
     */
    virtual ~OSoundCard();

    bool hasMixer() const { return _audio; };
    bool hasAudio() const { return _mixer; };

    OAudioInterface* audio() const { return _audio; };
    OMixerInterface* mixer() const { return _mixer; };

  protected:
    OAudioInterface* _audio;
    OMixerInterface* _mixer;

  private:
    void init();
  private:
    class Private;
    Private *d;
};

/*======================================================================================
 * OAudioInterface
 *======================================================================================*/

class OAudioInterface : public QObject
{
  Q_OBJECT

  public:
    /**
     * Constructor. Normally you don't create @ref OAudioInterface objects yourself,
     * but access them via the @ref OSoundCard interface.
     */
    OAudioInterface( QObject* parent, const char* name );
    /**
     * Destructor.
     */
    virtual ~OAudioInterface();

  protected:
    const int _sfd;

  private:
    void init();
  private:
    class Private;
    Private *d;
};


/*======================================================================================
 * OMixerInterface
 *======================================================================================*/

class OMixerInterface : public QObject
{
  Q_OBJECT

  public:

    typedef QMap<QString,int>::ConstIterator ChannelIterator;

    /**
     * Constructor. Normally you don't create @ref OMixerInterface objects yourself,
     * but access them via the @ref OSoundCard interface.
     */
    OMixerInterface( QObject* parent, const char* name );
    /**
     * Destructor.
     */
    virtual ~OMixerInterface();

    /**
     * @returns all available channels.
     */
    QStringList allChannels() const;
    /**
     * @returns recordable channels.
     */
    QStringList recChannels() const;
    /**
     * @returns playable channels.
     */
    QStringList playChannels() const;
    /**
     * @returns true, if the device features multiple recording sources.
     */
    bool hasMultipleRecording() const;
    /**
     * @returns true, if @a channel exists.
     */
    bool hasChannel( const QString& channel ) const;
    /**
     * @returns true, if @a channel is stereo.
     */
    bool isStereo( const QString& channel ) const;
    /**
     * @returns tru, if @a channel is a possible recording source.
     */
    bool isRecordable( const QString& channel ) const;
    /**
     * Set the @a left and @a right volumes for @a channel.
     * If no value for right is given, the value for left is taken for that.
     */
    void setVolume( const QString& channel, int left, int right = -1 );
    /**
     * @returns the volume of @a channel or -1, if the channel doesn't exist.
     * @note You might want to use @ref hasChannel() to check if a channel exists.
     */
    int volume( const QString& channel ) const;

  protected:
    int _fd;
    int _capmask;
    int _devmask;
    int _recmask;
    int _stmask;
    QMap<QString,int> _channels;

  private:
    void init();
  private:
    class Private;
    Private *d;
};

}
}

#endif // OSOUNDSYSTEM_H