コード例 #1
0
 public UndoConnectSyllables(int currentIndex, RomajiLyric current, RomajiLyric next, IList <RomajiLyric> collection)
 {
     this.next         = next;
     this.current      = current;
     this.collection   = collection;
     this.currentIndex = currentIndex;
 }
コード例 #2
0
        private void ConnectSyllableWithNext_Click(object sender, RoutedEventArgs e)
        {
            if (SelectedListBox?.SelectedItem == null)
            {
                return;
            }

            int         selectedIndex = SelectedListBox.SelectedIndex;
            RomajiLyric selected      = (RomajiLyric)SelectedListBox.SelectedItem;
            LyricLine   selectedLine  = (LyricLine)SelectedListBox.ItemsSource;

            if (selected == null || selectedIndex + 1 >= SelectedListBox.Items.Count)
            {
                return;
            }

            Vocal       selectedVocal = selected.Vocal;
            RomajiLyric next          = (RomajiLyric)SelectedListBox.Items[selectedIndex + 1];

            var undoAction = new UndoConnectSyllables(selectedIndex, new RomajiLyric(selected), next, selectedLine);

            UndoStack.Push(undoAction);

            if (selectedVocal.Lyric.EndsWith("-"))
            {
                selectedVocal.Lyric = selectedVocal.Lyric.Substring(0, selectedVocal.Lyric.Length - 1);
            }

            selectedVocal.Lyric += next.Vocal.Lyric;
            selectedVocal.Length = (float)Math.Round(selectedVocal.Length + next.Vocal.Length, 3, MidpointRounding.AwayFromZero);

            selectedLine.Remove(next);

            MatchRomajiToSymbols();
        }
コード例 #3
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();
        }
コード例 #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++;
            }
        }