| 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 <QtCore/qmath.h> |
| 29 |
|
| 30 |
#define PHONON_CLASSNAME VolumeFaderEffect |
| 31 |
#define PHONON_INTERFACENAME VolumeFaderInterface |
| 32 |
|
| 33 |
QT_BEGIN_NAMESPACE |
| 34 |
|
| 35 |
#ifndef QT_NO_PHONON_VOLUMEFADEREFFECT |
| 36 |
|
| 37 |
namespace Phonon |
| 38 |
{ |
| 39 |
PHONON_HEIR_IMPL(Effect) |
| 40 |
|
| 41 |
PHONON_INTERFACE_GETTER(float, volume, d->currentVolume) |
| 42 |
PHONON_INTERFACE_SETTER(setVolume, currentVolume, float) |
| 43 |
PHONON_INTERFACE_GETTER(Phonon::VolumeFaderEffect::FadeCurve, fadeCurve, d->fadeCurve) |
| 44 |
PHONON_INTERFACE_SETTER(setFadeCurve, fadeCurve, Phonon::VolumeFaderEffect::FadeCurve) |
| 45 |
|
| 46 |
#ifndef PHONON_LOG10OVER20 |
| 47 |
#define PHONON_LOG10OVER20 |
| 48 |
static const double log10over20 = 0.1151292546497022842; // ln(10) / 20 |
| 49 |
#endif // PHONON_LOG10OVER20 |
| 50 |
|
| 51 |
double VolumeFaderEffect::volumeDecibel() const |
| 52 |
{ |
| 53 |
return log(volume()) / log10over20; |
| 54 |
} |
| 55 |
|
| 56 |
void VolumeFaderEffect::setVolumeDecibel(double newVolumeDecibel) |
| 57 |
{ |
| 58 |
setVolume(exp(newVolumeDecibel * log10over20)); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
void VolumeFaderEffect::fadeIn(int fadeTime) |
| 63 |
{ |
| 64 |
fadeTo(1.0, fadeTime); |
| 65 |
} |
| 66 |
|
| 67 |
void VolumeFaderEffect::fadeOut(int fadeTime) |
| 68 |
{ |
| 69 |
fadeTo(0.0, fadeTime); |
| 70 |
} |
| 71 |
|
| 72 |
void VolumeFaderEffect::fadeTo(float volume, int fadeTime) |
| 73 |
{ |
| 74 |
K_D(VolumeFaderEffect); |
| 75 |
if (k_ptr->backendObject()) |
| 76 |
INTERFACE_CALL(fadeTo(volume, fadeTime)); |
| 77 |
else |
| 78 |
d->currentVolume = volume; |
| 79 |
} |
| 80 |
|
| 81 |
bool VolumeFaderEffectPrivate::aboutToDeleteBackendObject() |
| 82 |
{ |
| 83 |
if (m_backendObject) { |
| 84 |
currentVolume = pINTERFACE_CALL(volume()); |
| 85 |
fadeCurve = pINTERFACE_CALL(fadeCurve()); |
| 86 |
} |
| 87 |
return true; |
| 88 |
} |
| 89 |
|
| 90 |
void VolumeFaderEffectPrivate::setupBackendObject() |
| 91 |
{ |
| 92 |
Q_ASSERT(m_backendObject); |
| 93 |
|
| 94 |
// set up attributes |
| 95 |
pINTERFACE_CALL(setVolume(currentVolume)); |
| 96 |
pINTERFACE_CALL(setFadeCurve(fadeCurve)); |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
#endif //QT_NO_PHONON_VOLUMEFADEREFFECT |
| 102 |
|
| 103 |
QT_END_NAMESPACE |
| 104 |
|
| 105 |
#include "moc_volumefadereffect.cpp" |
| 106 |
|
| 107 |
#undef PHONON_CLASSNAME |
| 108 |
// vim: sw=4 ts=4 |