File: mixdevicecomposite.cpp

package info (click to toggle)
kmix 4%3A20.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,504 kB
  • sloc: cpp: 14,313; xml: 408; sh: 97; makefile: 7
file content (158 lines) | stat: -rw-r--r-- 4,372 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 * KMix -- KDE's full featured mini mixer
 *
 *
 * Copyright (C) 2010 Christian Esken <esken@kde.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this program; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "core/mixdevicecomposite.h"



const long MixDeviceComposite::VolMax = 10000;

MixDeviceComposite::MixDeviceComposite( Mixer* mixer,  const QString& id, QList<shared_ptr<MixDevice> >& mds, const QString& name, ChannelType type ) :
   MixDevice( mixer, id, name, type )  // this will use doNotRestore == true
{
    setArtificial(true);
    _compositePlaybackVolume = new Volume( MixDeviceComposite::VolMax, 0, true, false);
    _compositePlaybackVolume->addVolumeChannel(Volume::LEFT);
    _compositePlaybackVolume->addVolumeChannel(Volume::RIGHT);

    QListIterator<shared_ptr<MixDevice> > it(mds);
    while ( it.hasNext()) {
    	shared_ptr<MixDevice> md = it.next();
        _mds.append(md);
    }
}


MixDeviceComposite::~MixDeviceComposite()
{
    while ( ! _mds.empty() ) {
        _mds.removeAt(0);
    }
    delete _compositePlaybackVolume;
//    delete _compositeCaptureVolume;
}



Volume &MixDeviceComposite::playbackVolume()
{
    return (*_compositePlaybackVolume);
}

// Volume& MixDeviceComposite::captureVolume()
// {
//     return *_compositeCaptureVolume;
// }


void MixDeviceComposite::update()
{
    long volAvg;
    volAvg = calculateVolume( Volume::PlaybackVT  );
    _compositePlaybackVolume->setAllVolumes(volAvg);
    volAvg = calculateVolume( Volume::CaptureVT );
//     _compositeCaptureVolume->setAllVolumes(volAvg);

}

long MixDeviceComposite::calculateVolume(Volume::VolumeType vt)
{
    QListIterator<shared_ptr<MixDevice> > it(_mds);
    long volSum = 0;
    int  volCount = 0;
    while ( it.hasNext())
    {
    	shared_ptr<MixDevice> md = it.next();

        Volume& vol =  ( vt == Volume::CaptureVT ) ? md->captureVolume() : md->playbackVolume();
        if (vol.hasVolume() && (vol.maxVolume() != 0) ) {
            qreal normalizedVolume =
                      ( vol.getAvgVolumePercent(Volume::MALL) * MixDeviceComposite::VolMax )
                    /   vol.maxVolume();
            volSum += normalizedVolume;
            ++volCount;
        }
    }
    if ( volCount == 0 )
        return 0;
    else
        return (volSum/volCount);
}


bool MixDeviceComposite::isMuted() const
{
    bool isMuted = false;
    QListIterator<shared_ptr<MixDevice> > it(_mds);
    while ( it.hasNext()) {
    	shared_ptr<MixDevice> md = it.next();
        isMuted |= md->isMuted();
        if ( isMuted ) break;  // Enough. It can't get more true :-)
    }
    return isMuted;
}



void MixDeviceComposite::setMuted(bool value)
{
    QListIterator<shared_ptr<MixDevice> > it(_mds);
    while ( it.hasNext()) {
    	shared_ptr<MixDevice> md = it.next();
        md->setMuted(value);
    }
}

bool MixDeviceComposite::isRecSource() const
{
    bool isRecSource = false;
    QListIterator<shared_ptr<MixDevice> > it(_mds);
    while ( it.hasNext()) {
    	shared_ptr<MixDevice> md = it.next();
        isRecSource |= md->isRecSource();
        if ( isRecSource ) break;  // Enough. It can't get more true :-)
    }
    return isRecSource;
}


void MixDeviceComposite::setRecSource(bool value)
{
    QListIterator<shared_ptr<MixDevice> > it(_mds);
    while ( it.hasNext()) {
    	shared_ptr<MixDevice> md = it.next();
        md->setRecSource(value);
    }
}


bool MixDeviceComposite::isEnum() const
{
    bool isEnum = true;
    QListIterator<shared_ptr<MixDevice> > it(_mds);
    while ( it.hasNext()) {
    	shared_ptr<MixDevice> md = it.next();
        isEnum &= md->isEnum();
        if ( ! isEnum ) break;  // Enough. It can't get more false :-)
    }
    return isEnum;
}