Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the processor for able to switch display the lyric text or romanization text. #2176

Conversation

andy840119
Copy link
Member

What's the benefit of this change:

  1. All bindable event is wrapped in the processor and will be released if the processor is destroyed.
  2. This ruleset allows user to fill the romanization in the time-tag. I notice that some users create the karaoke song with romaji, should be better to create the Japanese song with romanization.

@andy840119 andy840119 added enhancement New feature or request code quality Improve code quality. Config Anything system change. labels Mar 3, 2024
@andy840119 andy840119 added this to the 2024.0505 milestone Mar 3, 2024
@andy840119
Copy link
Member Author

andy840119 commented Mar 3, 2024

And note that the romanization conversion is not implemented because conversion logic is complex and hard to maintain.
Will start implement if user request.

Here's the sample conversion made before:

private static IEnumerable<Tuple<RomanizationInfo, TimeTag?>> getRomanizationInfos(Lyric lyric)
{
    const string space = " ";

    var timeTags = lyric.TimeTags;

    int startCanterTextIndex = 0;

    for (int i = 0; i < timeTags.Count; i++)
    {
        var currentTimeTag = timeTags[i];
        var nextTimeTag = timeTags.GetNext(currentTimeTag);
        if (nextTimeTag == default)
            yield break;

        // get the center text index.
        bool hasEmptySpace = i != 0 && currentTimeTag.FirstSyllable;
        int startCenterTextIndex = startCanterTextIndex + (hasEmptySpace ? 1 : 0);

        var romanizationInfo = createRomanizationInfo(startCenterTextIndex, currentTimeTag, nextTimeTag);
        yield return new Tuple<RomanizationInfo, TimeTag?>(romanizationInfo, currentTimeTag);
        startCanterTextIndex += romanizationInfo.RomanizedSyllable.Length;

        if (!nextTimeTag.FirstSyllable)
            continue;

        // should add extra space if the next time tag is the first syllable.
        var newRomanizationInfo = new RomanizationInfo
        {
            RomanizedSyllableStartCharIndex = startCanterTextIndex,
            RomanizedSyllableEndCharIndex = startCanterTextIndex + space.Length,
            RomanizedSyllable = space,
        };
        yield return new Tuple<RomanizationInfo, TimeTag?>(newRomanizationInfo, null);
        startCanterTextIndex += newRomanizationInfo.RomanizedSyllable.Length;
    }

    yield break;

    static RomanizationInfo createRomanizationInfo(int startIndex, TimeTag currentTimeTag, TimeTag nextTimeTag) =>
        new()
        {
            RomanizedSyllableStartCharIndex = startIndex,
            RomanizedSyllableEndCharIndex = startIndex + currentTimeTag.RomanizedSyllable?.Length ?? 0,
            OriginLyricStartCharIndex = TextIndexUtils.ToCharIndex(currentTimeTag.Index),
            OriginLyricEndCharIndex = TextIndexUtils.ToCharIndex(nextTimeTag.Index),
            RomanizedSyllable = currentTimeTag.RomanizedSyllable ?? string.Empty,
        };
}

private struct RomanizationInfo
{
    public int RomanizedSyllableStartCharIndex { get; set; }

    public int RomanizedSyllableEndCharIndex { get; set; }

    public int OriginLyricStartCharIndex { get; set; }

    public int OriginLyricEndCharIndex { get; set; }

    public string RomanizedSyllable { get; set; }
}

or:

private static IEnumerable<TextIndexWithGapIndex> getGapIndexes(Lyric lyric)
{
    var timeTags = lyric.TimeTags;

    int startCanterTextIndex = 0;

    for (int i = 0; i < timeTags.Count; i++)
    {
        var timeTag = timeTags[i];
        var nextTimeTag = timeTags.GetNext(timeTag);
        if (nextTimeTag == default)
            yield break;

        // get the center text index.
        bool hasEmptySpace = i != 0 && timeTag.FirstSyllable;
        int startCenterTextIndex = startCanterTextIndex + (hasEmptySpace ? 1 : 0);
        int endCenterTextIndex = startCenterTextIndex + timeTag.RomanizedSyllable?.Length ?? 0;

        // get the gap index that
        int startGapIndex = TextIndexUtils.ToGapIndex(timeTag.Index);
        int endGapIndex = TextIndexUtils.ToGapIndex(nextTimeTag.Index);

        yield return new TextIndexWithGapIndex
        {
            TimeTag = timeTag,
            RomanizedSyllableStartCharIndex = startCenterTextIndex,
            RomanizedSyllableEndCharIndex = endCenterTextIndex,
            OriginLyricStartGapIndex = startGapIndex,
            OriginLyricEndGapIndex = endGapIndex,
        };

        startCanterTextIndex = endCenterTextIndex;
    }
}

private struct TextIndexWithGapIndex
{
    public TimeTag TimeTag { get; set; }

    public int? RomanizedSyllableStartCharIndex { get; set; }

    public int? RomanizedSyllableEndCharIndex { get; set; }

    public string RomanizedSyllable => TimeTag.RomanizedSyllable ?? string.Empty;

    public int OriginLyricStartGapIndex { get; set; }

    public int OriginLyricEndGapIndex { get; set; }
}

@andy840119 andy840119 force-pushed the implement-the-utils-to-create-the-position-text-from-time-tag branch from d8ac7a9 to 02510d9 Compare March 3, 2024 07:36
@andy840119 andy840119 force-pushed the implement-the-utils-to-create-the-position-text-from-time-tag branch from 02510d9 to b129572 Compare March 3, 2024 07:49
@andy840119
Copy link
Member Author

andy840119 commented Mar 3, 2024

先這樣
Config 之後可能需要調整,或許根據不同的歌曲會有不同設定
或是轉換成 mod (mod 會比 config 容易設定,並且也可以從遊玩去猜出 user 是不是本地人)

@andy840119 andy840119 merged commit 69c555f into karaoke-dev:master Mar 3, 2024
4 checks passed
@andy840119 andy840119 deleted the implement-the-utils-to-create-the-position-text-from-time-tag branch March 3, 2024 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality Improve code quality. Config Anything system change. enhancement New feature or request size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant