diff --git a/SDLWrapper/Music.cpp b/SDLWrapper/Music.cpp index 9bdae9b..0fd8a41 100644 --- a/SDLWrapper/Music.cpp +++ b/SDLWrapper/Music.cpp @@ -1,4 +1,5 @@ #include "Music.h" +#include "_caster.h" #include "begin_code.h" //private void Music::_set(Mix_Music* p) @@ -21,6 +22,11 @@ Music::Music(const std::string& Filename) _set(Mix_LoadMUS(Filename.c_str())); } +Music::Music(const RWOP& rwop,MusicType musicType) +{ + _set(Mix_LoadMUSType_RW(rwop._get(),_internal::getMixMusicTypeFromMusicType(musicType),0)); +} + bool Music::isReady() const { return (_get()!=nullptr); diff --git a/SDLWrapper/Music.h b/SDLWrapper/Music.h index aebc972..e5cbc1e 100644 --- a/SDLWrapper/Music.h +++ b/SDLWrapper/Music.h @@ -4,6 +4,8 @@ #include #include "ErrorViewer.h" #include "Audio.h" +#include "RWOP.h" +#include "_MusicType.h" #include "__Noncopyable.h" #include "__Plugin.h" #include "begin_code.h" @@ -13,8 +15,10 @@ class Music public: Music()=default; Music(const std::string& Filename); + Music(const RWOP& rwop,MusicType musicType); bool isReady() const; void release(); + MusicType getType() const; private: std::shared_ptr _music; void _set(Mix_Music*); diff --git a/SDLWrapper/RWOP.h b/SDLWrapper/RWOP.h index 6c0530a..bebefb3 100644 --- a/SDLWrapper/RWOP.h +++ b/SDLWrapper/RWOP.h @@ -23,6 +23,8 @@ private: void _set(SDL_RWops*); friend class Surface; friend class Renderer; + friend class Sound; + friend class Music; friend class _internal::Plugin; }; diff --git a/SDLWrapper/Sound.cpp b/SDLWrapper/Sound.cpp index 5852cd2..768f7bd 100644 --- a/SDLWrapper/Sound.cpp +++ b/SDLWrapper/Sound.cpp @@ -21,6 +21,11 @@ Sound::Sound(const std::string& WAVFilename) _set(Mix_LoadWAV(WAVFilename.c_str())); } +Sound::Sound(const RWOP& rwop) +{ + _set(Mix_LoadWAV_RW(rwop._get(),0)); +} + bool Sound::isReady() const { return (_get()!=nullptr); diff --git a/SDLWrapper/Sound.h b/SDLWrapper/Sound.h index 3ab2e48..9cb9043 100644 --- a/SDLWrapper/Sound.h +++ b/SDLWrapper/Sound.h @@ -4,6 +4,7 @@ #include #include "Audio.h" #include "ErrorViewer.h" +#include "RWOP.h" #include "__Plugin.h" #include "begin_code.h" class Sound @@ -11,6 +12,7 @@ class Sound public: Sound() = default; Sound(const std::string& WAVFilename); + Sound(const RWOP& rwop); bool isReady() const; void release(); private: diff --git a/SDLWrapper/_MusicType.h b/SDLWrapper/_MusicType.h new file mode 100644 index 0000000..7a11c5a --- /dev/null +++ b/SDLWrapper/_MusicType.h @@ -0,0 +1,8 @@ +#pragma once +#include "include.h" +#include "begin_code.h" +enum class MusicType +{ + None,CMD,WAV,MOD,MID,OGG,MP3,MP3MAD,FLAC,MODPLUG +}; +#include "end_code.h" diff --git a/SDLWrapper/_caster.cpp b/SDLWrapper/_caster.cpp index 7fdbd1b..7db951c 100644 --- a/SDLWrapper/_caster.cpp +++ b/SDLWrapper/_caster.cpp @@ -282,5 +282,64 @@ int getIntFromMixInitFlag(MixInitFlag flag) } } +MusicType getMusicTypeFromMixMusicType(Mix_MusicType type) +{ + switch(type) + { + case MUS_NONE: + return MusicType::None; + case MUS_CMD: + return MusicType::CMD; + case MUS_WAV: + return MusicType::WAV; + case MUS_MOD: + return MusicType::MOD; + case MUS_MID: + return MusicType::MID; + case MUS_OGG: + return MusicType::OGG; + case MUS_MP3: + return MusicType::MP3; + case MUS_MP3_MAD: + return MusicType::MP3MAD; + case MUS_FLAC: + return MusicType::FLAC; + case MUS_MODPLUG: + return MusicType::MODPLUG; + default: + return MusicType::None; + } +} + +Mix_MusicType getMixMusicTypeFromMusicType(MusicType type) +{ + switch(type) + { + case MusicType::None: + return MUS_NONE; + case MusicType::CMD: + return MUS_CMD; + case MusicType::WAV: + return MUS_WAV; + case MusicType::MOD: + return MUS_MOD; + case MusicType::MID: + return MUS_MID; + case MusicType::OGG: + return MUS_OGG; + case MusicType::MP3: + return MUS_MP3; + case MusicType::MP3MAD: + return MUS_MP3_MAD; + case MusicType::FLAC: + return MUS_FLAC; + case MusicType::MODPLUG: + return MUS_MODPLUG; + default: + return MUS_NONE; + } +} + + }/// End of namespace _internal #include "end_code.h" diff --git a/SDLWrapper/_caster.h b/SDLWrapper/_caster.h index 171c403..4583215 100644 --- a/SDLWrapper/_caster.h +++ b/SDLWrapper/_caster.h @@ -8,6 +8,7 @@ #include "_SDLInitFlag.h" #include "_IMGInitFlag.h" #include "_MixInitFlag.h" +#include "_MusicType.h" #include #include "begin_code.h" namespace _internal @@ -24,5 +25,7 @@ SDL_RendererFlip getSDLRendererFlipFromFlipMode(FlipMode mode); Uint32 getUint32FromSDLInitFlag(SDLInitFlag flag); int getIntFromIMGInitFlag(IMGInitFlag flag); int getIntFromMixInitFlag(MixInitFlag flag); +MusicType getMusicTypeFromMixMusicType(Mix_MusicType); +Mix_MusicType getMixMusicTypeFromMusicType(MusicType); }/// End of namespace _internal #include "end_code.h"