1 | /* This file is part of the KDE project |
2 | Copyright (C) 2006 Matthias Kretz <kretz@kde.org> |
3 | |
4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Lesser General Public |
6 | License as published by the Free Software Foundation; either |
7 | version 2.1 of the License, or (at your option) version 3, or any |
8 | later version accepted by the membership of KDE e.V. (or its |
9 | successor approved by the membership of KDE e.V.), Nokia Corporation |
10 | (or its successors, if any) and the KDE Free Qt Foundation, which shall |
11 | act as a proxy defined in Section 6 of version 3 of the license. |
12 | |
13 | This library is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | Lesser General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Lesser General Public |
19 | License along with this library. If not, see <http://www.gnu.org/licenses/>. |
20 | |
21 | */ |
22 | |
23 | #include "volumefadereffect.h" |
24 | #include "volumefadereffect_p.h" |
25 | #include "volumefaderinterface.h" |
26 | #include "factory_p.h" |
27 | |
28 | #include <qmath.h> |
29 | |
30 | #define PHONON_CLASSNAME VolumeFaderEffect |
31 | #define PHONON_INTERFACENAME VolumeFaderInterface |
32 | |
33 | #ifndef QT_NO_PHONON_VOLUMEFADEREFFECT |
34 | |
35 | namespace Phonon |
36 | { |
37 | PHONON_HEIR_IMPL(Effect) |
38 | |
39 | PHONON_INTERFACE_GETTER(float, volume, d->currentVolume) |
40 | PHONON_INTERFACE_SETTER(setVolume, currentVolume, float) |
41 | PHONON_INTERFACE_GETTER(Phonon::VolumeFaderEffect::FadeCurve, fadeCurve, d->fadeCurve) |
42 | PHONON_INTERFACE_SETTER(setFadeCurve, fadeCurve, Phonon::VolumeFaderEffect::FadeCurve) |
43 | |
44 | #ifndef PHONON_LOG10OVER20 |
45 | #define PHONON_LOG10OVER20 |
46 | static const double log10over20 = 0.1151292546497022842; // ln(10) / 20 |
47 | #endif // PHONON_LOG10OVER20 |
48 | |
49 | double VolumeFaderEffect::volumeDecibel() const |
50 | { |
51 | return log(x: volume()) / log10over20; |
52 | } |
53 | |
54 | void VolumeFaderEffect::setVolumeDecibel(double newVolumeDecibel) |
55 | { |
56 | setVolume(exp(x: newVolumeDecibel * log10over20)); |
57 | } |
58 | |
59 | |
60 | void VolumeFaderEffect::fadeIn(int fadeTime) |
61 | { |
62 | fadeTo(volume: 1.0, fadeTime); |
63 | } |
64 | |
65 | void VolumeFaderEffect::fadeOut(int fadeTime) |
66 | { |
67 | fadeTo(volume: 0.0, fadeTime); |
68 | } |
69 | |
70 | void VolumeFaderEffect::fadeTo(float volume, int fadeTime) |
71 | { |
72 | P_D(VolumeFaderEffect); |
73 | if (k_ptr->backendObject()) |
74 | INTERFACE_CALL(fadeTo(volume, fadeTime)); |
75 | else |
76 | d->currentVolume = volume; |
77 | } |
78 | |
79 | bool VolumeFaderEffectPrivate::aboutToDeleteBackendObject() |
80 | { |
81 | if (m_backendObject) { |
82 | currentVolume = pINTERFACE_CALL(volume()); |
83 | fadeCurve = pINTERFACE_CALL(fadeCurve()); |
84 | } |
85 | return true; |
86 | } |
87 | |
88 | void VolumeFaderEffectPrivate::setupBackendObject() |
89 | { |
90 | Q_ASSERT(m_backendObject); |
91 | |
92 | // set up attributes |
93 | pINTERFACE_CALL(setVolume(currentVolume)); |
94 | pINTERFACE_CALL(setFadeCurve(fadeCurve)); |
95 | } |
96 | } |
97 | |
98 | |
99 | #endif //QT_NO_PHONON_VOLUMEFADEREFFECT |
100 | |
101 | #include "moc_volumefadereffect.cpp" |
102 | |
103 | #undef PHONON_CLASSNAME |
104 | // vim: sw=4 ts=4 |
105 | |