~ubuntu-branches/ubuntu/natty/kdemultimedia/natty-proposed

« back to all changes in this revision

Viewing changes to kmix/mixdevice.h

  • Committer: Bazaar Package Importer
  • Author(s): Debian Qt/KDE Maintainers
  • Date: 2011-05-26 02:41:36 UTC
  • mfrom: (0.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 108.
  • Revision ID: james.westby@ubuntu.com-20110526024136-jjwsigfy402jhupm
Tags: upstream-4.6.3
ImportĀ upstreamĀ versionĀ 4.6.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//-*-C++-*-
2
 
/*
3
 
 * KMix -- KDE's full featured mini mixer
4
 
 *
5
 
 * Copyright Christian Esken <esken@kde.org>
6
 
 *
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.
11
 
 *
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.
16
 
 *
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.
20
 
 */
21
 
#ifndef MixDevice_h
22
 
#define MixDevice_h
23
 
 
24
 
//KMix
25
 
class Mixer;
26
 
#include "volume.h"
27
 
 
28
 
// KDE
29
 
#include <kconfig.h>
30
 
#include <kconfiggroup.h>
31
 
 
32
 
// Qt
33
 
#include <QList>
34
 
#include <QObject>
35
 
#include <QString>
36
 
 
37
 
 
38
 
// !!! This SHOULD be subclassed (MixDeviceVolume, MixDeviceEnum).
39
 
//     The isEnum() works out OK as a workaround, but it is insane
40
 
//     in the long run.
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.
44
 
 
45
 
/**
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.
49
 
 
50
 
   The class is called MixDevice for historical reasons. Today it is just the Synonym for "Control".
51
 
 
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.
55
 
 */
56
 
class MixDevice : public QObject
57
 
{
58
 
Q_OBJECT
59
 
 
60
 
public:
61
 
    // For each ChannelType a special icon exists
62
 
    enum ChannelType { AUDIO = 1,
63
 
                       BASS,
64
 
                       CD,
65
 
                       EXTERNAL,
66
 
                       MICROPHONE,
67
 
                       MIDI,
68
 
                       RECMONITOR,
69
 
                       TREBLE,
70
 
                       UNKNOWN,
71
 
                       VOLUME,
72
 
                       VIDEO,
73
 
                       SURROUND,
74
 
                       HEADPHONE,
75
 
                       DIGITAL,
76
 
                       AC97,
77
 
                       SURROUND_BACK,
78
 
                       SURROUND_LFE,
79
 
                       SURROUND_CENTERFRONT,
80
 
                       SURROUND_CENTERBACK,
81
 
                       SPEAKER,
82
 
                       MICROPHONE_BOOST,
83
 
                       MICROPHONE_FRONT_BOOST,
84
 
                       MICROPHONE_FRONT
85
 
                     };
86
 
 
87
 
   enum SwitchType { OnOff, Mute, Capture, Activator };
88
 
 
89
 
   /**
90
 
    * Constructor:
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.
96
 
    *
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
101
 
    */
102
 
   MixDevice( Mixer* mixer, const QString& id, const QString& name, ChannelType type = UNKNOWN );
103
 
   ~MixDevice();
104
 
 
105
 
   void addPlaybackVolume(Volume &playbackVol);
106
 
   void addCaptureVolume (Volume &captureVol);
107
 
   void addEnums (QList<QString*>& ref_enumList);
108
 
 
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; }
113
 
 
114
 
   /**
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.
118
 
   */
119
 
   const QString& id() const;
120
 
 
121
 
   // Returns the associated mixer
122
 
   Mixer* mixer() { return _mixer; }
123
 
 
124
 
   // operator==() is used currently only for duplicate detection with QList's contains() method
125
 
   bool operator==(const MixDevice& other) const;
126
 
 
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 ); }
134
 
 
135
 
   bool isEnum()                   { return ( ! _enumValues.empty() ); }
136
 
 
137
 
 
138
 
   Volume& playbackVolume();
139
 
   Volume& captureVolume();
140
 
 
141
 
   void setEnumId(int);
142
 
   unsigned int enumId();
143
 
   QList<QString>& enumValues();
144
 
 
145
 
   virtual void read( KConfig *config, const QString& grp );
146
 
   virtual void write( KConfig *config, const QString& grp );
147
 
 
148
 
   ChannelType type() { return _type; }
149
 
 
150
 
private:
151
 
   Mixer *_mixer;
152
 
   Volume _playbackVolume;
153
 
   Volume _captureVolume;
154
 
   int _enumCurrentId;
155
 
   QList<QString> _enumValues; // A MixDevice, that is an ENUM, has these _enumValues
156
 
 
157
 
   ChannelType _type;
158
 
 
159
 
   QString _name;   // Channel name
160
 
   QString _id;     // Primary key, used as part in config file keys
161
 
 
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);
164
 
 
165
 
};
166
 
 
167
 
#endif