-
Notifications
You must be signed in to change notification settings - Fork 15
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
Merged
andy840119
merged 10 commits into
karaoke-dev:master
from
andy840119:implement-the-utils-to-create-the-position-text-from-time-tag
Mar 3, 2024
Merged
Implement the processor for able to switch display the lyric text or romanization text. #2176
andy840119
merged 10 commits into
karaoke-dev:master
from
andy840119:implement-the-utils-to-create-the-position-text-from-time-tag
Mar 3, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
andy840119
added
enhancement
New feature or request
code quality
Improve code quality.
Config
Anything system change.
labels
Mar 3, 2024
And note that the romanization conversion is not implemented because conversion logic is complex and hard to maintain. 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; }
} |
… property for different type of the processor. Like lyric first/ romanization first display processor.
… and triggered amount. Also, write the base class to check that the property should be updated if the property is display.
…est cases for it.
andy840119
force-pushed
the
implement-the-utils-to-create-the-position-text-from-time-tag
branch
from
March 3, 2024 07:36
d8ac7a9
to
02510d9
Compare
andy840119
force-pushed
the
implement-the-utils-to-create-the-position-text-from-time-tag
branch
from
March 3, 2024 07:49
02510d9
to
b129572
Compare
先這樣 |
This was referenced Mar 3, 2024
andy840119
deleted the
implement-the-utils-to-create-the-position-text-from-time-tag
branch
March 3, 2024 08:09
This was referenced Mar 31, 2024
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's the benefit of this change: