1 /* 2 SPDX-FileCopyrightText: 2011 Ian Wadham <iandw.au at gmail dot com> 3 SPDX-FileCopyrightText: 2007 Luciano Montanaro <mikelima@cirulla.net> 4 5 SPDX-License-Identifier: GPL-2.0-or-later 6 */ 7 8 #ifndef KGRSOUNDS_H 9 #define KGRSOUNDS_H 10 11 #include <QObject> 12 #include <QVector> 13 #include <QElapsedTimer> 14 15 #include <KgSound> 16 17 class KGrSounds : public QObject 18 { 19 Q_OBJECT 20 public: 21 22 /** 23 * Construct the KGrSounds class. 24 */ 25 KGrSounds(); 26 ~KGrSounds() override; 27 28 /** 29 * Play a sound effect. 30 * This method returns a token that can be used to stop the sound if it is 31 * still playing. Trying to stop a completed sound has no effect. 32 */ 33 int play (int effect); 34 35 /** 36 * Stop playing the sound associated with the given token. 37 */ 38 void stop (int token); 39 40 /** 41 * Load a sound sample. 42 * A token is returned to use to play back the sample. 43 */ 44 int loadSound (const QString &fileName); 45 46 /** 47 * Set up a sound to have its latest start-time recorded. 48 */ 49 void setTimedSound (int i); 50 51 /** 52 * Stop sound and discard the loaded sound effects. 53 */ 54 void reset(); 55 56 /** 57 * Stop all sounds currently playing. 58 */ 59 void stopAllSounds(); 60 61 void setMuted (bool mute); 62 63 /** 64 * Change the volume of one type of sound (e.g. footstep) by a given factor. 65 * \param effect the effect number. 66 * \param volume 0.0 for mute, > 1.0 to increase, < 1.0 to decrease. 67 */ 68 void setVolume (int effect, qreal volume); 69 70 private: 71 QVector<KgSound *> sounds; 72 QVector<int> startTime; // Start times of timed sounds, else 0. 73 bool muted; 74 QElapsedTimer t; 75 }; 76 77 #endif // KGRSOUNDS_H 78