5 #include <Multimedia/SDX.h>
6 #include <Multimedia/Sound.h>
22 static bool nextRestart;
23 static int mainVolume;
25 Mix_Music* handle =
nullptr;
32 std::chrono::system_clock::time_point startTime;
33 double restartPosition = 0;
37 static void Finished()
41 auto diff = std::chrono::system_clock::now() - active->startTime;
42 active->restartPosition += (double)std::chrono::duration_cast<std::chrono::milliseconds>(diff).count() / 1000;
52 Music(
const char *ファイル名,
double 音量 = 1.0)
59 bool Load(
const char *ファイル名,
double 音量 = 1.0)
61 if (Loading::isLoading)
67 if (handle !=
nullptr){
return false; }
70 handle = Mix_LoadMUS(ファイル名);
71 volume = int(音量 * MIX_MAX_VOLUME);
79 if (handle ==
nullptr){
return false; }
81 Mix_FreeMusic(handle);
87 bool Play(
bool ループ再生フラグ =
true )
90 if (handle ==
nullptr){
return false; }
93 if (active && active->fadeOutTime > 0)
102 int isLoop = ( 1 - ループ再生フラグ * 2);
106 Mix_PlayMusic(handle, isLoop );
110 Mix_FadeInMusic(handle, isLoop , fadeInTime);
113 startTime = std::chrono::system_clock::now();
114 Mix_VolumeMusic(volume * mainVolume / MIX_MAX_VOLUME);
125 if (handle ==
nullptr){
return false; }
128 if (active && active->fadeOutTime > 0)
142 int isLoop = ( 1 - ループ再生フラグ * 2);
146 Mix_PlayMusic(handle, isLoop);
147 if (restartPosition > 0)
149 Mix_SetMusicPosition(restartPosition);
154 Mix_FadeInMusicPos(handle, isLoop, fadeInTime, restartPosition);
157 startTime = std::chrono::system_clock::now();
158 Mix_VolumeMusic(volume * mainVolume / MIX_MAX_VOLUME);
167 volume = int(音量 * 255);
174 fadeInTime = std::max(0,フェードイン時間);
181 fadeOutTime = std::max(0,フェードアウト時間);
189 return (Mix_PlayingMusic() == 1);
196 if (!
Check()){
return false; }
198 if (active->fadeOutTime <= 0)
204 Mix_FadeOutMusic( active->fadeOutTime );
214 Mix_VolumeMusic(
int(音量 * mainVolume));
222 mainVolume = int(音量 * MIX_MAX_VOLUME);
227 Mix_VolumeMusic(mainVolume * active->volume / MIX_MAX_VOLUME);
239 return next->
Restart(nextLoop);
243 return next->
Play(nextLoop);
void SetFadeInTime(int フェードイン時間)
再生時のフェードイン時間を設定[ミリ秒].
Definition: Music.h:172
void SetFadeOutTime(int フェードアウト時間)
停止時のフェードアウト時間を設定[ミリ秒].
Definition: Music.h:179
bool Destroy()
音声ファイルを解放.
Definition: Music.h:77
static void SetMainVolume(double 音量)
全体の音量を0~1.0の範囲で設定.
Definition: Music.h:219
ライブラリの初期化やシステム的な処理を行う関数群.
Definition: System.h:23
bool Play(bool ループ再生フラグ=true)
音声ファイルを先頭から再生.
Definition: Music.h:87
static bool Stop()
再生中のMusicを停止.
Definition: Music.h:194
bool Load(const char *ファイル名, double 音量=1.0)
音声ファイルを登録.
Definition: Music.h:59
static void AddLoading(std::function< void(void)> &&読み込み関数)
非同期読み込み処理に追加.
Definition: Loading.h:96
BGM用音声を表すクラス.
Definition: Music.h:15
static bool Update()
fadeOut付きで終了した後に次Musicを再生するための処理.
Definition: Music.h:233
static void ChangeVolume(double 音量)
再生中の音量を変更.
Definition: Music.h:212
bool Restart(bool ループ再生フラグ=true)
前回停止した位置から再生.
Definition: Music.h:122
void SetVolume(double 音量)
0~1.0で音量を設定.
Definition: Music.h:165
static bool Check()
再生中か確認.
Definition: Music.h:186
Music(const char *ファイル名, double 音量=1.0)
音声ファイルを登録.
Definition: Music.h:52