Skip to content

Commit b4ca30c

Browse files
authored
Merge pull request #576 from Tuupertunut/fix/extra-end-of-phrase
Fix extra end of phrase after the last note
2 parents 2e4f8b1 + a41b62f commit b4ca30c

2 files changed

Lines changed: 28 additions & 16 deletions

File tree

UltraStar Play/Assets/Editor/Tests/UltraStarSongFormatTest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ public void ShouldNotAddPhraseEndBeatIfSameAsMaxBeat()
3838
Assert.IsTrue(txt.Contains("-"));
3939
}
4040

41+
[Test]
42+
public void ShouldNotAddLastEndOfPhrase()
43+
{
44+
SongMeta songMeta = UltraStarSongParser.ParseFile($"{folderPath}/Duet.txt").SongMeta;
45+
string txt = UltraStarFormatWriter.ToUltraStarSongFormat(songMeta).Replace("\r\n", "\n");
46+
Assert.IsTrue(txt.Contains("First Vocals!\nP2"));
47+
Assert.IsTrue(txt.Contains("Second Vocals!\nE"));
48+
}
49+
4150
[Test]
4251
public void ShouldNotContainP1InSoloSong()
4352
{

UltraStar Play/Packages/playshared/Runtime/Songs/UltraStarSongFormat/UltraStarSongWriter/UltraStarSongWriter.cs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,37 +57,40 @@ private static void AppendVoice(StringBuilder sb, Voice voice, bool appendVoiceI
5757
// P1 is optional when only having one voice
5858
sb.AppendLine(voice.Id.ToString());
5959
}
60-
List<Sentence> sortedSentences = new(voice.Sentences);
61-
sortedSentences.Sort(Sentence.comparerByStartBeat);
62-
foreach (Sentence sentence in sortedSentences)
60+
List<Sentence> sortedSentences = SongMetaUtils.GetSortedSentences(voice);
61+
for (int i = 0; i < sortedSentences.Count; i++)
6362
{
64-
AppendSentence(sb, sentence);
63+
Sentence sentence = sortedSentences[i];
64+
// A linebreak should not be appended after the last sentence.
65+
bool appendLinebreak = i < sortedSentences.Count - 1;
66+
AppendSentence(sb, sentence, appendLinebreak);
6567
}
6668
}
6769

68-
private static void AppendSentence(StringBuilder sb, Sentence sentence)
70+
private static void AppendSentence(StringBuilder sb, Sentence sentence, bool appendLinebreak)
6971
{
7072
bool isEmpty = sentence.Notes.Count == 0;
7173
if (isEmpty)
7274
{
7375
return;
7476
}
7577

76-
List<Note> sortedNotes = new(sentence.Notes);
77-
sortedNotes.Sort(Note.comparerByStartBeat);
78+
List<Note> sortedNotes = SongMetaUtils.GetSortedNotes(sentence);
7879
foreach (Note note in sortedNotes)
7980
{
8081
AppendNote(sb, note);
8182
}
82-
83-
// TODO: Linebreak timing could be optional but is required by some other tools, https://github.com/UltraStar-Deluxe/format/issues/64
84-
sb.AppendLine($"- {sentence.ExtendedMaxBeat}");
85-
// if (sentence.ExtendedMaxBeat > sentence.MaxBeat)
86-
// {
87-
// sb.AppendLine($"- {sentence.ExtendedMaxBeat}");
88-
// } else {
89-
// sb.AppendLine($"-");
90-
// }
83+
if (appendLinebreak)
84+
{
85+
// TODO: Linebreak timing could be optional but is required by some other tools, https://github.com/UltraStar-Deluxe/format/issues/64
86+
sb.AppendLine($"- {sentence.ExtendedMaxBeat}");
87+
// if (sentence.ExtendedMaxBeat > sentence.MaxBeat)
88+
// {
89+
// sb.AppendLine($"- {sentence.ExtendedMaxBeat}");
90+
// } else {
91+
// sb.AppendLine($"-");
92+
// }
93+
}
9194
}
9295

9396
private static bool IsNotEmpty(Voice voice)

0 commit comments

Comments
 (0)