3
* KMix -- KDE's full featured mini mixer
6
* Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de>
7
* 1996-2000 Christian Esken <esken@kde.org>
8
* Sven Fischer <herpes@kawo2.rwth-aachen.de>
10
* This program is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Library General Public
12
* License as published by the Free Software Foundation; either
13
* version 2 of the License, or (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
* Library General Public License for more details.
20
* You should have received a copy of the GNU Library General Public
21
* License along with this program; if not, write to the Free
22
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36
I am using a fixed MAX_MIXDEVS #define here.
37
People might argue, that I should rather use the SOUND_MIXER_NRDEVICES
38
#define used by OSS. But using this #define is not good, because it is
39
evaluated during compile time. Compiling on one platform and running
40
on another with another version of OSS with a different value of
41
SOUND_MIXER_NRDEVICES is very bad. Because of this, usage of
42
SOUND_MIXER_NRDEVICES should be discouraged.
44
The #define below is only there for internal reasons.
45
In other words: Don't play around with this value
47
#define MAX_MIXDEVS 32
55
// For each ChannelType a special icon exists
56
enum ChannelType {AUDIO = 1, BASS, CD, EXTERNAL, MICROPHONE,
57
MIDI, RECMONITOR, TREBLE, UNKNOWN, VOLUME,
60
MixDevice(int num, Volume vol, bool recordable,
61
QString name, ChannelType type = UNKNOWN );
62
MixDevice(const MixDevice &md);
65
int num() const { return m_num; };
66
QString name() const { return m_name; };
67
bool isStereo() const { return (m_volume.channels() > 1); };
68
bool isRecordable() const { return m_recordable; };
69
bool isRecsrc() const { return m_recsrc; };
70
bool isMuted() const { return m_volume.isMuted(); };
72
void setMuted(bool value) { m_volume.setMuted( value ); };
73
void setRecsrc(bool value) { m_recsrc = value; };
74
void setVolume( Volume volume ) { m_volume = volume; };
75
void setVolume( int channel, int volume );
76
int getVolume( int channel ) const;
77
Volume getVolume() const { return m_volume; };
78
int rightVolume() const;
79
int leftVolume() const;
81
void read( KConfig *config, const QString& grp );
82
void write( KConfig *config, const QString& grp );
84
void setType( ChannelType channeltype ) { m_type = channeltype; };
85
ChannelType type() { return m_type; };
90
int m_num; // ioctl() device number of mixer
91
bool m_recordable; // Can it be recorded?
92
bool m_recsrc; // Is it an actual record source?
93
QString m_name; // Ascii channel name
97
class MixSet : public QList<MixDevice>
100
void read( KConfig *config, const QString& grp );
101
void write( KConfig *config, const QString& grp );
103
void clone( MixSet &orig );
105
QString name() { return m_name; };
106
void setName( const QString &name ) { m_name = name; };
113
class Mixer : public QObject
118
enum MixerError { ERR_PERM=1, ERR_WRITE, ERR_READ, ERR_NODEV, ERR_NOTSUPP,
119
ERR_OPEN, ERR_LASTERR, ERR_NOMEM, ERR_INCOMPATIBLESET };
121
Mixer( int device = -1, int card = -1 );
124
/// Static function. This function must be overloaded by any derived mixer class
125
/// to create and return an instance of the derived class.
126
static int getDriverNum();
127
static Mixer* getMixer( int driver, int device = 0, int card = 0 );
128
static Mixer* getMixer( int driver, MixSet set,int device = 0, int card = 0 );
130
void volumeSave( KConfig *config );
131
void volumeLoad( KConfig *config );
133
/// Tells the number of the mixing devices
134
unsigned int size() const;
135
/// Returns a pointer to the mix device with the given number
136
MixDevice* operator[](int val_i_num);
138
/// Grabs (opens) the mixer for further intraction
140
/// Releases (closes) the mixer
141
virtual int release();
142
/// Prints out a translated error text for the given error number on stderr
143
void errormsg(int mixer_error);
144
/// Returns a translated error text for the given error number.
145
/// Derived classes can override this method to produce platform
146
/// specific error descriptions.
147
virtual QString errorText(int mixer_error);
150
/// set/get mixer number used to identify mixers with equal names
151
void setMixerNum( int num );
154
/// get the actual MixSet
155
virtual MixSet getMixSet() { return m_mixDevices; };
156
/// Write a given MixSet to hardware
157
virtual void writeMixSet( MixSet set );
159
/// Set the record source(s) according to the given device mask
160
/// The default implementation does nothing.
162
/// Gets the currently active record source(s) as a device mask
163
/// The default implementation just returns the internal stored value.
164
/// This value can be outdated, when another applications change the record
165
/// source. You can override this in your derived class
166
// virtual unsigned int recsrc() const;
168
/// Returns the number of the master volume device */
169
int masterDevice() { return m_masterDevice; };
171
/// Reads the volume of the given device into VolLeft and VolRight.
172
/// Abstract method! You must implement it in your dericved class.
173
virtual int readVolumeFromHW( int devnum, Volume &vol ) = 0;
177
/// Writes the given volumes in the given device
178
/// Abstract method! You must implement it in your dericved class.
179
virtual int writeVolumeToHW( int devnum, Volume volume ) = 0;
180
virtual void readSetFromHW();
182
virtual void setBalance(int balance); // sets the m_balance (see there)
183
virtual void setRecsrc( int devnum, bool on = true);
186
void newBalance( Volume );
187
void newRecsrc( void );
192
int m_masterDevice; // device num for master volume
193
/// Derived classes MUST implement this to open the mixer. Returns a KMix error
195
virtual int openMixer() = 0;
196
virtual int releaseMixer() = 0;
198
virtual bool setRecsrcHW( int devnum, bool on) = 0;
199
virtual bool isRecsrcHW( int devnum ) = 0;
201
/// User friendly name of the Mixer (e.g. "IRIX Audio Mixer"). If your mixer API
202
/// gives you a usable name, use that name.
205
// mixer number to identify mixers with equal name correctly (set by the client)
209
int m_balance; // from -100 (just left) to 100 (just right)
211
// All mix devices of this phyisical device.
214
QList<MixSet> m_profiles;
217
int setupMixer() { return setupMixer( m_mixDevices ); };
218
int setupMixer( MixSet set );