2
* KMix -- KDE's full featured mini mixer
5
* Copyright (C) 2010 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.
22
#include "core/mixdevicecomposite.h"
26
const long MixDeviceComposite::VolMax = 10000;
28
MixDeviceComposite::MixDeviceComposite( Mixer* mixer, const QString& id, QList<MixDevice*>& mds, const QString& name, ChannelType type ) :
29
MixDevice( mixer, id, name, type ) // this will use doNotRestore == true
32
Volume::ChannelMask chn = Volume::MMAIN;
33
_compositePlaybackVolume = new Volume( chn, MixDeviceComposite::VolMax, 0, true, false);
34
_compositeCaptureVolume = new Volume();
36
QListIterator<MixDevice*> it(mds);
37
while ( it.hasNext()) {
38
MixDevice* md = it.next();
44
MixDeviceComposite::~MixDeviceComposite()
46
while ( ! _mds.empty() ) {
49
delete _compositePlaybackVolume;
50
delete _compositeCaptureVolume;
55
Volume& MixDeviceComposite::playbackVolume()
57
return *_compositePlaybackVolume;
60
Volume& MixDeviceComposite::captureVolume()
62
return *_compositeCaptureVolume;
66
void MixDeviceComposite::update()
69
volAvg = calculateVolume( Volume::PlaybackVT );
70
_compositePlaybackVolume->setAllVolumes(volAvg);
71
volAvg = calculateVolume( Volume::CaptureVT );
72
_compositeCaptureVolume->setAllVolumes(volAvg);
76
long MixDeviceComposite::calculateVolume(Volume::VolumeType vt)
78
QListIterator<MixDevice*> it(_mds);
81
while ( it.hasNext()) {
82
MixDevice* md = it.next();
84
Volume& vol = ( vt == Volume::CaptureVT ) ? md->captureVolume() : md->playbackVolume();
85
if (vol.hasVolume() && (vol.maxVolume() != 0) ) {
86
long normalizedVolume =
87
( vol.getAvgVolume(Volume::MALL) * MixDeviceComposite::VolMax )
89
volSum += normalizedVolume;
96
return (volSum/volCount);
100
bool MixDeviceComposite::isMuted()
102
bool isMuted = false;
103
QListIterator<MixDevice*> it(_mds);
104
while ( it.hasNext()) {
105
MixDevice* md = it.next();
106
isMuted |= md->isMuted();
107
if ( isMuted ) break; // Enough. It can't get more true :-)
114
void MixDeviceComposite::setMuted(bool value)
116
QListIterator<MixDevice*> it(_mds);
117
while ( it.hasNext()) {
118
MixDevice* md = it.next();
123
bool MixDeviceComposite::isRecSource()
125
bool isRecSource = false;
126
QListIterator<MixDevice*> it(_mds);
127
while ( it.hasNext()) {
128
MixDevice* md = it.next();
129
isRecSource |= md->isRecSource();
130
if ( isRecSource ) break; // Enough. It can't get more true :-)
136
void MixDeviceComposite::setRecSource(bool value)
138
QListIterator<MixDevice*> it(_mds);
139
while ( it.hasNext()) {
140
MixDevice* md = it.next();
141
md->setRecSource(value);
146
bool MixDeviceComposite::isEnum()
149
QListIterator<MixDevice*> it(_mds);
150
while ( it.hasNext()) {
151
MixDevice* md = it.next();
152
isEnum &= md->isEnum();
153
if ( ! isEnum ) break; // Enough. It can't get more false :-)