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:
Alexander Eckart committed 2012-02-21 21:27:13 +01:00
1 parent 5dcb7bcbcc
commit 5cfb22f096
5 files changed
+138 -88

No files matched your search

+117 -56
View File
@@ -13,17 +13,22 @@ namespace Vocaluxe.Base
{ {
private static CHelper Helper = new CHelper(); private static CHelper Helper = new CHelper();
private static int _CurrentMusicStream = -1; private static int _CurrentMusicStream = -1;
private static bool _Fading; private static string _CurrentMusicFilePath = String.Empty;
private static Stopwatch _FadeTimer = new Stopwatch();
private static Random _Random = new Random(); private static List<string> _AllFileNames = new List<string>();
private static List<string> _BackgroundMusicFileNames = new List<string>(); private static List<string> _BGMusicFileNames = new List<string>();
private static int _CurrentBackgroundMusicFileNameIndex;
private static bool _OwnMusicAdded; private static bool _OwnMusicAdded;
private static bool _BackgroundMusicAdded; private static bool _BackgroundMusicAdded;
public static void Init() 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(); AddBackgroundMusic();
} }
@@ -31,65 +36,62 @@ namespace Vocaluxe.Base
{ {
if (CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) if (CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON)
{ {
if (_BackgroundMusicFileNames.Count > 0) if (_AllFileNames.Count > 0)
{ {
CSound.Fade(_CurrentMusicStream, CConfig.BackgroundMusicVolume, CConfig.FadeTime); if (_CurrentMusicStream != -1)
CSound.Play(_CurrentMusicStream); {
CSound.Fade(_CurrentMusicStream, CConfig.BackgroundMusicVolume, CSettings.BackgroundMusicFadeTime);
CSound.Play(_CurrentMusicStream);
}
else
Next();
} }
} }
} }
public static void Stop() public static void Stop()
{ {
if (_BackgroundMusicFileNames.Count > 0) if (_AllFileNames.Count > 0)
CSound.FadeAndStop(_CurrentMusicStream, CConfig.BackgroundMusicVolume, CConfig.FadeTime); CSound.FadeAndStop(_CurrentMusicStream, CConfig.BackgroundMusicVolume, CSettings.BackgroundMusicFadeTime);
_CurrentMusicFilePath = String.Empty;
} }
public static void Pause() public static void Pause()
{ {
if (_BackgroundMusicFileNames.Count > 0) if (_AllFileNames.Count > 0)
CSound.FadeAndPause(_CurrentMusicStream, 0, CConfig.FadeTime); CSound.FadeAndPause(_CurrentMusicStream, 0f, CSettings.BackgroundMusicFadeTime);
} }
public static void Update() public static void Update()
{ {
if (_BackgroundMusicFileNames.Count > 0) if (_AllFileNames.Count > 0 && _CurrentMusicStream != -1)
{ {
float timeToPlay = CSound.GetLength(_CurrentMusicStream) - CSound.GetPosition(_CurrentMusicStream); float timeToPlay = CSound.GetLength(_CurrentMusicStream) - CSound.GetPosition(_CurrentMusicStream);
if (_FadeTimer.ElapsedMilliseconds >= CConfig.FadeTime * 1000)
{ if (timeToPlay <= CSettings.BackgroundMusicFadeTime)
_Fading = false;
_FadeTimer.Reset();
}
if ((timeToPlay <= CConfig.FadeTime) && !_Fading)
{
_FadeTimer.Start();
Next(); Next();
_Fading = true;
}
} }
} }
public static void Next() public static void Next()
{ {
if (_BackgroundMusicFileNames.Count > 0) if (_AllFileNames.Count > 0)
{ {
if (_CurrentMusicStream != -1) Stop();
CSound.FadeAndStop(_CurrentMusicStream, 0, CConfig.FadeTime);
_CurrentBackgroundMusicFileNameIndex = _Random.Next(_BackgroundMusicFileNames.Count); _CurrentMusicFilePath = _AllFileNames[CGame.Rand.Next(_AllFileNames.Count)];
_CurrentMusicStream = CSound.Load(_BackgroundMusicFileNames[_CurrentBackgroundMusicFileNameIndex]); _CurrentMusicStream = CSound.Load(_CurrentMusicFilePath);
CSound.SetStreamVolume(_CurrentMusicStream, 0f);
Play(); Play();
} }
else if (_BackgroundMusicAdded || _OwnMusicAdded) else
{ Stop();
if (_CurrentMusicStream != -1)
CSound.FadeAndStop(_CurrentMusicStream, 0, CConfig.FadeTime);
}
} }
public static void ApplyVolume() public static void ApplyVolume()
{ {
CSound.Fade(_CurrentMusicStream, CConfig.BackgroundMusicVolume, CConfig.FadeTime); CSound.SetStreamVolume(_CurrentMusicStream, CConfig.BackgroundMusicVolume);
} }
public static void AddOwnMusic() public static void AddOwnMusic()
@@ -98,19 +100,22 @@ namespace Vocaluxe.Base
{ {
foreach (CSong song in CSongs.AllSongs) foreach (CSong song in CSongs.AllSongs)
{ {
_BackgroundMusicFileNames.Add(song.GetMP3()); _AllFileNames.Add(song.GetMP3());
} }
} }
_OwnMusicAdded = true; _OwnMusicAdded = true;
Next();
} }
public static void RemoveOwnMusic() public static void RemoveOwnMusic()
{ {
foreach (CSong song in CSongs.AllSongs) _AllFileNames.Clear();
{
_BackgroundMusicFileNames.Remove(song.GetMP3()); if (_BackgroundMusicAdded)
} _AllFileNames.AddRange(_BGMusicFileNames);
if (IsPlaying() && !IsBackgroundFile(_CurrentMusicFilePath))
Next();
_OwnMusicAdded = false; _OwnMusicAdded = false;
} }
@@ -118,12 +123,8 @@ namespace Vocaluxe.Base
{ {
if (!_BackgroundMusicAdded) if (!_BackgroundMusicAdded)
{ {
_BackgroundMusicFileNames.AddRange(Helper.ListFiles(CSettings.sFolderBackgroundMusic, "*.mp3", true, true)); _AllFileNames.AddRange(_BGMusicFileNames);
_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));
_BackgroundMusicAdded = true; _BackgroundMusicAdded = true;
Next();
} }
} }
@@ -131,18 +132,78 @@ namespace Vocaluxe.Base
{ {
if (_BackgroundMusicAdded) if (_BackgroundMusicAdded)
{ {
List<string> removeList = new List<string>(); _AllFileNames.Clear();
removeList.AddRange(Helper.ListFiles(CSettings.sFolderBackgroundMusic, "*.mp3", true, true)); _OwnMusicAdded = false;
removeList.AddRange(Helper.ListFiles(CSettings.sFolderBackgroundMusic, "*.wav", true, true)); AddOwnMusic();
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);
}
_BackgroundMusicAdded = false; _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;
}
} }
} }
+2 -2
View File
@@ -138,8 +138,8 @@ namespace Vocaluxe.Base
public enum EBackgroundMusicSource public enum EBackgroundMusicSource
{ {
TR_CONFIG_NO_OWN_MUSIC, 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 #endregion Enums
+2
View File
@@ -92,6 +92,8 @@ namespace Vocaluxe.Base
public const bool TabNavigation = false; public const bool TabNavigation = false;
public const float BackgroundMusicFadeTime = 1.5f;
public static string GetVersionText() public static string GetVersionText()
{ {
string sVersion = "v" + iVersionMajor.ToString() + "." + string sVersion = "v" + iVersionMajor.ToString() + "." +
+13 -2
View File
@@ -132,6 +132,9 @@ namespace Vocaluxe.Screens
CLog.StartBenchmark(3, "Load Cover"); CLog.StartBenchmark(3, "Load Cover");
_SongLoaderThread.Start(); _SongLoaderThread.Start();
_timer.Start(); _timer.Start();
if (!CBackgroundMusic.IsPlaying())
CBackgroundMusic.Next();
} }
public override bool UpdateGame() public override bool UpdateGame()
@@ -163,6 +166,16 @@ namespace Vocaluxe.Screens
CLanguage.Translate("TR_SCREENLOAD_TOTAL") + ": " + CSongs.NumAllSongs.ToString() + " " + CLanguage.Translate("TR_SCREENLOAD_TOTAL") + ": " + CSongs.NumAllSongs.ToString() + " " +
CLanguage.Translate("TR_SCREENLOAD_SONGS") + " (" + CSongs.NumSongsWithCoverLoaded + " " + CLanguage.Translate("TR_SCREENLOAD_SONGS") + " (" + CSongs.NumSongsWithCoverLoaded + " " +
CLanguage.Translate("TR_SCREENLOAD_LOADED") + ")"; 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; return true;
} }
@@ -190,8 +203,6 @@ namespace Vocaluxe.Screens
_Intros[2].Close(); _Intros[2].Close();
CLog.StopBenchmark(3, "Load Cover"); 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() private void CheckStartIntroVideos()
+4 -28
View File
@@ -130,35 +130,11 @@ namespace Vocaluxe.Screens
} }
private void SaveConfig() 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.CheckAndApplyConfig(NewOffOn, NewSource, NewVolume);
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();
} }
} }
} }