File indexing completed on 2024-04-14 04:38:29

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 #ifndef PHONON_VOLUMEFADEREFFECT_H
0024 #define PHONON_VOLUMEFADEREFFECT_H
0025 
0026 #include "phonon_export.h"
0027 #include "effect.h"
0028 
0029 
0030 #ifndef QT_NO_PHONON_VOLUMEFADEREFFECT
0031 
0032 namespace Phonon
0033 {
0034     class VolumeFaderEffectPrivate;
0035 
0036     /** \class VolumeFaderEffect volumefadereffect.h phonon/VolumeFaderEffect
0037      * Audio effect to gradually fade the audio volume.
0038      *
0039      * This effect differs from gradually changing the output volume in that
0040      * a dedicated effect can change the volume in the smallest possible
0041      * steps while every other volume control will make more or less
0042      * noticeable steps.
0043      *
0044      * \ingroup PhononEffects
0045      * \author Matthias Kretz <kretz@kde.org>
0046      * \see AudioOutput::volume
0047      */
0048     class PHONON_EXPORT VolumeFaderEffect : public Effect
0049     {
0050         Q_OBJECT
0051         P_DECLARE_PRIVATE(VolumeFaderEffect)
0052         PHONON_HEIR(VolumeFaderEffect)
0053         Q_ENUMS(FadeCurve)
0054         /**
0055          * This is the current volume of the output as voltage factor.
0056          * Setting this property changes the volume immediately.
0057          *
0058          * 1.0 means 100%, 0.5 means 50% voltage/25% power, 0.0 means 0%
0059          *
0060          * \see volumeDecibel
0061          */
0062         Q_PROPERTY(float volume READ volume WRITE setVolume)
0063         /**
0064          * This is the current volume of the output in decibel.
0065          * Setting this property changes the volume immediately.
0066          *
0067          * 0 dB means no change in volume, -6dB means an attenuation of the
0068          * voltage to 50% and an attenuation of the power to 25%, -inf dB means
0069          * silence.
0070          *
0071          * \see volume
0072          */
0073         Q_PROPERTY(double volumeDecibel READ volumeDecibel WRITE setVolumeDecibel)
0074         /**
0075          * This property holds the fade curve to be used for the fadeIn(), fadeOut()
0076          * and fadeTo() slots.
0077          *
0078          * Defaults to Fade3Decibel.
0079          *
0080          * \see FadeCurve
0081          */
0082         Q_PROPERTY(FadeCurve fadeCurve READ fadeCurve WRITE setFadeCurve)
0083         public:
0084             /**
0085              * Determines the curve of the volume change.
0086              */
0087             enum FadeCurve {
0088                 /**
0089                  * "Crossfade curve" / "fast" fade out
0090                  *
0091                  * Often the best fade for a crossfade, as after half of the
0092                  * time the volume reached -3dB. This means that half the
0093                  * possible power (which is proportional to the square of the
0094                  * voltage) is reached. Summed, the maximum power of two audio
0095                  * signals fading with a -3dB curve will always be equal.
0096                  *
0097                  * For fading in or out the -3dB curve is too abrupt in the end.
0098                  *
0099                  * This is the default fade curve.
0100                  */
0101                 Fade3Decibel,
0102                 /**
0103                  * "Linear" fade out
0104                  *
0105                  * With a -6dB fade curve after half of the fading time -6dB has
0106                  * been reached. -6dB is equal to half of the voltage meaning
0107                  * that the voltage multiplier changes linearly from the start
0108                  * of the fade to the end.
0109                  */
0110                 Fade6Decibel,
0111                 /**
0112                  * "slow" fade out
0113                  *
0114                  * After half of the fade time -9dB are reached. So the fade is
0115                  * fast in the beginning and slow in the end. This is a good
0116                  * fade for ending music.
0117                  */
0118                 Fade9Decibel,
0119                 /**
0120                  * more extreme version of the -9dB fade
0121                  */
0122                 Fade12Decibel
0123             };
0124 
0125             float volume() const;
0126             double volumeDecibel() const;
0127 
0128             FadeCurve fadeCurve() const;
0129 
0130         public Q_SLOTS:
0131             /**
0132              * Tells the Fader to change the volume from the current volume to 100%
0133              * in \p fadeTime milliseconds.
0134              * Short for \c fadeTo(1.0, fadeTime).
0135              *
0136              * \param fadeTime the fade duration in milliseconds
0137              *
0138              * \see fadeTo
0139              * \see volume
0140              */
0141             void fadeIn(int fadeTime);
0142 
0143             /**
0144              * Tells the Fader to change the volume from the current volume to 0%
0145              * in \p fadeTime milliseconds.
0146              * Short for \c fadeTo(0.0, fadeTime).
0147              *
0148              * \param fadeTime the fade duration in milliseconds
0149              *
0150              * \see fadeTo
0151              */
0152             void fadeOut(int fadeTime);
0153 
0154             void setVolume(float volume);
0155             void setVolumeDecibel(double volumeDecibel);
0156 
0157             void setFadeCurve(FadeCurve curve);
0158 
0159             /**
0160              * Tells the Fader to change the volume from the current value to
0161              * \p volume in \p fadeTime milliseconds
0162              *
0163              * \see fadeIn
0164              * \see fadeOut
0165              */
0166             void fadeTo(float volume, int fadeTime);
0167     };
0168 } //namespace Phonon
0169 
0170 #endif //QT_NO_PHONON_VOLUMEFADEREFFECT
0171 
0172 
0173 // vim: sw=4 ts=4 tw=80
0174 #endif // PHONON_VOLUMEFADEREFFECT_H