File indexing completed on 2025-02-09 05:31:54
0001 /* This file is part of the KDE project 0002 Copyright (C) 2006 Matthias Kretz <kretz@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Lesser General Public 0006 License as published by the Free Software Foundation; either 0007 version 2.1 of the License, or (at your option) version 3, or any 0008 later version accepted by the membership of KDE e.V. (or its 0009 successor approved by the membership of KDE e.V.), Nokia Corporation 0010 (or its successors, if any) and the KDE Free Qt Foundation, which shall 0011 act as a proxy defined in Section 6 of version 3 of the license. 0012 0013 This library is distributed in the hope that it will be useful, 0014 but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 Lesser General Public License for more details. 0017 0018 You should have received a copy of the GNU Lesser General Public 0019 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0020 0021 */ 0022 0023 #include "volumefadereffect.h" 0024 #include "volumefadereffect_p.h" 0025 #include "volumefaderinterface.h" 0026 #include "factory_p.h" 0027 0028 #include <qmath.h> 0029 0030 #define PHONON_CLASSNAME VolumeFaderEffect 0031 #define PHONON_INTERFACENAME VolumeFaderInterface 0032 0033 #ifndef QT_NO_PHONON_VOLUMEFADEREFFECT 0034 0035 namespace Phonon 0036 { 0037 PHONON_HEIR_IMPL(Effect) 0038 0039 PHONON_INTERFACE_GETTER(float, volume, d->currentVolume) 0040 PHONON_INTERFACE_SETTER(setVolume, currentVolume, float) 0041 PHONON_INTERFACE_GETTER(Phonon::VolumeFaderEffect::FadeCurve, fadeCurve, d->fadeCurve) 0042 PHONON_INTERFACE_SETTER(setFadeCurve, fadeCurve, Phonon::VolumeFaderEffect::FadeCurve) 0043 0044 #ifndef PHONON_LOG10OVER20 0045 #define PHONON_LOG10OVER20 0046 static const double log10over20 = 0.1151292546497022842; // ln(10) / 20 0047 #endif // PHONON_LOG10OVER20 0048 0049 double VolumeFaderEffect::volumeDecibel() const 0050 { 0051 return log(volume()) / log10over20; 0052 } 0053 0054 void VolumeFaderEffect::setVolumeDecibel(double newVolumeDecibel) 0055 { 0056 setVolume(exp(newVolumeDecibel * log10over20)); 0057 } 0058 0059 0060 void VolumeFaderEffect::fadeIn(int fadeTime) 0061 { 0062 fadeTo(1.0, fadeTime); 0063 } 0064 0065 void VolumeFaderEffect::fadeOut(int fadeTime) 0066 { 0067 fadeTo(0.0, fadeTime); 0068 } 0069 0070 void VolumeFaderEffect::fadeTo(float volume, int fadeTime) 0071 { 0072 P_D(VolumeFaderEffect); 0073 if (k_ptr->backendObject()) 0074 INTERFACE_CALL(fadeTo(volume, fadeTime)); 0075 else 0076 d->currentVolume = volume; 0077 } 0078 0079 bool VolumeFaderEffectPrivate::aboutToDeleteBackendObject() 0080 { 0081 if (m_backendObject) { 0082 currentVolume = pINTERFACE_CALL(volume()); 0083 fadeCurve = pINTERFACE_CALL(fadeCurve()); 0084 } 0085 return true; 0086 } 0087 0088 void VolumeFaderEffectPrivate::setupBackendObject() 0089 { 0090 Q_ASSERT(m_backendObject); 0091 0092 // set up attributes 0093 pINTERFACE_CALL(setVolume(currentVolume)); 0094 pINTERFACE_CALL(setFadeCurve(fadeCurve)); 0095 } 0096 } 0097 0098 0099 #endif //QT_NO_PHONON_VOLUMEFADEREFFECT 0100 0101 #include "moc_volumefadereffect.cpp" 0102 0103 #undef PHONON_CLASSNAME 0104 // vim: sw=4 ts=4