private LyricItemCollection InternalBuildLyricObject(LyricItemCollection lyric, string sourceText)
        {
            var regex = new Regex(@"\[\d+:\d+.\d+\].+\n?");

            foreach (Match match in regex.Matches(sourceText))
            {
                lyric.Add(new LyricItem(match.Value));
            }

            return(lyric);
        }
Example #2
0
        public static LyricItemCollection operator +(LyricItemCollection left, LyricItemCollection right)
        {
            if (right.IsPruneMusic)
            {
                return(left);
            }

            var option        = left.Option;
            var newCollection = new LyricItemCollection(option);
            var indexDiff     = left.Count - right.Count;

            if (!option.IsOneLine)
            {
                left.ForEach(item => newCollection.Add(item));
                right.ForEach(item => newCollection.Add(item));

                newCollection.Sort();
                return(newCollection);
            }

            // 如果索引相等,直接根据索引快速匹配构建。
            if (indexDiff == 0)
            {
                newCollection.AddRange(left.Select((t, index) => t + right[index]));

                return(newCollection);
            }

            // 首先按照时间轴进行合并。
            var leftMarkDict  = BuildMarkDictionary(left);
            var rightMarkDict = BuildMarkDictionary(right);

            for (var leftIndex = 0; leftIndex < left.Count; leftIndex++)
            {
                var rightItem = right.Find(lyric => Math.Abs(lyric.SortScore - left[leftIndex].SortScore) < 0.001);
                if (rightItem != null)
                {
                    newCollection.Add(left[leftIndex] + rightItem);
                    var rightIndex = right.FindIndex(item => item == rightItem);
                    rightMarkDict[rightIndex] = true;
                }
                else
                {
                    newCollection.Add(left[leftIndex]);
                }

                leftMarkDict[leftIndex] = true;
            }

            // 遍历未处理的歌词项,将其添加到返回集合当中。
            var leftWaitProcessIndex = leftMarkDict
                                       .Where(item => !item.Value)
                                       .Select(pair => pair.Key);
            var rightWaitProcessIndex = rightMarkDict
                                        .Where(item => !item.Value)
                                        .Select(pair => pair.Key);

            leftWaitProcessIndex.Foreach(index => newCollection.Add(left[index]));
            rightWaitProcessIndex.Foreach(index => newCollection.Add(right[index]));

            newCollection.Sort();
            return(newCollection);
        }