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