Audio.hpp
Go to the documentation of this file.
1 
4 #ifndef GOSU_AUDIO_HPP
5 #define GOSU_AUDIO_HPP
6 
7 #ifdef WIN32
8 #ifndef NOMINMAX
9 #define NOMINMAX
10 #endif
11 #include <windows.h>
12 #endif
13 #include <Gosu/Fwd.hpp>
14 #include <Gosu/IO.hpp>
15 #include <Gosu/Platform.hpp>
16 #include <Gosu/TR1.hpp>
17 #include <memory>
18 #include <string>
19 
20 namespace Gosu
21 {
22  // Deprecated.
23  #ifndef SWIG
25  #endif
26 
33  {
34  int handle, extra;
35  bool alive() const;
36 
37  public:
39  SampleInstance(int handle, int extra);
40 
41  bool playing() const;
42  bool paused() const;
44  void pause();
45  void resume();
48  void stop();
49 
52  void changeVolume(double volume);
54  void changePan(double pan);
58  void changeSpeed(double speed);
59  };
60 
64  class Sample
65  {
66  struct SampleData;
67  std::tr1::shared_ptr<SampleData> data;
68 
69  public:
72  explicit Sample(const std::wstring& filename);
73 
76  explicit Sample(Reader reader);
77 
84  SampleInstance play(double volume = 1, double speed = 1,
85  bool looping = false) const;
86 
96  SampleInstance playPan(double pan, double volume = 1, double speed = 1,
97  bool looping = false) const;
98 
99  #ifndef SWIG
100  GOSU_DEPRECATED Sample(Audio& audio, const std::wstring& filename);
101  GOSU_DEPRECATED Sample(Audio& audio, Reader reader);
102  #endif
103  };
104 
107  class Song
108  {
109  class BaseData;
110  class ModuleData;
111  class StreamData;
112  GOSU_UNIQUE_PTR<BaseData> data;
113 
114 #if defined(GOSU_CPP11_ENABLED)
115  Song(Song&&) = delete;
116  Song& operator=(Song&&) = delete;
117  Song(const Song&) = delete;
118  Song& operator=(const Song&) = delete;
119 #else
120  Song(const Song&);
121  Song& operator=(const Song&);
122 #endif
123 
124  public:
128  explicit Song(const std::wstring& filename);
129 
132  explicit Song(Reader reader);
133 
134  ~Song();
135 
139  static Song* currentSong();
140 
143  void play(bool looping = false);
146  void pause();
149  bool paused() const;
152  void stop();
154  bool playing() const;
156  double volume() const;
158  void changeVolume(double volume);
159 
161  static void update();
162 
163  #ifndef SWIG
164  enum Type { stStream, stModule };
165  GOSU_DEPRECATED Song(Audio&, const std::wstring& filename);
166  GOSU_DEPRECATED Song(Audio&, Type type, Reader reader);
167  #endif
168  };
169 }
170 
171 #endif
Includes all parts of C++03 (TR1) that are relevant for Gosu.
static void update()
Called every tick by Window for management purposes.
void pause()
Pauses playback of the song.
#define GOSU_DEPRECATED
Definition: Platform.hpp:85
bool paused() const
Returns true if the song is the current song, but in paused mode.
bool playing() const
double volume() const
Returns the current volume of the song.
Contains declarations of all of Gosu&#39;s available classes.
SampleInstance(int handle, int extra)
Called by Sample, do not use.
SampleInstance playPan(double pan, double volume=1, double speed=1, bool looping=false) const
Plays the sample with panning.
static Song * currentSong()
Returns the song currently being played or paused, or 0 if no song has been played yet or the last so...
An instance of a Sample playing.
Definition: Audio.hpp:32
void changeVolume(double volume)
void changePan(double pan)
bool paused() const
Utility class that points to a specific position in a resource and offers an interface for sequential...
Definition: IO.hpp:27
Sample(const std::wstring &filename)
Constructs a sample that can be played on the specified audio system and loads the sample from a file...
class GOSU_DEPRECATED Audio
Definition: Audio.hpp:24
void play(bool looping=false)
Starts or resumes playback of the song.
Songs are less flexible than samples in that they can only be played one at a time and without pannin...
Definition: Audio.hpp:107
A sample is a short sound that is completely loaded in memory, can be played multiple times at once a...
Definition: Audio.hpp:64
SampleInstance play(double volume=1, double speed=1, bool looping=false) const
Plays the sample without panning.
bool playing() const
Returns true if the song is currently playing.
Macros and utility functions to facilitate programming on all of Gosu&#39;s supported platforms...
void changeSpeed(double speed)
void changeVolume(double volume)
Changes the volume of the song.
void pause()
Pauses this instance to be resumed afterwards. It will still keep a channel filled while paused...
Contains everything related to input and output.
void stop()
Stops this instance of a sound being played.
void stop()
Stops playback of this song if it is currently played or paused.