mirror of
https://github.com/Kiritow/MiniEngine.git
synced 2024-03-22 13:11:22 +08:00
Update Music Wrapper
This commit is contained in:
parent
4319ee521b
commit
0ea8797093
|
@ -1,20 +1,36 @@
|
|||
#include "Music.h"
|
||||
#include "begin_code.h"
|
||||
void Music::_set(Mix_Music* p)//private
|
||||
//private
|
||||
void Music::_set(Mix_Music* p)
|
||||
{
|
||||
_music.reset(p,Mix_FreeMusic);
|
||||
}
|
||||
|
||||
void Music::_clear()//private
|
||||
//private
|
||||
void Music::_clear()
|
||||
{
|
||||
_music.reset();
|
||||
}
|
||||
|
||||
Mix_Music* Music::_get()//private
|
||||
//private
|
||||
Mix_Music* Music::_get() const
|
||||
{
|
||||
return _music.get();
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
|
@ -27,20 +43,6 @@ std::string MusicPlayer::GetDecoderName(int index)
|
|||
return std::string(Mix_GetMusicDecoder(index));
|
||||
}
|
||||
|
||||
Music MusicPlayer::loadMusic(const std::string& Filename) throw(ErrorViewer)
|
||||
{
|
||||
Mix_Music* temp = Mix_LoadMUS(Filename.c_str());
|
||||
if (temp == nullptr)
|
||||
{
|
||||
ErrorViewer e;
|
||||
e.fetch();
|
||||
throw e;
|
||||
}
|
||||
Music m;
|
||||
m._set(temp);
|
||||
return m;
|
||||
}
|
||||
|
||||
int MusicPlayer::play(Music music, int loops)
|
||||
{
|
||||
m = music;
|
||||
|
@ -77,17 +79,17 @@ int MusicPlayer::fadeOut(int ms)
|
|||
return Mix_FadeOutMusic(ms);
|
||||
}
|
||||
|
||||
bool MusicPlayer::isPlaying()
|
||||
bool MusicPlayer::isPlaying() const
|
||||
{
|
||||
return (Mix_PlayingMusic() == 1);
|
||||
}
|
||||
|
||||
bool MusicPlayer::isPaused()
|
||||
bool MusicPlayer::isPaused() const
|
||||
{
|
||||
return (Mix_PausedMusic() == 1);
|
||||
}
|
||||
|
||||
int MusicPlayer::isFading()
|
||||
int MusicPlayer::isFading() const
|
||||
{
|
||||
switch (Mix_FadingMusic())
|
||||
{
|
||||
|
@ -102,10 +104,9 @@ int MusicPlayer::isFading()
|
|||
}
|
||||
}
|
||||
|
||||
//static
|
||||
int MusicPlayer::SetMusicPosition(double position)
|
||||
int MusicPlayer::setPosition(double second)
|
||||
{
|
||||
return Mix_SetMusicPosition(position);
|
||||
return Mix_SetMusicPosition(second);
|
||||
}
|
||||
|
||||
#include "end_code.h"
|
||||
|
|
|
@ -4,45 +4,43 @@
|
|||
#include <string>
|
||||
#include "ErrorViewer.h"
|
||||
#include "Audio.h"
|
||||
#include "__Noncopyable.h"
|
||||
#include "begin_code.h"
|
||||
/// Forward Declaration
|
||||
class Music
|
||||
{
|
||||
public:
|
||||
|
||||
protected:
|
||||
Music() = default;
|
||||
Music()=default;
|
||||
Music(const std::string& Filename);
|
||||
bool isReady() const;
|
||||
void release();
|
||||
private:
|
||||
std::shared_ptr<Mix_Music> _music;
|
||||
void _set(Mix_Music*);
|
||||
void _clear();
|
||||
Mix_Music* _get();
|
||||
Mix_Music* _get() const;
|
||||
friend class MusicPlayer;
|
||||
};
|
||||
|
||||
class MusicPlayer : public AudioPlayer
|
||||
class MusicPlayer : public AudioPlayer, public NonCopyable
|
||||
{
|
||||
public:
|
||||
static int GetDecoderNum();
|
||||
static std::string GetDecoderName(int index);
|
||||
|
||||
Music loadMusic(const std::string& Filename) throw (ErrorViewer);
|
||||
|
||||
/// Play Music. Loop: -1:Infinite, >0:Exact that time.
|
||||
int play(Music music, int loops);
|
||||
void pause();
|
||||
void resume();
|
||||
void rewind();
|
||||
int setPosition(double second);
|
||||
int stop();
|
||||
int fadeIn(int loops, int ms);
|
||||
int fadeOut(int ms);
|
||||
|
||||
bool isPlaying();
|
||||
bool isPaused();
|
||||
int isFading();
|
||||
|
||||
/// Experimental
|
||||
static int SetMusicPosition(double position);
|
||||
|
||||
bool isPlaying() const;
|
||||
bool isPaused() const;
|
||||
int isFading() const;
|
||||
private:
|
||||
Music m;
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#pragma once
|
||||
#include "begin_code.h"
|
||||
class NonCopyable
|
||||
{
|
||||
protected:
|
||||
|
@ -7,3 +8,4 @@ protected:
|
|||
NonCopyable(const NonCopyable&) = delete;
|
||||
NonCopyable& operator = (const NonCopyable&) = delete;
|
||||
};
|
||||
#include "end_code.h"
|
||||
|
|
Loading…
Reference in New Issue
Block a user