From ab30639f2896f37f57278e072750a59097e0c217 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 6 Dec 2020 14:29:30 +0900 Subject: [PATCH 1/8] Rename manager from LanguageManager to TranslateManager. --- .../Edit/TestSceneManageLanguagesDialog.cs | 4 ++-- .../Translate/Components/DrawableLanguageListItem.cs | 12 ++++++------ .../Translate/Components/ManageLanguagesDialog.cs | 4 ++-- .../Edit/Translate/TranslateEditSection.cs | 4 ++-- .../{LanguageManager.cs => TranslateManager.cs} | 2 +- .../Edit/Translate/TranslateScreen.cs | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) rename osu.Game.Rulesets.Karaoke/Edit/Translate/{LanguageManager.cs => TranslateManager.cs} (97%) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Edit/TestSceneManageLanguagesDialog.cs b/osu.Game.Rulesets.Karaoke.Tests/Edit/TestSceneManageLanguagesDialog.cs index 952fa69cc..f8579ab34 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Edit/TestSceneManageLanguagesDialog.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Edit/TestSceneManageLanguagesDialog.cs @@ -21,7 +21,7 @@ public class TestSceneManageLanguagesDialog : OsuManualInputManagerTestScene protected override Container Content { get; } = new Container { RelativeSizeAxes = Axes.Both }; private DialogOverlay dialogOverlay; - private LanguageManager manager; + private TranslateManager manager; private ManageLanguagesDialog dialog; @@ -35,7 +35,7 @@ private void load() base.Content.AddRange(new Drawable[] { - manager = new LanguageManager(), + manager = new TranslateManager(), Content, dialogOverlay = new DialogOverlay() }); diff --git a/osu.Game.Rulesets.Karaoke/Edit/Translate/Components/DrawableLanguageListItem.cs b/osu.Game.Rulesets.Karaoke/Edit/Translate/Components/DrawableLanguageListItem.cs index 96804dd4b..29160b459 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Translate/Components/DrawableLanguageListItem.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Translate/Components/DrawableLanguageListItem.cs @@ -26,7 +26,7 @@ public class DrawableLanguageListItem : OsuRearrangeableListItem - /// Whether the currently exists inside the . + /// Whether the currently exists inside the . /// public IBindable IsCreated => isCreated; @@ -36,7 +36,7 @@ public class DrawableLanguageListItem : OsuRearrangeableListItem. /// /// The . - /// Whether currently exists inside the . + /// Whether currently exists inside the . public DrawableLanguageListItem(BeatmapSetOnlineLanguage item, bool isCreated) : base(item) { @@ -60,7 +60,7 @@ private class ItemContent : CircularContainer private readonly BeatmapSetOnlineLanguage language; [Resolved(CanBeNull = true)] - private LanguageManager languageManager { get; set; } + private TranslateManager languageManager { get; set; } private Container textBoxPaddingContainer; private ItemTextBox textBox; @@ -160,7 +160,7 @@ public class DeleteButton : CompositeDrawable private DialogOverlay dialogOverlay { get; set; } [Resolved(CanBeNull = true)] - private LanguageManager languageManager { get; set; } + private TranslateManager translateManager { get; set; } private readonly BeatmapSetOnlineLanguage language; @@ -224,7 +224,7 @@ protected override bool OnClick(ClickEvent e) { background.FlashColour(Color4.White, 150); - if (!languageManager?.IsLanguageContainsTranslate(language) ?? false) + if (!translateManager?.IsLanguageContainsTranslate(language) ?? false) deleteLanguage(); else dialogOverlay?.Push(new DeleteLanguageDialog(language, deleteLanguage)); @@ -232,7 +232,7 @@ protected override bool OnClick(ClickEvent e) return true; } - private void deleteLanguage() => languageManager?.RemoveLanguage(language); + private void deleteLanguage() => translateManager?.RemoveLanguage(language); } } } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Translate/Components/ManageLanguagesDialog.cs b/osu.Game.Rulesets.Karaoke/Edit/Translate/Components/ManageLanguagesDialog.cs index 8b04d6453..30c06880a 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Translate/Components/ManageLanguagesDialog.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Translate/Components/ManageLanguagesDialog.cs @@ -21,14 +21,14 @@ public ManageLanguagesDialog() } [BackgroundDependencyLoader] - private void load(LanguageManager languageManager) + private void load(TranslateManager translateManager) { Children = new Drawable[] { new DrawableLanguageList { RelativeSizeAxes = Axes.Both, - Items = { BindTarget = languageManager?.Languages ?? new BindableList() } + Items = { BindTarget = translateManager?.Languages ?? new BindableList() } } }; } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Translate/TranslateEditSection.cs b/osu.Game.Rulesets.Karaoke/Edit/Translate/TranslateEditSection.cs index 6be984596..f1755f43b 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Translate/TranslateEditSection.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Translate/TranslateEditSection.cs @@ -141,9 +141,9 @@ Dimension[] createRowDimension() => editorBeatmap.HitObjects.OfType() } [BackgroundDependencyLoader] - private void load(LanguageManager languageManager, OsuColour colours) + private void load(TranslateManager translateManager, OsuColour colours) { - languageDropdown.ItemSource = languageManager?.Languages ?? new BindableList(); + languageDropdown.ItemSource = translateManager?.Languages ?? new BindableList(); timeSectionBackground.Colour = colours.ContextMenuGray; lyricSectionBackground.Colour = colours.Gray9; diff --git a/osu.Game.Rulesets.Karaoke/Edit/Translate/LanguageManager.cs b/osu.Game.Rulesets.Karaoke/Edit/Translate/TranslateManager.cs similarity index 97% rename from osu.Game.Rulesets.Karaoke/Edit/Translate/LanguageManager.cs rename to osu.Game.Rulesets.Karaoke/Edit/Translate/TranslateManager.cs index 5e9dd68c7..71a6ffda1 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Translate/LanguageManager.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Translate/TranslateManager.cs @@ -15,7 +15,7 @@ namespace osu.Game.Rulesets.Karaoke.Edit.Translate /// /// Handle create or delete language. /// - public class LanguageManager : Component + public class TranslateManager : Component { public readonly BindableList Languages = new BindableList(); diff --git a/osu.Game.Rulesets.Karaoke/Edit/Translate/TranslateScreen.cs b/osu.Game.Rulesets.Karaoke/Edit/Translate/TranslateScreen.cs index bfe5761ad..5b1866f41 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Translate/TranslateScreen.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Translate/TranslateScreen.cs @@ -18,13 +18,13 @@ public class TranslateScreen : EditorScreen protected readonly OverlayColourProvider ColourProvider; [Cached] - protected readonly LanguageManager LanguageManager; + protected readonly TranslateManager TranslateManager; public TranslateScreen() : base(EditorScreenMode.SongSetup) { ColourProvider = new OverlayColourProvider(OverlayColourScheme.Green); - Content.Add(LanguageManager = new LanguageManager()); + Content.Add(TranslateManager = new TranslateManager()); } [BackgroundDependencyLoader] From 8cf7bf667fd07ea3935ac8f3b056080f078ee1d2 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 6 Dec 2020 14:42:50 +0900 Subject: [PATCH 2/8] Now importer is able to auto-assign language now/ --- .../AssignLanguage/AssignLanguageSubScreen.cs | 10 ++++- .../Edit/Lyrics/LyricManager.cs | 45 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs diff --git a/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/AssignLanguage/AssignLanguageSubScreen.cs b/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/AssignLanguage/AssignLanguageSubScreen.cs index e552ae248..2e33c232c 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/AssignLanguage/AssignLanguageSubScreen.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/AssignLanguage/AssignLanguageSubScreen.cs @@ -19,6 +19,14 @@ public class AssignLanguageSubScreen : ImportLyricSubScreenWithTopNavigation public override IconUsage Icon => FontAwesome.Solid.Globe; + [Cached] + protected readonly LyricManager LyricManager; + + public AssignLanguageSubScreen() + { + AddInternal(LyricManager = new LyricManager()); + } + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); @@ -56,7 +64,7 @@ protected void AskForAutoAssignLanguage() { DialogOverlay.Push(new UseLanguageDetectorPopupDialog(ok => { - // todo : call manager to do that. + LyricManager.AutoDetectLyrcLanguage(); })); } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs new file mode 100644 index 000000000..5a63b6620 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs @@ -0,0 +1,45 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Game.Rulesets.Karaoke.Edit.Generator.Languages; +using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Screens.Edit; +using System.Linq; + +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics +{ + public class LyricManager : Component + { + [Resolved] + private EditorBeatmap beatmap { get; set; } + + [Resolved(CanBeNull = true)] + private IEditorChangeHandler changeHandler { get; set; } + + /// + /// Will auto-detect each 's and apply on them. + /// + public void AutoDetectLyrcLanguage() + { + var lyrics = beatmap.HitObjects.OfType().ToList(); + if (!lyrics.Any()) + return; + + // todo : should get the config fron setting. + var config = new LanguageDetectorConfig(); + var detector = new LanguageDetector(config); + + changeHandler?.BeginChange(); + + foreach (var lyric in lyrics) + { + var detectedLanguage = detector.DetectLanguage(lyric); + lyric.Language = detectedLanguage; + } + + changeHandler?.EndChange(); + } + } +} From 5e4fc2c44bbc2b483179bf96f4f94259995efd71 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 6 Dec 2020 15:47:48 +0900 Subject: [PATCH 3/8] implement auto generate time tag. --- .../Edit/TestSceneImportLyric.cs | 2 +- .../GenerateTimeTagSubScreen.cs | 10 ++- .../Edit/Lyrics/Components/LyricControl.cs | 6 +- .../Edit/Lyrics/TimeTagManager.cs | 84 +++++++++++++++++++ .../Utils/TimeTagsUtils.cs | 6 ++ 5 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs diff --git a/osu.Game.Rulesets.Karaoke.Tests/Edit/TestSceneImportLyric.cs b/osu.Game.Rulesets.Karaoke.Tests/Edit/TestSceneImportLyric.cs index 11deda5f6..7a1e81634 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Edit/TestSceneImportLyric.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Edit/TestSceneImportLyric.cs @@ -58,7 +58,7 @@ private void load() [Test] public void TestGoToStep() => Schedule(() => { - var temp = TestResources.GetTestLrcForImport("default"); + var temp = TestResources.GetTestLrcForImport("light"); Child = screen = new TestImportLyricScreen(new FileInfo(temp)); var steps = (ImportLyricStep[])Enum.GetValues(typeof(ImportLyricStep)); diff --git a/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/GenerateTimeTag/GenerateTimeTagSubScreen.cs b/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/GenerateTimeTag/GenerateTimeTagSubScreen.cs index 591fe470d..8d8fa6af8 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/GenerateTimeTag/GenerateTimeTagSubScreen.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/GenerateTimeTag/GenerateTimeTagSubScreen.cs @@ -19,6 +19,14 @@ public class GenerateTimeTagSubScreen : ImportLyricSubScreenWithTopNavigation public override IconUsage Icon => FontAwesome.Solid.Tag; + [Cached] + protected readonly TimeTagManager TimeTagManager; + + public GenerateTimeTagSubScreen() + { + AddInternal(TimeTagManager = new TimeTagManager()); + } + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); @@ -56,7 +64,7 @@ protected void AskForAutoGenerateTimeTag() { DialogOverlay.Push(new UseAutoGenerateTimeTagPopupDialog(ok => { - // todo : call manager to do that. + TimeTagManager.AutoGenerateTimeTag(); })); } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/LyricControl.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/LyricControl.cs index f18c5a540..8387587db 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/LyricControl.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/LyricControl.cs @@ -101,7 +101,11 @@ public override double LifetimeEnd protected void UpdateTimeTags() { timeTagContainer.Clear(); - foreach (var timeTag in TimeTagsBindable.Value) + var timeTags = TimeTagsBindable.Value; + if (timeTags == null) + return; + + foreach (var timeTag in timeTags) { var index = Math.Min(timeTag.Item1.Index, HitObject.Text.Length - 1); var percentage = timeTag.Item1.State == TimeTagIndex.IndexState.Start ? 0 : 1; diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs new file mode 100644 index 000000000..27da340e1 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs @@ -0,0 +1,84 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Game.Rulesets.Karaoke.Edit.Generator.TimeTags.Ja; +using osu.Game.Rulesets.Karaoke.Edit.Generator.TimeTags.Zh; +using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Screens.Edit; +using System; +using System.Linq; + +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics +{ + public class TimeTagManager : Component + { + [Resolved] + private EditorBeatmap beatmap { get; set; } + + [Resolved(CanBeNull = true)] + private IEditorChangeHandler changeHandler { get; set; } + + /// + /// Will auto-detect each 's and apply on them. + /// + public void AutoGenerateTimeTag() + { + var lyrics = beatmap.HitObjects.OfType().ToList(); + if (!lyrics.Any()) + return; + + changeHandler?.BeginChange(); + + var selector = new TimeTagGeneratorSelector(); + + foreach (var lyric in lyrics) + { + var detectedLanguage = selector.GenerateTimeTag(lyric); + lyric.TimeTags = detectedLanguage; + } + + changeHandler?.EndChange(); + } + + + public class TimeTagGeneratorSelector + { + private readonly Lazy jaTimeTagGenerator; + private readonly Lazy zhTimeTagGenerator; + + public TimeTagGeneratorSelector() + { + jaTimeTagGenerator = new Lazy(() => + { + // todo : get config from setting. + var config = new JaTimeTagGeneratorConfig(); + return new JaTimeTagGenerator(config); + }); + zhTimeTagGenerator = new Lazy(() => + { + // todo : get config from setting. + var config = new ZhTimeTagGeneratorConfig(); + return new ZhTimeTagGenerator(config); + }); + } + + public Tuple[] GenerateTimeTag(Lyric lyric) + { + // lazy to generate language detector and apply it's setting + switch (lyric.Language.LCID) + { + case 17: + case 1041: + return jaTimeTagGenerator.Value.CreateTimeTags(lyric); + case 1028: + return zhTimeTagGenerator.Value.CreateTimeTags(lyric); + default: + return null; + } + } + } + } +} diff --git a/osu.Game.Rulesets.Karaoke/Utils/TimeTagsUtils.cs b/osu.Game.Rulesets.Karaoke/Utils/TimeTagsUtils.cs index e398db2c0..e045ecc35 100644 --- a/osu.Game.Rulesets.Karaoke/Utils/TimeTagsUtils.cs +++ b/osu.Game.Rulesets.Karaoke/Utils/TimeTagsUtils.cs @@ -112,6 +112,9 @@ public static class TimeTagsUtils /// Fixed time tags. public static Tuple[] FixInvalid(Tuple[] timeTags, GroupCheck other = GroupCheck.Asc, SelfCheck self = SelfCheck.BasedOnStart) { + if (timeTags == null || timeTags.Length == 0) + return timeTags; + var sortedTimeTags = Sort(timeTags); var groupedTimeTags = sortedTimeTags.GroupBy(x => x.Item1.Index); @@ -184,6 +187,9 @@ public static class TimeTagsUtils public static IReadOnlyDictionary ToDictionary(Tuple[] timeTags, bool applyFix = true, GroupCheck other = GroupCheck.Asc, SelfCheck self = SelfCheck.BasedOnStart) { + if (timeTags == null) + return new Dictionary(); + // sorted value var sortedTimeTags = applyFix ? FixInvalid(timeTags, other, self) : Sort(timeTags); From 99804e5541137160ddf38a4e3aeed07b31a8a04c Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 6 Dec 2020 15:52:45 +0900 Subject: [PATCH 4/8] Implement remove and add new import lyric. --- .../Edit/ImportLyric/ImportLyricManager.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/ImportLyricManager.cs b/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/ImportLyricManager.cs index ac1c90a27..943d7101c 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/ImportLyricManager.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/ImportLyricManager.cs @@ -8,6 +8,7 @@ using osu.Framework.Graphics; using osu.Game.Beatmaps; using osu.Game.Rulesets.Karaoke.Beatmaps.Formats; +using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Screens.Edit; namespace osu.Game.Rulesets.Karaoke.Edit.ImportLyric @@ -52,10 +53,12 @@ public void ImportLrcFile(FileInfo info) var decoder = new LrcDecoder(); var lrcBeatmap = decoder.Decode(reader); - // todo : remove all notes and lyric - // or just clear all beatmap because not really sure is singer should be removed also? + // remove all hit objects (note and lyric) from beatmap + editorBeatmap.Clear(); // then re-add the lyric. + var lyrics = lrcBeatmap.HitObjects.OfType(); + editorBeatmap.AddRange(lyrics); } } } From 3cff1a7404a28d9469b082c77f1faa3acfe895b0 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 6 Dec 2020 16:03:39 +0900 Subject: [PATCH 5/8] Add ruby/romaji generator and auto generate ruby in import screen. --- .../AssignLanguage/AssignLanguageSubScreen.cs | 3 +- .../GenerateRuby/GenerateRubySubScreen.cs | 12 +++- .../GenerateTimeTagSubScreen.cs | 3 +- .../Edit/Lyrics/LyricManager.cs | 2 +- .../Edit/Lyrics/TimeTagManager.cs | 8 +-- .../Edit/RubyRomaji/RubyRomajiManager.cs | 72 +++++++++++++++++++ 6 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 osu.Game.Rulesets.Karaoke/Edit/RubyRomaji/RubyRomajiManager.cs diff --git a/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/AssignLanguage/AssignLanguageSubScreen.cs b/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/AssignLanguage/AssignLanguageSubScreen.cs index 2e33c232c..8b5ce3522 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/AssignLanguage/AssignLanguageSubScreen.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/AssignLanguage/AssignLanguageSubScreen.cs @@ -64,7 +64,8 @@ protected void AskForAutoAssignLanguage() { DialogOverlay.Push(new UseLanguageDetectorPopupDialog(ok => { - LyricManager.AutoDetectLyrcLanguage(); + if (ok) + LyricManager.AutoDetectLyricLanguage(); })); } diff --git a/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/GenerateRuby/GenerateRubySubScreen.cs b/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/GenerateRuby/GenerateRubySubScreen.cs index f0a84d24c..c7247f401 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/GenerateRuby/GenerateRubySubScreen.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/GenerateRuby/GenerateRubySubScreen.cs @@ -1,6 +1,7 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. +using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Game.Rulesets.Karaoke.Edit.RubyRomaji; @@ -17,6 +18,14 @@ public class GenerateRubySubScreen : ImportLyricSubScreenWithTopNavigation public override IconUsage Icon => FontAwesome.Solid.Gem; + [Cached] + protected readonly RubyRomajiManager RubyRomajiManager; + + public GenerateRubySubScreen() + { + AddInternal(RubyRomajiManager = new RubyRomajiManager()); + } + protected override TopNavigation CreateNavigation() => new GenerateRubyNavigation(this); @@ -42,7 +51,8 @@ protected void AskForAutoGenerateRuby() { DialogOverlay.Push(new UseAutoGenerateRubyPopupDialog(ok => { - // todo : call manager to do that. + if (ok) + RubyRomajiManager.AutoGenerateRubyTags(); })); } diff --git a/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/GenerateTimeTag/GenerateTimeTagSubScreen.cs b/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/GenerateTimeTag/GenerateTimeTagSubScreen.cs index 8d8fa6af8..fdadbabec 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/GenerateTimeTag/GenerateTimeTagSubScreen.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ImportLyric/GenerateTimeTag/GenerateTimeTagSubScreen.cs @@ -64,7 +64,8 @@ protected void AskForAutoGenerateTimeTag() { DialogOverlay.Push(new UseAutoGenerateTimeTagPopupDialog(ok => { - TimeTagManager.AutoGenerateTimeTag(); + if (ok) + TimeTagManager.AutoGenerateTimeTags(); })); } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs index 5a63b6620..2757af619 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs @@ -21,7 +21,7 @@ public class LyricManager : Component /// /// Will auto-detect each 's and apply on them. /// - public void AutoDetectLyrcLanguage() + public void AutoDetectLyricLanguage() { var lyrics = beatmap.HitObjects.OfType().ToList(); if (!lyrics.Any()) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs index 27da340e1..d0e73e746 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs @@ -24,7 +24,7 @@ public class TimeTagManager : Component /// /// Will auto-detect each 's and apply on them. /// - public void AutoGenerateTimeTag() + public void AutoGenerateTimeTags() { var lyrics = beatmap.HitObjects.OfType().ToList(); if (!lyrics.Any()) @@ -36,8 +36,8 @@ public void AutoGenerateTimeTag() foreach (var lyric in lyrics) { - var detectedLanguage = selector.GenerateTimeTag(lyric); - lyric.TimeTags = detectedLanguage; + var timeTags = selector.GenerateTimeTags(lyric); + lyric.TimeTags = timeTags; } changeHandler?.EndChange(); @@ -65,7 +65,7 @@ public TimeTagGeneratorSelector() }); } - public Tuple[] GenerateTimeTag(Lyric lyric) + public Tuple[] GenerateTimeTags(Lyric lyric) { // lazy to generate language detector and apply it's setting switch (lyric.Language.LCID) diff --git a/osu.Game.Rulesets.Karaoke/Edit/RubyRomaji/RubyRomajiManager.cs b/osu.Game.Rulesets.Karaoke/Edit/RubyRomaji/RubyRomajiManager.cs new file mode 100644 index 000000000..22628ad84 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/RubyRomaji/RubyRomajiManager.cs @@ -0,0 +1,72 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Game.Rulesets.Karaoke.Edit.Generator.RubyTags.Ja; +using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Screens.Edit; +using System; +using System.Linq; + +namespace osu.Game.Rulesets.Karaoke.Edit.RubyRomaji +{ + public class RubyRomajiManager : Component + { + [Resolved] + private EditorBeatmap beatmap { get; set; } + + [Resolved(CanBeNull = true)] + private IEditorChangeHandler changeHandler { get; set; } + + /// + /// Will auto-detect each 's and apply on them. + /// + public void AutoGenerateRubyTags() + { + var lyrics = beatmap.HitObjects.OfType().ToList(); + if (!lyrics.Any()) + return; + + changeHandler?.BeginChange(); + + var selector = new RubyTagGeneratorSelector(); + + foreach (var lyric in lyrics) + { + var rubyTags = selector.GenerateRubyTags(lyric); + lyric.RubyTags = rubyTags; + } + + changeHandler?.EndChange(); + } + + public class RubyTagGeneratorSelector + { + private readonly Lazy jaRubyTagGenerator; + + public RubyTagGeneratorSelector() + { + jaRubyTagGenerator = new Lazy(() => + { + // todo : get config from setting. + var config = new JaRubyTagGeneratorConfig(); + return new JaRubyTagGenerator(config); + }); + } + + public RubyTag[] GenerateRubyTags(Lyric lyric) + { + // lazy to generate language detector and apply it's setting + switch (lyric.Language.LCID) + { + case 17: + case 1041: + return jaRubyTagGenerator.Value.CreateRubyTags(lyric); + default: + return null; + } + } + } + } +} From cace49c9ceedb0260f52086d31c137baedcb0a93 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 6 Dec 2020 16:23:57 +0900 Subject: [PATCH 6/8] Post clean-up. --- .../Edit/Generator/TimeTags/Ja/JaTimeTagGenerator.cs | 1 + .../Edit/Generator/TimeTags/Zh/ZhTimeTagGenerator.cs | 1 + .../Edit/Lyrics/Components/Badges/LanguageInfoBadge.cs | 5 +---- .../Edit/Lyrics/Components/LyricControl.cs | 2 +- .../Edit/Lyrics/DrawableLyricEditListItem.cs | 2 +- osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs | 2 +- osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs | 3 ++- .../Edit/RubyRomaji/RubyRomajiManager.cs | 1 + osu.Game.Rulesets.Karaoke/Edit/Style/NoteStylePreview.cs | 2 +- .../Edit/Translate/TranslateEditSection.cs | 1 - 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/TimeTags/Ja/JaTimeTagGenerator.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/TimeTags/Ja/JaTimeTagGenerator.cs index c9735aa78..9d2e8dab0 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Generator/TimeTags/Ja/JaTimeTagGenerator.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/TimeTags/Ja/JaTimeTagGenerator.cs @@ -139,6 +139,7 @@ protected override void TimeTagLogic(Lyric lyric, List> timeTags) { var text = lyric.Text; + for (var i = 1; i < text.Length; i++) { if (CharUtils.IsChinese(text[i])) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/LanguageInfoBadge.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/LanguageInfoBadge.cs index 1cbb890ac..ef98df15c 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/LanguageInfoBadge.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/Badges/LanguageInfoBadge.cs @@ -16,10 +16,7 @@ public LanguageInfoBadge(Lyric lyric) { var language = value.NewValue; - if (language == null) - BadgeText = "None"; - else - BadgeText = language.DisplayName; + BadgeText = language == null ? "None" : language.DisplayName; }, true); } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/LyricControl.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/LyricControl.cs index 8387587db..81bdc5034 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/LyricControl.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Components/LyricControl.cs @@ -72,7 +72,7 @@ protected override void ApplyFont(KaraokeFont font) return; // todo : need to delay until karaoke text has been calculated. - ScheduleAfterChildren(() => UpdateTimeTags()); + ScheduleAfterChildren(UpdateTimeTags); } protected override void ApplyLayout(KaraokeLayout layout) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs index 055f88b12..a02a0c3a6 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/DrawableLyricEditListItem.cs @@ -108,7 +108,7 @@ protected override Drawable CreateContent() // in larger size should use real icon. new LanguageInfoBadge(Model) { - Margin = new MarginPadding{ Right = 5 } + Margin = new MarginPadding { Right = 5 } } } }, diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs index 2757af619..4645a6d97 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricManager.cs @@ -27,7 +27,7 @@ public void AutoDetectLyricLanguage() if (!lyrics.Any()) return; - // todo : should get the config fron setting. + // todo : should get the config from setting. var config = new LanguageDetectorConfig(); var detector = new LanguageDetector(config); diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs index d0e73e746..5a016325c 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/TimeTagManager.cs @@ -43,7 +43,6 @@ public void AutoGenerateTimeTags() changeHandler?.EndChange(); } - public class TimeTagGeneratorSelector { private readonly Lazy jaTimeTagGenerator; @@ -73,8 +72,10 @@ public TimeTagGeneratorSelector() case 17: case 1041: return jaTimeTagGenerator.Value.CreateTimeTags(lyric); + case 1028: return zhTimeTagGenerator.Value.CreateTimeTags(lyric); + default: return null; } diff --git a/osu.Game.Rulesets.Karaoke/Edit/RubyRomaji/RubyRomajiManager.cs b/osu.Game.Rulesets.Karaoke/Edit/RubyRomaji/RubyRomajiManager.cs index 22628ad84..fd83ca9dc 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/RubyRomaji/RubyRomajiManager.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/RubyRomaji/RubyRomajiManager.cs @@ -63,6 +63,7 @@ public RubyTag[] GenerateRubyTags(Lyric lyric) case 17: case 1041: return jaRubyTagGenerator.Value.CreateRubyTags(lyric); + default: return null; } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Style/NoteStylePreview.cs b/osu.Game.Rulesets.Karaoke/Edit/Style/NoteStylePreview.cs index c939e63bb..3b3733142 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Style/NoteStylePreview.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Style/NoteStylePreview.cs @@ -71,7 +71,7 @@ public class PreviewScrollingInfo : IScrollingInfo public IBindable TimeRange { get; } = new BindableDouble(); - public IScrollAlgorithm Algorithm { get; set; } = new ZeroScrollAlgorithm(); + public IScrollAlgorithm Algorithm { get; } = new ZeroScrollAlgorithm(); private class ZeroScrollAlgorithm : IScrollAlgorithm { diff --git a/osu.Game.Rulesets.Karaoke/Edit/Translate/TranslateEditSection.cs b/osu.Game.Rulesets.Karaoke/Edit/Translate/TranslateEditSection.cs index f1755f43b..af34356c5 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Translate/TranslateEditSection.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Translate/TranslateEditSection.cs @@ -1,7 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; From 6bec1c034c808d061665d2332396d148d317deaa Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 6 Dec 2020 16:31:24 +0900 Subject: [PATCH 7/8] Add missing resource. Oops. --- .../Resources/Testing/Lrc/light.lrc | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 osu.Game.Rulesets.Karaoke.Tests/Resources/Testing/Lrc/light.lrc diff --git a/osu.Game.Rulesets.Karaoke.Tests/Resources/Testing/Lrc/light.lrc b/osu.Game.Rulesets.Karaoke.Tests/Resources/Testing/Lrc/light.lrc new file mode 100644 index 000000000..41d51fe78 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke.Tests/Resources/Testing/Lrc/light.lrc @@ -0,0 +1,34 @@ +枯れた世界に輝く 名もない永遠の華 +強く生きていけるよう 私を変えていく + +あぁ、わかっていたの 本当は +光なんて求めちゃいけないってこと + +あぁ、それでもきっと人は +輝く未来なんてものを求めてさまよう + +女神なんて 信じてるわけじゃない +未来をこの 手で切り開く勇気が 強さがほしい +あなたを守りたい + +枯れた世界に輝く 名もない永遠の華 +強く生きていけるよう 私を変えていく + +あぁ、例えこの世が暗く +絶望に飲み込まれても 私は大丈夫 + +あなたがいればそこは +灰色(いろ)(いろ)の景色(いろ)(いろ)さえ色づき始める + +華もきっと 咲き誇るときを終え +いつかきっと また蕾をつけるだろう  +終わることない +生命(いのち)が続くまでは + +あなたの手を離さない 瞳に誓う 永遠の恋 +強く儚い思いを 守り続けていたい + +枯れた世界に輝く 名もない永遠の華 +強く生き抜きけるように 私を変えていく +あなたの手を離さない 瞳に誓う 永遠の恋 +強く儚い思いを 守り続けていたい \ No newline at end of file From 4268585b7dd69da4c01ddbd52ff9a758104f7b87 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 6 Dec 2020 16:42:00 +0900 Subject: [PATCH 8/8] Should remove checking if not have time tag. --- osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LrcEncoder.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LrcEncoder.cs b/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LrcEncoder.cs index 9ee473c2d..44d7b65e1 100644 --- a/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LrcEncoder.cs +++ b/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LrcEncoder.cs @@ -35,9 +35,6 @@ private LyricLine encodeLyric(Objects.Lyric lyric) => private IEnumerable convertTimeTag(string text, IReadOnlyDictionary tags) { - if (tags == null || !tags.Any()) - throw new ArgumentNullException($"{nameof(tags)} cannot be null."); - var totalTags = text.Length * 2 + 2; for (int i = 0; i < totalTags; i++)