~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to kmix/mixer.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

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
 *
 
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>
 
9
 *
 
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.
 
14
 *
 
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.
 
19
 *
 
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.
 
23
 */
 
24
 
 
25
#ifndef MIXER_H
 
26
#define MIXER_H
 
27
 
 
28
#include <qstring.h>
 
29
#include <qobject.h>
 
30
#include <qintdict.h>
 
31
#include <qlist.h>
 
32
 
 
33
#include "volume.h"
 
34
 
 
35
/*
 
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.
 
43
 
 
44
   The #define below is only there for internal reasons.
 
45
   In other words: Don't play around with this value
 
46
 */
 
47
#define MAX_MIXDEVS 32
 
48
 
 
49
class Volume;
 
50
class KConfig;
 
51
 
 
52
class MixDevice
 
53
{
 
54
   public:
 
55
      // For each ChannelType a special icon exists
 
56
      enum ChannelType {AUDIO = 1, BASS, CD, EXTERNAL, MICROPHONE,
 
57
                        MIDI, RECMONITOR, TREBLE, UNKNOWN, VOLUME,
 
58
                        VIDEO, SURROUND};
 
59
 
 
60
      MixDevice(int num, Volume vol, bool recordable,
 
61
                QString name, ChannelType type = UNKNOWN );
 
62
      MixDevice(const MixDevice &md);
 
63
      ~MixDevice() {};
 
64
 
 
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(); };
 
71
 
 
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;
 
80
 
 
81
      void read( KConfig *config, const QString& grp );
 
82
      void write( KConfig *config, const QString& grp );
 
83
 
 
84
      void setType( ChannelType channeltype ) { m_type = channeltype; };
 
85
      ChannelType type() { return m_type; };
 
86
 
 
87
   protected:
 
88
      Volume m_volume;
 
89
      ChannelType 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
 
94
};
 
95
 
 
96
 
 
97
class MixSet : public QList<MixDevice>
 
98
{
 
99
   public:
 
100
      void read( KConfig *config, const QString& grp );
 
101
      void write( KConfig *config, const QString& grp );
 
102
 
 
103
      void clone( MixSet &orig );
 
104
 
 
105
      QString name() { return m_name; };
 
106
      void setName( const QString &name ) { m_name = name; };
 
107
 
 
108
   private:
 
109
      QString m_name;
 
110
};
 
111
 
 
112
 
 
113
class Mixer : public QObject
 
114
{
 
115
      Q_OBJECT
 
116
 
 
117
   public:
 
118
      enum MixerError { ERR_PERM=1, ERR_WRITE, ERR_READ, ERR_NODEV, ERR_NOTSUPP,
 
119
                        ERR_OPEN, ERR_LASTERR, ERR_NOMEM, ERR_INCOMPATIBLESET };
 
120
 
 
121
      Mixer( int device = -1, int card = -1 );
 
122
      virtual ~Mixer() {};
 
123
 
 
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 );
 
129
 
 
130
      void volumeSave( KConfig *config );
 
131
      void volumeLoad( KConfig *config );
 
132
 
 
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);
 
137
 
 
138
      /// Grabs (opens) the mixer for further intraction
 
139
      virtual int grab();
 
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);
 
148
      QString mixerName();
 
149
 
 
150
      /// set/get mixer number used to identify mixers with equal names
 
151
      void setMixerNum( int num );
 
152
      int mixerNum();
 
153
 
 
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 );
 
158
 
 
159
      /// Set the record source(s) according to the given device mask
 
160
      /// The default implementation does nothing.
 
161
 
 
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;
 
167
 
 
168
      /// Returns the number of the master volume device */
 
169
      int masterDevice() { return m_masterDevice; };
 
170
 
 
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;
 
174
 
 
175
 
 
176
   public slots:
 
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();
 
181
 
 
182
      virtual void setBalance(int balance); // sets the m_balance (see there)
 
183
      virtual void setRecsrc( int devnum, bool on = true);
 
184
 
 
185
   signals:
 
186
      void newBalance( Volume );
 
187
      void newRecsrc( void );
 
188
 
 
189
   protected:
 
190
      int m_devnum;
 
191
      int m_cardnum;
 
192
      int m_masterDevice; // device num for master volume
 
193
      /// Derived classes MUST implement this to open the mixer. Returns a KMix error
 
194
      // code (O=OK).
 
195
      virtual int openMixer() = 0;
 
196
      virtual int releaseMixer() = 0;
 
197
 
 
198
      virtual bool setRecsrcHW( int devnum, bool on) = 0;
 
199
      virtual bool isRecsrcHW( int devnum ) = 0;
 
200
 
 
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.
 
203
      QString m_mixerName;
 
204
 
 
205
      // mixer number to identify mixers with equal name correctly (set by the client)
 
206
      int m_mixerNum;
 
207
 
 
208
      bool m_isOpen;
 
209
      int m_balance; // from -100 (just left) to 100 (just right)
 
210
 
 
211
      // All mix devices of this phyisical device.
 
212
      MixSet m_mixDevices;
 
213
 
 
214
      QList<MixSet> m_profiles;
 
215
 
 
216
   public:
 
217
      int setupMixer() { return setupMixer( m_mixDevices ); };
 
218
      int setupMixer( MixSet set );
 
219
};
 
220
 
 
221
#endif