Skip to content

Commit

Permalink
Merge pull request #1136 from maiko3tattun/0512_FixMargeExpression
Browse files Browse the repository at this point in the history
[Important] Fix unable to open old projects that contains P flag
  • Loading branch information
stakira authored Jun 9, 2024
2 parents 4c2e770 + 0bb4a9b commit 16b0158
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions OpenUtau.Core/Ustx/UExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,7 @@ public UExpression Clone() {
value = value,
};
}

public override string ToString() => $"{abbr.ToUpper()}: {value}";
}
}
10 changes: 7 additions & 3 deletions OpenUtau.Core/Ustx/UProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,27 @@ public void MargeExpression(string oldAbbr, string newAbbr) {
parts.Where(p => p is UVoicePart)
.OfType<UVoicePart>()
.ForEach(p => p.notes.ForEach(n => ConvertNoteExp(n, tracks[p.trackNo])));
} else if (voiceParts != null &&voiceParts.Count > 0) {
} else if (voiceParts != null && voiceParts.Count > 0) {
voiceParts.ForEach(p => p.notes.ForEach(n => ConvertNoteExp(n, tracks[p.trackNo])));
}
expressions.Remove(oldAbbr);

void ConvertNoteExp(UNote note, UTrack track) {
if (note.phonemeExpressions.Any(e => e.abbr == oldAbbr)) {
note.phonemeExpressions.ForEach(oldExp => {
var toRemove = new List<UExpression>();
note.phonemeExpressions.Where(e => e.abbr == oldAbbr).ForEach(oldExp => {
if (!note.phonemeExpressions.Any(newExp => newExp.abbr == newAbbr && newExp.index == oldExp.index)) {
// When there is only old exp, convert it to new exp
oldExp.abbr = newAbbr;
if (track.TryGetExpDescriptor(this, newAbbr, out var descriptor)) {
oldExp.descriptor = descriptor;
}
} else {
note.phonemeExpressions.Remove(oldExp);
// When both old and new exp exist, remove the old one
toRemove.Add(oldExp);
}
});
toRemove.ForEach(exp => note.phonemeExpressions.Remove(exp));
}
}
}
Expand Down

0 comments on commit 16b0158

Please sign in to comment.