3
* KMix -- KDE's full featured mini mixer
5
* Copyright Christian Esken <esken@kde.org>
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Library General Public
9
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Library General Public License for more details.
17
* You should have received a copy of the GNU Library General Public
18
* License along with this program; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30
#include <kconfiggroup.h>
38
// !!! This SHOULD be subclassed (MixDeviceVolume, MixDeviceEnum).
39
// The isEnum() works out OK as a workaround, but it is insane
41
// Additionally there might be Implementations for virtual MixDevice's, e.g.
42
// MixDeviceRecselector, MixDeviceCrossfader.
43
// I am not sure if a MixDeviceBalancing would work out.
46
* This is the abstraction of a single control of a sound card, e.g. the PCM control. A control
47
* can contain the 5 following subcontrols: playback-volume, capture-volume, playback-switch,
48
* capture-switch and enumeration.
50
The class is called MixDevice for historical reasons. Today it is just the Synonym for "Control".
52
Design hint: In the past I (esken) considered merging the MixDevice and Volume classes.
53
I finally decided against it, as it seems better to have the MixDevice being the container
54
for the embedded subcontrol(s). These could be either Volume, Enum or some virtual MixDevice.
56
class MixDevice : public QObject
61
// For each ChannelType a special icon exists
62
enum ChannelType { AUDIO = 1,
83
MICROPHONE_FRONT_BOOST,
87
enum SwitchType { OnOff, Mute, Capture, Activator };
91
* @par mixer The mixer this control belongs to
92
* @par id Defines the ID, e.g. used in looking up the keys in kmixrc. Also it is used heavily inside KMix as unique key.
93
* It is advised to set a nice name, like 'PCM:2', which would mean
94
* "2nd PCM device of the sound card". The ID's may NOT contain whitespace.
95
* The Creator (normally the backend) MUST pass distinct ID's for each MixDevices of one card.
97
* Virtual Controls (controls not created by a backend) are prefixed with "KMix::", e.g.
98
* "KMix::RecSelector:0"
99
* @par name is the readable name. This one is presented to the user in the GUI
100
* @par type The control type. It is only used to find an appropriate icon
102
MixDevice( Mixer* mixer, const QString& id, const QString& name, ChannelType type = UNKNOWN );
105
void addPlaybackVolume(Volume &playbackVol);
106
void addCaptureVolume (Volume &captureVol);
107
void addEnums (QList<QString*>& ref_enumList);
109
// Returns a user readable name of the control.
110
QString readableName() { return _name; }
111
// Sets a user readable name for the control.
112
void setReadableName(QString& name) { _name = name; }
115
* Returns an ID of this MixDevice, as passed in the constructor. The Creator (normally the backend)
116
* MUST ensure that all MixDevices's of one card have unique ID's.
117
* The ID is used through the whole KMix application (including the config file) for identifying controls.
119
const QString& id() const;
121
// Returns the associated mixer
122
Mixer* mixer() { return _mixer; }
124
// operator==() is used currently only for duplicate detection with QList's contains() method
125
bool operator==(const MixDevice& other) const;
127
// Methods for handling the switches. This methods are useful, because the Sswitch in the Volume object
128
// is an abstract concept. It places no interpration on the meaning of the switch (e.g. does "switch set" mean
129
// "mute on", or does it mean "playback on".
130
bool isMuted() { return ( _playbackVolume.hasSwitch() && ! _playbackVolume.isSwitchActivated() ); }
131
void setMuted(bool value) { _playbackVolume.setSwitch( ! value ); }
132
bool isRecSource() { return ( _captureVolume.hasSwitch() && _captureVolume.isSwitchActivated() ); }
133
void setRecSource(bool value) { _captureVolume.setSwitch( value ); }
135
bool isEnum() { return ( ! _enumValues.empty() ); }
138
Volume& playbackVolume();
139
Volume& captureVolume();
142
unsigned int enumId();
143
QList<QString>& enumValues();
145
virtual void read( KConfig *config, const QString& grp );
146
virtual void write( KConfig *config, const QString& grp );
148
ChannelType type() { return _type; }
152
Volume _playbackVolume;
153
Volume _captureVolume;
155
QList<QString> _enumValues; // A MixDevice, that is an ENUM, has these _enumValues
159
QString _name; // Channel name
160
QString _id; // Primary key, used as part in config file keys
162
void readPlaybackOrCapture(const KConfigGroup& config, const char* nameLeftVolume, const char* nameRightVolume, bool capture);
163
void writePlaybackOrCapture(KConfigGroup& config, const char* nameLeftVolume, const char* nameRightVolume, bool capture);