Add Music ctors from RWops based on undocumented SDL_mixer functions

Fixes #92
This commit is contained in:
Dmitry Marakasov 2017-04-21 14:50:03 +03:00
parent e6738b9dad
commit bb2ff1f066
3 changed files with 42 additions and 1 deletions

View File

@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## 0.14.0 - unreleased
### Added
* ```Window::GetOpacity()``` and ```Window()::SetOpacity()``` wrappers for functions appeared in SDL 2.0.5
* ```Music``` RWops constructors based on undocumented SDL_mixer functions
### Changed
* libSDL2pp now follows SDL2 include path conventions, finding and using SDL2 headers without SDL2/ prefix

View File

@ -21,8 +21,9 @@
#include <cassert>
#include <SDL2pp/Music.hh>
#include <SDL2pp/Exception.hh>
#include <SDL2pp/Music.hh>
#include <SDL2pp/RWops.hh>
namespace SDL2pp {
@ -35,6 +36,16 @@ Music::Music(const std::string& file) {
throw Exception("Mix_LoadMUS");
}
Music::Music(RWops& rwops) {
if ((music_ = Mix_LoadMUS_RW(rwops.Get(), 0)) == nullptr)
throw Exception("Mix_LoadMUS_RW");
}
Music::Music(RWops& rwops, Mix_MusicType type) {
if ((music_ = Mix_LoadMUSType_RW(rwops.Get(), type, 0)) == nullptr)
throw Exception("Mix_LoadMUSType_RW");
}
Music::~Music() {
if (music_ != nullptr)
Mix_FreeMusic(music_);

View File

@ -30,6 +30,8 @@
namespace SDL2pp {
class RWops;
////////////////////////////////////////////////////////////
/// \brief %Music data
///
@ -63,6 +65,33 @@ public:
////////////////////////////////////////////////////////////
explicit Music(const std::string& file);
////////////////////////////////////////////////////////////
/// \brief Load music using RWops
///
/// This uses undocumented SDL_Mixer function. Comment
/// in SDL_mixer.h suggests it's only indended to work with
/// Ogg and MikMod.
///
/// \param[in] rwops SDL2pp::RWops used to access music data
///
/// \throws SDL2pp::Exception
///
////////////////////////////////////////////////////////////
explicit Music(RWops& rwops);
////////////////////////////////////////////////////////////
/// \brief Load music using RWops
///
/// This uses undocumented SDL_Mixer function.
///
/// \param[in] rwops SDL2pp::RWops used to access music data
/// \param[in] type Music type to load
///
/// \throws SDL2pp::Exception
///
////////////////////////////////////////////////////////////
Music(RWops& rwops, Mix_MusicType type);
////////////////////////////////////////////////////////////
/// \brief Destructor
///