From bb2ff1f066bc7d1c9f7f5a0dea6c8c4cc0f42c87 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Fri, 21 Apr 2017 14:50:03 +0300 Subject: [PATCH] Add Music ctors from RWops based on undocumented SDL_mixer functions Fixes #92 --- CHANGES.md | 1 + SDL2pp/Music.cc | 13 ++++++++++++- SDL2pp/Music.hh | 29 +++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index ba1ca60..d422eae 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/SDL2pp/Music.cc b/SDL2pp/Music.cc index f6cbd79..6c797d5 100644 --- a/SDL2pp/Music.cc +++ b/SDL2pp/Music.cc @@ -21,8 +21,9 @@ #include -#include #include +#include +#include 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_); diff --git a/SDL2pp/Music.hh b/SDL2pp/Music.hh index 82644cc..014aba7 100644 --- a/SDL2pp/Music.hh +++ b/SDL2pp/Music.hh @@ -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 ///