P-E-R-R-Y
Utilitaires, contrats et vendors du moteur, en une seule doc
Loading...
Searching...
No Matches
SfmlMusic Class Reference

sfml music stream. More...

#include <SfmlMusic.hpp>

Inheritance diagram for SfmlMusic:
Collaboration diagram for SfmlMusic:

Public Member Functions

 SfmlMusic (std::string path)
 ~SfmlMusic () override=default
bool isReady () const override
void play () override
 Starts playback.
void pause () override
 Suspends playback without touching the position.
void stop () override
 Stops playback AND rewinds to zero.
void update () override
 Must be called every frame.
void setVolume (float volume) override
 set the volume of the music
float getVolume () const override
 get the volume of the music
void setLoop (bool loop) override
 set the music to loop or not
bool getLoop () const override
 get if the music is looping or not
void setTime (float position) override
 Set the time of the music in seconds.
float getTime () const override
 Get the current time of the music in seconds.
float getLength () const override
 Get the Length of the music.
void setPosition (Vector3f position) override
 set the 3D position of the music, for backends that spatialize against a listener. A backend without real spatial audio may just store this and keep playing at full volume - a no-op here still leaves usable music, unlike a fake 3D model with nothing to render.
Vector3f getPosition () const override
 get the 3D position of the music
void setVelocity (Vector3f velocity) override
 set the velocity of the music, used by backends that apply a doppler effect
Vector3f getVelocity () const override
 get the velocity of the music
Public Member Functions inherited from audio::IMusic
virtual ~IMusic ()=default

Detailed Description

sfml music stream.

sf::Music already carries the three states (stopped/playing/paused), so play()/pause()/stop() just guard on getStatus() - raylib, by contrast, had to track an enum by hand. setTime() clamps the position, sfml falling back to zero past the end.

Constructor & Destructor Documentation

◆ SfmlMusic()

SfmlMusic::SfmlMusic ( std::string path)
inline

◆ ~SfmlMusic()

SfmlMusic::~SfmlMusic ( )
overridedefault

Member Function Documentation

◆ getLength()

float SfmlMusic::getLength ( ) const
inlineoverridevirtual

Get the Length of the music.

Returns
float

Implements audio::IMusic.

◆ getLoop()

bool SfmlMusic::getLoop ( ) const
inlineoverridevirtual

get if the music is looping or not

Returns
true
false

Implements audio::IMusic.

◆ getPosition()

Vector3f SfmlMusic::getPosition ( ) const
inlineoverridevirtual

get the 3D position of the music

Returns
Vector3f

Implements audio::IMusic.

◆ getTime()

float SfmlMusic::getTime ( ) const
inlineoverridevirtual

Get the current time of the music in seconds.

Returns
float

Implements audio::IMusic.

◆ getVelocity()

Vector3f SfmlMusic::getVelocity ( ) const
inlineoverridevirtual

get the velocity of the music

Returns
Vector3f

Implements audio::IMusic.

◆ getVolume()

float SfmlMusic::getVolume ( ) const
inlineoverridevirtual

get the volume of the music

Returns
float

Implements audio::IMusic.

◆ isReady()

bool SfmlMusic::isReady ( ) const
inlineoverridevirtual

Implements audio::IMusic.

◆ pause()

void SfmlMusic::pause ( )
inlineoverridevirtual

Suspends playback without touching the position.

Does nothing if the stream is not playing. Idempotent.

Implements audio::IMusic.

◆ play()

void SfmlMusic::play ( )
inlineoverridevirtual

Starts playback.

Three states, and every action does ONLY what it says :

stopped --play()--> playing  --pause()--> paused
paused  --play()--> playing  (resumes where it was)
stopped --play()--> playing  (from zero)

play() on a stream that is already playing DOES NOTHING. It does not restart from the beginning : without that rule, a play() called every frame stutters on one vendor and plays normally on the other. To restart, call stop() then play(), or setTime(0) - explicitly.

Implements audio::IMusic.

◆ setLoop()

void SfmlMusic::setLoop ( bool loop)
inlineoverridevirtual

set the music to loop or not

Parameters
loop

Implements audio::IMusic.

◆ setPosition()

void SfmlMusic::setPosition ( Vector3f position)
inlineoverridevirtual

set the 3D position of the music, for backends that spatialize against a listener. A backend without real spatial audio may just store this and keep playing at full volume - a no-op here still leaves usable music, unlike a fake 3D model with nothing to render.

Parameters
position

Implements audio::IMusic.

◆ setTime()

void SfmlMusic::setTime ( float position)
inlineoverridevirtual

Set the time of the music in seconds.

The position is CLAMPED to [0, getLength()] : asking past the end stops at the end, a negative value rewinds to zero. Without that rule each vendor improvises - raylib wrapped around (115s on a 109s track gave 6s) where sfml fell to 0.

Parameters
position

Implements audio::IMusic.

◆ setVelocity()

void SfmlMusic::setVelocity ( Vector3f velocity)
inlineoverridevirtual

set the velocity of the music, used by backends that apply a doppler effect

Parameters
velocity

Implements audio::IMusic.

◆ setVolume()

void SfmlMusic::setVolume ( float volume)
inlineoverridevirtual

set the volume of the music

Parameters
volume

Implements audio::IMusic.

◆ stop()

void SfmlMusic::stop ( )
inlineoverridevirtual

Stops playback AND rewinds to zero.

Does nothing if the stream is already stopped. Idempotent.

Implements audio::IMusic.

◆ update()

void SfmlMusic::update ( )
inlineoverridevirtual

Must be called every frame.

On a backend that refills its buffer in a thread this is a no-op - the call stays mandatory and always valid, otherwise game code would have to know which vendor is behind it.

This is also where a non-looping stream that reaches its end moves itself into the state of a stop().

Implements audio::IMusic.


The documentation for this class was generated from the following file: