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

« back to all changes in this revision

Viewing changes to kmix/core/mixdevicecomposite.cpp

  • 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
/*
 
2
 * KMix -- KDE's full featured mini mixer
 
3
 *
 
4
 *
 
5
 * Copyright (C) 2010 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
#include "core/mixdevicecomposite.h"
 
23
 
 
24
 
 
25
 
 
26
const long MixDeviceComposite::VolMax = 10000;
 
27
 
 
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
 
30
{
 
31
    setArtificial(true);
 
32
    Volume::ChannelMask chn = Volume::MMAIN;
 
33
    _compositePlaybackVolume = new Volume( chn, MixDeviceComposite::VolMax, 0, true, false);
 
34
    _compositeCaptureVolume  = new Volume();
 
35
 
 
36
    QListIterator<MixDevice*> it(mds);
 
37
    while ( it.hasNext()) {
 
38
        MixDevice* md = it.next();
 
39
        _mds.append(md);
 
40
    }
 
41
}
 
42
 
 
43
 
 
44
MixDeviceComposite::~MixDeviceComposite()
 
45
{
 
46
    while ( ! _mds.empty() ) {
 
47
        _mds.removeAt(0);
 
48
    }
 
49
    delete _compositePlaybackVolume;
 
50
    delete _compositeCaptureVolume;
 
51
}
 
52
 
 
53
 
 
54
 
 
55
Volume& MixDeviceComposite::playbackVolume()
 
56
{
 
57
    return *_compositePlaybackVolume;
 
58
}
 
59
 
 
60
Volume& MixDeviceComposite::captureVolume()
 
61
{
 
62
    return *_compositeCaptureVolume;
 
63
}
 
64
 
 
65
 
 
66
void MixDeviceComposite::update()
 
67
{
 
68
    long volAvg;
 
69
    volAvg = calculateVolume( Volume::PlaybackVT  );
 
70
    _compositePlaybackVolume->setAllVolumes(volAvg);
 
71
    volAvg = calculateVolume( Volume::CaptureVT );
 
72
    _compositeCaptureVolume->setAllVolumes(volAvg);
 
73
 
 
74
}
 
75
 
 
76
long MixDeviceComposite::calculateVolume(Volume::VolumeType vt)
 
77
{
 
78
    QListIterator<MixDevice*> it(_mds);
 
79
    long volSum = 0;
 
80
    int  volCount = 0;
 
81
    while ( it.hasNext()) {
 
82
        MixDevice* md = it.next();
 
83
 
 
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 )
 
88
                    /   vol.maxVolume();
 
89
            volSum += normalizedVolume;
 
90
            ++volCount;
 
91
        }
 
92
    }
 
93
    if ( volCount == 0 )
 
94
        return 0;
 
95
    else
 
96
        return (volSum/volCount);
 
97
}
 
98
 
 
99
 
 
100
bool MixDeviceComposite::isMuted()
 
101
{
 
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 :-)
 
108
    }
 
109
    return isMuted;
 
110
}
 
111
 
 
112
 
 
113
 
 
114
void MixDeviceComposite::setMuted(bool value)
 
115
{
 
116
    QListIterator<MixDevice*> it(_mds);
 
117
    while ( it.hasNext()) {
 
118
        MixDevice* md = it.next();
 
119
        md->setMuted(value);
 
120
    }
 
121
}
 
122
 
 
123
bool MixDeviceComposite::isRecSource()
 
124
{
 
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 :-)
 
131
    }
 
132
    return isRecSource;
 
133
}
 
134
 
 
135
 
 
136
void MixDeviceComposite::setRecSource(bool value)
 
137
{
 
138
    QListIterator<MixDevice*> it(_mds);
 
139
    while ( it.hasNext()) {
 
140
        MixDevice* md = it.next();
 
141
        md->setRecSource(value);
 
142
    }
 
143
}
 
144
 
 
145
 
 
146
bool MixDeviceComposite::isEnum()
 
147
{
 
148
    bool isEnum = true;
 
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 :-)
 
154
    }
 
155
    return isEnum;
 
156
}
 
157