File indexing completed on 2024-10-13 03:43:43

0001 /*
0002     SPDX-FileCopyrightText: 2011 Ian Wadham <iandw.au at gmail dot com>
0003     SPDX-FileCopyrightText: 2007 Luciano Montanaro <mikelima@cirulla.net>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef KGRSOUNDS_H
0009 #define KGRSOUNDS_H
0010 
0011 #include <QList>
0012 #include <QObject>
0013 #include <QElapsedTimer>
0014 
0015 #include <KGameSound>
0016 
0017 class KGrSounds : public QObject
0018 {
0019     Q_OBJECT
0020 public:
0021 
0022     /**
0023      * Construct the KGrSounds class.
0024      */
0025     KGrSounds();
0026     ~KGrSounds() override;
0027 
0028     /**
0029      * Play a sound effect. 
0030      * This method returns a token that can be used to stop the sound if it is
0031      * still playing. Trying to stop a completed sound has no effect.
0032      */
0033     int play (int effect);
0034 
0035     /**
0036      * Stop playing the sound associated with the given token.
0037      */
0038     void stop (int token);
0039 
0040     /** 
0041      * Load a sound sample.
0042      * A token is returned to use to play back the sample.
0043      */
0044     int loadSound (const QString &fileName);
0045 
0046     /** 
0047      * Set up a sound to have its latest start-time recorded.
0048      */
0049     void setTimedSound (int i);
0050 
0051     /** 
0052      * Stop sound and discard the loaded sound effects.
0053      */
0054     void reset();
0055 
0056     /**
0057      * Stop all sounds currently playing.
0058      */
0059     void stopAllSounds();
0060 
0061     void setMuted (bool mute);
0062 
0063     /**
0064      * Change the volume of one type of sound (e.g. footstep) by a given factor.
0065      * \param effect the effect number.
0066      * \param volume 0.0 for mute, > 1.0 to increase, < 1.0 to decrease.
0067      */
0068     void setVolume (int effect, qreal volume);
0069 
0070 private:
0071     QList<KGameSound *> sounds;
0072     QList<int>       startTime; // Start times of timed sounds, else 0.
0073     bool             muted;
0074     QElapsedTimer    t;
0075 };
0076 
0077 #endif // KGRSOUNDS_H