From 44e4acc8cfce990d943fe0094d10e51e5e2516b0 Mon Sep 17 00:00:00 2001 From: Maiko Date: Sun, 12 May 2024 17:40:35 +0900 Subject: [PATCH 1/6] Fix MargeExpression --- OpenUtau.Core/Ustx/UProject.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenUtau.Core/Ustx/UProject.cs b/OpenUtau.Core/Ustx/UProject.cs index 8597b8e19..b1b62a212 100644 --- a/OpenUtau.Core/Ustx/UProject.cs +++ b/OpenUtau.Core/Ustx/UProject.cs @@ -97,7 +97,7 @@ public void MargeExpression(string oldAbbr, string newAbbr) { void ConvertNoteExp(UNote note, UTrack track) { if (note.phonemeExpressions.Any(e => e.abbr == oldAbbr)) { - note.phonemeExpressions.ForEach(oldExp => { + note.phonemeExpressions.Where(e => e.abbr == oldAbbr).ForEach(oldExp => { if (!note.phonemeExpressions.Any(newExp => newExp.abbr == newAbbr && newExp.index == oldExp.index)) { oldExp.abbr = newAbbr; if (track.TryGetExpDescriptor(this, newAbbr, out var descriptor)) { From 1240eceb90ae7ff6d782937a9d2a0987cfc1c460 Mon Sep 17 00:00:00 2001 From: Maiko Date: Sun, 19 May 2024 20:55:24 +0900 Subject: [PATCH 2/6] Fixed two identical flags in one phoneme --- OpenUtau.Core/Ustx/UExpression.cs | 2 ++ OpenUtau.Core/Ustx/UProject.cs | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/OpenUtau.Core/Ustx/UExpression.cs b/OpenUtau.Core/Ustx/UExpression.cs index 8ccf660a1..cf9e294ba 100644 --- a/OpenUtau.Core/Ustx/UExpression.cs +++ b/OpenUtau.Core/Ustx/UExpression.cs @@ -116,5 +116,7 @@ public UExpression Clone() { value = value, }; } + + public override string ToString() => $"{abbr.ToUpper()}: {value}"; } } diff --git a/OpenUtau.Core/Ustx/UProject.cs b/OpenUtau.Core/Ustx/UProject.cs index b1b62a212..c8b57d9b2 100644 --- a/OpenUtau.Core/Ustx/UProject.cs +++ b/OpenUtau.Core/Ustx/UProject.cs @@ -90,23 +90,27 @@ public void MargeExpression(string oldAbbr, string newAbbr) { parts.Where(p => p is UVoicePart) .OfType() .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)) { + var toRemove = new List(); 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)); } } } From b87751c16808c20b759ec36e7907cf7f7288bc7b Mon Sep 17 00:00:00 2001 From: Maiko Date: Sun, 19 May 2024 22:08:33 +0900 Subject: [PATCH 3/6] =?UTF-8?q?[JA=20VCV]=20Support=20*=20=E3=81=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JapaneseVCVPhonemizer.cs | 79 ++++++++++--------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/OpenUtau.Plugin.Builtin/JapaneseVCVPhonemizer.cs b/OpenUtau.Plugin.Builtin/JapaneseVCVPhonemizer.cs index c80019e08..1c1d8773f 100644 --- a/OpenUtau.Plugin.Builtin/JapaneseVCVPhonemizer.cs +++ b/OpenUtau.Plugin.Builtin/JapaneseVCVPhonemizer.cs @@ -40,40 +40,21 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN var note = notes[0]; var currentLyric = note.lyric.Normalize(); //measures for Unicode - // Get color - string color = string.Empty; - int toneShift = 0; - int? alt = null; - if (note.phonemeAttributes != null) { - var attr = note.phonemeAttributes.FirstOrDefault(attr => attr.index == 0); - color = attr.voiceColor; - toneShift = attr.toneShift; - alt = attr.alternate; - } - if (!string.IsNullOrEmpty(note.phoneticHint)) { // If a hint is present, returns the hint. - currentLyric = note.phoneticHint.Normalize(); - if (singer.TryGetMappedOto(currentLyric + alt, note.tone + toneShift, color, out var phAlt)) { - return new Result { - phonemes = new Phoneme[] { - new Phoneme { - phoneme = phAlt.Alias, - } - }, - }; - } else if(singer.TryGetMappedOto(currentLyric, note.tone + toneShift, color, out var ph)){ + if (CheckOtoUntilHit(new string[] { note.phoneticHint.Normalize() }, note, out var ph)) { return new Result { phonemes = new Phoneme[] { - new Phoneme { - phoneme = ph.Alias, - } - }, + new Phoneme { + phoneme = ph.Alias, + } + }, }; } } + // The alias for no previous neighbour note. For example, "- な" for "な". - var phoneme = $"- {currentLyric}"; + string[] tests = new string[] { $"- {currentLyric}" , currentLyric}; if (prevNeighbour != null) { // If there is a previous neighbour note, first get its hint or lyric. var prevLyric = prevNeighbour.Value.lyric.Normalize(); @@ -85,25 +66,51 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN // Look up the trailing vowel. For example "a" for "ゃ". if (vowelLookup.TryGetValue(unicode.LastOrDefault() ?? string.Empty, out var vow)) { // Now replace "- な" initially set to "a な". - phoneme = $"{vow} {currentLyric}"; + tests = new string[] { $"{vow} {currentLyric}", $"* {currentLyric}", currentLyric, $"- {currentLyric}" }; } } - if (singer.TryGetMappedOto(phoneme + alt, note.tone + toneShift, color, out var otoAlt)) { - phoneme = otoAlt.Alias; - } else if (singer.TryGetMappedOto(phoneme, note.tone + toneShift, color, out var oto)) { - phoneme = oto.Alias; - } else if (singer.TryGetMappedOto(currentLyric + alt, note.tone + toneShift, color, out oto)) { - phoneme = oto.Alias; - } else { - phoneme = currentLyric; + if (CheckOtoUntilHit(tests, note, out var oto)) { + return new Result { + phonemes = new Phoneme[] { + new Phoneme { + phoneme = oto.Alias, + } + }, + }; } return new Result { phonemes = new Phoneme[] { new Phoneme { - phoneme = phoneme, + phoneme = currentLyric, } }, }; } + + private bool CheckOtoUntilHit(string[] input, Note note, out UOto oto) { + oto = default; + var attr = note.phonemeAttributes?.FirstOrDefault(attr => attr.index == 0) ?? default; + string color = attr.voiceColor ?? ""; + + var otos = new List(); + foreach (string test in input) { + if (singer.TryGetMappedOto(test + attr.alternate, note.tone + attr.toneShift, color, out var otoAlt)) { + otos.Add(otoAlt); + } else if (singer.TryGetMappedOto(test, note.tone + attr.toneShift, color, out var otoCandidacy)) { + otos.Add(otoCandidacy); + } + } + + if (otos.Count > 0) { + if (otos.Any(oto => (oto.Color ?? string.Empty) == color)) { + oto = otos.Find(oto => (oto.Color ?? string.Empty) == color); + return true; + } else { + oto = otos.First(); + return true; + } + } + return false; + } } } From 4d45f9608ec83c59d7c03ee82e277843530913cb Mon Sep 17 00:00:00 2001 From: Maiko Date: Sun, 19 May 2024 22:10:05 +0900 Subject: [PATCH 4/6] [JA CVVC] remove unnecessary codes --- OpenUtau.Plugin.Builtin/JapaneseCVVCPhonemizer.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/OpenUtau.Plugin.Builtin/JapaneseCVVCPhonemizer.cs b/OpenUtau.Plugin.Builtin/JapaneseCVVCPhonemizer.cs index e833e2e47..6626397ae 100644 --- a/OpenUtau.Plugin.Builtin/JapaneseCVVCPhonemizer.cs +++ b/OpenUtau.Plugin.Builtin/JapaneseCVVCPhonemizer.cs @@ -103,7 +103,6 @@ static JapaneseCVVCPhonemizer() { private bool checkOtoUntilHit(string[] input, Note note, out UOto oto) { oto = default; var attr = note.phonemeAttributes?.FirstOrDefault(attr => attr.index == 0) ?? default; - var attr1 = note.phonemeAttributes?.FirstOrDefault(attr => attr.index == 1) ?? default; var otos = new List(); foreach (string test in input) { @@ -119,11 +118,9 @@ private bool checkOtoUntilHit(string[] input, Note note, out UOto oto) { if (otos.Any(oto => (oto.Color ?? string.Empty) == color)) { oto = otos.Find(oto => (oto.Color ?? string.Empty) == color); return true; - } else if (otos.Any(oto => (color ?? string.Empty) == color)) { - oto = otos.Find(oto => (color ?? string.Empty) == color); - return true; } else { - return false; + oto = otos.First(); + return true; } } return false; From 81baca637e06b9d92787b004301c2c88cea4eba7 Mon Sep 17 00:00:00 2001 From: Maiko Date: Sun, 19 May 2024 22:12:57 +0900 Subject: [PATCH 5/6] =?UTF-8?q?Revert=20"[JA=20VCV]=20Support=20*=20?= =?UTF-8?q?=E3=81=82"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit b87751c16808c20b759ec36e7907cf7f7288bc7b. --- .../JapaneseVCVPhonemizer.cs | 79 +++++++++---------- 1 file changed, 36 insertions(+), 43 deletions(-) diff --git a/OpenUtau.Plugin.Builtin/JapaneseVCVPhonemizer.cs b/OpenUtau.Plugin.Builtin/JapaneseVCVPhonemizer.cs index 1c1d8773f..c80019e08 100644 --- a/OpenUtau.Plugin.Builtin/JapaneseVCVPhonemizer.cs +++ b/OpenUtau.Plugin.Builtin/JapaneseVCVPhonemizer.cs @@ -40,21 +40,40 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN var note = notes[0]; var currentLyric = note.lyric.Normalize(); //measures for Unicode + // Get color + string color = string.Empty; + int toneShift = 0; + int? alt = null; + if (note.phonemeAttributes != null) { + var attr = note.phonemeAttributes.FirstOrDefault(attr => attr.index == 0); + color = attr.voiceColor; + toneShift = attr.toneShift; + alt = attr.alternate; + } + if (!string.IsNullOrEmpty(note.phoneticHint)) { // If a hint is present, returns the hint. - if (CheckOtoUntilHit(new string[] { note.phoneticHint.Normalize() }, note, out var ph)) { + currentLyric = note.phoneticHint.Normalize(); + if (singer.TryGetMappedOto(currentLyric + alt, note.tone + toneShift, color, out var phAlt)) { + return new Result { + phonemes = new Phoneme[] { + new Phoneme { + phoneme = phAlt.Alias, + } + }, + }; + } else if(singer.TryGetMappedOto(currentLyric, note.tone + toneShift, color, out var ph)){ return new Result { phonemes = new Phoneme[] { - new Phoneme { - phoneme = ph.Alias, - } - }, + new Phoneme { + phoneme = ph.Alias, + } + }, }; } } - // The alias for no previous neighbour note. For example, "- な" for "な". - string[] tests = new string[] { $"- {currentLyric}" , currentLyric}; + var phoneme = $"- {currentLyric}"; if (prevNeighbour != null) { // If there is a previous neighbour note, first get its hint or lyric. var prevLyric = prevNeighbour.Value.lyric.Normalize(); @@ -66,51 +85,25 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN // Look up the trailing vowel. For example "a" for "ゃ". if (vowelLookup.TryGetValue(unicode.LastOrDefault() ?? string.Empty, out var vow)) { // Now replace "- な" initially set to "a な". - tests = new string[] { $"{vow} {currentLyric}", $"* {currentLyric}", currentLyric, $"- {currentLyric}" }; + phoneme = $"{vow} {currentLyric}"; } } - if (CheckOtoUntilHit(tests, note, out var oto)) { - return new Result { - phonemes = new Phoneme[] { - new Phoneme { - phoneme = oto.Alias, - } - }, - }; + if (singer.TryGetMappedOto(phoneme + alt, note.tone + toneShift, color, out var otoAlt)) { + phoneme = otoAlt.Alias; + } else if (singer.TryGetMappedOto(phoneme, note.tone + toneShift, color, out var oto)) { + phoneme = oto.Alias; + } else if (singer.TryGetMappedOto(currentLyric + alt, note.tone + toneShift, color, out oto)) { + phoneme = oto.Alias; + } else { + phoneme = currentLyric; } return new Result { phonemes = new Phoneme[] { new Phoneme { - phoneme = currentLyric, + phoneme = phoneme, } }, }; } - - private bool CheckOtoUntilHit(string[] input, Note note, out UOto oto) { - oto = default; - var attr = note.phonemeAttributes?.FirstOrDefault(attr => attr.index == 0) ?? default; - string color = attr.voiceColor ?? ""; - - var otos = new List(); - foreach (string test in input) { - if (singer.TryGetMappedOto(test + attr.alternate, note.tone + attr.toneShift, color, out var otoAlt)) { - otos.Add(otoAlt); - } else if (singer.TryGetMappedOto(test, note.tone + attr.toneShift, color, out var otoCandidacy)) { - otos.Add(otoCandidacy); - } - } - - if (otos.Count > 0) { - if (otos.Any(oto => (oto.Color ?? string.Empty) == color)) { - oto = otos.Find(oto => (oto.Color ?? string.Empty) == color); - return true; - } else { - oto = otos.First(); - return true; - } - } - return false; - } } } From 0bb4a9b8199c94203f534142c61d13002586c99a Mon Sep 17 00:00:00 2001 From: Maiko Date: Sun, 19 May 2024 22:13:04 +0900 Subject: [PATCH 6/6] Revert "[JA CVVC] remove unnecessary codes" This reverts commit 4d45f9608ec83c59d7c03ee82e277843530913cb. --- OpenUtau.Plugin.Builtin/JapaneseCVVCPhonemizer.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/OpenUtau.Plugin.Builtin/JapaneseCVVCPhonemizer.cs b/OpenUtau.Plugin.Builtin/JapaneseCVVCPhonemizer.cs index 6626397ae..e833e2e47 100644 --- a/OpenUtau.Plugin.Builtin/JapaneseCVVCPhonemizer.cs +++ b/OpenUtau.Plugin.Builtin/JapaneseCVVCPhonemizer.cs @@ -103,6 +103,7 @@ static JapaneseCVVCPhonemizer() { private bool checkOtoUntilHit(string[] input, Note note, out UOto oto) { oto = default; var attr = note.phonemeAttributes?.FirstOrDefault(attr => attr.index == 0) ?? default; + var attr1 = note.phonemeAttributes?.FirstOrDefault(attr => attr.index == 1) ?? default; var otos = new List(); foreach (string test in input) { @@ -118,9 +119,11 @@ private bool checkOtoUntilHit(string[] input, Note note, out UOto oto) { if (otos.Any(oto => (oto.Color ?? string.Empty) == color)) { oto = otos.Find(oto => (oto.Color ?? string.Empty) == color); return true; - } else { - oto = otos.First(); + } else if (otos.Any(oto => (color ?? string.Empty) == color)) { + oto = otos.Find(oto => (color ?? string.Empty) == color); return true; + } else { + return false; } } return false;