Ejemplo n.º 1
0
        /// <summary>
        /// 保存NRC歌词
        /// </summary>
        /// <param name="savepath"></param>
        public void ExportNRCFile(string savepath)
        {
            NRCModel nm = new NRCModel();

            nm.LyricType = LyricType.NRC;
            nm.NRCS      = new List <NRCSentenceModel>();
            foreach (NRCSentence nrcs in NRCSList)
            {
                NRCSentenceModel nrcsm = new NRCSentenceModel();
                nrcsm.StartTime = nrcs.StartTime;
                Debug.WriteLine(nrcs.ToString() + "->" + nrcs.StartTime);
                nrcsm.NRCWord = new List <NRCWordModel>();
                foreach (NRCWord nrcw in nrcs.NWList)
                {
                    nrcsm.NRCWord.Add(nrcw.Data);
                }
                nm.NRCS.Add(nrcsm);
            }

            File.WriteAllText(savepath, JsonConvert.SerializeObject(nm));
        }
Ejemplo n.º 2
0
        private void LoadLRC(string str)
        {
            //NRC.NRCS.Clear();

            try
            {
                //Regex reg = new Regex(@"\[(?<time>([0-9]\d)\:([0-9]\d)\.([0-9]\d))\](?<lrc>.*?)(\n)", RegexOptions.IgnoreCase);
                Regex reg = new Regex(@"\[(?<time>(.*?)\:(.*?)\.(.*?))\](?<lrc>.*?)(\r|\n)", RegexOptions.IgnoreCase);

                // 搜索匹配的字符串
                MatchCollection matches = reg.Matches(str);


                // 取得匹配项列表
                foreach (Match match in matches)
                {
                    string time = match.Groups["time"].Value;

                    string lrc = match.Groups["lrc"].Value;
                    //lrc = lrc.Replace(" ", "");

                    Debug.WriteLine(time + "/" + lrc);

                    if (lrc != string.Empty)
                    {
                        NRCSentenceModel nrcsm = new NRCSentenceModel();
                        nrcsm.StartTime = ToDouble(time);
                        nrcsm.NRCWord   = new List <NRCWordModel>();


                        //把歌词一个个字切出来

                        for (int i = 0; i < lrc.Length; i++)
                        {
                            //nrcsm.NRCWord.Add();
                            string   c  = lrc.Substring(i, 1);
                            CharType ct = GetCharType(c);

                            NRCWordModel nrcwm = new NRCWordModel();
                            nrcwm.PlayTime  = 1000;                         //测试数据,默认吟唱时间1秒
                            nrcwm.StartTime = nrcsm.StartTime + (i * 1000); //测试数据,字开始时间
                            nrcwm.Word      = c;

                            //什么鸡掰代码 写完自己都看晕了
                            if (i == 0 || ct == CharType.Chinese)
                            {
                                //创建新字组

                                nrcsm.NRCWord.Add(nrcwm);
                            }
                            else if (ct == CharType.English)
                            {
                                CharType ctlast = GetCharType(lrc.Substring((i - 1), 1));
                                if (ctlast != CharType.Chinese && ctlast != CharType.Space)
                                {
                                    nrcsm.NRCWord[nrcsm.NRCWord.Count - 1].Word += c;
                                    Debug.WriteLine("char:" + c + ",last char:" + lrc.Substring((i - 1), 1) + ",laststr:" + nrcsm.NRCWord[nrcsm.NRCWord.Count - 1].Word);
                                }
                                else
                                {
                                    //创建新字组
                                    nrcsm.NRCWord.Add(nrcwm);
                                }
                            }
                            else if (ct == CharType.Space || ct == CharType.Symbol)
                            {
                                nrcsm.NRCWord[nrcsm.NRCWord.Count - 1].Word += c;
                            }

                            //Debug.WriteLine(c + "->" + ct);
                        }
                        //加入歌词
                        NRC.NRCS.Add(nrcsm);
                    }
                }
                Debug.WriteLine("加载网易云歌词成功!");
            }
            catch (Exception ec)
            {
                Debug.WriteLine("加载网易云歌词失败." + ec);
            }
        }