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

« back to all changes in this revision

Viewing changes to kmix/backends/mixer_backend.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 2006-2007 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
 
 
22
#ifndef MIXER_BACKEND_H
 
23
#define MIXER_BACKEND_H
 
24
 
 
25
#include "core/mixer.h"
 
26
 
 
27
class Mixer_Backend : public QObject
 
28
{
 
29
      Q_OBJECT
 
30
 
 
31
friend class Mixer;
 
32
 
 
33
// The Mixer Backend's may only be accessed from the Mixer class.
 
34
protected:
 
35
  Mixer_Backend(Mixer *mixer, int devnum);
 
36
  virtual ~Mixer_Backend();
 
37
 
 
38
  /// Derived classes MUST implement this to open the mixer. Returns a KMix error code (O=OK).
 
39
  virtual int open() = 0;
 
40
  virtual int close() = 0;
 
41
 
 
42
  /*
 
43
   * Returns the driver name, e.g. "ALSA" or "OSS". This virtual method is for looking up the
 
44
   * driver name on instanciated objects.
 
45
   *
 
46
   * Please note, that there is also a static implementation of the driverName
 
47
   * (Because there is no "virtual static" in C++, I need the method twice). 
 
48
   * The static implementation is for the Mixer Factory (who needs it *before* instanciating an object).
 
49
   * While it is not a member function, its implementation can still be found in the corresponding
 
50
   * Backend implementation. For example in mixer_oss.cpp there is a global function called OSS_getDriverName().
 
51
   */
 
52
  virtual QString getDriverName() = 0;
 
53
 
 
54
  /**
 
55
   * Opens the mixer, if it constitures a valid Device. You should return "false", when
 
56
   * the Mixer with the devnum given in the constructor is not supported by the Backend. The two
 
57
   * typical cases are:
 
58
   * (1) No such hardware installed
 
59
   * (2) The hardware exists, but has no mixer support (e.g. external soundcard with only mechanical volume knobs)
 
60
   * The implementation calls open(), checks the return code and whether the number of
 
61
   * supported channels is > 0. The device remains opened if it is valid, otherwise a close() is done.
 
62
   */
 
63
  bool openIfValid();
 
64
 
 
65
  /** @return true, if the Mixer is open (and thus can be operated) */
 
66
  bool isOpen();
 
67
  
 
68
  virtual bool prepareUpdateFromHW();
 
69
  void readSetFromHWforceUpdate() const;
 
70
 
 
71
  /// Volume Read
 
72
  virtual int readVolumeFromHW( const QString& id, MixDevice * ) = 0;
 
73
  /// Volume Write
 
74
  virtual int writeVolumeToHW( const QString& id, MixDevice * ) = 0;
 
75
 
 
76
  /// Enums
 
77
  virtual void setEnumIdHW(const QString& id, unsigned int);
 
78
  virtual unsigned int enumIdHW(const QString& id);
 
79
 
 
80
  /// Recording Switches
 
81
  virtual void setRecsrcHW( const QString& id, bool on) = 0;
 
82
  //virtual bool isRecsrcHW( const QString& id ) = 0;
 
83
 
 
84
  virtual bool moveStream( const QString& id, const QString& destId );
 
85
 
 
86
  /// Overwrite in the backend if the backend can see changes without polling
 
87
  virtual bool needsPolling() { return true; }
 
88
 
 
89
  MixDevice* recommendedMaster();
 
90
 
 
91
  /** Return a translated error text for the given error number.
 
92
   * Subclasses can override this method to produce platform
 
93
   * specific error descriptions.
 
94
   */
 
95
  virtual QString errorText(int mixer_error);
 
96
  /// Prints out a translated error text for the given error number on stderr
 
97
  void errormsg(int mixer_error);
 
98
 
 
99
 
 
100
  /// Returns translated WhatsThis messages for a control.Translates from 
 
101
  virtual QString translateKernelToWhatsthis(const QString &kernelName);
 
102
  
 
103
   /// Translate ID to internal device number
 
104
   virtual int id2num(const QString& id);
 
105
 
 
106
   // Return an Universal Device Identification (suitable for the OS, especially for Hotplug and Unplug events)
 
107
   virtual QString& udi() { return _udi; };
 
108
 
 
109
  int m_devnum;
 
110
  /// User friendly name of the Mixer (e.g. "IRIX Audio Mixer"). If your mixer API
 
111
  /// gives you a usable name, use that name.
 
112
  QString m_mixerName;
 
113
  // All controls of this card
 
114
  MixSet m_mixDevices;
 
115
 
 
116
  /******************************************************************************************
 
117
   * Please don't access the next vars from the Mixer class (even though Mixer is a friend).
 
118
   * There are proper accesor methods for them.
 
119
   ******************************************************************************************/
 
120
  bool m_isOpen;
 
121
  // The MixDevice that would qualify best as MasterDevice (according to the taste of the Backend developer)
 
122
  MixDevice* m_recommendedMaster;
 
123
   // The Mixer is stored her only for one reason: The backend creates the MixDevice's, and it has shown
 
124
   // that it is helpful if the MixDevice's know their correspondig Mixer. KMix lived 10 years without that,
 
125
   // but just believe me. It's *really* better, for example, you can put controls of different soundcards in
 
126
   // one View. That is very cool! Also the MDW doesn't need to store the Mixer any longer (MDW is a GUI element,
 
127
   // so that was 'wrong' anyhow
 
128
  Mixer* _mixer;
 
129
  QTimer* _pollingTimer;
 
130
  QString _udi;  // Universal Device Identification
 
131
  
 
132
  mutable bool _readSetFromHWforceUpdate;
 
133
 
 
134
signals:
 
135
  void controlChanged( void );
 
136
  void controlsReconfigured( const QString& mixer_ID );
 
137
 
 
138
public slots:
 
139
  virtual void reinit() {};
 
140
 
 
141
protected slots:
 
142
  virtual void readSetFromHW();
 
143
};
 
144
 
 
145
#endif