Exemplo n.º 1
0
        public static void LoadPreview(CSong song, float start = -1f)
        {
            if (song == null)
            {
                throw new ArgumentNullException("song");
            }

            if (!IsPlayingPreview)
            {
                Pause();
                CSound.SetGlobalVolume(CConfig.PreviewMusicVolume);
            }

            bool songChanged = _CurPlayer.SongID != song.ID;

            _PreviewPlayer.Load(song);


            //Change song position only if song is changed or near to end
            if (songChanged || _CurPlayer.Position + 30 < _CurPlayer.Length)
            {
                _PreviewStartHelperTask = new Task(() =>
                {
                    float length = _PreviewPlayer.Length;
                    if (length < 1)
                    {
                        length = 30; // If length is unknow or invalid assume a length of 30s
                    }
                    if (start < 0)
                    {
                        start = (song.Preview.Source == EDataSource.None) ? length / 4f : song.Preview.StartTime;
                    }
                    if (start > length - 5f)
                    {
                        start = Math.Max(0f, Math.Min(length / 4f, length - 5f));
                    }
                    if (start >= 0.5f)
                    {
                        start -= 0.5f;
                    }

                    _PreviewPlayer.Position = start;
                    Play();
                });
                _CurPlayer = _PreviewPlayer;
            }
            else
            {
                _PreviewStartHelperTask.Dispose();
                _PreviewStartHelperTask = null;
                _PreviewPlayer.Position = _CurPlayer.Position;
                _CurPlayer = _PreviewPlayer;
                Play();
            }
        }
Exemplo n.º 2
0
 public static void StopPreview()
 {
     if (!IsPlayingPreview)
     {
         return;
     }
     Stop();
     _CurPlayer = _BGPlayer;
     if (_MusicSource != EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC)
     {
         _CurPlayer.Load(CSongs.GetSong(_PreviewPlayer.SongID));
         _CurPlayer.Position = _PreviewPlayer.Position;
     }
     CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume);
 }
Exemplo n.º 3
0
 private static void _FinishScreenFading()
 {
     if (_Fading == null)
     {
         return;
     }
     Debug.Assert(NextScreen != null);
     CurrentScreen.OnClose();
     CurrentScreen = NextScreen;
     NextScreen    = null;
     CurrentScreen.OnShowFinish();
     CSound.SetGlobalVolume(CConfig.GetVolumeByType(CurrentScreen.CurrentMusicType));
     if (CurrentScreen.CurrentMusicType == EMusicType.Background || CurrentScreen.CurrentMusicType == EMusicType.Preview || CurrentScreen.CurrentMusicType == EMusicType.BackgroundPreview)
     {
         CBackgroundMusic.Disabled         = false;
         CBackgroundMusic.IsPlayingPreview = CurrentScreen.CurrentMusicType == EMusicType.Preview || CurrentScreen.CurrentMusicType == EMusicType.BackgroundPreview;
     }
     _Fading = null;
 }
Exemplo n.º 4
0
 public void SetGlobalVolume(int volume)
 {
     CSound.SetGlobalVolume(volume);
 }
Exemplo n.º 5
0
        public static bool Draw()
        {
            if (NextScreen != null && _Fading == null)
            {
                _Fading = new CFading(0f, 1f, CConfig.Config.Graphics.FadeTime);

                if (NextScreen.PartyModeID != -1)
                {
                    CFonts.PartyModeID = NextScreen.PartyModeID;
                    NextScreen.OnShow();
                    CFonts.PartyModeID = -1;
                }
                else
                {
                    NextScreen.OnShow();
                }
                if (_Cursor.IsActive)
                {
                    NextScreen.ProcessMouseMove(_Cursor.X, _Cursor.Y);
                }

                HidePopup(EPopupScreens.PopupPlayerControl);
                if (NextScreen.CurrentMusicType != EMusicType.Background && NextScreen.CurrentMusicType != EMusicType.Preview && NextScreen.CurrentMusicType != EMusicType.BackgroundPreview)
                {
                    CBackgroundMusic.Disabled = true;
                }
            }

            if (_Fading != null)
            {
                Debug.Assert(NextScreen != null);
                bool  finished;
                float newAlpha = _Fading.GetValue(out finished);

                if (!finished)
                {
                    ZOffset = CSettings.ZFar / 2;
                    _DrawScreen(CurrentScreen);

                    GlobalAlpha = newAlpha;
                    ZOffset     = 0f;
                    _DrawScreen(NextScreen);

                    GlobalAlpha = 1f;
                    int oldVol = CConfig.GetVolumeByType(CurrentScreen.CurrentMusicType);
                    int newVol = CConfig.GetVolumeByType(NextScreen.CurrentMusicType);
                    CSound.SetGlobalVolume((int)((newVol - oldVol) * newAlpha + oldVol));
                }
                else
                {
                    _FinishScreenFading();
                    if (_Cursor.IsActive)
                    {
                        CurrentScreen.ProcessMouseMove(_Cursor.X, _Cursor.Y);
                    }

                    _DrawScreen(CurrentScreen);
                }
            }
            else
            {
                _DrawScreen(CurrentScreen);
            }

            foreach (IMenu popup in _PopupScreens)
            {
                popup.Draw();
            }

            _Cursor.Draw();
            _DrawDebugInfos();

            return(true);
        }