mirror of
https://github.com/jayfunc/BetterLyrics.git
synced 2026-01-12 10:54:55 +08:00
feat: float and glow effect now can be adapted to auto word-by-word effect
This commit is contained in:
@@ -19,9 +19,10 @@ namespace BetterLyrics.WinUI3.Extensions
|
||||
new LyricsLine
|
||||
{
|
||||
StartMs = 0,
|
||||
EndMs = (int)TimeSpan.FromMinutes(99).TotalMilliseconds,
|
||||
EndMs = (int)TimeSpan.FromSeconds(30).TotalMilliseconds,
|
||||
PrimaryText = "● ● ●",
|
||||
PrimarySyllables = [new BaseLyrics { Text = "● ● ●", StartMs = 0, EndMs = (int)TimeSpan.FromMinutes(99).TotalMilliseconds }],
|
||||
PrimarySyllables = [new BaseLyrics { Text = "● ● ●", StartMs = 0, EndMs = (int)TimeSpan.FromSeconds(30).TotalMilliseconds }],
|
||||
IsPrimaryHasRealSyllableInfo = true,
|
||||
},
|
||||
],
|
||||
LanguageCode = "N/A",
|
||||
|
||||
@@ -68,11 +68,17 @@ namespace BetterLyrics.WinUI3.Logic
|
||||
for (int i = safeStart; i <= safeEnd; i++)
|
||||
{
|
||||
var line = lines[i];
|
||||
|
||||
var lineHeight = line.PrimaryLineHeight;
|
||||
|
||||
if (lineHeight == null || lineHeight <= 0) continue;
|
||||
|
||||
bool isWordAnimationEnabled = lyricsEffect.WordByWordEffectMode switch
|
||||
{
|
||||
Enums.WordByWordEffectMode.Auto => line.IsPrimaryHasRealSyllableInfo,
|
||||
Enums.WordByWordEffectMode.Always => true,
|
||||
Enums.WordByWordEffectMode.Never => false,
|
||||
_ => line.IsPrimaryHasRealSyllableInfo
|
||||
};
|
||||
|
||||
double targetCharFloat = lyricsEffect.IsLyricsFloatAnimationAmountAutoAdjust
|
||||
? lineHeight.Value * 0.1
|
||||
: lyricsEffect.LyricsFloatAnimationAmount;
|
||||
@@ -187,6 +193,8 @@ namespace BetterLyrics.WinUI3.Logic
|
||||
line.YOffsetTransition.Start(targetYScrollOffset);
|
||||
}
|
||||
|
||||
if (isWordAnimationEnabled)
|
||||
{
|
||||
if (isSecondaryLinePlayingChanged)
|
||||
{
|
||||
// 辉光动画
|
||||
@@ -275,11 +283,11 @@ namespace BetterLyrics.WinUI3.Logic
|
||||
}
|
||||
}
|
||||
|
||||
// 使动画步进一帧
|
||||
foreach (var renderChar in line.PrimaryRenderChars)
|
||||
{
|
||||
renderChar.Update(elapsedTime);
|
||||
}
|
||||
}
|
||||
|
||||
line.Update(elapsedTime);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace BetterLyrics.WinUI3.Logic
|
||||
switch (wordByWordEffectMode)
|
||||
{
|
||||
case WordByWordEffectMode.Auto:
|
||||
if (line.PrimaryRenderSyllables.Count > 1)
|
||||
if (line.IsPrimaryHasRealSyllableInfo)
|
||||
{
|
||||
return CalculateSyllableProgress(currentTimeMs, line, lineEndMs);
|
||||
}
|
||||
@@ -106,7 +106,7 @@ namespace BetterLyrics.WinUI3.Logic
|
||||
state.SyllableProgress = 1f;
|
||||
return state;
|
||||
case WordByWordEffectMode.Always:
|
||||
if (line.PrimaryRenderSyllables.Count > 1)
|
||||
if (line.IsPrimaryHasRealSyllableInfo)
|
||||
{
|
||||
return CalculateSyllableProgress(currentTimeMs, line, lineEndMs);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ namespace BetterLyrics.WinUI3.Models.Lyrics
|
||||
public new string Text => PrimaryText;
|
||||
public new int StartIndex = 0;
|
||||
|
||||
public bool IsPrimaryHasRealSyllableInfo { get; set; } = false;
|
||||
|
||||
public LyricsLine()
|
||||
{
|
||||
for (int charStartIndex = 0; charStartIndex < PrimaryText.Length; charStartIndex++)
|
||||
|
||||
@@ -76,6 +76,8 @@ namespace BetterLyrics.WinUI3.Models.Lyrics
|
||||
|
||||
public double? PrimaryLineHeight => PrimaryRenderChars.FirstOrDefault()?.LayoutRect.Height;
|
||||
|
||||
public bool IsPrimaryHasRealSyllableInfo { get; set; }
|
||||
|
||||
public RenderLyricsLine(LyricsLine lyricsLine) : base(lyricsLine)
|
||||
{
|
||||
AngleTransition = new(
|
||||
@@ -130,6 +132,7 @@ namespace BetterLyrics.WinUI3.Models.Lyrics
|
||||
PrimaryText = lyricsLine.PrimaryText;
|
||||
SecondaryText = lyricsLine.SecondaryText;
|
||||
PrimaryRenderSyllables = lyricsLine.PrimarySyllables.Select(x => new RenderLyricsSyllable(x)).ToList();
|
||||
IsPrimaryHasRealSyllableInfo = lyricsLine.IsPrimaryHasRealSyllableInfo;
|
||||
}
|
||||
|
||||
public void UpdateCenterPosition(double maxWidth, TextAlignmentType type)
|
||||
|
||||
@@ -46,7 +46,8 @@ namespace BetterLyrics.WinUI3.Parsers.LyricsParser
|
||||
{
|
||||
StartMs = syllables[0].StartMs,
|
||||
PrimaryText = string.Concat(syllables.Select(s => s.Text)),
|
||||
PrimarySyllables = syllables
|
||||
PrimarySyllables = syllables,
|
||||
IsPrimaryHasRealSyllableInfo = true
|
||||
});
|
||||
}
|
||||
else
|
||||
@@ -68,19 +69,13 @@ namespace BetterLyrics.WinUI3.Parsers.LyricsParser
|
||||
content = bracketRegex!.Replace(line, "").Trim();
|
||||
if (content == "//") content = "";
|
||||
|
||||
lrcLines.Add(new LyricsLine
|
||||
var lyricsLine = new LyricsLine
|
||||
{
|
||||
StartMs = lineStartMs,
|
||||
PrimarySyllables = [
|
||||
new BaseLyrics
|
||||
{
|
||||
StartIndex = 0,
|
||||
StartMs = lineStartMs,
|
||||
Text = content
|
||||
}
|
||||
],
|
||||
PrimaryText = content
|
||||
});
|
||||
PrimaryText = content,
|
||||
IsPrimaryHasRealSyllableInfo = false
|
||||
};
|
||||
lrcLines.Add(lyricsLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace BetterLyrics.WinUI3.Parsers.LyricsParser
|
||||
{
|
||||
StartMs = lineRead.StartTime ?? 0,
|
||||
PrimaryText = lineRead.Text,
|
||||
PrimarySyllables = [],
|
||||
IsPrimaryHasRealSyllableInfo = true,
|
||||
};
|
||||
|
||||
var syllables = (lineRead as Lyricify.Lyrics.Models.SyllableLineInfo)?.Syllables;
|
||||
|
||||
@@ -127,7 +127,8 @@ namespace BetterLyrics.WinUI3.Parsers.LyricsParser
|
||||
StartMs = containerStartMs,
|
||||
EndMs = containerEndMs,
|
||||
PrimaryText = fullOriginalText,
|
||||
PrimarySyllables = syllables
|
||||
PrimarySyllables = syllables,
|
||||
IsPrimaryHasRealSyllableInfo = true,
|
||||
});
|
||||
|
||||
var transSpan = container.Elements()
|
||||
@@ -151,7 +152,8 @@ namespace BetterLyrics.WinUI3.Parsers.LyricsParser
|
||||
{
|
||||
StartMs = startMs,
|
||||
EndMs = endMs,
|
||||
PrimaryText = text
|
||||
PrimaryText = text,
|
||||
IsPrimaryHasRealSyllableInfo = false,
|
||||
});
|
||||
}
|
||||
else
|
||||
@@ -160,7 +162,8 @@ namespace BetterLyrics.WinUI3.Parsers.LyricsParser
|
||||
{
|
||||
StartMs = startMs,
|
||||
EndMs = endMs,
|
||||
PrimaryText = ""
|
||||
PrimaryText = "",
|
||||
IsPrimaryHasRealSyllableInfo = false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ namespace BetterLyrics.WinUI3.Parsers.LyricsParser
|
||||
GenerateTransliterationLyricsData();
|
||||
|
||||
EnsureEndMs(lyricsSearchResult?.Duration);
|
||||
EnsureSyllables();
|
||||
|
||||
return _lyricsDataArr;
|
||||
}
|
||||
@@ -313,5 +314,44 @@ namespace BetterLyrics.WinUI3.Parsers.LyricsParser
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoke this after <see cref="EnsureEndMs"/>
|
||||
/// </summary>
|
||||
private void EnsureSyllables()
|
||||
{
|
||||
foreach (var lyricsData in _lyricsDataArr)
|
||||
{
|
||||
if (lyricsData == null) continue;
|
||||
|
||||
var lines = lyricsData.LyricsLines;
|
||||
if (lines == null) continue;
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (line == null) continue;
|
||||
if (line.IsPrimaryHasRealSyllableInfo) continue;
|
||||
if (line.PrimarySyllables.Count > 0) continue;
|
||||
|
||||
var content = line.PrimaryText;
|
||||
var length = content.Length;
|
||||
if (length == 0) continue;
|
||||
|
||||
var avgSyllableDuration = line.DurationMs / length;
|
||||
if (avgSyllableDuration == 0) continue;
|
||||
|
||||
for (int j = 0; j < length; j++)
|
||||
{
|
||||
line.PrimarySyllables.Add(new BaseLyrics
|
||||
{
|
||||
Text = content[j].ToString(),
|
||||
StartIndex = j,
|
||||
StartMs = line.StartMs + avgSyllableDuration * j,
|
||||
EndMs = line.StartMs + avgSyllableDuration * (j + 1),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user