Skip to content

Commit

Permalink
Merge pull request #107 from jitwxs/dev
Browse files Browse the repository at this point in the history
Release v4.6
  • Loading branch information
jitwxs authored Jul 10, 2022
2 parents 95e9358 + f6add9e commit 3c5f3c0
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 9 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.5";
public const string Version = "v4.6";

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

Expand Down
10 changes: 9 additions & 1 deletion MusicLyricApp/Bean/MusicLyricsVO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ public enum RomajiSystemEnum
[Description("平文式")] HEPBURN = 2,
}

// 译文缺省规则
public enum TranslateLyricDefaultRuleEnum
{
[Description("忽略展示")] IGNORE = 0,
[Description("展示空行")] EMPTY_LINE = 1,
[Description("填充原文")] FILL_ORIGIN = 2,
}

/**
* 错误码
*/
Expand Down Expand Up @@ -412,7 +420,7 @@ public bool IsIllegalContent()
return true;
}

if ("//".Equals(Content))
if ("//".Equals(Content.Trim()))
{
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions MusicLyricApp/Bean/SettingBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public class ConfigBean
/// 自动检查更新
/// </summary>
public bool AutoCheckUpdate = true;

/// <summary>
/// 译文缺省规则
/// </summary>
public TranslateLyricDefaultRuleEnum TranslateLyricDefaultRule = TranslateLyricDefaultRuleEnum.IGNORE;

/// <summary>
/// 罗马音相关配置
Expand Down
32 changes: 29 additions & 3 deletions MusicLyricApp/SettingForm.Designer.cs

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

1 change: 1 addition & 0 deletions MusicLyricApp/SettingForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private void Save_Btn_Click(object sender, EventArgs e)
_settingBean.Config.RomajiConfig.Enable = ShowRomaji_CheckBox.Checked;
_settingBean.Config.RomajiConfig.ModeEnum = (RomajiModeEnum)RomajiMode_ComboBox.SelectedIndex;
_settingBean.Config.RomajiConfig.SystemEnum = (RomajiSystemEnum)RomajiSystem_ComboBox.SelectedIndex;
_settingBean.Config.TranslateLyricDefaultRule = (TranslateLyricDefaultRuleEnum)TranLyricDefaultRule_ComboBox.SelectedIndex;

Close();
}
Expand Down
59 changes: 55 additions & 4 deletions MusicLyricApp/Utils/LyricUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private static async Task<List<LyricLineVo>> FormatLyric(string originLrc, strin
return translateLyrics;
}

List<LyricLineVo> res = null;
List<LyricLineVo> res;
switch (showLrcType)
{
case ShowLrcTypeEnum.ORIGIN_PRIOR_ISOLATED:
Expand All @@ -102,8 +102,11 @@ private static async Task<List<LyricLineVo>> FormatLyric(string originLrc, strin
case ShowLrcTypeEnum.TRANSLATE_PRIOR_MERGE:
res = MergeLrc(originLyrics, translateLyrics, searchInfo.SettingBean.Param.LrcMergeSeparator, false);
break;
default:
throw new NotSupportedException("not support showLrcType: " + showLrcType);
}
return res;

return DealTranslateLyricDefaultRule(res, searchInfo.SettingBean.Config.TranslateLyricDefaultRule);
}

/**
Expand Down Expand Up @@ -180,9 +183,9 @@ private static List<LyricLineVo> SortLrc(List<LyricLineVo> originLyrics, List<Ly
/**
* 双语歌词合并
*/
private static List<LyricLineVo> MergeLrc(List<LyricLineVo> originLrcs, List<LyricLineVo> translateLrcs, string splitStr, bool hasOriginLrcPrior)
private static List<LyricLineVo> MergeLrc(List<LyricLineVo> originList, List<LyricLineVo> translateList, string splitStr, bool hasOriginLrcPrior)
{
var c = SortLrc(originLrcs, translateLrcs, hasOriginLrcPrior);
var c = SortLrc(originList, translateList, hasOriginLrcPrior);

var list = new List<LyricLineVo>
{
Expand All @@ -206,6 +209,54 @@ private static List<LyricLineVo> MergeLrc(List<LyricLineVo> originLrcs, List<Lyr
return list;
}

/**
* 译文缺省逻辑处理
*/
private static List<LyricLineVo> DealTranslateLyricDefaultRule(List<LyricLineVo> voList, TranslateLyricDefaultRuleEnum rule)
{
if (rule != TranslateLyricDefaultRuleEnum.IGNORE)
{
var timestampCounts = new Dictionary<long, int>();

foreach (var key in voList.Select(one => one.Timestamp.TimeOffset))
{
if (timestampCounts.ContainsKey(key))
{
timestampCounts[key] += 1;
}
else
{
timestampCounts.Add(key,1);
}
}

var dealTimestamps = (from pair in timestampCounts where pair.Value == 1 select pair.Key).ToList();
dealTimestamps.Sort((a, b) => a.CompareTo(b));

var dealTimestampIndex = 0;

for (var i = 0; i < voList.Count; i++)
{
var cur = voList[i];
var timestamp = dealTimestamps[dealTimestampIndex];

if (cur.Timestamp.TimeOffset == timestamp)
{
var content = rule == TranslateLyricDefaultRuleEnum.FILL_ORIGIN ? cur.Content : "";
voList.Insert(++i, new LyricLineVo(content, cur.Timestamp));
dealTimestampIndex++;

if (dealTimestampIndex >= dealTimestamps.Count)
{
break;
}
}
}
}

return voList;
}

/**
* 歌词排序函数
*/
Expand Down

0 comments on commit 3c5f3c0

Please sign in to comment.