Skip to content

Commit

Permalink
Update to v1.4
Browse files Browse the repository at this point in the history
added ability to copy a sound fx buffer from an external sound buffer directly; presumes full volume but can be modified afterwards.

added ability to get current music pause state; that is, whether the current music's state is current paused or not - returns a boolean.

added ability to 'restart' the current music from the beginning. this applies when the music is playing, stopped or paused.

updated year and version number.
  • Loading branch information
Hapaxia committed Nov 13, 2021
1 parent 3e56cae commit 1ddc36c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion SfmlSoundSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SFML Sound System (https://github.com/Hapaxia/SfmlSoundSystem)
//
// Copyright(c) 2016-2018 M.J.Silk
// Copyright(c) 2016-2021 M.J.Silk
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
Expand Down
2 changes: 1 addition & 1 deletion SfmlSoundSystem/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// Common
//
// Copyright(c) 2016-2018 M.J.Silk
// Copyright(c) 2016-2021 M.J.Silk
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
Expand Down
13 changes: 12 additions & 1 deletion SfmlSoundSystem/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// Control
//
// Copyright(c) 2016-2018 M.J.Silk
// Copyright(c) 2016-2021 M.J.Silk
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -75,6 +75,12 @@ void Control::update()
previous.stop();
}

bool Control::copyBuffer(const std::string& soundId, const sf::SoundBuffer& soundBuffer)
{
return m_bufferVolumes.emplace(soundId, 1.f).second &&
m_buffers.emplace(soundId, soundBuffer).second;
}

bool Control::loadBuffer(const std::string& soundId, const std::vector<char>& memoryBlock)
{
sf::SoundBuffer soundBuffer;
Expand Down Expand Up @@ -177,6 +183,11 @@ sf::Time Control::getCurrentMusicPosition() const
return sf::Time::Zero;
}

bool Control::restartMusic()
{
return playMusic(m_currentMusic);
}

void Control::pauseMusic()
{
if (getCurrentMusicStatus() == sf::SoundSource::Status::Playing)
Expand Down
12 changes: 10 additions & 2 deletions SfmlSoundSystem/Control.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// Control
//
// Copyright(c) 2016-2018 M.J.Silk
// Copyright(c) 2016-2021 M.J.Silk
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -50,12 +50,13 @@
namespace sfmlSoundSystem
{

// SSS (SFML Sound System) v1.3 - Control
// SSS (SFML Sound System) v1.4 - Control
class Control
{
public:
Control();
void update();
bool copyBuffer(const std::string& soundId, const sf::SoundBuffer& soundBuffer);
bool loadBuffer(const std::string& soundId, const std::vector<char>& memoryBlock);
bool linkMusic(const std::string& musicId, std::vector<char>& memoryBlock);
bool loadBuffer(const std::string& soundId, const char* memoryBlock, std::size_t memorySize);
Expand All @@ -67,6 +68,7 @@ class Control
bool assignVolumeSound(const std::string& soundId, float volume = 1.f);
bool assignVolumeMusic(const std::string& musicId, float volume = 1.f);
sf::Time getCurrentMusicPosition() const;
bool restartMusic();
void pauseMusic();
void resumeMusic();
void stopFx();
Expand All @@ -78,6 +80,7 @@ class Control
std::string getCurrentMusic() const;
sf::SoundSource::Status getCurrentMusicStatus() const;
unsigned int getNumberOfSoundsPlaying() const;
bool getIsCurrentlyPaused() const;



Expand Down Expand Up @@ -136,5 +139,10 @@ inline unsigned int Control::getNumberOfSoundsPlaying() const
return total;
}

inline bool Control::getIsCurrentlyPaused() const
{
return getCurrentMusicStatus() == sf::SoundSource::Status::Paused;
}

} // namespace sfmlSoundSystem
#endif // SFMLSOUNDSYSTEM_CONTROL_HPP

0 comments on commit 1ddc36c

Please sign in to comment.