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.
27 #include "core/MediaController.h"
28 #include "core/volume.h"
33 class DBusControlWrapper;
37 #include <kconfiggroup.h>
45 * This is the abstraction of a single control of a sound card, e.g. the PCM control. A control
46 * can contain the 5 following subcontrols: playback-volume, capture-volume, playback-switch,
47 * capture-switch and enumeration.
49 The class is called MixDevice for historical reasons. Today it is just the Synonym for "Control".
51 Design hint: In the past I (esken) considered merging the MixDevice and Volume classes.
52 I finally decided against it, as it seems better to have the MixDevice being the container
53 for the embedded subcontrol(s). These could be either Volume, Enum or some virtual MixDevice.
55 class MixDevice : public QObject
60 // For each ChannelType a special icon exists
61 enum ChannelType { AUDIO = 1,
82 MICROPHONE_FRONT_BOOST,
87 // Some specific applications
92 APPLICATION_CLEMENTINE,
93 // Hint: VLC still has compatibility problems:
94 // 2.0 is not detected
95 // 2.2-nightly has volume issues (total overdrive)
99 enum SwitchType { OnOff, Mute, Capture, Activator };
102 * Constructor for a MixDevice.
103 * After having constructed a MixDevice, you <b>must</b> add it to the ControlPool
104 * by calling addToPool(). You may then <b>not</b> delete this object.
106 * @par mixer The mixer this control belongs to
107 * @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.
108 * It is advised to set a nice name, like 'PCM:2', which would mean
109 * "2nd PCM device of the sound card". The ID's may NOT contain whitespace.
110 * The Creator (normally the backend) MUST pass distinct ID's for each MixDevices of one card.
112 * Virtual Controls (controls not created by a backend) are prefixed with "KMix::", e.g.
113 * "KMix::RecSelector:0"
114 * @par name is the readable name. This one is presented to the user in the GUI
115 * @par type The control type. It is only used to find an appropriate icon
117 MixDevice( Mixer* mixer, const QString& id, const QString& name, ChannelType type );
118 MixDevice( Mixer* mixer, const QString& id, const QString& name, const QString& iconName = "", MixSet* moveDestinationMixSet = 0 );
123 std::shared_ptr<MixDevice> addToPool();
125 const QString& iconName() const { return _iconName; }
127 void addPlaybackVolume(Volume &playbackVol);
128 void addCaptureVolume (Volume &captureVol);
129 void addEnums (QList<QString*>& ref_enumList);
131 // Media controls. New for KMix 4.0
132 MediaController* getMediaController();
133 // TODO move all media player controls to the MediaController class
138 // Returns a user readable name of the control.
139 QString readableName() { return _name; }
140 // Sets a user readable name for the control.
141 void setReadableName(QString& name) { _name = name; }
143 QString configGroupName(QString prefix);
146 * Returns an ID of this MixDevice, as passed in the constructor. The Creator (normally the backend)
147 * MUST ensure that all MixDevices's of one card have unique ID's.
148 * The ID is used through the whole KMix application (including the config file) for identifying controls.
151 const QString& id() const;
152 QString getFullyQualifiedId();
155 * Returns the DBus path for this MixDevice
157 const QString dbusPath();
159 // Returns the associated mixer
160 Mixer* mixer() { return _mixer; }
162 // operator==() is used currently only for duplicate detection with QList's contains() method
163 bool operator==(const MixDevice& other) const;
165 // Methods for handling the switches. This methods are useful, because the Switch in the Volume object
166 // is an abstract concept. It places no interpretation on the meaning of the switch (e.g. does "switch set" mean
167 // "mute on", or does it mean "playback on", or "Capture active", or ...
168 virtual bool isMuted();
169 virtual bool isVirtuallyMuted();
170 virtual void setMuted(bool value);
171 virtual bool hasMuteSwitch();
172 virtual void toggleMute();
173 virtual bool isRecSource();
174 virtual bool isNotRecSource();
175 virtual void setRecSource(bool value);
176 virtual bool isEnum();
178 * Returns whether this is an application stream.
180 virtual bool isApplicationStream() const { return _applicationStream; };
182 * Mark this MixDevice as application stream
184 void setApplicationStream(bool applicationStream) { _applicationStream = applicationStream; }
186 bool isMovable() const
188 return (0 != _moveDestinationMixSet);
190 MixSet *getMoveDestinationMixSet() const
192 return _moveDestinationMixSet;
195 bool isArtificial() const
199 void setArtificial(bool artificial)
201 _artificial = artificial;
204 void setControlProfile(ProfControl* control);
205 ProfControl* controlProfile();
207 virtual Volume& playbackVolume();
208 virtual Volume& captureVolume();
211 unsigned int enumId();
212 QList<QString>& enumValues();
214 bool hasPhysicalMuteSwitch();
216 bool read( KConfig *config, const QString& grp );
217 bool write( KConfig *config, const QString& grp );
218 int getUserfriendlyVolumeLevel();
220 void increaseOrDecreaseVolume(bool decrease, Volume::VolumeTypeFlag volumeType);
223 void init( Mixer* mixer, const QString& id, const QString& name, const QString& iconName, MixSet* moveDestinationMixSet );
226 QString getVolString(Volume::ChannelID chid, bool capture);
228 Volume _playbackVolume;
229 Volume _captureVolume;
231 QList<QString> _enumValues; // A MixDevice, that is an ENUM, has these _enumValues
233 DBusControlWrapper *_dbusControlWrapper;
234 MediaController* mediaController;
236 // A virtual control. It will not be saved/restored and/or doesn't get shortcuts
237 // Actually we discriminate those "virtual" controls in artificial controls and dynamic controls:
238 // Type Shortcut Restore
239 // Artificial: yes no Virtual::GlobalMaster or Virtual::CaptureGroup_3 (controls that are constructed artificially from other controls)
240 // Dynamic : no no Controls that come and go, like Pulse Stream controls
242 MixSet *_moveDestinationMixSet;
244 bool _applicationStream;
246 QString _name; // Channel name
247 QString _id; // Primary key, used as part in config file keys
248 ProfControl *_profControl;
250 void readPlaybackOrCapture(const KConfigGroup& config, bool capture);
251 void writePlaybackOrCapture(KConfigGroup& config, bool capture);