mirror of
https://github.com/SFML/SFML.git
synced 2024-11-24 20:31:05 +08:00
Make Sound::Status a scoped enumeration
This commit is contained in:
parent
04c36fdd1a
commit
bdd348c142
@ -28,7 +28,7 @@ void playSound()
|
||||
sound.play();
|
||||
|
||||
// Loop while the sound is playing
|
||||
while (sound.getStatus() == sf::Sound::Playing)
|
||||
while (sound.getStatus() == sf::Sound::Status::Playing)
|
||||
{
|
||||
// Leave some CPU time for other processes
|
||||
sf::sleep(sf::milliseconds(100));
|
||||
@ -62,7 +62,7 @@ void playMusic(const std::filesystem::path& filename)
|
||||
music.play();
|
||||
|
||||
// Loop while the music is playing
|
||||
while (music.getStatus() == sf::Music::Playing)
|
||||
while (music.getStatus() == sf::Music::Status::Playing)
|
||||
{
|
||||
// Leave some CPU time for other processes
|
||||
sf::sleep(sf::milliseconds(100));
|
||||
|
@ -110,7 +110,7 @@ int main()
|
||||
sound.play();
|
||||
|
||||
// Wait until finished
|
||||
while (sound.getStatus() == sf::Sound::Playing)
|
||||
while (sound.getStatus() == sf::Sound::Status::Playing)
|
||||
{
|
||||
// Display the playing position
|
||||
std::cout << "\rPlaying... " << sound.getPlayingOffset().asSeconds() << " sec ";
|
||||
|
@ -179,7 +179,7 @@ void doServer(unsigned short port)
|
||||
audioStream.start(port);
|
||||
|
||||
// Loop until the sound playback is finished
|
||||
while (audioStream.getStatus() != sf::SoundStream::Stopped)
|
||||
while (audioStream.getStatus() != sf::SoundStream::Status::Stopped)
|
||||
{
|
||||
// Leave some CPU time for other threads
|
||||
sf::sleep(sf::milliseconds(100));
|
||||
@ -195,7 +195,7 @@ void doServer(unsigned short port)
|
||||
audioStream.play();
|
||||
|
||||
// Loop until the sound playback is finished
|
||||
while (audioStream.getStatus() != sf::SoundStream::Stopped)
|
||||
while (audioStream.getStatus() != sf::SoundStream::Status::Stopped)
|
||||
{
|
||||
// Leave some CPU time for other threads
|
||||
sf::sleep(sf::milliseconds(100));
|
||||
|
@ -49,7 +49,7 @@ public:
|
||||
/// \brief Enumeration of the sound source states
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
enum Status
|
||||
enum class Status
|
||||
{
|
||||
Stopped, //!< Sound is not playing
|
||||
Paused, //!< Sound is paused
|
||||
|
@ -164,7 +164,7 @@ void Music::setLoopPoints(TimeSpan timePoints)
|
||||
setPlayingOffset(oldPos);
|
||||
|
||||
// Resume
|
||||
if (oldStatus == Playing)
|
||||
if (oldStatus == Status::Playing)
|
||||
play();
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ struct Sound::Impl
|
||||
soundConfig.endCallback = [](void* userData, ma_sound* soundPtr)
|
||||
{
|
||||
auto& impl = *static_cast<Impl*>(userData);
|
||||
impl.status = Stopped;
|
||||
impl.status = Status::Stopped;
|
||||
|
||||
// Seek back to the start of the sound when it finishes playing
|
||||
if (const ma_result result = ma_sound_seek_to_pcm_frame(soundPtr, 0); result != MA_SUCCESS)
|
||||
@ -214,7 +214,7 @@ struct Sound::Impl
|
||||
std::size_t cursor{}; //!< The current playing position
|
||||
bool looping{}; //!< True if we are looping the sound
|
||||
const SoundBuffer* buffer{}; //!< Sound buffer bound to the source
|
||||
Status status{Stopped}; //!< The status
|
||||
Status status{Status::Stopped}; //!< The status
|
||||
};
|
||||
|
||||
|
||||
@ -249,7 +249,7 @@ Sound::~Sound()
|
||||
////////////////////////////////////////////////////////////
|
||||
void Sound::play()
|
||||
{
|
||||
if (m_impl->status == Playing)
|
||||
if (m_impl->status == Status::Playing)
|
||||
setPlayingOffset(Time::Zero);
|
||||
|
||||
if (const ma_result result = ma_sound_start(&m_impl->sound); result != MA_SUCCESS)
|
||||
@ -258,7 +258,7 @@ void Sound::play()
|
||||
}
|
||||
else
|
||||
{
|
||||
m_impl->status = Playing;
|
||||
m_impl->status = Status::Playing;
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,8 +272,8 @@ void Sound::pause()
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_impl->status == Playing)
|
||||
m_impl->status = Paused;
|
||||
if (m_impl->status == Status::Playing)
|
||||
m_impl->status = Status::Paused;
|
||||
}
|
||||
}
|
||||
|
||||
@ -288,7 +288,7 @@ void Sound::stop()
|
||||
else
|
||||
{
|
||||
setPlayingOffset(Time::Zero);
|
||||
m_impl->status = Stopped;
|
||||
m_impl->status = Status::Stopped;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ struct SoundStream::Impl
|
||||
// Seek back to the start of the sound when it finishes playing
|
||||
auto& impl = *static_cast<Impl*>(userData);
|
||||
impl.streaming = true;
|
||||
impl.status = Stopped;
|
||||
impl.status = Status::Stopped;
|
||||
|
||||
if (const ma_result result = ma_sound_seek_to_pcm_frame(soundPtr, 0); result != MA_SUCCESS)
|
||||
err() << "Failed to seek sound to frame 0: " << ma_result_description(result) << std::endl;
|
||||
@ -250,7 +250,7 @@ struct SoundStream::Impl
|
||||
std::vector<SoundChannel> channelMap{}; //!< The map of position in sample frame to sound channel
|
||||
bool loop{}; //!< Loop flag (true to loop, false to play once)
|
||||
bool streaming{true}; //!< True if we are still streaming samples from the source
|
||||
Status status{Stopped}; //!< The status
|
||||
Status status{Status::Stopped}; //!< The status
|
||||
};
|
||||
|
||||
|
||||
@ -279,7 +279,7 @@ void SoundStream::initialize(unsigned int channelCount, unsigned int sampleRate,
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::play()
|
||||
{
|
||||
if (m_impl->status == Playing)
|
||||
if (m_impl->status == Status::Playing)
|
||||
setPlayingOffset(Time::Zero);
|
||||
|
||||
if (const ma_result result = ma_sound_start(&m_impl->sound); result != MA_SUCCESS)
|
||||
@ -288,7 +288,7 @@ void SoundStream::play()
|
||||
}
|
||||
else
|
||||
{
|
||||
m_impl->status = Playing;
|
||||
m_impl->status = Status::Playing;
|
||||
}
|
||||
}
|
||||
|
||||
@ -302,8 +302,8 @@ void SoundStream::pause()
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_impl->status == Playing)
|
||||
m_impl->status = Paused;
|
||||
if (m_impl->status == Status::Playing)
|
||||
m_impl->status = Status::Paused;
|
||||
}
|
||||
}
|
||||
|
||||
@ -318,7 +318,7 @@ void SoundStream::stop()
|
||||
else
|
||||
{
|
||||
setPlayingOffset(Time::Zero);
|
||||
m_impl->status = Stopped;
|
||||
m_impl->status = Status::Stopped;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user