private void convertButton_Click(object sender, EventArgs e) { int mcIndex = startOffsetCombo.SelectedIndex; Tuple <TimeSpan, TimeSpan> timing = Tuple.Create(new TimeSpan(), new TimeSpan()); List <LipSyncConvertData> convertData = new List <LipSyncConvertData>(); if (LipSyncTextConvert.StandardDictExists() == false) { //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible) MessageBoxForm.msgIcon = SystemIcons.Error; //this is used if you want to add a system icon to the message form. var messageBox = new MessageBoxForm("Unable to find Standard Phoneme Dictionary", "Error", false, false); messageBox.ShowDialog(); return; } LipSyncTextConvert.InitDictionary(); if (NewTranslation != null) { var selectedMarkCollection = (markCollectionCombo.SelectedItem as ComboBoxItem)?.Value as MarkCollection; List <string> subStrings = CreateSubstringList(); var selMC = selectedMarkCollection?.Marks.Select(x => x.StartTime).ToList(); bool doPhonemeAlign = (alignCombo.SelectedIndex != -1) && (alignCombo.SelectedItem.Equals("Phoneme")); if (mcIndex == -1) { selMC = null; mcIndex = 0; } foreach (string strElem in subStrings) { if (string.IsNullOrWhiteSpace(strElem)) { continue; } int phonemeIndex = 0; List <PhonemeType> phonemeList = LipSyncTextConvert.TryConvert(strElem.Trim()); if (phonemeList.Count == 0) { EventHandler <TranslateFailureEventArgs> failHandler = TranslateFailure; TranslateFailureEventArgs failArgs = new TranslateFailureEventArgs(); failArgs.FailedWord = strElem; failHandler(this, failArgs); //At this point, we should have it corrected, if not, then ignore phonemeList = LipSyncTextConvert.TryConvert(strElem); } if (phonemeList.Count == 0) { //User has bailed on one of the conversions return; } if (doPhonemeAlign == false) { timing = CalcPhonemeTimespans(selMC, mcIndex++, phonemeList.Count); } foreach (PhonemeType phoneme in phonemeList) { if (doPhonemeAlign == true) { timing = CalcPhonemeTimespans(selMC, mcIndex++, 1); phonemeIndex = 0; } long startTicks = timing.Item1.Ticks + (timing.Item2.Ticks * phonemeIndex++); convertData.Add(new LipSyncConvertData(startTicks, timing.Item2.Ticks, phoneme, strElem)); } if (checkBoxClearText.Checked) { textBox.Text = ""; } } EventHandler <NewTranslationEventArgs> handler = NewTranslation; NewTranslationEventArgs args = new NewTranslationEventArgs(); args.PhonemeData = convertData; if (markCollectionRadio.Checked) { args.Placement = TranslatePlacement.Mark; } else if (cursorRadio.Checked) { args.Placement = TranslatePlacement.Cursor; } else { args.Placement = TranslatePlacement.Clipboard; } if (startOffsetCombo.SelectedItem != null) { args.FirstMark = (TimeSpan)startOffsetCombo.SelectedItem; } handler(this, args); if (markCollectionRadio.Checked) { int markIncrement = 0; switch (alignCombo.Text) { case "Phoneme": markIncrement = convertData.Count; break; case "Word": markIncrement = subStrings.Count; break; case "Phrase": markIncrement = 1; break; } if (startOffsetCombo.SelectedIndex + markIncrement < startOffsetCombo.Items.Count) { startOffsetCombo.SelectedIndex = startOffsetCombo.SelectedIndex + markIncrement; } } } }
private void convertButton_Click(object sender, EventArgs e) { int mcIndex = startOffsetCombo.SelectedIndex; Tuple <TimeSpan, TimeSpan> timing = Tuple.Create(new TimeSpan(), new TimeSpan()); List <LipSyncConvertData> convertData = new List <LipSyncConvertData>(); if (LipSyncTextConvert.StandardDictExists() == false) { MessageBox.Show("Unable to find Standard Phoneme Dictionary", "Error", MessageBoxButtons.OK); return; } LipSyncTextConvert.InitDictionary(); if (NewTranslation != null) { List <string> subStrings = CreateSubstringList(); MarkCollection selMC = MarkCollections.Find(x => x.Name.Equals(markCollectionCombo.SelectedItem)); bool doPhonemeAlign = (alignCombo.SelectedIndex != -1) && (alignCombo.SelectedItem.Equals("Phoneme")); if (mcIndex == -1) { selMC = null; mcIndex = 0; } foreach (string strElem in subStrings) { if (string.IsNullOrWhiteSpace(strElem)) { continue; } int phonemeIndex = 0; List <PhonemeType> phonemeList = LipSyncTextConvert.TryConvert(strElem.Trim()); if (phonemeList.Count == 0) { EventHandler <TranslateFailureEventArgs> failHandler = TranslateFailure; TranslateFailureEventArgs failArgs = new TranslateFailureEventArgs(); failArgs.FailedWord = strElem; failHandler(this, failArgs); //At this point, we should have it corrected, if not, then ignore phonemeList = LipSyncTextConvert.TryConvert(strElem); } if (phonemeList.Count == 0) { //User has bailed on one of the conversions return; } if (doPhonemeAlign == false) { timing = CalcPhonemeTimespans(selMC, mcIndex++, phonemeList.Count); } foreach (PhonemeType phoneme in phonemeList) { if (doPhonemeAlign == true) { timing = CalcPhonemeTimespans(selMC, mcIndex++, 1); phonemeIndex = 0; } long startTicks = timing.Item1.Ticks + (timing.Item2.Ticks * phonemeIndex++); convertData.Add(new LipSyncConvertData(startTicks, timing.Item2.Ticks, phoneme, strElem)); } } EventHandler <NewTranslationEventArgs> handler = NewTranslation; NewTranslationEventArgs args = new NewTranslationEventArgs(); args.PhonemeData = convertData; if (markCollectionRadio.Checked) { args.Placement = TranslatePlacement.Mark; } else if (cursorRadio.Checked) { args.Placement = TranslatePlacement.Cursor; } else { args.Placement = TranslatePlacement.Clipboard; } if (startOffsetCombo.SelectedItem != null) { args.FirstMark = (TimeSpan)startOffsetCombo.SelectedItem; } handler(this, args); } }