RWOP can now work with Music and Sound loading

This commit is contained in:
Kirigaya Kazuto 2017-07-04 22:38:33 +08:00
parent 977721b226
commit 52918909e9
8 changed files with 89 additions and 0 deletions

View File

@ -1,4 +1,5 @@
#include "Music.h" #include "Music.h"
#include "_caster.h"
#include "begin_code.h" #include "begin_code.h"
//private //private
void Music::_set(Mix_Music* p) void Music::_set(Mix_Music* p)
@ -21,6 +22,11 @@ Music::Music(const std::string& Filename)
_set(Mix_LoadMUS(Filename.c_str())); _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 bool Music::isReady() const
{ {
return (_get()!=nullptr); return (_get()!=nullptr);

View File

@ -4,6 +4,8 @@
#include <string> #include <string>
#include "ErrorViewer.h" #include "ErrorViewer.h"
#include "Audio.h" #include "Audio.h"
#include "RWOP.h"
#include "_MusicType.h"
#include "__Noncopyable.h" #include "__Noncopyable.h"
#include "__Plugin.h" #include "__Plugin.h"
#include "begin_code.h" #include "begin_code.h"
@ -13,8 +15,10 @@ class Music
public: public:
Music()=default; Music()=default;
Music(const std::string& Filename); Music(const std::string& Filename);
Music(const RWOP& rwop,MusicType musicType);
bool isReady() const; bool isReady() const;
void release(); void release();
MusicType getType() const;
private: private:
std::shared_ptr<Mix_Music> _music; std::shared_ptr<Mix_Music> _music;
void _set(Mix_Music*); void _set(Mix_Music*);

View File

@ -23,6 +23,8 @@ private:
void _set(SDL_RWops*); void _set(SDL_RWops*);
friend class Surface; friend class Surface;
friend class Renderer; friend class Renderer;
friend class Sound;
friend class Music;
friend class _internal::Plugin; friend class _internal::Plugin;
}; };

View File

@ -21,6 +21,11 @@ Sound::Sound(const std::string& WAVFilename)
_set(Mix_LoadWAV(WAVFilename.c_str())); _set(Mix_LoadWAV(WAVFilename.c_str()));
} }
Sound::Sound(const RWOP& rwop)
{
_set(Mix_LoadWAV_RW(rwop._get(),0));
}
bool Sound::isReady() const bool Sound::isReady() const
{ {
return (_get()!=nullptr); return (_get()!=nullptr);

View File

@ -4,6 +4,7 @@
#include <string> #include <string>
#include "Audio.h" #include "Audio.h"
#include "ErrorViewer.h" #include "ErrorViewer.h"
#include "RWOP.h"
#include "__Plugin.h" #include "__Plugin.h"
#include "begin_code.h" #include "begin_code.h"
class Sound class Sound
@ -11,6 +12,7 @@ class Sound
public: public:
Sound() = default; Sound() = default;
Sound(const std::string& WAVFilename); Sound(const std::string& WAVFilename);
Sound(const RWOP& rwop);
bool isReady() const; bool isReady() const;
void release(); void release();
private: private:

8
SDLWrapper/_MusicType.h Normal file
View File

@ -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"

View File

@ -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 }/// End of namespace _internal
#include "end_code.h" #include "end_code.h"

View File

@ -8,6 +8,7 @@
#include "_SDLInitFlag.h" #include "_SDLInitFlag.h"
#include "_IMGInitFlag.h" #include "_IMGInitFlag.h"
#include "_MixInitFlag.h" #include "_MixInitFlag.h"
#include "_MusicType.h"
#include <vector> #include <vector>
#include "begin_code.h" #include "begin_code.h"
namespace _internal namespace _internal
@ -24,5 +25,7 @@ SDL_RendererFlip getSDLRendererFlipFromFlipMode(FlipMode mode);
Uint32 getUint32FromSDLInitFlag(SDLInitFlag flag); Uint32 getUint32FromSDLInitFlag(SDLInitFlag flag);
int getIntFromIMGInitFlag(IMGInitFlag flag); int getIntFromIMGInitFlag(IMGInitFlag flag);
int getIntFromMixInitFlag(MixInitFlag flag); int getIntFromMixInitFlag(MixInitFlag flag);
MusicType getMusicTypeFromMixMusicType(Mix_MusicType);
Mix_MusicType getMixMusicTypeFromMusicType(MusicType);
}/// End of namespace _internal }/// End of namespace _internal
#include "end_code.h" #include "end_code.h"