36 _music = Mix_LoadMUS(path.c_str());
38 std::cerr <<
"Failed to load music: " << Mix_GetError() << std::endl;
45 Mix_FreeMusic(_music);
48 bool isReady()
const override {
return _music !=
nullptr; }
53 if (mine() && Mix_PausedMusic()) {
57 Mix_PlayMusic(_music, _loop ? -1 : 0);
59 Mix_VolumeMusic(
static_cast<int>(_volume * MIX_MAX_VOLUME));
81 Mix_VolumeMusic(
static_cast<int>(volume * MIX_MAX_VOLUME));
84 float getVolume()
const override {
return _volume; }
89 void setLoop(
bool loop)
override { _loop = loop; }
90 bool getLoop()
const override {
return _loop; }
96 if (Mix_SetMusicPosition(position) == 0)
103 float getTime()
const override {
return _elapsed; }
109 const double length = Mix_MusicDuration(_music);
111 return (length < 0) ? 0.f :
static_cast<float>(length);
123 bool mine()
const {
return _music !=
nullptr && _current == _music; }
125 Mix_Music *_music =
nullptr;
128 static inline Mix_Music *_current =
nullptr;
132 float _elapsed = 0.f;
void update() override
SDL_mixer decode sur son propre fil : rien a pousser par frame.
Definition SdlMusic.hpp:76
float getVolume() const override
get the volume of the music
Definition SdlMusic.hpp:84
void stop() override
Stops playback AND rewinds to zero.
Definition SdlMusic.hpp:67
SdlMusic(std::string path)
Definition SdlMusic.hpp:35
void setVelocity(Vector3f velocity) override
set the velocity of the music, used by backends that apply a doppler effect
Definition SdlMusic.hpp:118
void pause() override
Suspends playback without touching the position.
Definition SdlMusic.hpp:62
~SdlMusic() override
Definition SdlMusic.hpp:41
void play() override
Starts playback.
Definition SdlMusic.hpp:50
void setTime(float position) override
Set the time of the music in seconds.
Definition SdlMusic.hpp:92
void setPosition(Vector3f position) override
set the 3D position of the music, for backends that spatialize against a listener....
Definition SdlMusic.hpp:115
bool isReady() const override
Definition SdlMusic.hpp:48
Vector3f getPosition() const override
get the 3D position of the music
Definition SdlMusic.hpp:116
Vector3f getVelocity() const override
get the velocity of the music
Definition SdlMusic.hpp:119
void setLoop(bool loop) override
set the music to loop or not
Definition SdlMusic.hpp:89
float getLength() const override
Get the Length of the music.
Definition SdlMusic.hpp:105
float getTime() const override
Get the current time of the music in seconds.
Definition SdlMusic.hpp:103
void setVolume(float volume) override
set the volume of the music
Definition SdlMusic.hpp:78
bool getLoop() const override
get if the music is looping or not
Definition SdlMusic.hpp:90
Vector3< double > Vector3f
Definition Vector3.hpp:121