update of background music:
change options order, added own fade time value, no more unneeded bg music changes, fixed volume control in option screen
This commit is contained in:
1 parent
5dcb7bcbcc
commit
5cfb22f096
5 files changed
+138
-88
No files matched your search
@@ -13,17 +13,22 @@ namespace Vocaluxe.Base
|
||||
{
|
||||
private static CHelper Helper = new CHelper();
|
||||
private static int _CurrentMusicStream = -1;
|
||||
private static bool _Fading;
|
||||
private static Stopwatch _FadeTimer = new Stopwatch();
|
||||
private static Random _Random = new Random();
|
||||
private static List<string> _BackgroundMusicFileNames = new List<string>();
|
||||
private static int _CurrentBackgroundMusicFileNameIndex;
|
||||
private static string _CurrentMusicFilePath = String.Empty;
|
||||
|
||||
private static List<string> _AllFileNames = new List<string>();
|
||||
private static List<string> _BGMusicFileNames = new List<string>();
|
||||
|
||||
private static bool _OwnMusicAdded;
|
||||
private static bool _BackgroundMusicAdded;
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
if(CConfig.BackgroundMusicSource == EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC || CConfig.BackgroundMusicSource == EBackgroundMusicSource.TR_CONFIG_OWN_MUSIC)
|
||||
_BGMusicFileNames.AddRange(Helper.ListFiles(CSettings.sFolderBackgroundMusic, "*.mp3", true, true));
|
||||
_BGMusicFileNames.AddRange(Helper.ListFiles(CSettings.sFolderBackgroundMusic, "*.wav", true, true));
|
||||
_BGMusicFileNames.AddRange(Helper.ListFiles(CSettings.sFolderBackgroundMusic, "*.ogg", true, true));
|
||||
_BGMusicFileNames.AddRange(Helper.ListFiles(CSettings.sFolderBackgroundMusic, "*.wma", true, true));
|
||||
|
||||
if(CConfig.BackgroundMusicSource != EBackgroundMusicSource.TR_CONFIG_ONLY_OWN_MUSIC)
|
||||
AddBackgroundMusic();
|
||||
}
|
||||
|
||||
@@ -31,65 +36,62 @@ namespace Vocaluxe.Base
|
||||
{
|
||||
if (CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON)
|
||||
{
|
||||
if (_BackgroundMusicFileNames.Count > 0)
|
||||
if (_AllFileNames.Count > 0)
|
||||
{
|
||||
CSound.Fade(_CurrentMusicStream, CConfig.BackgroundMusicVolume, CConfig.FadeTime);
|
||||
CSound.Play(_CurrentMusicStream);
|
||||
if (_CurrentMusicStream != -1)
|
||||
{
|
||||
CSound.Fade(_CurrentMusicStream, CConfig.BackgroundMusicVolume, CSettings.BackgroundMusicFadeTime);
|
||||
CSound.Play(_CurrentMusicStream);
|
||||
}
|
||||
else
|
||||
Next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Stop()
|
||||
{
|
||||
if (_BackgroundMusicFileNames.Count > 0)
|
||||
CSound.FadeAndStop(_CurrentMusicStream, CConfig.BackgroundMusicVolume, CConfig.FadeTime);
|
||||
if (_AllFileNames.Count > 0)
|
||||
CSound.FadeAndStop(_CurrentMusicStream, CConfig.BackgroundMusicVolume, CSettings.BackgroundMusicFadeTime);
|
||||
|
||||
_CurrentMusicFilePath = String.Empty;
|
||||
}
|
||||
|
||||
public static void Pause()
|
||||
{
|
||||
if (_BackgroundMusicFileNames.Count > 0)
|
||||
CSound.FadeAndPause(_CurrentMusicStream, 0, CConfig.FadeTime);
|
||||
if (_AllFileNames.Count > 0)
|
||||
CSound.FadeAndPause(_CurrentMusicStream, 0f, CSettings.BackgroundMusicFadeTime);
|
||||
}
|
||||
|
||||
public static void Update()
|
||||
{
|
||||
if (_BackgroundMusicFileNames.Count > 0)
|
||||
if (_AllFileNames.Count > 0 && _CurrentMusicStream != -1)
|
||||
{
|
||||
float timeToPlay = CSound.GetLength(_CurrentMusicStream) - CSound.GetPosition(_CurrentMusicStream);
|
||||
if (_FadeTimer.ElapsedMilliseconds >= CConfig.FadeTime * 1000)
|
||||
{
|
||||
_Fading = false;
|
||||
_FadeTimer.Reset();
|
||||
}
|
||||
if ((timeToPlay <= CConfig.FadeTime) && !_Fading)
|
||||
{
|
||||
_FadeTimer.Start();
|
||||
|
||||
if (timeToPlay <= CSettings.BackgroundMusicFadeTime)
|
||||
Next();
|
||||
_Fading = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Next()
|
||||
{
|
||||
if (_BackgroundMusicFileNames.Count > 0)
|
||||
if (_AllFileNames.Count > 0)
|
||||
{
|
||||
if (_CurrentMusicStream != -1)
|
||||
CSound.FadeAndStop(_CurrentMusicStream, 0, CConfig.FadeTime);
|
||||
_CurrentBackgroundMusicFileNameIndex = _Random.Next(_BackgroundMusicFileNames.Count);
|
||||
_CurrentMusicStream = CSound.Load(_BackgroundMusicFileNames[_CurrentBackgroundMusicFileNameIndex]);
|
||||
Stop();
|
||||
|
||||
_CurrentMusicFilePath = _AllFileNames[CGame.Rand.Next(_AllFileNames.Count)];
|
||||
_CurrentMusicStream = CSound.Load(_CurrentMusicFilePath);
|
||||
CSound.SetStreamVolume(_CurrentMusicStream, 0f);
|
||||
Play();
|
||||
}
|
||||
else if (_BackgroundMusicAdded || _OwnMusicAdded)
|
||||
{
|
||||
if (_CurrentMusicStream != -1)
|
||||
CSound.FadeAndStop(_CurrentMusicStream, 0, CConfig.FadeTime);
|
||||
}
|
||||
else
|
||||
Stop();
|
||||
}
|
||||
|
||||
public static void ApplyVolume()
|
||||
{
|
||||
CSound.Fade(_CurrentMusicStream, CConfig.BackgroundMusicVolume, CConfig.FadeTime);
|
||||
CSound.SetStreamVolume(_CurrentMusicStream, CConfig.BackgroundMusicVolume);
|
||||
}
|
||||
|
||||
public static void AddOwnMusic()
|
||||
@@ -98,19 +100,22 @@ namespace Vocaluxe.Base
|
||||
{
|
||||
foreach (CSong song in CSongs.AllSongs)
|
||||
{
|
||||
_BackgroundMusicFileNames.Add(song.GetMP3());
|
||||
_AllFileNames.Add(song.GetMP3());
|
||||
}
|
||||
}
|
||||
_OwnMusicAdded = true;
|
||||
Next();
|
||||
}
|
||||
|
||||
public static void RemoveOwnMusic()
|
||||
{
|
||||
foreach (CSong song in CSongs.AllSongs)
|
||||
{
|
||||
_BackgroundMusicFileNames.Remove(song.GetMP3());
|
||||
}
|
||||
_AllFileNames.Clear();
|
||||
|
||||
if (_BackgroundMusicAdded)
|
||||
_AllFileNames.AddRange(_BGMusicFileNames);
|
||||
|
||||
if (IsPlaying() && !IsBackgroundFile(_CurrentMusicFilePath))
|
||||
Next();
|
||||
|
||||
_OwnMusicAdded = false;
|
||||
}
|
||||
|
||||
@@ -118,12 +123,8 @@ namespace Vocaluxe.Base
|
||||
{
|
||||
if (!_BackgroundMusicAdded)
|
||||
{
|
||||
_BackgroundMusicFileNames.AddRange(Helper.ListFiles(CSettings.sFolderBackgroundMusic, "*.mp3", true, true));
|
||||
_BackgroundMusicFileNames.AddRange(Helper.ListFiles(CSettings.sFolderBackgroundMusic, "*.wav", true, true));
|
||||
_BackgroundMusicFileNames.AddRange(Helper.ListFiles(CSettings.sFolderBackgroundMusic, "*.ogg", true, true));
|
||||
_BackgroundMusicFileNames.AddRange(Helper.ListFiles(CSettings.sFolderBackgroundMusic, "*.wma", true, true));
|
||||
_AllFileNames.AddRange(_BGMusicFileNames);
|
||||
_BackgroundMusicAdded = true;
|
||||
Next();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,18 +132,78 @@ namespace Vocaluxe.Base
|
||||
{
|
||||
if (_BackgroundMusicAdded)
|
||||
{
|
||||
List<string> removeList = new List<string>();
|
||||
removeList.AddRange(Helper.ListFiles(CSettings.sFolderBackgroundMusic, "*.mp3", true, true));
|
||||
removeList.AddRange(Helper.ListFiles(CSettings.sFolderBackgroundMusic, "*.wav", true, true));
|
||||
removeList.AddRange(Helper.ListFiles(CSettings.sFolderBackgroundMusic, "*.ogg", true, true));
|
||||
removeList.AddRange(Helper.ListFiles(CSettings.sFolderBackgroundMusic, "*.wma", true, true));
|
||||
|
||||
foreach (string s in removeList)
|
||||
{
|
||||
_BackgroundMusicFileNames.Remove(s);
|
||||
}
|
||||
_AllFileNames.Clear();
|
||||
_OwnMusicAdded = false;
|
||||
AddOwnMusic();
|
||||
_BackgroundMusicAdded = false;
|
||||
|
||||
if (IsPlaying() && IsBackgroundFile(_CurrentMusicFilePath))
|
||||
Next();
|
||||
}
|
||||
}
|
||||
|
||||
public static void CheckAndApplyConfig(EOffOn NewOnOff, EBackgroundMusicSource NewSource, float NewVolume)
|
||||
{
|
||||
if (CConfig.BackgroundMusic != NewOnOff)
|
||||
{
|
||||
CConfig.BackgroundMusic = NewOnOff;
|
||||
if (NewOnOff == EOffOn.TR_CONFIG_ON)
|
||||
Play();
|
||||
else
|
||||
Pause();
|
||||
}
|
||||
|
||||
if (CConfig.BackgroundMusicSource != NewSource)
|
||||
{
|
||||
CConfig.BackgroundMusicSource = NewSource;
|
||||
|
||||
switch (NewSource)
|
||||
{
|
||||
case EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC:
|
||||
if (!_BackgroundMusicAdded)
|
||||
AddBackgroundMusic();
|
||||
|
||||
RemoveOwnMusic();
|
||||
break;
|
||||
|
||||
case EBackgroundMusicSource.TR_CONFIG_ONLY_OWN_MUSIC:
|
||||
if (!_OwnMusicAdded)
|
||||
AddOwnMusic();
|
||||
|
||||
RemoveBackgroundMusic();
|
||||
break;
|
||||
case EBackgroundMusicSource.TR_CONFIG_OWN_MUSIC:
|
||||
if (!_BackgroundMusicAdded)
|
||||
AddBackgroundMusic();
|
||||
|
||||
if (!_OwnMusicAdded)
|
||||
AddOwnMusic();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (CConfig.BackgroundMusicVolume != NewVolume)
|
||||
{
|
||||
CConfig.BackgroundMusicVolume = (int)NewVolume;
|
||||
ApplyVolume();
|
||||
}
|
||||
|
||||
CConfig.SaveConfig();
|
||||
}
|
||||
|
||||
public static bool IsPlaying()
|
||||
{
|
||||
return CSound.IsPlaying(_CurrentMusicStream);
|
||||
}
|
||||
|
||||
private static bool IsBackgroundFile(string FilePath)
|
||||
{
|
||||
foreach (string file in _BGMusicFileNames)
|
||||
{
|
||||
if (file == FilePath)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,8 +138,8 @@ namespace Vocaluxe.Base
|
||||
public enum EBackgroundMusicSource
|
||||
{
|
||||
TR_CONFIG_NO_OWN_MUSIC,
|
||||
TR_CONFIG_ONLY_OWN_MUSIC,
|
||||
TR_CONFIG_OWN_MUSIC
|
||||
TR_CONFIG_OWN_MUSIC,
|
||||
TR_CONFIG_ONLY_OWN_MUSIC
|
||||
}
|
||||
|
||||
#endregion Enums
|
||||
|
||||
@@ -91,6 +91,8 @@ namespace Vocaluxe.Base
|
||||
public const float LyricHelperMinTime = 0.2f;
|
||||
|
||||
public const bool TabNavigation = false;
|
||||
|
||||
public const float BackgroundMusicFadeTime = 1.5f;
|
||||
|
||||
public static string GetVersionText()
|
||||
{
|
||||
|
||||
@@ -132,6 +132,9 @@ namespace Vocaluxe.Screens
|
||||
CLog.StartBenchmark(3, "Load Cover");
|
||||
_SongLoaderThread.Start();
|
||||
_timer.Start();
|
||||
|
||||
if (!CBackgroundMusic.IsPlaying())
|
||||
CBackgroundMusic.Next();
|
||||
}
|
||||
|
||||
public override bool UpdateGame()
|
||||
@@ -163,6 +166,16 @@ namespace Vocaluxe.Screens
|
||||
CLanguage.Translate("TR_SCREENLOAD_TOTAL") + ": " + CSongs.NumAllSongs.ToString() + " " +
|
||||
CLanguage.Translate("TR_SCREENLOAD_SONGS") + " (" + CSongs.NumSongsWithCoverLoaded + " " +
|
||||
CLanguage.Translate("TR_SCREENLOAD_LOADED") + ")";
|
||||
|
||||
if (CSongs.SongsLoaded && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON &&
|
||||
CConfig.BackgroundMusicSource != EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC)
|
||||
{
|
||||
CBackgroundMusic.AddOwnMusic();
|
||||
|
||||
if (!CBackgroundMusic.IsPlaying())
|
||||
CBackgroundMusic.Next();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -190,8 +203,6 @@ namespace Vocaluxe.Screens
|
||||
_Intros[2].Close();
|
||||
|
||||
CLog.StopBenchmark(3, "Load Cover");
|
||||
if(CConfig.BackgroundMusicSource == EBackgroundMusicSource.TR_CONFIG_ONLY_OWN_MUSIC || CConfig.BackgroundMusicSource == EBackgroundMusicSource.TR_CONFIG_OWN_MUSIC)
|
||||
CBackgroundMusic.AddOwnMusic();
|
||||
}
|
||||
|
||||
private void CheckStartIntroVideos()
|
||||
|
||||
@@ -130,35 +130,11 @@ namespace Vocaluxe.Screens
|
||||
}
|
||||
private void SaveConfig()
|
||||
{
|
||||
CConfig.BackgroundMusic = (EOffOn)SelectSlides[htSelectSlides(SelectSlideBackgroundMusic)].Selection;
|
||||
EOffOn NewOffOn = (EOffOn)SelectSlides[htSelectSlides(SelectSlideBackgroundMusic)].Selection;
|
||||
EBackgroundMusicSource NewSource = (EBackgroundMusicSource)SelectSlides[htSelectSlides(SelectSlideBackgroundMusicSource)].Selection;
|
||||
float NewVolume = SelectSlides[htSelectSlides(SelectSlideBackgroundMusicVolume)].Selection * 5;
|
||||
|
||||
if (CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON)
|
||||
CBackgroundMusic.Play();
|
||||
else
|
||||
CBackgroundMusic.Pause();
|
||||
|
||||
CConfig.BackgroundMusicVolume = SelectSlides[htSelectSlides(SelectSlideBackgroundMusicVolume)].Selection * 5;
|
||||
CBackgroundMusic.ApplyVolume();
|
||||
|
||||
if (CConfig.BackgroundMusicSource != (EBackgroundMusicSource)SelectSlides[htSelectSlides(SelectSlideBackgroundMusicSource)].Selection)
|
||||
{
|
||||
CConfig.BackgroundMusicSource = (EBackgroundMusicSource)SelectSlides[htSelectSlides(SelectSlideBackgroundMusicSource)].Selection;
|
||||
if (CConfig.BackgroundMusicSource == EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC)
|
||||
{
|
||||
CBackgroundMusic.RemoveOwnMusic();
|
||||
CBackgroundMusic.AddBackgroundMusic();
|
||||
}
|
||||
if (CConfig.BackgroundMusicSource == EBackgroundMusicSource.TR_CONFIG_ONLY_OWN_MUSIC)
|
||||
{
|
||||
CBackgroundMusic.RemoveBackgroundMusic();
|
||||
CBackgroundMusic.AddOwnMusic();
|
||||
}
|
||||
if (CConfig.BackgroundMusicSource == EBackgroundMusicSource.TR_CONFIG_OWN_MUSIC)
|
||||
CBackgroundMusic.AddOwnMusic();
|
||||
|
||||
}
|
||||
|
||||
CConfig.SaveConfig();
|
||||
CBackgroundMusic.CheckAndApplyConfig(NewOffOn, NewSource, NewVolume);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user