1#ifndef RAYLIB_CPP_INCLUDE_MUSIC_HPP_
2#define RAYLIB_CPP_INCLUDE_MUSIC_HPP_
9#include "./raylib-cpp-utils.hpp"
10#include "./RaylibException.hpp"
18 Music(::AudioStream stream = {
nullptr,
nullptr, 0, 0, 0},
19 unsigned int frameCount = 0,
22 void *ctxData =
nullptr) : ::Music{stream, frameCount, looping, ctxType, ctxData} {}
24 Music(const ::Music& music) {
33 Music(
const std::string_view fileName) {
42 Music(
const std::string_view fileType,
unsigned char* data,
int dataSize) {
43 Load(fileType, data, dataSize);
51 Music(
const std::string_view fileType, std::span<unsigned char> data) {
62 other.looping =
false;
64 other.ctxData =
nullptr;
74 GETTER(::AudioStream, Stream, stream)
75 GETTER(
unsigned int, FrameCount, frameCount)
76 GETTERSETTER(
bool, Looping, looping)
77 GETTER(
int, CtxType, ctxType)
78 GETTER(
void*, CtxData, ctxData)
96 other.ctxData =
nullptr;
97 other.looping =
false;
108 ::UnloadMusicStream(*
this);
115 ::PlayMusicStream(*
this);
123 ::UpdateMusicStream(*
this);
131 ::StopMusicStream(*
this);
139 ::PauseMusicStream(*
this);
147 ::ResumeMusicStream(*
this);
155 SeekMusicStream(*
this, position);
163 return ::IsMusicStreamPlaying(*
this);
170 ::SetMusicVolume(*
this, volume);
178 ::SetMusicPitch(*
this, pitch);
186 ::SetMusicPan(*
this, pan);
194 return ::GetMusicTimeLength(*
this);
201 return ::GetMusicTimePlayed(*
this);
209 void Load(
const std::string_view fileName) {
210 set(::LoadMusicStream(fileName.data()));
212 throw RaylibException(TextFormat(
"Failed to load Music from file: %s", fileName.data()));
221 void Load(
const std::string_view fileType,
unsigned char* data,
int dataSize) {
222 set(::LoadMusicStreamFromMemory(fileType.data(), data, dataSize));
224 throw RaylibException(TextFormat(
"Failed to load Music from %s file dat", fileType.data()));
233 void Load(
const std::string_view fileType, std::span<unsigned char> data) {
234 set(::LoadMusicStreamFromMemory(fileType.data(), data.data(),
static_cast<int>(data.size())));
236 throw RaylibException(TextFormat(
"Failed to load Music from %s file dat", fileType.data()));
246 return ::IsMusicReady(*
this);
250 void set(const ::Music& music) {
251 stream = music.stream;
252 frameCount = music.frameCount;
253 looping = music.looping;
254 ctxType = music.ctxType;
255 ctxData = music.ctxData;
Music stream type (audio file streaming from memory)
Music(const std::string_view fileName)
Load music stream from file.
bool IsPlaying() const
Check if music is playing.
Music & Seek(float position)
Seek music to a position (in seconds)
Music & SetVolume(float volume)
Set volume for music.
void Load(const std::string_view fileType, unsigned char *data, int dataSize)
Load music stream from memory.
Music(const std::string_view fileType, std::span< unsigned char > data)
Load music stream from memory.
bool IsReady() const
Retrieve whether or not the Music has been loaded.
float GetTimePlayed() const
Get current music time played (in seconds)
Music & SetPan(float pan=0.5f)
Set pan for a music (0.5 is center)
Music & Stop()
Stop music playing.
Music & Play()
Start music playing.
void Load(const std::string_view fileType, std::span< unsigned char > data)
Load music stream from memory.
~Music()
Unload music stream.
Music(const std::string_view fileType, unsigned char *data, int dataSize)
Load music stream from memory.
Music & Resume()
Resume music playing.
Music & SetPitch(float pitch)
Set pitch for music.
float GetTimeLength() const
Get music time length (in seconds)
Music & Pause()
Pause music playing.
Music & Update()
Updates buffers for music streaming.
void Unload()
Unload music stream.
void Load(const std::string_view fileName)
Load music stream from file.
Exception used for most raylib-related exceptions.