raylib-cpp
C++ object-oriented wrapper library for raylib.
Sound.hpp
1 /*
2 * LICENSE: zlib/libpng
3 *
4 * raylib-cpp is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
5 * BSD-like license that allows static linking with closed source software:
6 *
7 * Copyright (c) 2020 Rob Loach (@RobLoach)
8 *
9 * This software is provided "as-is", without any express or implied warranty. In no event
10 * will the authors be held liable for any damages arising from the use of this software.
11 *
12 * Permission is granted to anyone to use this software for any purpose, including commercial
13 * applications, and to alter it and redistribute it freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not claim that you
16 * wrote the original software. If you use this software in a product, an acknowledgment
17 * in the product documentation would be appreciated but is not required.
18 *
19 * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
20 * as being the original software.
21 *
22 * 3. This notice may not be removed or altered from any source distribution.
23 */
24 
25 #ifndef RAYLIB_CPP_INCLUDE_SOUND_HPP_
26 #define RAYLIB_CPP_INCLUDE_SOUND_HPP_
27 
28 #include <string>
29 
30 #include "./raylib.hpp"
31 #include "./raylib-cpp-utils.hpp"
32 
33 namespace raylib {
37 class Sound : public ::Sound {
38  public:
39  Sound(const ::Sound& vec) {
40  set(vec);
41  }
42 
43  Sound(const std::string& fileName) {
44  set(LoadSound(fileName.c_str()));
45  }
46 
47  Sound(const ::Wave& wave) {
48  set(LoadSoundFromWave(wave));
49  }
50 
51  ~Sound() {
52  Unload();
53  }
54 
55  GETTERSETTER(unsigned int, SampleCount, sampleCount)
56  GETTERSETTER(::AudioStream, Stream, stream)
57 
58  Sound& operator=(const ::Sound& sound) {
59  set(sound);
60  return *this;
61  }
62 
66  inline Sound& Update(const void *data, int sampleCount) {
67  ::UpdateSound(*this, data, sampleCount);
68  return *this;
69  }
70 
74  inline void Unload() {
75  ::UnloadSound(*this);
76  }
77 
81  inline Sound& Play() {
82  ::PlaySound(*this);
83  return *this;
84  }
85 
89  inline Sound& Stop() {
90  ::StopSound(*this);
91  return *this;
92  }
93 
97  inline Sound& Pause() {
98  ::PauseSound(*this);
99  return *this;
100  }
101 
105  inline Sound& Resume() {
106  ::ResumeSound(*this);
107  return *this;
108  }
109 
113  inline Sound& PlayMulti() {
114  ::PlaySoundMulti(*this);
115  return *this;
116  }
117 
121  inline Sound& StopMulti() {
122  ::StopSoundMulti();
123  return *this;
124  }
125 
129  inline bool IsPlaying() const {
130  return ::IsSoundPlaying(*this);
131  }
132 
136  inline Sound& SetVolume(float volume) {
137  ::SetSoundVolume(*this, volume);
138  return *this;
139  }
140 
144  inline Sound& SetPitch(float pitch) {
145  ::SetSoundPitch(*this, pitch);
146  return *this;
147  }
148 
149  protected:
150  inline void set(const ::Sound& sound) {
151  sampleCount = sound.sampleCount;
152  stream = sound.stream;
153  }
154 };
155 } // namespace raylib
156 
157 #endif // RAYLIB_CPP_INCLUDE_SOUND_HPP_
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:31
raylib::Sound::~Sound
~Sound()
Definition: Sound.hpp:51
raylib::Sound::Update
Sound & Update(const void *data, int sampleCount)
Update sound buffer with new data.
Definition: Sound.hpp:66
raylib::Sound::set
void set(const ::Sound &sound)
Definition: Sound.hpp:150
raylib::Sound::StopMulti
Sound & StopMulti()
Stop any sound playing (using multichannel buffer pool)
Definition: Sound.hpp:121
raylib::Sound::SetVolume
Sound & SetVolume(float volume)
Set volume for a sound (1.0 is max level)
Definition: Sound.hpp:136
raylib::Sound
Wave/Sound management functions.
Definition: Sound.hpp:37
raylib::Sound::Pause
Sound & Pause()
Pause a sound.
Definition: Sound.hpp:97
raylib::Sound::Resume
Sound & Resume()
Resume a paused sound.
Definition: Sound.hpp:105
raylib::Sound::Sound
Sound(const ::Sound &vec)
Definition: Sound.hpp:39
raylib::Sound::Stop
Sound & Stop()
Stop playing a sound.
Definition: Sound.hpp:89
raylib::Sound::IsPlaying
bool IsPlaying() const
Check if a sound is currently playing.
Definition: Sound.hpp:129
raylib::Sound::Unload
void Unload()
Unload sound.
Definition: Sound.hpp:74
raylib::AudioStream
AudioStream management functions.
Definition: AudioStream.hpp:35
raylib::Sound::Sound
Sound(const ::Wave &wave)
Definition: Sound.hpp:47
raylib::Sound::SetPitch
Sound & SetPitch(float pitch)
Set pitch for a sound (1.0 is base level)
Definition: Sound.hpp:144
raylib::Sound::Play
Sound & Play()
Play a sound.
Definition: Sound.hpp:81
raylib::Sound::PlayMulti
Sound & PlayMulti()
Play a sound (using multichannel buffer pool)
Definition: Sound.hpp:113
raylib::Sound::Sound
Sound(const std::string &fileName)
Definition: Sound.hpp:43