1#ifndef RAYLIB_CPP_INCLUDE_MUSIC_HPP_
2#define RAYLIB_CPP_INCLUDE_MUSIC_HPP_
8#include "./RaylibException.hpp"
9#include "./raylib-cpp-utils.hpp"
10#include "./raylib.hpp"
19 ::AudioStream stream = {
nullptr,
nullptr, 0, 0, 0},
20 unsigned int frameCount = 0,
23 void* ctxData =
nullptr)
24 : ::Music{stream, frameCount, looping, ctxType, ctxData} {}
26 Music(const ::Music& music) : ::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;
72 GETTER(::AudioStream, Stream, stream)
73 GETTER(
unsigned int, FrameCount, frameCount)
74 GETTERSETTER(
bool, Looping, looping)
75 GETTER(
int, CtxType, ctxType)
76 GETTER(
void*, CtxData, ctxData)
94 other.ctxData =
nullptr;
95 other.looping =
false;
105 void Unload() { ::UnloadMusicStream(*
this); }
111 ::PlayMusicStream(*
this);
119 ::UpdateMusicStream(*
this);
127 ::StopMusicStream(*
this);
135 ::PauseMusicStream(*
this);
143 ::ResumeMusicStream(*
this);
151 SeekMusicStream(*
this, position);
158 [[nodiscard]]
bool IsPlaying()
const { return ::IsMusicStreamPlaying(*
this); }
164 ::SetMusicVolume(*
this, volume);
172 ::SetMusicPitch(*
this, pitch);
180 ::SetMusicPan(*
this, pan);
187 [[nodiscard]]
float GetTimeLength()
const { return ::GetMusicTimeLength(*
this); }
192 [[nodiscard]]
float GetTimePlayed()
const { return ::GetMusicTimePlayed(*
this); }
199 void Load(
const std::string_view fileName) {
200 set(::LoadMusicStream(fileName.data()));
202 throw RaylibException(TextFormat(
"Failed to load Music from file: %s", fileName.data()));
211 void Load(
const std::string_view fileType,
unsigned char* data,
int dataSize) {
212 set(::LoadMusicStreamFromMemory(fileType.data(), data, dataSize));
214 throw RaylibException(TextFormat(
"Failed to load Music from %s file dat", fileType.data()));
223 void Load(
const std::string_view fileType, std::span<unsigned char> data) {
224 set(::LoadMusicStreamFromMemory(fileType.data(), data.data(),
static_cast<int>(data.size())));
226 throw RaylibException(TextFormat(
"Failed to load Music from %s file dat", fileType.data()));
235 bool IsValid()
const { return ::IsMusicValid(*
this); }
237 void set(const ::Music& music) {
238 stream = music.stream;
239 frameCount = music.frameCount;
240 looping = music.looping;
241 ctxType = music.ctxType;
242 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.
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.
bool IsValid() const
Retrieve whether or not the Music has been loaded.
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.
All raylib-cpp classes and functions appear in the raylib namespace.