SGL
gsound.h
1 /*
2  * File: gsound.h
3  * --------------
4  * This file defines a class that represents a sound.
5  *
6  * @version 2021/04/09
7  * - added sgl namespace
8  * @version 2021/04/03
9  * - removed dependencies
10  * - renamed to GSound
11  * @version 2018/10/23
12  * - reimplemented in C++ using QSound class
13  * @version 2018/09/25
14  * - added doc comments for new documentation generation
15  */
16 
17 
18 #ifndef _gsound_h
19 #define _gsound_h
20 
21 #include <string>
22 #include <QMediaPlayer>
23 
24 namespace sgl {
25 
45 class GSound {
46 public:
51  static long getDuration();
52 
57  static int getVolume();
58 
63  static void pause();
64 
69  static void playSound(const string& filename);
70 
75  static void setVolume(int volume);
76 
80  static void stop();
81 
82 
83  // begin old object-oriented interface (kept for backward compatibility)
84 
89  GSound(const string& filename);
90 
94  virtual ~GSound();
95 
100  void play();
101 
102 private:
103  static QMediaPlayer* _qmediaPlayer;
104 
105  static void initialize();
106 
107  string _filename;
108 };
109 
110 } // namespace sgl
111 
112 #endif // _gsound_h
static int getVolume()
Returns the overall audio volume from 0 (silence) to 100 (full volume).
Definition: gsound.cpp:35
static long getDuration()
Returns the duration of the sound clip that is currently playing.
Definition: gsound.cpp:30
Definition: console.h:45
static void setVolume(int volume)
Sets the overall audio volume from 0 (silence) to 100 (full volume).
Definition: gsound.cpp:73
static void pause()
Pauses playing the sound, if it is playing.
Definition: gsound.cpp:50
GSound(string filename)
Creates a Sound object by reading in the contents of the specified file or URL.
Definition: gsound.cpp:79
static void stop()
Stops playing the sound, if it is playing.
Definition: gsound.cpp:68
This class encapsulates a sound file.
Definition: gsound.h:45
virtual ~GSound()
Frees the memory associated with the sound.
Definition: gsound.cpp:84
static void playSound(string filename)
Starts playing the sound if not playing, or unpauses if paused.
Definition: gsound.cpp:55
void play()
Starts playing the sound.
Definition: gsound.cpp:88