@@ -40,40 +40,21 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN
4040 var note = notes [ 0 ] ;
4141 var currentLyric = note . lyric . Normalize ( ) ; //measures for Unicode
4242
43- // Get color
44- string color = string . Empty ;
45- int toneShift = 0 ;
46- int ? alt = null ;
47- if ( note . phonemeAttributes != null ) {
48- var attr = note . phonemeAttributes . FirstOrDefault ( attr => attr . index == 0 ) ;
49- color = attr . voiceColor ;
50- toneShift = attr . toneShift ;
51- alt = attr . alternate ;
52- }
53-
5443 if ( ! string . IsNullOrEmpty ( note . phoneticHint ) ) {
5544 // If a hint is present, returns the hint.
56- currentLyric = note . phoneticHint . Normalize ( ) ;
57- if ( singer . TryGetMappedOto ( currentLyric + alt , note . tone + toneShift , color , out var phAlt ) ) {
58- return new Result {
59- phonemes = new Phoneme [ ] {
60- new Phoneme {
61- phoneme = phAlt . Alias ,
62- }
63- } ,
64- } ;
65- } else if ( singer . TryGetMappedOto ( currentLyric , note . tone + toneShift , color , out var ph ) ) {
45+ if ( CheckOtoUntilHit ( new string [ ] { note . phoneticHint . Normalize ( ) } , note , out var ph ) ) {
6646 return new Result {
6747 phonemes = new Phoneme [ ] {
68- new Phoneme {
69- phoneme = ph . Alias ,
70- }
71- } ,
48+ new Phoneme {
49+ phoneme = ph . Alias ,
50+ }
51+ } ,
7252 } ;
7353 }
7454 }
55+
7556 // The alias for no previous neighbour note. For example, "- な" for "な".
76- var phoneme = $ "- { currentLyric } ";
57+ string [ ] tests = new string [ ] { $ "- { currentLyric } " , currentLyric } ;
7758 if ( prevNeighbour != null ) {
7859 // If there is a previous neighbour note, first get its hint or lyric.
7960 var prevLyric = prevNeighbour . Value . lyric . Normalize ( ) ;
@@ -85,25 +66,51 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN
8566 // Look up the trailing vowel. For example "a" for "ゃ".
8667 if ( vowelLookup . TryGetValue ( unicode . LastOrDefault ( ) ?? string . Empty , out var vow ) ) {
8768 // Now replace "- な" initially set to "a な".
88- phoneme = $ "{ vow } { currentLyric } ";
69+ tests = new string [ ] { $ "{ vow } { currentLyric } ", $ "* { currentLyric } " , currentLyric , $ "- { currentLyric } " } ;
8970 }
9071 }
91- if ( singer . TryGetMappedOto ( phoneme + alt , note . tone + toneShift , color , out var otoAlt ) ) {
92- phoneme = otoAlt . Alias ;
93- } else if ( singer . TryGetMappedOto ( phoneme , note . tone + toneShift , color , out var oto ) ) {
94- phoneme = oto . Alias ;
95- } else if ( singer . TryGetMappedOto ( currentLyric + alt , note . tone + toneShift , color , out oto ) ) {
96- phoneme = oto . Alias ;
97- } else {
98- phoneme = currentLyric ;
72+ if ( CheckOtoUntilHit ( tests , note , out var oto ) ) {
73+ return new Result {
74+ phonemes = new Phoneme [ ] {
75+ new Phoneme {
76+ phoneme = oto . Alias ,
77+ }
78+ } ,
79+ } ;
9980 }
10081 return new Result {
10182 phonemes = new Phoneme [ ] {
10283 new Phoneme {
103- phoneme = phoneme ,
84+ phoneme = currentLyric ,
10485 }
10586 } ,
10687 } ;
10788 }
89+
90+ private bool CheckOtoUntilHit ( string [ ] input , Note note , out UOto oto ) {
91+ oto = default ;
92+ var attr = note . phonemeAttributes ? . FirstOrDefault ( attr => attr . index == 0 ) ?? default ;
93+ string color = attr . voiceColor ?? "" ;
94+
95+ var otos = new List < UOto > ( ) ;
96+ foreach ( string test in input ) {
97+ if ( singer . TryGetMappedOto ( test + attr . alternate , note . tone + attr . toneShift , color , out var otoAlt ) ) {
98+ otos . Add ( otoAlt ) ;
99+ } else if ( singer . TryGetMappedOto ( test , note . tone + attr . toneShift , color , out var otoCandidacy ) ) {
100+ otos . Add ( otoCandidacy ) ;
101+ }
102+ }
103+
104+ if ( otos . Count > 0 ) {
105+ if ( otos . Any ( oto => ( oto . Color ?? string . Empty ) == color ) ) {
106+ oto = otos . Find ( oto => ( oto . Color ?? string . Empty ) == color ) ;
107+ return true ;
108+ } else {
109+ oto = otos . First ( ) ;
110+ return true ;
111+ }
112+ }
113+ return false ;
114+ }
108115 }
109116}
0 commit comments