/// <summary> /// Initializes a new instance of the <see cref="LrcFile"/> class. /// </summary> /// <param name="metadata">The metadata.</param> /// <param name="lyrics">The lyrics.</param> /// <param name="applyOffset">if set to <c>true</c> apply the offset in metadata, otherwise ignore the offset.</param> public LrcFile(ILrcMetadata metadata, IEnumerable <IOneLineLyric> lyrics, bool applyOffset) { if (metadata == null) { throw new ArgumentNullException("metadata"); } if (lyrics == null) { throw new ArgumentNullException("lyrics"); } Metadata = metadata; var array = lyrics.OrderBy(l => l.Timestamp).ToArray(); for (var i = 0; i < array.Length; ++i) { if (applyOffset && metadata.Offset.HasValue) { var oneLineLyric = array[i] as OneLineLyric; if (oneLineLyric != null) { oneLineLyric.Timestamp -= metadata.Offset.Value; } else { array[i] = new OneLineLyric(array[i].Timestamp - metadata.Offset.Value, array[i].Content); } } if (i > 0 && array[i].Timestamp == array[i - 1].Timestamp) { throw new FormatException(string.Format("Found duplicate timestamp '{0}' with lyric '{1}' and '{2}'.", array[i].Timestamp, array[i - 1].Content, array[i].Content)); } } _lyrics = array; }
/// <summary> /// Initializes a new instance of the <see cref="LrcFile"/> class. /// </summary> /// <param name="metadata">The metadata.</param> /// <param name="lyrics">The lyrics.</param> /// <param name="applyOffset">if set to <c>true</c> apply the offset in metadata, otherwise ignore the offset.</param> public LrcParser(ILrcMetadata metadata, IEnumerable <IOneLineLyric> lyrics, bool applyOffset) { if (lyrics == null) { throw new ArgumentNullException("lyrics"); } Metadata = metadata ?? throw new ArgumentNullException("metadata"); var array = lyrics.OrderBy(l => l.Timestamp).ToList(); for (var i = 0; i < array.Count; ++i) { if (applyOffset && metadata.Offset.HasValue) { if (array[i] is OneLineLyric oneLineLyric) { oneLineLyric.Timestamp -= metadata.Offset.Value; } else { array[i] = new OneLineLyric(array[i].Timestamp - metadata.Offset.Value, array[i].Content); } } if (i > 0 && array[i].Timestamp == array[i - 1].Timestamp) { //ignore. //throw new FormatException(string.Format("Found duplicate timestamp '{0}' with lyric '{1}' and '{2}'.", array[i].Timestamp, array[i - 1].Content, array[i].Content)); } } _lyrics = array; }