MiniEngine/SDLWrapper/Music.cpp

113 lines
1.6 KiB
C++
Raw Normal View History

#include "Music.h"
#include "begin_code.h"
2017-06-23 13:17:55 +08:00
//private
void Music::_set(Mix_Music* p)
{
_music.reset(p,Mix_FreeMusic);
}
2017-06-23 13:17:55 +08:00
//private
void Music::_clear()
{
_music.reset();
}
2017-06-23 13:17:55 +08:00
//private
Mix_Music* Music::_get() const
{
return _music.get();
}
2017-06-23 13:17:55 +08:00
Music::Music(const std::string& Filename)
{
_set(Mix_LoadMUS(Filename.c_str()));
}
bool Music::isReady() const
{
return (_get()!=nullptr);
}
void Music::release()
{
_clear();
}
//static
int MusicPlayer::GetDecoderNum()
{
return Mix_GetNumMusicDecoders();
}
//static
std::string MusicPlayer::GetDecoderName(int index)
{
return std::string(Mix_GetMusicDecoder(index));
}
int MusicPlayer::play(Music music, int loops)
{
m = music;
return Mix_PlayMusic(m._get(), loops);
}
void MusicPlayer::pause()
{
Mix_PauseMusic();
}
void MusicPlayer::resume()
{
Mix_ResumeMusic();
}
void MusicPlayer::rewind()
{
Mix_RewindMusic();
}
int MusicPlayer::stop()
{
return Mix_HaltMusic();
}
int MusicPlayer::fadeIn(int loops, int ms)
{
return Mix_FadeInMusic(m._get(), loops, ms);
}
int MusicPlayer::fadeOut(int ms)
{
return Mix_FadeOutMusic(ms);
}
2017-06-23 13:17:55 +08:00
bool MusicPlayer::isPlaying() const
{
return (Mix_PlayingMusic() == 1);
}
2017-06-23 13:17:55 +08:00
bool MusicPlayer::isPaused() const
{
return (Mix_PausedMusic() == 1);
}
2017-06-23 13:17:55 +08:00
int MusicPlayer::isFading() const
{
switch (Mix_FadingMusic())
{
case MIX_NO_FADING:
return 0;
case MIX_FADING_IN:
return 1;
case MIX_FADING_OUT:
return 2;
default:
return -1;
}
}
2017-06-23 13:17:55 +08:00
int MusicPlayer::setPosition(double second)
{
2017-06-23 13:17:55 +08:00
return Mix_SetMusicPosition(second);
}
#include "end_code.h"