예제 #1
0
 public UndoConnectSymbols(int currentIndex, ParsedLyric current, ParsedLyric next, IList <ParsedLyric> collection)
 {
     this.next         = next;
     this.current      = current;
     this.collection   = collection;
     this.currentIndex = currentIndex;
 }
예제 #2
0
        private void CombineSymbolsMenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (SelectedListBox?.SelectedItem == null)
            {
                return;
            }

            RomajiLyric selected = (RomajiLyric)SelectedListBox.SelectedItem;
            int         index    = SymbolsAndWords.FindIndex(s => ReferenceEquals(s, selected.Japanese));

            if (index == -1 || index + 1 >= SymbolsAndWords.Count)
            {
                return;
            }

            var undo = new UndoConnectSymbols(index, SymbolsAndWords[index], SymbolsAndWords[index + 1], SymbolsAndWords);

            UndoStack.Push(undo);

            ParsedLyric combination = selected.Japanese + SymbolsAndWords[index + 1];

            SymbolsAndWords.RemoveAt(index + 1);

            SymbolsAndWords[index] = combination;

            MatchRomajiToSymbols();
        }
예제 #3
0
        private bool IsMatch(ParsedLyric word, int lineIndex, int romajiLyricIndex)
        {
            string lyric    = LyricLines[lineIndex][romajiLyricIndex].Vocal.Lyric;
            string fullWord = string.Empty;

            // Check if first letter matches
            if (!word.Content.Substring(0, 1).Equals(lyric.Substring(0, 1), StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            do
            {
                lyric = LyricLines[lineIndex][romajiLyricIndex].Vocal.Lyric;

                if (lyric.EndsWith("-") || lyric.EndsWith("+"))
                {
                    fullWord += lyric.Substring(0, lyric.Length - 1);
                }
                else
                {
                    fullWord += lyric;
                }

                ++romajiLyricIndex;
            }while (lyric.EndsWith("-") && romajiLyricIndex < LyricLines[lineIndex].Count);

            return(fullWord.Equals(word.Content, StringComparison.OrdinalIgnoreCase));
        }
예제 #4
0
        private void MatchRomajiToSymbols()
        {
            if (SymbolsAndWords.Count == 0)
            {
                ParseCharacters();
            }

            int romajiLyricIndex = 0;
            int lineIndex        = 0;

            for (int i = 0; i < SymbolsAndWords.Count; i++)
            {
                if (lineIndex == LyricLines.Count)
                {
                    break;
                }

                RomajiLyric romaji = LyricLines[lineIndex][romajiLyricIndex];

                string lyric = romaji.Vocal.Lyric;

                bool prevWasDifferentWord   = romajiLyricIndex == 0 || !LyricLines[lineIndex][romajiLyricIndex - 1].Vocal.Lyric.EndsWith("-");
                bool isFirstSyllableOfAWord = prevWasDifferentWord && lyric.EndsWith("-");

                ParsedLyric parsedLyric = SymbolsAndWords[i];

                // Break any parsed words into syllables as they appear in the XML lyrics
                if (isFirstSyllableOfAWord &&
                    parsedLyric.FirstCharacterIsLatin() &&
                    lyric != parsedLyric.Content &&
                    IsMatch(parsedLyric, lineIndex, romajiLyricIndex))
                {
                    // Replace current parsed word with first syllable
                    string unsplitWord = parsedLyric.Content;
                    parsedLyric.Content         = lyric;
                    parsedLyric.OriginalUnsplit = unsplitWord;

                    int    indexIncrement = 1;
                    string nextLyric;

                    // Insert rest of the syllables of a polysyllabic word into the list
                    do
                    {
                        nextLyric = LyricLines[lineIndex][romajiLyricIndex + indexIncrement].Vocal.Lyric;
                        SymbolsAndWords.Insert(i + indexIncrement, new ParsedLyric(nextLyric)
                        {
                            OriginalUnsplit = unsplitWord
                        });
                        ++indexIncrement;
                    }while (nextLyric.EndsWith("-"));
                }

                romaji.Japanese = parsedLyric;

                // Move to next line
                if (++romajiLyricIndex >= LyricLines[lineIndex].Count)
                {
                    romajiLyricIndex = 0;
                    lineIndex++;
                }
            }

            // Remove any previously matched Japanese from remaining syllables
            while (lineIndex < LyricLines.Count)
            {
                while (romajiLyricIndex < LyricLines[lineIndex].Count)
                {
                    LyricLines[lineIndex][romajiLyricIndex].Japanese = null;
                    romajiLyricIndex++;
                }
                romajiLyricIndex = 0;
                lineIndex++;
            }
        }