Fix missing song length and wrong volumes (int=0-100, float=0-1)

Also fade in preview music
This commit is contained in:
Flamefire committed 2014-11-27 23:06:01 +01:00
1 parent b99f9467de
commit 4a78dd4b31
17 files changed
+65 -73

No files matched your search

@@ -366,7 +366,6 @@ namespace VocaluxeLib.PartyModes.Challenge
_SetNumJokers(); _SetNumJokers();
_SetTeamNames(); _SetTeamNames();
GameData.CatSongIndices = null; GameData.CatSongIndices = null;
CBase.Graphics.FadeTo(EScreen.Song);
} }
private void _SetNumJokers() private void _SetNumJokers()
@@ -193,7 +193,8 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
break; break;
case EStage.Main: case EStage.Main:
_Stage = EStage.Singing; _Stage = EStage.Singing;
_StartNextRound(); if (!_StartNextRound())
CBase.Graphics.FadeTo(EScreen.Party);
break; break;
case EStage.Singing: case EStage.Singing:
_Stage = EStage.Main; _Stage = EStage.Main;
@@ -335,7 +336,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
Next(); Next();
} }
private void _StartNextRound() private bool _StartNextRound()
{ {
_ScreenSongOptions.Selection.RandomOnly = _ScreenSongOptions.Sorting.Tabs != EOffOn.TR_CONFIG_ON; _ScreenSongOptions.Selection.RandomOnly = _ScreenSongOptions.Sorting.Tabs != EOffOn.TR_CONFIG_ON;
_ScreenSongOptions.Selection.CategoryChangeAllowed = _ScreenSongOptions.Sorting.Tabs == EOffOn.TR_CONFIG_ON; _ScreenSongOptions.Selection.CategoryChangeAllowed = _ScreenSongOptions.Sorting.Tabs == EOffOn.TR_CONFIG_ON;
@@ -343,8 +344,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
_SetTeamNames(); _SetTeamNames();
GameData.CatSongIndices = null; GameData.CatSongIndices = null;
if (_RandomizeSongs()) return _RandomizeSongs();
CBase.Graphics.FadeTo(EScreen.Sing);
} }
private bool _RandomizeSongs() private bool _RandomizeSongs()
@@ -383,7 +383,6 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
if (visibleSongs.Count == 0) if (visibleSongs.Count == 0)
{ {
CBase.Log.LogError("CPartyChallengeMedleyMode Error: There are no songs!"); CBase.Log.LogError("CPartyChallengeMedleyMode Error: There are no songs!");
CBase.Graphics.FadeTo(EScreen.Party);
return false; return false;
} }
@@ -407,7 +406,6 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
if (ids.Count == 0) if (ids.Count == 0)
{ {
CBase.Log.LogError("CPartyChallengeMedleyMode Error: There are no medley songs!"); CBase.Log.LogError("CPartyChallengeMedleyMode Error: There are no medley songs!");
CBase.Graphics.FadeTo(EScreen.Party);
return false; return false;
} }
@@ -347,7 +347,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
{ {
base.OnClose(); base.OnClose();
CBase.BackgroundMusic.SetDisabled(false); CBase.BackgroundMusic.SetDisabled(false);
CBase.Sound.Fade(_PreviewStream, 0f, 0.5f, EStreamAction.Close); CBase.Sound.Fade(_PreviewStream, 0, 0.5f, EStreamAction.Close);
} }
private void _CreateFields() private void _CreateFields()
@@ -511,9 +511,9 @@ namespace VocaluxeLib.PartyModes.TicTacToe
_PreviewStream = CBase.Sound.Load(song.GetMP3()); _PreviewStream = CBase.Sound.Load(song.GetMP3());
CBase.Sound.SetGlobalVolume(CBase.Config.GetMusicVolume(EMusicType.Preview)); CBase.Sound.SetGlobalVolume(CBase.Config.GetMusicVolume(EMusicType.Preview));
CBase.Sound.SetPosition(_PreviewStream, song.Preview.StartTime); CBase.Sound.SetPosition(_PreviewStream, song.Preview.StartTime);
CBase.Sound.SetStreamVolume(_PreviewStream, 0f); CBase.Sound.SetStreamVolume(_PreviewStream, 0);
CBase.Sound.Play(_PreviewStream); CBase.Sound.Play(_PreviewStream);
CBase.Sound.Fade(_PreviewStream, 1f, 1f); CBase.Sound.Fade(_PreviewStream, 100, 1f);
} }
private void _UpdatePlayerInformation() private void _UpdatePlayerInformation()
@@ -593,13 +593,13 @@ namespace VocaluxeLib.PartyModes.TicTacToe
private void _NextRound() private void _NextRound()
{ {
CBase.Sound.Fade(_PreviewStream, 0f, 0.5f, EStreamAction.Close); CBase.Sound.Fade(_PreviewStream, 0, 0.5f, EStreamAction.Close);
_PartyMode.Next(); _PartyMode.Next();
} }
private void _EndParty() private void _EndParty()
{ {
CBase.Sound.Fade(_PreviewStream, 0f, 0.5f, EStreamAction.Close); CBase.Sound.Fade(_PreviewStream, 0, 0.5f, EStreamAction.Close);
CBase.Graphics.FadeTo(EScreen.Party); CBase.Graphics.FadeTo(EScreen.Party);
} }
@@ -618,7 +618,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
private void _Back() private void _Back()
{ {
CBase.Sound.Fade(_PreviewStream, 0f, 0.5f, EStreamAction.Close); CBase.Sound.Fade(_PreviewStream, 0, 0.5f, EStreamAction.Close);
_PartyMode.Back(); _PartyMode.Back();
} }
+3 -2
View File
@@ -161,10 +161,8 @@ namespace Vocaluxe.Base
_AddBackgroundMusic(); _AddBackgroundMusic();
_SongPlayer = new CSongPlayer(); _SongPlayer = new CSongPlayer();
_SongPlayer.Volume = CConfig.BackgroundMusicVolume;
_PreviewPlayer = new CSongPlayer(); _PreviewPlayer = new CSongPlayer();
_PreviewPlayer.Volume = CConfig.PreviewMusicVolume;
_PreviewPlayer.RepeatSong = true; _PreviewPlayer.RepeatSong = true;
_VideoEnabled = (CConfig.Config.Video.VideoBackgrounds == EOffOn.TR_CONFIG_ON && CConfig.Config.Video.VideosToBackground == EOffOn.TR_CONFIG_ON); _VideoEnabled = (CConfig.Config.Video.VideoBackgrounds == EOffOn.TR_CONFIG_ON && CConfig.Config.Video.VideosToBackground == EOffOn.TR_CONFIG_ON);
@@ -213,6 +211,7 @@ namespace Vocaluxe.Base
_PreviewPlayer.Stop(); _PreviewPlayer.Stop();
_PlaysPreview = false; _PlaysPreview = false;
Pause(); Pause();
CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume);
} }
else else
{ {
@@ -344,6 +343,7 @@ namespace Vocaluxe.Base
start = song.Preview.StartTime; start = song.Preview.StartTime;
_PlaysPreview = true; _PlaysPreview = true;
CSound.SetGlobalVolume(CConfig.PreviewMusicVolume);
_PreviewPlayer.Load(song, start); _PreviewPlayer.Load(song, start);
float startposition = song.Preview.StartTime; float startposition = song.Preview.StartTime;
@@ -375,6 +375,7 @@ namespace Vocaluxe.Base
{ {
_PreviewPlayer.Stop(); _PreviewPlayer.Stop();
_PlaysPreview = false; _PlaysPreview = false;
CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume);
} }
/// <summary> /// <summary>
+1 -1
View File
@@ -271,7 +271,7 @@ namespace Vocaluxe.Base
CurrentScreen = NextScreen; CurrentScreen = NextScreen;
NextScreen = null; NextScreen = null;
CurrentScreen.OnShowFinish(); CurrentScreen.OnShowFinish();
CSound.SetGlobalVolume(CConfig.GetVolumeByType(CurrentScreen.CurrentMusicType) / 100f); CSound.SetGlobalVolume(CConfig.GetVolumeByType(CurrentScreen.CurrentMusicType));
_Fading = null; _Fading = null;
} }
+2 -2
View File
@@ -843,7 +843,7 @@ namespace Vocaluxe.Base
CSound.Play(soundStream); CSound.Play(soundStream);
} }
public void Fade(int soundStream, float targetVolume, float duration, EStreamAction afterFadeAction = EStreamAction.Nothing) public void Fade(int soundStream, int targetVolume, float duration, EStreamAction afterFadeAction = EStreamAction.Nothing)
{ {
CSound.Fade(soundStream, targetVolume, duration, afterFadeAction); CSound.Fade(soundStream, targetVolume, duration, afterFadeAction);
} }
@@ -868,7 +868,7 @@ namespace Vocaluxe.Base
return CSound.GetLength(soundStream); return CSound.GetLength(soundStream);
} }
public void SetStreamVolume(int soundStream, float volume) public void SetStreamVolume(int soundStream, int volume)
{ {
CSound.SetStreamVolume(soundStream, volume); CSound.SetStreamVolume(soundStream, volume);
} }
+12 -8
View File
@@ -60,7 +60,11 @@ namespace Vocaluxe.Base
return _Playback.Init(); return _Playback.Init();
} }
public static void SetGlobalVolume(float volume) /// <summary>
/// Sets the volume (in percent 0-100)
/// </summary>
/// <param name="volume"></param>
public static void SetGlobalVolume(int volume)
{ {
_Playback.SetGlobalVolume(volume); _Playback.SetGlobalVolume(volume);
} }
@@ -109,27 +113,27 @@ namespace Vocaluxe.Base
_Playback.Stop(stream); _Playback.Stop(stream);
} }
public static void Fade(int stream, float targetVolume, float seconds, EStreamAction afterFadeAction = EStreamAction.Nothing) public static void Fade(int stream, int targetVolume, float seconds, EStreamAction afterFadeAction = EStreamAction.Nothing)
{ {
_Playback.Fade(stream, targetVolume, seconds, afterFadeAction); _Playback.Fade(stream, targetVolume, seconds, afterFadeAction);
} }
public static void FadeAndPause(int stream, float targetVolume, float seconds) public static void FadeAndPause(int stream, int targetVolume, float seconds)
{ {
Fade(stream, targetVolume, seconds, EStreamAction.Pause); Fade(stream, targetVolume, seconds, EStreamAction.Pause);
} }
public static void FadeAndClose(int stream, float targetVolume, float seconds) public static void FadeAndClose(int stream, int targetVolume, float seconds)
{ {
Fade(stream, targetVolume, seconds, EStreamAction.Close); Fade(stream, targetVolume, seconds, EStreamAction.Close);
} }
public static void FadeAndStop(int stream, float targetVolume, float seconds) public static void FadeAndStop(int stream, int targetVolume, float seconds)
{ {
Fade(stream, targetVolume, seconds, EStreamAction.Stop); Fade(stream, targetVolume, seconds, EStreamAction.Stop);
} }
public static void SetStreamVolume(int stream, float volume) public static void SetStreamVolume(int stream, int volume)
{ {
_Playback.SetStreamVolume(stream, volume); _Playback.SetStreamVolume(stream, volume);
} }
@@ -204,8 +208,8 @@ namespace Vocaluxe.Base
} }
if (length > 0f) if (length > 0f)
{ {
SetStreamVolume(stream, 0f); SetStreamVolume(stream, 0);
Fade(stream, 100f, length); Fade(stream, 100, length);
} }
} }
return stream; return stream;
+13 -12
View File
@@ -15,6 +15,7 @@
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>. // along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion #endregion
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using VocaluxeLib; using VocaluxeLib;
@@ -62,19 +63,19 @@ namespace Vocaluxe.Lib.Sound.Playback
} }
} }
public float GetGlobalVolume() public int GetGlobalVolume()
{ {
return (_Initialized) ? _GlobalVolume * 100f : 100f; return (_Initialized) ? (int) Math.Round(_GlobalVolume * 100) : 100;
} }
public void SetGlobalVolume(float volume) public void SetGlobalVolume(int volume)
{ {
if (!_Initialized) if (!_Initialized)
return; return;
volume = volume.Clamp(0f, 100f) / 100f; float volumeF = volume.Clamp(0, 100) / 100f;
foreach (IAudioStream stream in _Streams) foreach (IAudioStream stream in _Streams)
stream.VolumeMax = volume; stream.VolumeMax = volumeF;
_GlobalVolume = volume; _GlobalVolume = volumeF;
} }
public int GetStreamCount() public int GetStreamCount()
@@ -178,28 +179,28 @@ namespace Vocaluxe.Lib.Sound.Playback
} }
} }
public void Fade(int streamID, float targetVolume, float seconds, EStreamAction afterFadeAction = EStreamAction.Nothing) public void Fade(int streamID, int targetVolume, float seconds, EStreamAction afterFadeAction = EStreamAction.Nothing)
{ {
if (!_Initialized) if (!_Initialized)
return; return;
targetVolume = targetVolume.Clamp(0f, 100f) / 100f; float targetVolumeF = targetVolume.Clamp(0, 100) / 100f;
lock (_Streams) lock (_Streams)
{ {
if (_StreamExists(streamID)) if (_StreamExists(streamID))
_Streams[_GetStreamIndex(streamID)].Fade(targetVolume, seconds, afterFadeAction); _Streams[_GetStreamIndex(streamID)].Fade(targetVolumeF, seconds, afterFadeAction);
} }
} }
public void SetStreamVolume(int streamID, float volume) public void SetStreamVolume(int streamID, int volume)
{ {
if (!_Initialized) if (!_Initialized)
return; return;
volume = volume.Clamp(0f, 100f) / 100f; float volumeF = volume.Clamp(0, 100) / 100f;
lock (_Streams) lock (_Streams)
{ {
if (_StreamExists(streamID)) if (_StreamExists(streamID))
{ {
_Streams[_GetStreamIndex(streamID)].Volume = volume; _Streams[_GetStreamIndex(streamID)].Volume = volumeF;
_Streams[_GetStreamIndex(streamID)].CancelFading(); _Streams[_GetStreamIndex(streamID)].CancelFading();
} }
} }
@@ -58,8 +58,9 @@ namespace Vocaluxe.Lib.Sound.Playback.GstreamerSharp
get get
{ {
//TODO: Is it ok, to remove this? Gst should post a message if duration was changed so this should not be required //TODO: Is it ok, to remove this? Gst should post a message if duration was changed so this should not be required
//if (base.Length < 0 && _Element != null) // Removing would not work in some cases where length is not know at startup
// _UpdateDuration(); if (base.Length < 0 && _Element != null)
_UpdateDuration();
return base.Length >= 0f ? base.Length : 0f; return base.Length >= 0f ? base.Length : 0f;
} }
} }
+4 -4
View File
@@ -23,14 +23,14 @@ namespace Vocaluxe.Lib.Sound.Playback
{ {
bool Init(); bool Init();
void Close(); void Close();
float GetGlobalVolume(); int GetGlobalVolume();
/// <summary> /// <summary>
/// Set the global (maximum) volume<br /> /// Set the global (maximum) volume<br />
/// All streams (existent and future ones) will have their maximum volume set to this value /// All streams (existent and future ones) will have their maximum volume set to this value
/// </summary> /// </summary>
/// <param name="volume">Volume in percent</param> /// <param name="volume">Volume in percent</param>
void SetGlobalVolume(float volume); void SetGlobalVolume(int volume);
int GetStreamCount(); int GetStreamCount();
void CloseAll(); void CloseAll();
@@ -42,14 +42,14 @@ namespace Vocaluxe.Lib.Sound.Playback
void Play(int streamID); void Play(int streamID);
void Pause(int streamID); void Pause(int streamID);
void Stop(int streamID); void Stop(int streamID);
void Fade(int streamID, float targetVolume, float seconds, EStreamAction afterFadeAction = EStreamAction.Nothing); void Fade(int streamID, int targetVolume, float seconds, EStreamAction afterFadeAction = EStreamAction.Nothing);
/// <summary> /// <summary>
/// Set the streams current volume. Cancels fading /// Set the streams current volume. Cancels fading
/// </summary> /// </summary>
/// <param name="streamID">Id of the stream (optained by Load)</param> /// <param name="streamID">Id of the stream (optained by Load)</param>
/// <param name="volume">Volume in percent</param> /// <param name="volume">Volume in percent</param>
void SetStreamVolume(int streamID, float volume); void SetStreamVolume(int streamID, int volume);
float GetLength(int streamID); float GetLength(int streamID);
float GetPosition(int streamID); float GetPosition(int streamID);
@@ -113,7 +113,7 @@ namespace Vocaluxe.Screens
int volume = _SelectSlides[_SelectSlideVolume].Selection * 5; int volume = _SelectSlides[_SelectSlideVolume].Selection * 5;
CConfig.SetVolumeByType(CGraphics.CurrentScreen.CurrentMusicType, volume); CConfig.SetVolumeByType(CGraphics.CurrentScreen.CurrentMusicType, volume);
CConfig.SaveConfig(); CConfig.SaveConfig();
CSound.SetGlobalVolume(volume / 100f); CSound.SetGlobalVolume(volume);
} }
private void _UpdateSlides() private void _UpdateSlides()
+1 -1
View File
@@ -150,7 +150,7 @@ namespace Vocaluxe.Screens
CConfig.SaveConfig(); CConfig.SaveConfig();
CBackgroundMusic.SetMusicSource(CConfig.Config.Sound.BackgroundMusicSource); CBackgroundMusic.SetMusicSource(CConfig.Config.Sound.BackgroundMusicSource);
CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume / 100f); CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume);
if (CConfig.Config.Sound.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON) if (CConfig.Config.Sound.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON)
CBackgroundMusic.Play(); CBackgroundMusic.Play();
else else
+2 -2
View File
@@ -97,7 +97,7 @@ namespace Vocaluxe.Screens
private int _CurrentStream = -1; private int _CurrentStream = -1;
private float _Length = -1f; private float _Length = -1f;
//private int _NextStream = -1; //private int _NextStream = -1;
private const float _Volume = 100f; private const int _Volume = 100;
private CVideoStream _CurrentVideo; private CVideoStream _CurrentVideo;
private EAspect _VideoAspect = EAspect.Crop; private EAspect _VideoAspect = EAspect.Crop;
private CTextureRef _CurrentWebcamFrameTexture; private CTextureRef _CurrentWebcamFrameTexture;
@@ -477,7 +477,7 @@ namespace Vocaluxe.Screens
{ {
if (_CurrentStream > -1) if (_CurrentStream > -1)
{ {
CSound.FadeAndClose(_CurrentStream, 0f, 0.5f); CSound.FadeAndClose(_CurrentStream, 0, 0.5f);
_CurrentStream = -1; _CurrentStream = -1;
} }
CRecord.Stop(); CRecord.Stop();
+2 -2
View File
@@ -267,14 +267,14 @@ namespace VocaluxeLib
int Load(string soundFile, bool loop = false, bool prescan = false); int Load(string soundFile, bool loop = false, bool prescan = false);
void SetPosition(int soundStream, float newPosition); void SetPosition(int soundStream, float newPosition);
void Play(int soundStream); void Play(int soundStream);
void Fade(int soundStream, float targetVolume, float duration, EStreamAction afterFadeAction = EStreamAction.Nothing); void Fade(int soundStream, int targetVolume, float duration, EStreamAction afterFadeAction = EStreamAction.Nothing);
void Close(int soundStream); void Close(int soundStream);
bool IsFinished(int soundStream); bool IsFinished(int soundStream);
float GetPosition(int soundStream); float GetPosition(int soundStream);
float GetLength(int soundStream); float GetLength(int soundStream);
void SetStreamVolume(int soundStream, float volume); void SetStreamVolume(int soundStream, int volume);
void SetGlobalVolume(int volume); void SetGlobalVolume(int volume);
} }
@@ -480,7 +480,7 @@ namespace VocaluxeLib.Menu.SongMenu
{ {
foreach (CStatic tile in _Tiles) foreach (CStatic tile in _Tiles)
{ {
if (tile.Selected && Selected) if (tile.Selected)
tile.Draw(EAspect.Crop, SelectedTileZoomFactor, -0.1f); tile.Draw(EAspect.Crop, SelectedTileZoomFactor, -0.1f);
else else
{ {
+2 -9
View File
@@ -133,14 +133,7 @@ namespace VocaluxeLib.Utils.Player
Load(file, position, autoplay); Load(file, position, autoplay);
} }
public new void Play() public override void Stop()
{
CBase.Sound.SetPosition(_StreamID, _StartPosition);
CBase.Video.Skip(_Video, _StartPosition, _Song.VideoGap);
TogglePause();
}
public new void Stop()
{ {
base.Stop(); base.Stop();
@@ -150,7 +143,7 @@ namespace VocaluxeLib.Utils.Player
CBase.Video.Close(ref _Video); CBase.Video.Close(ref _Video);
} }
public new void TogglePause() public override void TogglePause()
{ {
if (IsPlaying && _Video != null) if (IsPlaying && _Video != null)
{ {
+8 -13
View File
@@ -15,21 +15,16 @@
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>. // along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion #endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace VocaluxeLib.Utils.Player namespace VocaluxeLib.Utils.Player
{ {
public class CSoundPlayer public class CSoundPlayer
{ {
protected int _StreamID = -1; protected int _StreamID = -1;
protected float _Volume; protected int _Volume = 100;
protected float _StartPosition; protected float _StartPosition;
protected float _FadeTime = CBase.Settings.GetSoundPlayerFadeTime(); protected readonly float _FadeTime = CBase.Settings.GetSoundPlayerFadeTime();
public float Volume public int Volume
{ {
set set
{ {
@@ -107,19 +102,19 @@ namespace VocaluxeLib.Utils.Player
return; return;
CBase.Sound.SetPosition(_StreamID, _StartPosition); CBase.Sound.SetPosition(_StreamID, _StartPosition);
CBase.Sound.SetStreamVolume(_StreamID, 0f); CBase.Sound.SetStreamVolume(_StreamID, 0);
CBase.Sound.Fade(_StreamID, Volume, _FadeTime); CBase.Sound.Fade(_StreamID, Volume, _FadeTime);
CBase.Sound.Play(_StreamID); CBase.Sound.Play(_StreamID);
IsPlaying = true; IsPlaying = true;
} }
public void TogglePause() public virtual void TogglePause()
{ {
if (_StreamID == -1) if (_StreamID == -1)
return; return;
if (IsPlaying) if (IsPlaying)
CBase.Sound.Fade(_StreamID, 0f, _FadeTime, EStreamAction.Pause); CBase.Sound.Fade(_StreamID, 0, _FadeTime, EStreamAction.Pause);
else else
{ {
CBase.Sound.Fade(_StreamID, Volume, _FadeTime); CBase.Sound.Fade(_StreamID, Volume, _FadeTime);
@@ -129,12 +124,12 @@ namespace VocaluxeLib.Utils.Player
IsPlaying = !IsPlaying; IsPlaying = !IsPlaying;
} }
public void Stop() public virtual void Stop()
{ {
if (_StreamID == -1 || !IsPlaying) if (_StreamID == -1 || !IsPlaying)
return; return;
CBase.Sound.Fade(_StreamID, 0f, _FadeTime, EStreamAction.Close); CBase.Sound.Fade(_StreamID, 0, _FadeTime, EStreamAction.Close);
_StreamID = -1; _StreamID = -1;
IsPlaying = false; IsPlaying = false;