示例#1
0
        private void RefreshLyricTime()
        {
            if (HyPlayList.lyricpos < 0 || HyPlayList.lyricpos >= LyricList.Count)
            {
                return;
            }
            if (HyPlayList.lyricpos == -1)
            {
                lastitem?.OnHind();
                LyricBoxContainer.ChangeView(null, 0, null, false);
            }
            LyricItem item = LyricList[HyPlayList.lyricpos];

            if (item == null)
            {
                return;
            }
            lastitem?.OnHind();
            item?.OnShow();
            lastitem = item;
            if (sclock > 0)
            {
                sclock--;
                return;
            }
            GeneralTransform transform = item?.TransformToVisual((UIElement)LyricBoxContainer.Content);
            Point?           position  = transform?.TransformPoint(new Point(0, 0));

            LyricBoxContainer.ChangeView(null, position?.Y - (LyricBoxContainer.ViewportHeight / 3), null, false);
        }
示例#2
0
        public void LoadLyricsBox()
        {
            LyricBox.Children.Clear();
            double blanksize = (LyricBoxContainer.ViewportHeight / 2);

            if (double.IsNaN(blanksize) || blanksize == 0)
            {
                blanksize = Window.Current.Bounds.Height / 3;
            }
            LyricBox.Children.Add(new Grid()
            {
                Height = blanksize
            });
            if (HyPlayList.Lyrics.Count == 0)
            {
                LyricItem lrcitem = new LyricItem(SongLyric.PureSong);
                lrcitem.Width = LyricWidth;
                LyricBox.Children.Add(lrcitem);
            }
            else
            {
                foreach (SongLyric songLyric in HyPlayList.Lyrics)
                {
                    LyricItem lrcitem = new LyricItem(songLyric);
                    lrcitem.Margin = new Thickness(0, 10, 0, 10);
                    lrcitem.Width  = LyricWidth;
                    LyricBox.Children.Add(lrcitem);
                }
            }
            LyricBox.Children.Add(new Grid()
            {
                Height = blanksize
            });
        }
 void PositionAllLyrics()
 {
     for (int i = 0; i < currentLyrics.Count; ++i)
     {
         LyricItem item = currentLyrics[i];
         PositionLyricItem(i, item);
     }
 }
示例#4
0
        private void RefreshLyricTime(TimeSpan nowtime)
        {
            LyricItem lastlrcitem = null;
            bool      showed      = false;

            foreach (UIElement lyricBoxChild in LyricBox.Children)
            {
                if (lyricBoxChild is LyricItem lrcitem)
                {
                    if (HyPlayList.Player.PlaybackSession.Position < lrcitem.Lrc.LyricTime)
                    {
                        if (!showed)
                        {
                            lastlrcitem?.OnShow();
                            lrcitem.OnHind();
                            if (sclock > 0)
                            {
                                sclock--;
                                return;
                            }

                            var transform = lastlrcitem?.TransformToVisual((UIElement)LyricBoxContainer.Content);
                            var position  = transform?.TransformPoint(new Point(0, 0));
                            LyricBoxContainer.ChangeView(null, position?.Y - (LyricBoxContainer.ViewportHeight / 3), null, false);;
                            showed = true;
                        }
                        else
                        {
                            lrcitem.OnHind();
                        }
                    }
                    else
                    {
                        lrcitem.OnHind();
                    }
                    lastlrcitem = lrcitem;
                }
            }

            if (!showed && lastlrcitem != null)
            {
                lastlrcitem.OnShow();
                if (sclock > 0)
                {
                    sclock--;
                    return;
                }
                var transform = lastlrcitem.TransformToVisual((UIElement)LyricBoxContainer.Content);
                var position  = transform.TransformPoint(new Point(0, 0));
                LyricBoxContainer.ChangeView(null, position.Y - (LyricBoxContainer.ViewportHeight / 3), null, false);
                showed = true;
            }

            //暂停按钮
            PlayStateIcon.Glyph = HyPlayList.isPlaying ? "\uEDB4" : "\uEDB5";
            //播放进度
            ProgressBarPlayProg.Value = HyPlayList.Player.PlaybackSession.Position.TotalMilliseconds;
        }
