Skip to content

Commit

Permalink
Merge pull request #1474 from andy840119/implement-reference-lyric-se…
Browse files Browse the repository at this point in the history
…ction

Implement reference lyric section and auto-generate feature.
  • Loading branch information
andy840119 authored Jul 25, 2022
2 parents 31d13e2 + 26857d4 commit a87d832
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using osu.Game.Configuration;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Language;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Notes;
using osu.Game.Rulesets.Karaoke.Edit.Generator.ReferenceLyric;
using osu.Game.Rulesets.Karaoke.Edit.Generator.RomajiTags.Ja;
using osu.Game.Rulesets.Karaoke.Edit.Generator.RubyTags.Ja;
using osu.Game.Rulesets.Karaoke.Edit.Generator.TimeTags.Ja;
Expand All @@ -18,6 +19,9 @@ protected override void InitialiseDefaults()
{
base.InitialiseDefaults();

// Language detection
SetDefault(KaraokeRulesetEditGeneratorSetting.ReferenceLyricDetectorConfig, CreateDefaultConfig<ReferenceLyricDetectorConfig>());

// Language detection
SetDefault(KaraokeRulesetEditGeneratorSetting.LanguageDetectorConfig, CreateDefaultConfig<LanguageDetectorConfig>());

Expand All @@ -41,12 +45,12 @@ protected override void InitialiseDefaults()

public enum KaraokeRulesetEditGeneratorSetting
{
// Reference lyric detection.
ReferenceLyricDetectorConfig,

// Language detection
LanguageDetectorConfig,

// Layout generator
LayoutGeneratorConfig,

// Note generator
NoteGeneratorConfig,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface ILyricAutoGenerateChangeHandler

public enum LyricAutoGenerateProperty
{
DetectReferenceLyric,

DetectLanguage,

AutoGenerateRubyTags,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Language;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Notes;
using osu.Game.Rulesets.Karaoke.Edit.Generator.ReferenceLyric;
using osu.Game.Rulesets.Karaoke.Edit.Generator.RomajiTags;
using osu.Game.Rulesets.Karaoke.Edit.Generator.RubyTags;
using osu.Game.Rulesets.Karaoke.Edit.Generator.TimeTags;
Expand All @@ -32,6 +33,10 @@ public bool CanGenerate(LyricAutoGenerateProperty autoGenerateProperty)
{
switch (autoGenerateProperty)
{
case LyricAutoGenerateProperty.DetectReferenceLyric:
var referenceLyricDetector = createLyricDetector<Lyric>();
return canDetect(referenceLyricDetector);

case LyricAutoGenerateProperty.DetectLanguage:
var languageDetector = createLyricDetector<CultureInfo>();
return canDetect(languageDetector);
Expand Down Expand Up @@ -67,6 +72,10 @@ public IDictionary<Lyric, LocalisableString> GetNotGeneratableLyrics(LyricAutoGe
{
switch (autoGenerateProperty)
{
case LyricAutoGenerateProperty.DetectReferenceLyric:
var referenceLyricDetector = createLyricDetector<Lyric>();
return getInvalidMessageFromDetector(referenceLyricDetector);

case LyricAutoGenerateProperty.DetectLanguage:
var languageDetector = createLyricDetector<CultureInfo>();
return getInvalidMessageFromDetector(languageDetector);
Expand Down Expand Up @@ -106,6 +115,15 @@ public void AutoGenerate(LyricAutoGenerateProperty autoGenerateProperty)
{
switch (autoGenerateProperty)
{
case LyricAutoGenerateProperty.DetectReferenceLyric:
var referenceLyricDetector = createLyricDetector<Lyric>();
PerformOnSelection(lyric =>
{
var detectedLanguage = referenceLyricDetector.Detect(lyric);
lyric.ReferenceLyric = detectedLanguage;
});
break;

case LyricAutoGenerateProperty.DetectLanguage:
var languageDetector = createLyricDetector<CultureInfo>();
PerformOnSelection(lyric =>
Expand Down Expand Up @@ -161,9 +179,14 @@ private ILyricPropertyDetector<T> createLyricDetector<T>()
{
switch (typeof(T))
{
case Type t when t == typeof(Lyric):
var lyrics = beatmap.HitObjects.OfType<Lyric>().ToArray();
var referenceLyricDetectorConfig = generatorConfigManager.Get<ReferenceLyricDetectorConfig>(KaraokeRulesetEditGeneratorSetting.ReferenceLyricDetectorConfig);
return (ILyricPropertyDetector<T>)new ReferenceLyricDetector(lyrics, referenceLyricDetectorConfig);

case Type t when t == typeof(CultureInfo):
var config = generatorConfigManager.Get<LanguageDetectorConfig>(KaraokeRulesetEditGeneratorSetting.LanguageDetectorConfig);
return (ILyricPropertyDetector<T>)new LanguageDetector(config);
var languageDetectorConfig = generatorConfigManager.Get<LanguageDetectorConfig>(KaraokeRulesetEditGeneratorSetting.LanguageDetectorConfig);
return (ILyricPropertyDetector<T>)new LanguageDetector(languageDetectorConfig);

default:
throw new NotSupportedException();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Karaoke.Edit.Generator.ReferenceLyric;

namespace osu.Game.Rulesets.Karaoke.Edit.Configs.Generator.ReferenceLyric
{
public class GenericSection : GeneratorConfigSection<ReferenceLyricDetectorConfig>
{
private readonly LabelledSwitchButton ignorePrefixAndPostfixSymbol;

protected override string Title => "Generic";

public GenericSection(Bindable<ReferenceLyricDetectorConfig> current)
: base(current)
{
Children = new Drawable[]
{
ignorePrefixAndPostfixSymbol = new LabelledSwitchButton
{
Label = "Ruby as Katakana",
Description = "Ruby as Katakana.",
},
};

RegisterConfig(ignorePrefixAndPostfixSymbol.Current, nameof(ReferenceLyricDetectorConfig.IgnorePrefixAndPostfixSymbol));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using osu.Framework.Bindables;
using osu.Game.Overlays;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.Edit.Generator.ReferenceLyric;

namespace osu.Game.Rulesets.Karaoke.Edit.Configs.Generator.ReferenceLyric
{
public class ReferenceLyricGeneratorConfigDialog : GeneratorConfigDialog<ReferenceLyricDetectorConfig>
{
protected override KaraokeRulesetEditGeneratorSetting Config => KaraokeRulesetEditGeneratorSetting.NoteGeneratorConfig;

protected override OverlayColourScheme OverlayColourScheme => OverlayColourScheme.Green;

protected override string Title => "Reference lyric config";

protected override string Description => "Change config for reference lyric detector.";

protected override GeneratorConfigSection[] CreateConfigSection(Bindable<ReferenceLyricDetectorConfig> current)
{
return new GeneratorConfigSection[]
{
new GenericSection(current),
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using osu.Framework.Bindables;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.Edit.Generator.ReferenceLyric;

namespace osu.Game.Rulesets.Karaoke.Edit.Configs.Generator.ReferenceLyric
{
public class ReferenceLyricDetectorConfigPopover : GeneratorConfigPopover<ReferenceLyricDetectorConfig>
{
protected override KaraokeRulesetEditGeneratorSetting Config => KaraokeRulesetEditGeneratorSetting.ReferenceLyricDetectorConfig;

protected override GeneratorConfigSection[] CreateConfigSection(Bindable<ReferenceLyricDetectorConfig> current)
{
return new GeneratorConfigSection[]
{
new GenericSection(current),
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Game.Rulesets.Karaoke.Edit.Checks.Configs;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Types;

namespace osu.Game.Rulesets.Karaoke.Edit.Generator.ReferenceLyric
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Reference
{
public class ReferenceExtend : EditExtend
{
public override ExtendDirection Direction => ExtendDirection.Right;

public override float ExtendWidth => 300;

public ReferenceExtend()
{
Children = new[]
{
new ReferenceLyricAutoGenerateSection(),
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Graphics.UserInterface;
using osu.Framework.Localisation;
using osu.Game.Rulesets.Karaoke.Edit.Components.Containers;
using osu.Game.Rulesets.Karaoke.Edit.Configs.Generator.ReferenceLyric;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Components;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Reference
{
public class ReferenceLyricAutoGenerateSection : Section
{
protected override LocalisableString Title => "Auto generate";

public ReferenceLyricAutoGenerateSection()
{
Children = new[]
{
new ReferenceLyricAutoGenerateSubsection()
};
}

private class ReferenceLyricAutoGenerateSubsection : AutoGenerateSubsection
{
public ReferenceLyricAutoGenerateSubsection()
: base(LyricAutoGenerateProperty.DetectReferenceLyric)
{
}

protected override InvalidLyricAlertTextContainer CreateInvalidLyricAlertTextContainer()
=> new InvalidLyricLanguageAlertTextContainer();

protected override ConfigButton CreateConfigButton()
=> new ReferenceLyricAutoGenerateConfigButton();

protected class InvalidLyricLanguageAlertTextContainer : InvalidLyricAlertTextContainer
{
private const string language_mode = "LANGUAGE_MODE";

public InvalidLyricLanguageAlertTextContainer()
{
SwitchToEditorMode(language_mode, "edit language mode", LyricEditorMode.Language);
Text = $"Seems some lyric missing language, go to [{language_mode}] to fill the language.";
}
}

protected class ReferenceLyricAutoGenerateConfigButton : ConfigButton
{
public override Popover GetPopover()
=> new ReferenceLyricDetectorConfigPopover();
}
}
}
}
2 changes: 2 additions & 0 deletions osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Languages;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Notes;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Reference;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.RubyRomaji;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Singers;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Texting;
Expand Down Expand Up @@ -230,6 +231,7 @@ EditExtend getExtendArea() =>
Mode switch
{
LyricEditorMode.Texting => new TextingExtend(),
LyricEditorMode.Reference => new ReferenceExtend(),
LyricEditorMode.Language => new LanguageExtend(),
LyricEditorMode.EditRuby => new RubyTagExtend(),
LyricEditorMode.EditRomaji => new RomajiTagExtend(),
Expand Down

0 comments on commit a87d832

Please sign in to comment.