5 #include <Multimedia/SDX.h>
6 #include <Multimedia/Sound.h>
21 static bool nextRestart;
23 Mix_Music* handle =
nullptr;
30 std::chrono::system_clock::time_point startTime;
31 double restartPosition = 0;
35 static void Finished()
39 auto diff = std::chrono::system_clock::now() - active->startTime;
40 active->restartPosition += (double)std::chrono::duration_cast<std::chrono::milliseconds>(diff).count() / 1000;
50 Music(
const char *ファイル名,
double 音量 = 1.0)
57 bool Load(
const char *ファイル名,
double 音量 = 1.0)
59 if (Loading::isLoading)
65 if (handle !=
nullptr){
return false; }
68 handle = Mix_LoadMUS(ファイル名);
69 volume = int(音量 * 255);
77 if (handle ==
nullptr){
return false; }
79 Mix_FreeMusic(handle);
85 bool Play(
bool ループ再生フラグ =
true )
88 if (handle ==
nullptr){
return false; }
91 if (active && active->fadeOutTime > 0)
100 int isLoop = ( 1 - ループ再生フラグ * 2);
104 Mix_PlayMusic(handle, isLoop );
108 Mix_FadeInMusic(handle, isLoop , fadeInTime);
111 startTime = std::chrono::system_clock::now();
112 Mix_VolumeMusic(volume / 2);
123 if (handle ==
nullptr){
return false; }
126 if (active && active->fadeOutTime > 0)
140 int isLoop = ( 1 - ループ再生フラグ * 2);
144 Mix_PlayMusic(handle, isLoop);
145 if (restartPosition > 0)
147 Mix_SetMusicPosition(restartPosition);
152 Mix_FadeInMusicPos(handle, isLoop, fadeInTime, restartPosition);
155 startTime = std::chrono::system_clock::now();
156 Mix_VolumeMusic(volume / 2);
165 volume = int(音量 * 255);
172 fadeInTime = std::max(0,フェードイン時間);
179 fadeOutTime = std::max(0,フェードアウト時間);
187 return (Mix_PlayingMusic() == 1);
194 if (!
Check()){
return false; }
196 if (active->fadeOutTime <= 0)
202 Mix_FadeOutMusic( active->fadeOutTime );
212 Mix_VolumeMusic(
int(音量 * 255));
223 return next->
Restart(nextLoop);
227 return next->
Play(nextLoop);
void SetFadeInTime(int フェードイン時間)
再生時のフェードイン時間を設定[ミリ秒].
Definition: Music.h:170
void SetFadeOutTime(int フェードアウト時間)
停止時のフェードアウト時間を設定[ミリ秒].
Definition: Music.h:177
bool Destroy()
音声ファイルを解放.
Definition: Music.h:75
ライブラリの初期化やシステム的な処理を行う関数群.
Definition: System.h:13
bool Play(bool ループ再生フラグ=true)
音声ファイルを先頭から再生.
Definition: Music.h:85
static bool Stop()
再生中のMusicを停止.
Definition: Music.h:192
bool Load(const char *ファイル名, double 音量=1.0)
音声ファイルを登録.
Definition: Music.h:57
static void AddLoading(std::function< void(void)> &&読み込み関数)
非同期読み込み処理に追加.
Definition: Loading.h:96
BGM用音声を表すクラス.
Definition: Music.h:14
static bool Update()
fadeOut付きで終了した後に次Musicを再生するための処理.
Definition: Music.h:217
static void ChangeVolume(double 音量)
再生中の音量を変更.
Definition: Music.h:210
bool Restart(bool ループ再生フラグ=true)
前回停止した位置から再生.
Definition: Music.h:120
void SetVolume(double 音量)
0~1.0で音量を設定.
Definition: Music.h:163
static bool Check()
再生中か確認.
Definition: Music.h:184
Music(const char *ファイル名, double 音量=1.0)
音声ファイルを登録.
Definition: Music.h:50