示例#5
0
    // search current lyric, timestamp in [item.mTimestamp, item.mNextTimestamp)
    public LyricItem SearchCurrentItem(Int64 timestamp)
    {
        LyricItem item = null;

        foreach (LyricItem it in mItems)
        {
            if (timestamp >= it.mTimestamp && timestamp < it.mNextTimestamp)
            {
                item = it;
                break;
            }
        }
        return(item);
    }
示例#6
0
        public void LoadLyricsBox()
        {
            LyricBox.Children.Clear();
            double blanksize = (LyricBoxContainer.ViewportHeight / 2);

            if (double.IsNaN(blanksize) || blanksize == 0)
            {
                blanksize = Window.Current.Bounds.Height / 3;
            }

            LyricBox.Children.Add(new Grid()
            {
                Height = blanksize
            });
            if (HyPlayList.Lyrics.Count == 0)
            {
                LyricItem lrcitem = new LyricItem(SongLyric.PureSong)
                {
                    Width = LyricWidth
                };
                LyricBox.Children.Add(lrcitem);
            }
            else
            {
                foreach (SongLyric songLyric in HyPlayList.Lyrics)
                {
                    LyricItem lrcitem = new LyricItem(songLyric)
                    {
                        Width = LyricWidth
                    };
                    LyricBox.Children.Add(lrcitem);
                }
            }

            LyricBox.Children.Add(new Grid()
            {
                Height = blanksize
            });
            LyricList = LyricBox.Children.OfType <LyricItem>().ToList();
            lastlrcid = HyPlayList.NowPlayingItem.GetHashCode();
            Task.Run((() =>
            {
                Common.Invoke((async() =>
                {
                    await Task.Delay(500);
                    RefreshLyricTime();
                }));
            }));
        }
    void PositionLyricItem(int index, LyricItem item)
    {
        RectTransform transform = item.lyricItemInterface.GetComponent <RectTransform>();

        float startYPos = templatePosition.y;
        float rowOffset = (rowHeight + rowHeightPadding) * index;
        float yPos      = startYPos - rowOffset;

        Vector3 position = transform.localPosition;

        position.y = yPos;
        transform.localPosition = position;

        UpdateScrollContentSize();
    }
示例#8
0
    protected void UpdateLyric()
    {
        // test code
        // get current music play timestamp
        Int64 timestamp = GetCurrentTimestamp();
        // search current lyric
        LyricItem currentItem     = mLyric.SearchCurrentItem(timestamp);
        string    text            = "";
        string    uiTextLyricName = "Canvas/TextLyric";
        string    uiTextTimeName  = "Canvas/TextTime";

        UnityEngine.UI.Text uiTextLyric = GameObject.Find(uiTextLyricName).GetComponent <UnityEngine.UI.Text>();
        if (null != uiTextLyric)
        {
            // show lyrics from index (currentItem.mIndex - showLyricSize) to (currentItem.mIndex + showLyricSize)
            List <LyricItem> items = mLyric.GetItems();
            int showLyricSize      = 3;
            foreach (LyricItem item in items)
            {
                if (item == currentItem)
                {
                    // if current lyric, highlight text with color (R, G, B)
                    text += Lyric.WrapStringWithColorTag(item.mText, 255, 0, 0) + System.Environment.NewLine;
                }
                else if ((null == currentItem && item.mIndex < showLyricSize) ||
                         (null != currentItem && item.mIndex >= currentItem.mIndex - showLyricSize &&
                          item.mIndex <= currentItem.mIndex + showLyricSize))
                {
                    text += item.mText + System.Environment.NewLine;
                }
            }
            uiTextLyric.text = text;
        }
        else
        {
            Debug.LogError("GetComponent " + uiTextLyricName + " failed");
        }
        UnityEngine.UI.Text uiTextTime = GameObject.Find(uiTextTimeName).GetComponent <UnityEngine.UI.Text>();
        if (null != uiTextTime)
        {
            // show timestamp
            uiTextTime.text = "time: " + Lyric.TimestampToString(timestamp);
        }
        else
        {
            Debug.LogError("GetComponent " + uiTextTimeName + " failed");
        }
    }
    public void Add()
    {
        LyricEditorItemInterface newLyricInterface = GameObject.Instantiate(lyricItemTemplate, lyricItemTemplate.transform.parent).GetComponent <LyricEditorItemInterface>();

        newLyricInterface.gameObject.SetActive(true);
        var newItem = new LyricItem(newLyricInterface);

        currentLyrics.Add(newItem);

        PositionAllLyrics();

        if (currentSelectedItemIndex == INVALID_ITEM_INDEX)
        {
            SelectLyric(currentLyrics[0].lyricItemInterface);
        }
    }
