Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the recording caret algorithm might calculate wrong position if time-tag is not order in the lyric. #1166

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
temp.
andy840119 committed Sep 6, 2022
commit cef77ba43428b634d097386a06dbd0dfde7f93b4
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.CaretPosition;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.CaretPosition.Algorithms;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Tests.Helper;

namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Lyrics.CaretPosition.Algorithms
{
@@ -115,6 +116,18 @@ protected Lyric[] GetLyricsByMethodName(string methodName)
throw new MissingMethodException("Test method is not exist.");

return (Lyric[])theMethod.GetValue(this)!;

/*
var lyrics = theMethod.GetValue(this) as Lyric[] ?? Array.Empty<Lyric>();

foreach (var lyric in lyrics)
{
// because time-tag will not always sort by order, so we need to shuffle the time-tag in the list for testing.
lyric.TimeTags = TestCaseListHelper.Shuffle(lyric.TimeTags);
}

return lyrics;
*/
}
}
}
Original file line number Diff line number Diff line change
@@ -2,10 +2,12 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.Extensions;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Utils;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.CaretPosition.Algorithms
{
@@ -41,7 +43,7 @@ public override bool PositionMovable(TimeTagCaretPosition position)
if (previousLyric == null)
return null;

var timeTags = previousLyric.TimeTags.Where(timeTagMovable).ToArray();
var timeTags = sortTimeTag(previousLyric.TimeTags.Where(timeTagMovable)).ToArray();
var upTimeTag = timeTags.FirstOrDefault(x => x.Index >= currentTimeTag.Index)
?? timeTags.LastOrDefault();

@@ -65,7 +67,7 @@ public override bool PositionMovable(TimeTagCaretPosition position)
if (nextLyric == null)
return null;

var timeTags = nextLyric.TimeTags.Where(timeTagMovable).ToArray();
var timeTags = sortTimeTag(nextLyric.TimeTags.Where(timeTagMovable)).ToArray();
var downTimeTag = timeTags.FirstOrDefault(x => x.Index >= currentTimeTag.Index)
?? timeTags.LastOrDefault();

@@ -77,7 +79,7 @@ public override bool PositionMovable(TimeTagCaretPosition position)

public override TimeTagCaretPosition? MoveLeft(TimeTagCaretPosition currentPosition)
{
var timeTags = Lyrics.SelectMany(x => x.TimeTags).ToArray();
var timeTags = getAllSortedTimeTag();
var previousTimeTag = timeTags.GetPreviousMatch(currentPosition.TimeTag, timeTagMovable);
if (previousTimeTag == null)
return null;
@@ -87,7 +89,7 @@ public override bool PositionMovable(TimeTagCaretPosition position)

public override TimeTagCaretPosition? MoveRight(TimeTagCaretPosition currentPosition)
{
var timeTags = Lyrics.SelectMany(x => x.TimeTags).ToArray();
var timeTags = getAllSortedTimeTag();
var nextTimeTag = timeTags.GetNextMatch(currentPosition.TimeTag, timeTagMovable);
if (nextTimeTag == null)
return null;
@@ -97,7 +99,7 @@ public override bool PositionMovable(TimeTagCaretPosition position)

public override TimeTagCaretPosition? MoveToFirst()
{
var timeTags = Lyrics.SelectMany(x => x.TimeTags).ToArray();
var timeTags = getAllSortedTimeTag();
var firstTimeTag = timeTags.FirstOrDefault(timeTagMovable);
if (firstTimeTag == null)
return null;
@@ -107,7 +109,7 @@ public override bool PositionMovable(TimeTagCaretPosition position)

public override TimeTagCaretPosition? MoveToLast()
{
var timeTags = Lyrics.SelectMany(x => x.TimeTags).ToArray();
var timeTags = getAllSortedTimeTag();
var lastTimeTag = timeTags.LastOrDefault(timeTagMovable);
if (lastTimeTag == null)
return null;
@@ -123,6 +125,12 @@ public override bool PositionMovable(TimeTagCaretPosition position)
return targetTimeTag == null ? null : new TimeTagCaretPosition(lyric, targetTimeTag);
}

private IEnumerable<TimeTag> sortTimeTag(IEnumerable<TimeTag> timeTags)
=> TimeTagsUtils.Sort(timeTags);

private IEnumerable<TimeTag> getAllSortedTimeTag()
=> sortTimeTag(Lyrics.SelectMany(x => x.TimeTags));

private TimeTagCaretPosition? timeTagToPosition(TimeTag timeTag)
{
var lyric = timeTagInLyric(timeTag);