Skip to content

Commit

Permalink
Merge pull request #104 from jitwxs/dev
Browse files Browse the repository at this point in the history
Release v4.5
  • Loading branch information
jitwxs authored Jun 19, 2022
2 parents e6cfa03 + 09f0fe6 commit 6fe2af3
Show file tree
Hide file tree
Showing 14 changed files with 370 additions and 287 deletions.
2 changes: 1 addition & 1 deletion MusicLyricApp/Bean/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace MusicLyricApp.Bean
{
public static class Constants
{
public const string Version = "v4.4";
public const string Version = "v4.5";

public static readonly string SettingPath = Environment.CurrentDirectory + "\\MusicLyricAppSetting.json";

Expand Down
138 changes: 88 additions & 50 deletions MusicLyricApp/Bean/MusicLyricsVO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ public enum SearchTypeEnum
// 强制两位类型
public enum DotTypeEnum
{
[Description("不启用")] DISABLE = 0,
[Description("截位")] DOWN = 1,
[Description("四舍五入")] HALF_UP = 2
[Description("截位")] DOWN = 0,
[Description("四舍五入")] HALF_UP = 1
}

// 输出文件格式
Expand Down Expand Up @@ -200,18 +199,12 @@ public bool IsEmpty()

public class LyricTimestamp : IComparable
{
public long Minute { get; private set; }
public long Minute { get; }

public string MinuteS { get; private set; }

public long Second { get; private set; }
public long Second { get; }

public string SecondS { get; private set; }

public long Millisecond { get; private set; }
public long Millisecond { get; }

public string MillisecondS { get; private set; }

public long TimeOffset { get;}

public LyricTimestamp(long millisecond)
Expand All @@ -225,10 +218,6 @@ public LyricTimestamp(long millisecond)
Second = millisecond % 60;

Minute = millisecond / 60;

UpdateMinute(Minute);
UpdateSecond(Second);
UpdateMillisecond(Millisecond);
}

public LyricTimestamp(string timestamp)
Expand All @@ -255,24 +244,8 @@ public LyricTimestamp(string timestamp)
}
}

UpdateMinute(Minute);
UpdateSecond(Second);
UpdateMillisecond(Millisecond);

TimeOffset = (Minute * 60 + Second) * 1000 + Millisecond;
}

public string ToString(OutputFormatEnum outputFormat)
{
if (outputFormat == OutputFormatEnum.LRC)
{
return "[" + MinuteS + ":" + SecondS + "." + MillisecondS + "]";
}
else
{
return "00:" + MinuteS + ":" + SecondS + "," + MillisecondS;
}
}

public int CompareTo(object input)
{
Expand Down Expand Up @@ -306,24 +279,83 @@ public int CompareTo(object input)
}
}

private void UpdateMinute(long value)
{
Minute = value;
MinuteS = value.ToString("00");
}

private void UpdateSecond(long value)
public string PrintTimestamp(string timestampFormat, DotTypeEnum dotTypeEnum)
{
Second = value;
SecondS = value.ToString("00");
var output = timestampFormat;

long actualMinute;
if (output.Contains("HH"))
{
var hour = Minute / 60;
actualMinute = Minute % 60;
output = output.Replace("HH", hour.ToString("00"));
}
else
{
actualMinute = Minute;
}

if (output.Contains("mm"))
{
output = output.Replace("mm", actualMinute.ToString("00"));
}

if (output.Contains("ss"))
{
output = output.Replace("ss", Second.ToString("00"));
}

if (output.Contains("SSS"))
{
output = output.Replace("SSS", Millisecond.ToString("000"));
}

if (output.Contains("SS"))
{
var actualMillisecond = AdjustMillisecondScale(2, dotTypeEnum);
output = output.Replace("SS", actualMillisecond.ToString("00"));
}

if (output.Contains("S"))
{
var actualMillisecond = AdjustMillisecondScale(1, dotTypeEnum);
output = output.Replace("S", actualMillisecond.ToString("0"));
}

return output;
}

public void UpdateMillisecond(long value, int scale = 3)
/// <summary>
/// 调整毫秒位数
/// </summary>
/// <param name="scale">位数,取值为 1 ~ 3</param>
/// <param name="dotTypeEnum">截位规则</param>
/// <returns></returns>
private long AdjustMillisecondScale(int scale, DotTypeEnum dotTypeEnum)
{
var format = new StringBuilder().Insert(0, "0", scale).ToString();

Millisecond = value;
MillisecondS = Millisecond.ToString(format);
var limit = 1;
for (var i = 0; i < scale; i++)
{
limit *= 10;
}

var actualMillisecond = Millisecond;

while (actualMillisecond >= limit)
{
var round = 0;
if (dotTypeEnum == DotTypeEnum.HALF_UP)
{
if (actualMillisecond % 10 >= 5)
{
round = 1;
}
}

actualMillisecond = actualMillisecond / 10 + round;
}

return actualMillisecond;
}
}

Expand All @@ -339,7 +371,13 @@ public class LyricLineVo : IComparable
/// </summary>
public string Content { get; set; }

public LyricLineVo(string lyricLine = "")
public LyricLineVo(string content, LyricTimestamp timestamp)
{
Timestamp = timestamp;
Content = content;
}

public LyricLineVo(string lyricLine)
{
var index = lyricLine.IndexOf("]");
if (index == -1)
Expand Down Expand Up @@ -381,10 +419,10 @@ public bool IsIllegalContent()

return false;
}
public override string ToString()

public string Print(string timestampFormat, DotTypeEnum dotType)
{
return Timestamp.ToString(OutputFormatEnum.LRC) + Content;
return Timestamp.PrintTimestamp(timestampFormat, dotType) + Content.Trim();
}
}

Expand Down
12 changes: 11 additions & 1 deletion MusicLyricApp/Bean/SettingBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,21 @@ public class PersistParamBean
/// 指定歌词合并的分隔符
/// </summary>
public string LrcMergeSeparator = String.Empty;

/// <summary>
/// LRC 歌词时间戳格式
/// </summary>
public string LrcTimestampFormat = "[mm:ss.SSS]";

/// <summary>
/// SRT 歌词时间戳格式
/// </summary>
public string SrtTimestampFormat = "HH:mm:ss,SSS";

/// <summary>
/// 小数位处理策略
/// </summary>
public DotTypeEnum DotType = DotTypeEnum.DISABLE;
public DotTypeEnum DotType = DotTypeEnum.DOWN;

/// <summary>
/// 输出文件名类型
Expand Down
57 changes: 20 additions & 37 deletions MusicLyricApp/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6fe2af3

Please sign in to comment.