Skip to content

Commit

Permalink
Merge pull request #72 from andy840119/lyric-time-tag-should-be-absol…
Browse files Browse the repository at this point in the history
…ute-time

"<mm:dd.ss>" in the lyric store the absolute time, not the relative time.
  • Loading branch information
andy840119 authored Jul 28, 2024
2 parents 6e87b2f + cb9834a commit 731b2f3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## 2024.0728
## 2024.0728.2
* "<mm:dd.ss>" in the `.lrc` file is absolute time, not the relative time.

## 2024.0728.1
* Add `StartTime` property in the `Model.Lyric` class. This property is used to store the start time of the lyric.~~
* `LrcParse` is re-written. Now it can follow the [LRC and Enhanced LRC format](https://en.wikipedia.org/wiki/LRC_(file_format) to decode/encode the lyric correctly.
* Create the `KarParser`, which is used to parse the Karaoke file with format like `[00:51.00]ka[01:29.99]ra[01:48.29]o[02:31.00]ke[02:41.99]`.
4 changes: 2 additions & 2 deletions LrcParser.Tests/Parser/Lrc/LrcParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void TestDecode()
{
var lrcText = new[]
{
"[00:17.00] <00:00.00>帰<00:01.00>り<00:02.00>道<00:03.00>は<00:04.00>",
"[00:17.00] <00:17.00>帰<00:18.00>り<00:19.00>道<00:20.00>は<00:21.00>",
};

var song = new Song
Expand Down Expand Up @@ -65,7 +65,7 @@ public void TestEncode()

var lrcText = new[]
{
"[00:17.00] <00:00.00>帰<00:01.00>り<00:02.00>道<00:03.00>は<00:04.00>",
"[00:17.00] <00:17.00>帰<00:18.00>り<00:19.00>道<00:20.00>は<00:21.00>",
};

checkEncode(song, lrcText);
Expand Down
12 changes: 6 additions & 6 deletions LrcParser/Parser/Lrc/LrcParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ static IEnumerable<Lyric> convertLyric(LrcLyric lrcLyric)
{
Text = lrcLyric.Text,
StartTime = startTime,
TimeTags = getTimeTags(lrcLyric.TimeTags, startTime),
TimeTags = getTimeTags(lrcLyric.TimeTags),
};
}
}

static SortedDictionary<TextIndex, int?> getTimeTags(SortedDictionary<TextIndex, int> timeTags, int offsetTime)
=> new(timeTags.ToDictionary(k => k.Key, v => v.Value + offsetTime as int?));
static SortedDictionary<TextIndex, int?> getTimeTags(SortedDictionary<TextIndex, int> timeTags)
=> new(timeTags.ToDictionary(k => k.Key, v => v.Value as int?));
}

protected override IEnumerable<object> PreProcess(Song song)
Expand All @@ -58,7 +58,7 @@ protected override IEnumerable<object> PreProcess(Song song)
{
Text = lyric.Text,
StartTimes = [lyric.StartTime],
TimeTags = getTimeTags(lyric.TimeTags, -lyric.StartTime),
TimeTags = getTimeTags(lyric.TimeTags),
};
}

Expand All @@ -72,7 +72,7 @@ protected override IEnumerable<object> PreProcess(Song song)

yield break;

static SortedDictionary<TextIndex, int> getTimeTags(SortedDictionary<TextIndex, int?> timeTags, int offsetTime = 0)
=> new(timeTags.Where(x => x.Value.HasValue).ToDictionary(k => k.Key, v => v.Value!.Value + offsetTime));
static SortedDictionary<TextIndex, int> getTimeTags(SortedDictionary<TextIndex, int?> timeTags)
=> new(timeTags.Where(x => x.Value.HasValue).ToDictionary(k => k.Key, v => v.Value!.Value));
}
}
2 changes: 1 addition & 1 deletion LrcParser/Parser/Lrc/Metadata/LrcLyric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public LrcLyric()

/// <summary>
/// Time tags.
/// It's the relative time from the start time.
/// It's the absolute time.
/// </summary>
public SortedDictionary<TextIndex, int> TimeTags { get; set; } = new();

Expand Down

0 comments on commit 731b2f3

Please sign in to comment.