Skip to content
Merged
Changes from 2 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,37 +57,42 @@ private static void AppendVoice(StringBuilder sb, Voice voice, bool appendVoiceI
// P1 is optional when only having one voice
sb.AppendLine(voice.Id.ToString());
}
List<Sentence> sortedSentences = new(voice.Sentences);
sortedSentences.Sort(Sentence.comparerByStartBeat);
foreach (Sentence sentence in sortedSentences)
List<Sentence> sortedSentences = SongMetaUtils.GetSortedSentences(voice);
// Process the last sentence separately. A linebreak should not be appended after the last sentence.
foreach (Sentence sentence in sortedSentences.SkipLast(1))
{
AppendSentence(sb, sentence);
AppendSentence(sb, sentence, true);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer setting the flag based on "is this the last sentence".
Consider to iterate by index, then check if index matches (sentences length - 1).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean something like

for all sentences
{
    AppendSentence(... , (i == last))
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored that loop to check index.

}
if (sortedSentences.Count > 0)
{
AppendSentence(sb, sortedSentences.Last(), false);
}
}

private static void AppendSentence(StringBuilder sb, Sentence sentence)
private static void AppendSentence(StringBuilder sb, Sentence sentence, bool appendLinebreak)
{
bool isEmpty = sentence.Notes.Count == 0;
if (isEmpty)
{
return;
}

List<Note> sortedNotes = new(sentence.Notes);
sortedNotes.Sort(Note.comparerByStartBeat);
List<Note> sortedNotes = SongMetaUtils.GetSortedNotes(sentence);
foreach (Note note in sortedNotes)
{
AppendNote(sb, note);
}

// TODO: Linebreak timing could be optional but is required by some other tools, https://github.com/UltraStar-Deluxe/format/issues/64
sb.AppendLine($"- {sentence.ExtendedMaxBeat}");
// if (sentence.ExtendedMaxBeat > sentence.MaxBeat)
// {
// sb.AppendLine($"- {sentence.ExtendedMaxBeat}");
// } else {
// sb.AppendLine($"-");
// }
if (appendLinebreak)
{
// TODO: Linebreak timing could be optional but is required by some other tools, https://github.com/UltraStar-Deluxe/format/issues/64
sb.AppendLine($"- {sentence.ExtendedMaxBeat}");
// if (sentence.ExtendedMaxBeat > sentence.MaxBeat)
// {
// sb.AppendLine($"- {sentence.ExtendedMaxBeat}");
// } else {
// sb.AppendLine($"-");
// }
}
}

private static bool IsNotEmpty(Voice voice)
Expand Down
Loading