diff --git a/osu.Game.Rulesets.Karaoke.Tests/Utils/NoteUtilsTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Utils/NoteUtilsTest.cs index e3af176b0..cdd228694 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Utils/NoteUtilsTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Utils/NoteUtilsTest.cs @@ -68,11 +68,11 @@ public void TestSeparateNoteTime(double[] time, double percentage, double[] firs } [Test] - public void TestSeparateLyricOtherPtoperty() + public void TestSeparateNoteOtherProperty() { + const double percentage = 0.3; var lyric = new Lyric(); - const double percentage = 0.3; var note = new Note { StartTime = 1000, @@ -80,7 +80,7 @@ public void TestSeparateLyricOtherPtoperty() StartIndex = 1, EndIndex = 2, Text = "ka", - Singers = new int[] { 0 }, + Singers = new[] { 0 }, Display = false, Tone = new Tone(-1, true), ParentLyric = lyric @@ -112,5 +112,38 @@ static void testRemainProperty(Note expect, Note actual) Assert.AreEqual(expect.ParentLyric, actual.ParentLyric); } } + + [TestCase(new double[] { 1000, 1000 }, new double[] { 2000, 4000 }, new double[] { 1000, 5000 })] + [TestCase(new double[] { 1000, 2500 }, new double[] { 3500, 2500 }, new double[] { 1000, 5000 })] + [TestCase(new double[] { 1000, 0 }, new double[] { 1000, 0 }, new double[] { 1000, 0 })] // it's ok to combine if duration is 0. + public void TestCombineNoteTime(double[] firstTime, double[] secondTime, double[] actualTime) + { + const int start_index = 3; + const int end_index = 5; + + var lyric = new Lyric(); + + var firstNote = new Note + { + StartIndex = start_index, + EndIndex = end_index, + ParentLyric = lyric, + StartTime = firstTime[0], + Duration = firstTime[1], + }; + + var secondNote = new Note + { + StartIndex = start_index, + EndIndex = end_index, + ParentLyric = lyric, + StartTime = secondTime[0], + Duration = secondTime[1], + }; + + var combineNote = NoteUtils.CombineNote(firstNote, secondNote); + Assert.AreEqual(combineNote.StartTime, actualTime[0]); + Assert.AreEqual(combineNote.Duration, actualTime[1]); + } } } diff --git a/osu.Game.Rulesets.Karaoke/Objects/Note.cs b/osu.Game.Rulesets.Karaoke/Objects/Note.cs index 024ef59b7..1d7bd3fc5 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Note.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Note.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 Newtonsoft.Json; using osu.Framework.Bindables; using osu.Game.Rulesets.Judgements; diff --git a/osu.Game.Rulesets.Karaoke/Utils/NoteUtils.cs b/osu.Game.Rulesets.Karaoke/Utils/NoteUtils.cs index caa3ae59f..f9a7c93e4 100644 --- a/osu.Game.Rulesets.Karaoke/Utils/NoteUtils.cs +++ b/osu.Game.Rulesets.Karaoke/Utils/NoteUtils.cs @@ -8,7 +8,7 @@ namespace osu.Game.Rulesets.Karaoke.Utils { public static class NoteUtils { - public static Note SliceNote(Note note, double startPercentage, double durationPercentage) + public static Note SliceNote(Note note, double startPercentage, double durationPercentage) { if (startPercentage < 0 || startPercentage + durationPercentage > 1) throw new ArgumentOutOfRangeException($"{nameof(Note)} cannot assign split range of start from {startPercentage} and duration {durationPercentage}"); @@ -18,6 +18,7 @@ public static Note SliceNote(Note note, double startPercentage, double duration return copyByTime(note, startTime, duration); } + public static Tuple SplitNote(Note note, double percentage = 0.5) { if (percentage < 0 || percentage > 1) @@ -38,25 +39,37 @@ public static Tuple SplitNote(Note note, double percentage = 0.5) return new Tuple(firstNote, secondNote); } - private static Note copyByTime(Note oritinNote, double startTime, double duration) + public static Note CombineNote(Note firstLyric, Note secondLyric) + { + if (firstLyric.ParentLyric != secondLyric.ParentLyric) + throw new InvalidOperationException($"{nameof(firstLyric.ParentLyric)} and {nameof(secondLyric.ParentLyric)} should be same."); + + if (firstLyric.StartIndex != secondLyric.StartIndex) + throw new InvalidOperationException($"{nameof(firstLyric.StartIndex)} and {nameof(secondLyric.StartIndex)} should be same."); + + if (firstLyric.EndIndex != secondLyric.EndIndex) + throw new InvalidOperationException($"{nameof(firstLyric.EndIndex)} and {nameof(secondLyric.EndIndex)} should be same."); + + var startTime = Math.Min(firstLyric.StartTime, secondLyric.StartTime); + var endTime = Math.Max(firstLyric.EndTime, secondLyric.EndTime); + + return copyByTime(firstLyric, startTime, endTime - startTime); + } + + private static Note copyByTime(Note originNote, double startTime, double duration) { return new Note { StartTime = startTime, Duration = duration, - StartIndex = oritinNote.StartIndex, - EndIndex = oritinNote.EndIndex, - Text = oritinNote.Text, - Singers = oritinNote.Singers?.Clone() as int[], - Display = oritinNote.Display, - Tone = oritinNote.Tone, - ParentLyric = oritinNote.ParentLyric + StartIndex = originNote.StartIndex, + EndIndex = originNote.EndIndex, + Text = originNote.Text, + Singers = originNote.Singers?.Clone() as int[], + Display = originNote.Display, + Tone = originNote.Tone, + ParentLyric = originNote.ParentLyric }; } - - public static Note CombineNote(Note firstLyric, Note secondLyric) - { - return null; - } } }