示例#10
0
        private void RefreshLyricTime(SongLyric LRC)
        {
            LyricItem item = LyricList.Find(t => t.Lrc.LyricTime == LRC.LyricTime);

            item.OnShow();
            if (sclock > 0)
            {
                sclock--;
                return;
            }

            GeneralTransform transform = item?.TransformToVisual((UIElement)LyricBoxContainer.Content);
            Point?           position  = transform?.TransformPoint(new Point(0, 0));

            LyricBoxContainer.ChangeView(null, position?.Y - (LyricBoxContainer.ViewportHeight / 3), null, false);;
            LyricList.FindAll(t => t.Lrc.LyricTime != LRC.LyricTime).ForEach(t => t.OnHind());
        }
    void PopulateFromCurrentSong()
    {
        Song currentSong = ChartEditor.Instance.currentSong;

        ClearLyricObjects();

        foreach (MoonscraperChartEditor.Song.Event eventObject in currentSong.events)
        {
            if (eventObject.title.StartsWith(LyricEditorItemInterface.c_lyricPrefix))
            {
                LyricEditorItemInterface newLyricInterface = GameObject.Instantiate(lyricItemTemplate, lyricItemTemplate.transform.parent).GetComponent <LyricEditorItemInterface>();
                newLyricInterface.gameObject.SetActive(true);
                var newItem = new LyricItem(newLyricInterface);
                newItem.lyricItemInterface.SetLyricEvent(eventObject);
                currentLyrics.Add(newItem);
            }
        }

        SelectLyric(INVALID_ITEM_INDEX);
    }
    public void Delete()
    {
        if (currentSelectedItemIndex == INVALID_ITEM_INDEX)
        {
            return;
        }

        LyricItem itemToDelete = currentLyrics[currentSelectedItemIndex];

        itemToDelete.lyricItemInterface.TryRemoveLyric();
        GameObject.Destroy(itemToDelete.lyricItemInterface.gameObject);
        currentLyrics.RemoveAt(currentSelectedItemIndex);

        // Shift position of all UI down a row
        PositionAllLyrics();

        if (currentSelectedItemIndex >= currentLyrics.Count)
        {
            SelectLyric(currentSelectedItemIndex - 1);
        }
    }
示例#13
0
    protected void UpdateTimestamp()
    {
        // sort the items with timestamp
        mItems.Sort();

        int       index    = 0;
        LyricItem lastItem = null;

        foreach (LyricItem item in mItems)
        {
            // add the timestamp with global offset
            item.mTimestamp += mOffset;
            item.mIndex      = index++;

            // update next timestamp
            if (null != lastItem)
            {
                lastItem.mNextTimestamp = item.mTimestamp;
            }
            lastItem = item;
        }
    }
