 |
raylib-cpp
C++ object-oriented wrapper library for raylib.
|
1 #ifndef RAYLIB_CPP_INCLUDE_MUSIC_HPP_
2 #define RAYLIB_CPP_INCLUDE_MUSIC_HPP_
6 #include "./raylib.hpp"
7 #include "./raylib-cpp-utils.hpp"
8 #include "./RaylibException.hpp"
24 stream.buffer =
nullptr;
27 Music(const ::Music& music) {
36 Music(
const std::string& fileName) {
37 if (!
Load(fileName)) {
38 throw RaylibException(TextFormat(
"Failed to load Music from file: %s", fileName.c_str()));
47 Music(
const std::string& fileType,
unsigned char* data,
int dataSize) {
48 if (!
Load(fileType, data, dataSize)) {
49 throw RaylibException(TextFormat(
"Failed to load Music from %s file", fileType.c_str()));
59 other.ctxData =
nullptr;
60 other.looping =
false;
73 GETTERSETTER(
unsigned int, FrameCount, frameCount)
74 GETTERSETTER(
bool, Looping, looping)
75 GETTERSETTER(
int, CtxType, ctxType)
76 GETTERSETTER(
void*, CtxData, ctxData)
94 other.ctxData =
nullptr;
95 other.looping =
false;
106 ::UnloadMusicStream(*
this);
113 ::PlayMusicStream(*
this);
121 ::UpdateMusicStream(*
this);
129 ::StopMusicStream(*
this);
137 ::PauseMusicStream(*
this);
145 ::ResumeMusicStream(*
this);
153 SeekMusicStream(*
this, position);
161 return ::IsMusicStreamPlaying(*
this);
168 ::SetMusicVolume(*
this, volume);
176 ::SetMusicPitch(*
this, pitch);
184 return ::GetMusicTimeLength(*
this);
191 return ::GetMusicTimePlayed(*
this);
197 bool Load(
const std::string& fileName) {
198 set(::LoadMusicStream(fileName.c_str()));
205 bool Load(
const std::string& fileType,
unsigned char* data,
int dataSize) {
206 set(::LoadMusicStreamFromMemory(fileType.c_str(), data, dataSize));
216 return stream.buffer !=
nullptr;
220 inline void set(const ::Music& music) {
221 ctxType = music.ctxType;
222 ctxData = music.ctxData;
223 looping = music.looping;
224 frameCount = music.frameCount;
225 stream = music.stream;
230 #endif // RAYLIB_CPP_INCLUDE_MUSIC_HPP_
Music(const std::string &fileType, unsigned char *data, int dataSize)
Load music stream from memory.
All raylib-cpp classes and functions appear in the raylib namespace.
Music & SetPitch(float pitch)
Set pitch for music.
Music & Stop()
Stop music playing.
Music & SetVolume(float volume)
Set volume for music.
Music & Resume()
Resume music playing.
Music & Play()
Start music playing.
Music & Pause()
Pause music playing.
bool IsPlaying() const
Check if music is playing.
bool IsReady() const
Retrieve whether or not the Music has been loaded.
~Music()
Unload music stream.
Music(const std::string &fileName)
Load music stream from file.
void Unload()
Unload music stream.
bool Load(const std::string &fileType, unsigned char *data, int dataSize)
Load music stream from memory.
Music()
Default Music constructor to build an empty Music object.
Music stream type (audio file streaming from memory)
bool Load(const std::string &fileName)
Load music stream from file.
Music & Seek(float position)
Seek music to a position (in seconds)
AudioStream management functions.
Exception used for most raylib-related exceptions.
Music & Update()
Updates buffers for music streaming.
float GetTimeLength() const
Get music time length (in seconds)
float GetTimePlayed() const
Get current music time played (in seconds)