-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from andy840119/pattern-generator
Fix lyric's start time issue.
- Loading branch information
Showing
5 changed files
with
145 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
osu.Game.Rulesets.Karaoke/Beatmaps/Patterns/IPatternGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Beatmaps.Patterns | ||
{ | ||
public interface IPatternGenerator<T> | ||
{ | ||
void Generate(IEnumerable<T> hitObjects); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
osu.Game.Rulesets.Karaoke/Beatmaps/Patterns/LegacyKaraokeLayoutGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// 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.Extensions.IEnumerableExtensions; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Beatmaps.Patterns | ||
{ | ||
public class LegacyKaraokeLayoutGenerator : IPatternGenerator<LyricLine> | ||
{ | ||
private const int number_of_line = 2; | ||
|
||
public void Generate(IEnumerable<LyricLine> hitObjects) | ||
{ | ||
var lyrics = hitObjects.ToList(); | ||
|
||
// Re-arrange layout | ||
assignLayoutArrangement(lyrics); | ||
|
||
// Re-assign time | ||
assignLyricTime(lyrics); | ||
} | ||
|
||
/// <summary> | ||
/// Calculate arrangement and assign layout number | ||
/// </summary> | ||
/// <example> | ||
/// Lyric | Anchor | LayoutIndex | | ||
/// ---------------------------------------- | ||
/// **** (left) 1 | ||
/// ***** (right) 0 | ||
/// ----------- | ||
/// ******* (left) 3 | ||
/// ***** (left) 4 | ||
/// ***** (left) 5 | ||
/// ----------- | ||
/// ******* (left) 6 | ||
/// ***** (left) 7 | ||
/// ****** (right) 8 | ||
/// **** (right) 9 | ||
/// ----------- | ||
/// ****** (left) 10 | ||
/// ****** (right) 11 | ||
/// ****** (left) 12 | ||
/// ****** (right) 13 | ||
/// </example> | ||
/// <param name="lyrics"></param> | ||
/// <param name="bottomOnly"></param> | ||
private void assignLayoutArrangement(IList<LyricLine> lyrics, bool bottomOnly = false) | ||
{ | ||
// Force change to new line if lyric has long time | ||
const int new_lyric_line_time = 15000; | ||
|
||
// Apply layout index | ||
for (int i = 0; i < lyrics.Count; i++) | ||
{ | ||
var previousCycleLyric = i >= number_of_line ? lyrics[i - number_of_line] : null; | ||
var previousLyric = i >= 1 ? lyrics[i - 1] : null; | ||
var lyric = lyrics[i]; | ||
|
||
// Force change layout | ||
if (lyric.StartTime - previousLyric?.EndTime > new_lyric_line_time) | ||
lyric.LayoutIndex = 1; | ||
// Change to next layout | ||
else if (previousLyric?.LayoutIndex == 1) | ||
lyric.LayoutIndex = 0; | ||
// Change to first layout index | ||
else | ||
lyric.LayoutIndex = 1; | ||
} | ||
} | ||
|
||
private void assignLyricTime(IList<LyricLine> lyrics) | ||
{ | ||
// Reset working time | ||
lyrics.ForEach(h => h.InitialWorkingTime()); | ||
|
||
// Apply start time | ||
for (int i = 0; i < lyrics.Count; i++) | ||
{ | ||
var lastLyricLine = i >= number_of_line ? lyrics[i - number_of_line] : null; | ||
var lyricLine = lyrics[i]; | ||
|
||
if (lastLyricLine != null) | ||
{ | ||
// Adjust start time and end time | ||
var lyricEndTime = lyricLine.EndTime; | ||
lyricLine.StartTime = lastLyricLine.EndTime + 1000; | ||
|
||
// Should re-assign duration here | ||
lyricLine.Duration = lyricEndTime - lyricLine.StartTime; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters