diff --git a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs index 63da92cb..4635d741 100644 --- a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs +++ b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs @@ -366,7 +366,6 @@ namespace VocaluxeLib.PartyModes.Challenge _SetNumJokers(); _SetTeamNames(); GameData.CatSongIndices = null; - CBase.Graphics.FadeTo(EScreen.Song); } private void _SetNumJokers() diff --git a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs index b21b9321..2cb2a866 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs @@ -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; } diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs index 2be6da11..fe1ccfd7 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs @@ -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(); } diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index 806194ce..119d73e8 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -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); } /// diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index 9cee027a..4494d790 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -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; } diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index 2d7e038a..320b8697 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -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); } diff --git a/Vocaluxe/Base/CSound.cs b/Vocaluxe/Base/CSound.cs index 97ce0467..dc76f86f 100644 --- a/Vocaluxe/Base/CSound.cs +++ b/Vocaluxe/Base/CSound.cs @@ -60,7 +60,11 @@ namespace Vocaluxe.Base return _Playback.Init(); } - public static void SetGlobalVolume(float volume) + /// + /// Sets the volume (in percent 0-100) + /// + /// + 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; diff --git a/Vocaluxe/Lib/Sound/Playback/CPlaybackBase.cs b/Vocaluxe/Lib/Sound/Playback/CPlaybackBase.cs index dc702c8b..d3e4a168 100644 --- a/Vocaluxe/Lib/Sound/Playback/CPlaybackBase.cs +++ b/Vocaluxe/Lib/Sound/Playback/CPlaybackBase.cs @@ -15,6 +15,7 @@ // along with Vocaluxe. If not, see . #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(); } } diff --git a/Vocaluxe/Lib/Sound/Playback/GstreamerSharp/CGstreamerSharpAudioStream.cs b/Vocaluxe/Lib/Sound/Playback/GstreamerSharp/CGstreamerSharpAudioStream.cs index f1b7f2fc..ca0d602d 100644 --- a/Vocaluxe/Lib/Sound/Playback/GstreamerSharp/CGstreamerSharpAudioStream.cs +++ b/Vocaluxe/Lib/Sound/Playback/GstreamerSharp/CGstreamerSharpAudioStream.cs @@ -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; } } diff --git a/Vocaluxe/Lib/Sound/Playback/IPlayback.cs b/Vocaluxe/Lib/Sound/Playback/IPlayback.cs index 1a414037..1dd10288 100644 --- a/Vocaluxe/Lib/Sound/Playback/IPlayback.cs +++ b/Vocaluxe/Lib/Sound/Playback/IPlayback.cs @@ -23,14 +23,14 @@ namespace Vocaluxe.Lib.Sound.Playback { bool Init(); void Close(); - float GetGlobalVolume(); + int GetGlobalVolume(); /// /// Set the global (maximum) volume
/// All streams (existent and future ones) will have their maximum volume set to this value ///
/// Volume in percent - 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); /// /// Set the streams current volume. Cancels fading /// /// Id of the stream (optained by Load) /// Volume in percent - void SetStreamVolume(int streamID, float volume); + void SetStreamVolume(int streamID, int volume); float GetLength(int streamID); float GetPosition(int streamID); diff --git a/Vocaluxe/Screens/CPopupScreenVolumeControl.cs b/Vocaluxe/Screens/CPopupScreenVolumeControl.cs index 944031b8..4bb77849 100644 --- a/Vocaluxe/Screens/CPopupScreenVolumeControl.cs +++ b/Vocaluxe/Screens/CPopupScreenVolumeControl.cs @@ -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() diff --git a/Vocaluxe/Screens/CScreenOptionsSound.cs b/Vocaluxe/Screens/CScreenOptionsSound.cs index d7c9b3b4..b3deb818 100644 --- a/Vocaluxe/Screens/CScreenOptionsSound.cs +++ b/Vocaluxe/Screens/CScreenOptionsSound.cs @@ -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 diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index 8daa0c08..1b1eec3a 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -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(); diff --git a/VocaluxeLib/IBasic.cs b/VocaluxeLib/IBasic.cs index d122783c..d4e367fc 100644 --- a/VocaluxeLib/IBasic.cs +++ b/VocaluxeLib/IBasic.cs @@ -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); } diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index e0111002..eabca5e4 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -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 { diff --git a/VocaluxeLib/Utils/Player/CSongPlayer.cs b/VocaluxeLib/Utils/Player/CSongPlayer.cs index 92a848a7..0b22f47b 100644 --- a/VocaluxeLib/Utils/Player/CSongPlayer.cs +++ b/VocaluxeLib/Utils/Player/CSongPlayer.cs @@ -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) { diff --git a/VocaluxeLib/Utils/Player/CSoundPlayer.cs b/VocaluxeLib/Utils/Player/CSoundPlayer.cs index 79da904a..b132643b 100644 --- a/VocaluxeLib/Utils/Player/CSoundPlayer.cs +++ b/VocaluxeLib/Utils/Player/CSoundPlayer.cs @@ -15,21 +15,16 @@ // along with Vocaluxe. If not, see . #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;