示例#14
0
        private static void PrePlay()
        {
            //音乐缓存如果存在,从本地播放
            if (File.Exists(DownloadManager.MusicCachePath + PlayMusic.Id + ".tmp"))
            {
                Source = DownloadManager.MusicCachePath + PlayMusic.Id + ".tmp";
            }
            else
            {
                Source = (PlayMusic as IApi).GetMusicUrl();
            }

            //歌词缓存检测
            if (File.Exists(DownloadManager.LyricCachePath + PlayMusic.Id + ".lrc"))
            {
                Lyric = LyricItem.Parse(File.ReadAllText(DownloadManager.LyricCachePath + PlayMusic.Id + ".lrc"));
            }
            else
            {
                string lyric = (PlayMusic as IApi).GetLyric();
                DownloadManager.SaveFile(Encoding.UTF8.GetBytes(lyric), DownloadManager.LyricCachePath, PlayMusic.Id + ".lrc");
                Lyric = LyricItem.Parse(lyric);
            }

            //专辑封面缓存检测
            if (PlayMusic.Origin == Enum.MusicSource.Local)
            {
                try
                {
                    Properties.Resources.DefaultCover.Save(DownloadManager.CoverCachePath + PlayMusic.Id + ".jpg");
                }
                catch
                {
                    //忽略
                }
            }
            if (!File.Exists(DownloadManager.CoverCachePath + PlayMusic.Id + ".jpg"))
            {
                //异步下载图片
                DownloadManager.DownloadFileAsync((PlayMusic as IApi).GetCoverUrl(), DownloadManager.CoverCachePath, PlayMusic.Id + ".jpg", null,
                                                  new Action <object, int>((sender, e) =>
                {
                    if (PageManager.CurrentPage == PageManager.LyricPage)
                    {
                        ViewModelManager.MainWindowViewModel.SetBackground(1);
                        ViewModelManager.LyricPageViewModel.Cover = new Uri($"pack://siteoforigin:,,,/Cache/Cover/{PlayMusic.Id}.jpg", UriKind.Absolute);
                    }
                    ViewModelManager.MainWindowViewModel.CoverSource = new Uri($"pack://siteoforigin:,,,/Cache/Cover/{PlayMusic.Id}.jpg", UriKind.Absolute);
                }));
            }
            else
            {
                if (PageManager.CurrentPage == PageManager.LyricPage)
                {
                    ViewModelManager.MainWindowViewModel.SetBackground(1);
                }
                ViewModelManager.MainWindowViewModel.CoverSource = new Uri($"pack://siteoforigin:,,,/Cache/Cover/{PlayMusic.Id}.jpg", UriKind.Absolute);
            }


            //如果当前页面是歌词页面,重新加载歌词页面
            if (PageManager.CurrentPage == PageManager.LyricPage)
            {
                //直接加载会抛异常,需要使用Dispatcher.Invoke
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    ViewModelManager.LyricPageViewModel.Init(Lyric);
                }));
            }
        }
示例#15
0
        public void OnSongChange(HyPlayItem mpi)
        {
            if (mpi != null)
            {
                Invoke((async() =>
                {
                    try
                    {
                        if (mpi.ItemType == HyPlayItemType.Local)
                        {
                            BitmapImage img = new BitmapImage();
                            await img.SetSourceAsync((await mpi.AudioInfo.LocalSongFile.GetThumbnailAsync(ThumbnailMode.MusicView, 9999)));
                            ImageAlbum.ImageSource = img;
                        }
                        else
                        {
                            ImageAlbum.ImageSource = new BitmapImage(new Uri(mpi.AudioInfo.Picture));
                        }

                        TextBlockSinger.Text = mpi.AudioInfo.Artist;
                        TextBlockSongTitle.Text = mpi.AudioInfo.SongName;
                        Background = new ImageBrush()
                        {
                            ImageSource = ImageAlbum.ImageSource, Stretch = Stretch.UniformToFill
                        };
                        ProgressBarPlayProg.Maximum = mpi.AudioInfo.LengthInMilliseconds;
                        SliderVolumn.Value = HyPlayList.Player.Volume * 100;

                        if (lastlrcid != HyPlayList.NowPlayingItem.GetHashCode())
                        {
                            //歌词加载中提示
                            double blanksize = (LyricBoxContainer.ViewportHeight / 2);
                            if (double.IsNaN(blanksize) || blanksize == 0)
                            {
                                blanksize = Window.Current.Bounds.Height / 3;
                            }
                            LyricBox.Children.Clear();
                            LyricBox.Children.Add(new Grid()
                            {
                                Height = blanksize
                            });
                            LyricItem lrcitem = new LyricItem(SongLyric.LoadingLyric)
                            {
                                Width = LyricWidth
                            };
                            LyricList = new List <LyricItem>()
                            {
                                lrcitem
                            };
                            LyricBox.Children.Add(lrcitem);
                            LyricBox.Children.Add(new Grid()
                            {
                                Height = blanksize
                            });
                        }
                    }
                    catch (Exception) { }
                    ;
                }));
            }
        }