Example #1
0
 private void AudioWaveform_OnPositionSelected(object sender, AudioVisualizer.ParagraphEventArgs e)
 {
     mediaPlayer.CurrentPosition = e.Seconds;
     if (e.Paragraph != null)
         SubtitleListview1.SelectIndexAndEnsureVisible(_subtitle.GetIndex(e.Paragraph));
 }
Example #2
0
        private void AudioWaveform_OnTimeChanged(object sender, AudioVisualizer.ParagraphEventArgs e)
        {
            var paragraph = e.Paragraph;
            var beforeParagraph = e.BeforeParagraph;
            if (beforeParagraph == null)
                beforeParagraph = paragraph;

            if (beforeParagraph.StartTime.TotalMilliseconds == paragraph.StartTime.TotalMilliseconds &&
                beforeParagraph.EndTime.TotalMilliseconds == paragraph.EndTime.TotalMilliseconds)
                _makeHistoryPaused = true;

            int selectedIndex = FirstSelectedIndex;
            int index = _subtitle.Paragraphs.IndexOf(paragraph);
            if (index == _subtitleListViewIndex)
            {
                // Make history item for rollback (change paragraph back for history + change again)
                _subtitle.Paragraphs[index] = new Paragraph(beforeParagraph);
                MakeHistoryForUndoOnlyIfNotResent(string.Format(_language.VideoControls.BeforeChangingTimeInWaveformX, "#" + paragraph.Number + " " + paragraph.Text));
                _subtitle.Paragraphs[index] = paragraph;
                _makeHistoryPaused = true;

                Paragraph original = null;
                if (_subtitleAlternate != null && SubtitleListview1.IsAlternateTextColumnVisible)
                    original = Utilities.GetOriginalParagraph(index, beforeParagraph, _subtitleAlternate.Paragraphs);

                if (Configuration.Settings.General.UseTimeFormatHHMMSSFF)
                { // so we don't get weird rounds we'll use whole frames when moving start time
                    double fr = TimeCode.BaseUnit / Configuration.Settings.General.CurrentFrameRate;
                    if (e.BeforeParagraph != null && e.BeforeParagraph.StartTime.TotalMilliseconds != e.Paragraph.StartTime.TotalMilliseconds &&
                        e.BeforeParagraph.Duration.TotalMilliseconds == e.Paragraph.Duration.TotalMilliseconds)
                    {
                        // move paragraph
                        paragraph.StartTime.TotalMilliseconds = ((int)Math.Round(paragraph.StartTime.TotalMilliseconds / fr)) * fr;
                        paragraph.EndTime.TotalMilliseconds = paragraph.StartTime.TotalMilliseconds + e.BeforeParagraph.Duration.TotalMilliseconds;
                    }
                    else if (e.BeforeParagraph != null && e.BeforeParagraph.EndTime.TotalMilliseconds == e.Paragraph.EndTime.TotalMilliseconds)
                    {
                        paragraph.EndTime.TotalMilliseconds = ((int)Math.Round(paragraph.EndTime.TotalMilliseconds / fr)) * fr;
                        int end = SubtitleFormat.MillisecondsToFrames(paragraph.EndTime.TotalMilliseconds);
                        int dur = SubtitleFormat.MillisecondsToFrames(paragraph.Duration.TotalMilliseconds);
                        paragraph.StartTime.TotalMilliseconds = SubtitleFormat.FramesToMilliseconds(end - dur);
                    }
                }

                timeUpDownStartTime.TimeCode = paragraph.StartTime;
                var durationInSeconds = (decimal)(paragraph.Duration.TotalSeconds);
                if (durationInSeconds >= numericUpDownDuration.Minimum && durationInSeconds <= numericUpDownDuration.Maximum)
                {
                    SetDurationInSeconds((double)durationInSeconds);
                    if (e.MouseDownParagraphType == AudioVisualizer.MouseDownParagraphType.Start)
                    {
                        paragraph.EndTime.TotalMilliseconds = e.BeforeParagraph.EndTime.TotalMilliseconds;
                    }
                }

                MovePrevNext(e, beforeParagraph, index);

                if (original != null)
                {
                    original.StartTime.TotalMilliseconds = paragraph.StartTime.TotalMilliseconds;
                    original.EndTime.TotalMilliseconds = paragraph.EndTime.TotalMilliseconds;
                }
            }
            else if (_subtitleAlternate != null && SubtitleListview1.IsAlternateTextColumnVisible && Configuration.Settings.General.ShowOriginalAsPreviewIfAvailable)
            {
                index = _subtitleAlternate.GetIndex(paragraph);
                if (index >= 0)
                {
                    // Make history item for rollback (change paragraph back for history + change again)
                    _subtitleAlternate.Paragraphs[index] = new Paragraph(beforeParagraph);
                    MakeHistoryForUndoOnlyIfNotResent(string.Format(_language.VideoControls.BeforeChangingTimeInWaveformX, "#" + paragraph.Number + " " + paragraph.Text));
                    _subtitleAlternate.Paragraphs[index] = paragraph;
                    _makeHistoryPaused = true;

                    var current = Utilities.GetOriginalParagraph(index, beforeParagraph, _subtitle.Paragraphs);
                    if (current != null)
                    {
                        current.StartTime.TotalMilliseconds = paragraph.StartTime.TotalMilliseconds;
                        current.EndTime.TotalMilliseconds = paragraph.EndTime.TotalMilliseconds;

                        index = _subtitle.GetIndex(current);

                        SubtitleListview1.SetStartTimeAndDuration(index, paragraph);

                        if (index == selectedIndex)
                        {
                            timeUpDownStartTime.TimeCode = paragraph.StartTime;
                            var durationInSeconds = (decimal)(paragraph.Duration.TotalSeconds);
                            if (durationInSeconds >= numericUpDownDuration.Minimum && durationInSeconds <= numericUpDownDuration.Maximum)
                                SetDurationInSeconds((double)durationInSeconds);
                        }
                    }
                }
            }
            else if (_subtitleAlternate != null && SubtitleListview1.IsAlternateTextColumnVisible)
            {
                index = _subtitle.GetIndex(paragraph);
                if (index >= 0)
                {
                    // Make history item for rollback (change paragraph back for history + change again)
                    _subtitle.Paragraphs[index] = new Paragraph(beforeParagraph);
                    MakeHistoryForUndoOnlyIfNotResent(string.Format(_language.VideoControls.BeforeChangingTimeInWaveformX, "#" + paragraph.Number + " " + paragraph.Text));
                    _subtitle.Paragraphs[index] = paragraph;
                    _makeHistoryPaused = true;

                    MovePrevNext(e, beforeParagraph, index);

                    var original = Utilities.GetOriginalParagraph(index, beforeParagraph, _subtitleAlternate.Paragraphs);
                    if (original != null)
                    {
                        original.StartTime.TotalMilliseconds = paragraph.StartTime.TotalMilliseconds;
                        original.EndTime.TotalMilliseconds = paragraph.EndTime.TotalMilliseconds;
                    }
                    SubtitleListview1.SetStartTimeAndDuration(index, paragraph);
                }
            }
            else
            {
                if (index >= 0)
                {
                    // Make history item for rollback (change paragraph back for history + change again)
                    _subtitle.Paragraphs[index] = new Paragraph(beforeParagraph);
                    MakeHistoryForUndoOnlyIfNotResent(string.Format(_language.VideoControls.BeforeChangingTimeInWaveformX, "#" + paragraph.Number + " " + paragraph.Text));
                    _subtitle.Paragraphs[index] = paragraph;
                    _makeHistoryPaused = true;

                    MovePrevNext(e, beforeParagraph, index);

                    if (_subtitleAlternate != null)
                    {
                        var original = Utilities.GetOriginalParagraph(index, beforeParagraph, _subtitleAlternate.Paragraphs);
                        if (original != null)
                        {
                            original.StartTime.TotalMilliseconds = paragraph.StartTime.TotalMilliseconds;
                            original.EndTime.TotalMilliseconds = paragraph.EndTime.TotalMilliseconds;
                        }
                    }
                }

                SubtitleListview1.SetStartTimeAndDuration(index, paragraph);
            }
            beforeParagraph.StartTime.TotalMilliseconds = paragraph.StartTime.TotalMilliseconds;
            beforeParagraph.EndTime.TotalMilliseconds = paragraph.EndTime.TotalMilliseconds;
            _makeHistoryPaused = false;
        }
Example #3
0
        private void MovePrevNext(AudioVisualizer.ParagraphEventArgs e, Paragraph beforeParagraph, int index)
        {
            if (e.MovePreviousOrNext)
            {
                if (e.MouseDownParagraphType == AudioVisualizer.MouseDownParagraphType.Start)
                {
                    var prev = _subtitle.GetParagraphOrDefault(index - 1);
                    if (prev != null)
                    {
                        Paragraph originalPrev = null;
                        if (_subtitleAlternate != null && SubtitleListview1.IsAlternateTextColumnVisible)
                            originalPrev = Utilities.GetOriginalParagraph(index - 1, prev, _subtitleAlternate.Paragraphs);

                        prev.EndTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds + (e.Paragraph.StartTime.TotalMilliseconds - beforeParagraph.StartTime.TotalMilliseconds);
                        SubtitleListview1.SetStartTimeAndDuration(index - 1, prev);
                        audioVisualizer.Invalidate();

                        if (originalPrev != null)
                        {
                            originalPrev.EndTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds;
                        }
                    }
                }
                else if (e.MouseDownParagraphType == AudioVisualizer.MouseDownParagraphType.End)
                {
                    var next = _subtitle.GetParagraphOrDefault(index + 1);
                    if (next != null)
                    {
                        Paragraph originalNext = null;
                        if (_subtitleAlternate != null && SubtitleListview1.IsAlternateTextColumnVisible)
                            originalNext = Utilities.GetOriginalParagraph(index + 1, next, _subtitleAlternate.Paragraphs);

                        next.StartTime.TotalMilliseconds = next.StartTime.TotalMilliseconds + (e.Paragraph.EndTime.TotalMilliseconds - beforeParagraph.EndTime.TotalMilliseconds);
                        SubtitleListview1.SetStartTimeAndDuration(index + 1, next);
                        audioVisualizer.Invalidate();

                        if (originalNext != null)
                        {
                            originalNext.StartTime.TotalMilliseconds = next.StartTime.TotalMilliseconds;
                        }
                    }
                }
            }
        }
Example #4
0
        private void AudioWaveform_OnParagraphRightClicked(object sender, AudioVisualizer.ParagraphEventArgs e)
        {
            SubtitleListview1.SelectIndexAndEnsureVisible(_subtitle.GetIndex(e.Paragraph));

            addParagraphHereToolStripMenuItem.Visible = false;
            addParagraphAndPasteToolStripMenuItem.Visible = false;
            deleteParagraphToolStripMenuItem.Visible = true;
            toolStripMenuItemFocusTextbox.Visible = true;
            splitToolStripMenuItem1.Visible = true;
            mergeWithPreviousToolStripMenuItem.Visible = true;
            mergeWithNextToolStripMenuItem.Visible = true;
            toolStripSeparator11.Visible = true;
            toolStripMenuItemWaveformPlaySelection.Visible = true;
            toolStripSeparator24.Visible = true;

            _audioWaveformRightClickSeconds = e.Seconds;
            contextMenuStripWaveform.Show(MousePosition.X, MousePosition.Y);
        }
Example #5
0
        private void AudioWaveform_OnNewSelectionRightClicked(object sender, AudioVisualizer.ParagraphEventArgs e)
        {
            SubtitleListview1.SelectIndexAndEnsureVisible(_subtitle.GetIndex(e.Paragraph));

            addParagraphHereToolStripMenuItem.Visible = true;
            addParagraphAndPasteToolStripMenuItem.Visible = Clipboard.ContainsText();

            deleteParagraphToolStripMenuItem.Visible = false;
            toolStripMenuItemFocusTextbox.Visible = false;
            splitToolStripMenuItem1.Visible = false;
            mergeWithPreviousToolStripMenuItem.Visible = false;
            mergeWithNextToolStripMenuItem.Visible = false;

            contextMenuStripWaveform.Show(MousePosition.X, MousePosition.Y);
        }
Example #6
0
        private void AudioWaveform_OnSingleClick(object sender, AudioVisualizer.ParagraphEventArgs e)
        {
            timerWaveform.Stop();
            _endSeconds = -1;
            if (mediaPlayer.VideoPlayer != null)
                mediaPlayer.Pause();

            mediaPlayer.CurrentPosition = e.Seconds;

            int index = -1;
            if (SubtitleListview1.SelectedItems.Count > 0)
                index = SubtitleListview1.SelectedItems[0].Index;
            SetWaveformPosition(audioVisualizer.StartPositionSeconds, e.Seconds, index);
            timerWaveform.Start();
        }
Example #7
0
        private void AudioWaveform_OnTimeChangedAndOffsetRest(object sender, AudioVisualizer.ParagraphEventArgs e)
        {
            if (mediaPlayer.VideoPlayer == null)
                return;

            int index = _subtitle.Paragraphs.IndexOf(e.Paragraph);
            if (index < 0)
            {
                if (_subtitleAlternate != null && SubtitleListview1.IsAlternateTextColumnVisible && Configuration.Settings.General.ShowOriginalAsPreviewIfAvailable)
                {
                    index = _subtitleAlternate.GetIndex(e.Paragraph);
                    if (index >= 0)
                    {
                        var current = Utilities.GetOriginalParagraph(index, e.Paragraph, _subtitle.Paragraphs);
                        if (current != null)
                        {
                            index = _subtitle.Paragraphs.IndexOf(current);
                        }
                    }
                }
                else if (_subtitleAlternate != null && SubtitleListview1.IsAlternateTextColumnVisible)
                {
                    index = _subtitle.GetIndex(e.Paragraph);
                }
            }
            if (index >= 0)
            {
                SubtitleListview1.SelectIndexAndEnsureVisible(index);
                mediaPlayer.CurrentPosition = e.Seconds;
                ButtonSetStartAndOffsetRestClick(null, null);
            }
            audioVisualizer.Invalidate();
        }
Example #8
0
 private void AudioWaveform_OnDoubleClickNonParagraph(object sender, AudioVisualizer.ParagraphEventArgs e)
 {
     if (mediaPlayer.VideoPlayer != null)
     {
         _endSeconds = -1;
         if (e.Paragraph == null)
         {
             if (Configuration.Settings.VideoControls.WaveformDoubleClickOnNonParagraphAction == "PlayPause")
                 mediaPlayer.TogglePlayPause();
         }
         else
         {
             SubtitleListview1.SelectIndexAndEnsureVisible(_subtitle.GetIndex(e.Paragraph));
         }
     }
 }
Example #9
0
 private void AudioWaveform_OnNonParagraphRightClicked(object sender, AudioVisualizer.ParagraphEventArgs e)
 {
     addParagraphHereToolStripMenuItem.Visible = false;
     addParagraphAndPasteToolStripMenuItem.Visible = false;
     deleteParagraphToolStripMenuItem.Visible = false;
     toolStripMenuItemFocusTextbox.Visible = true;
     splitToolStripMenuItem1.Visible = false;
     mergeWithPreviousToolStripMenuItem.Visible = false;
     mergeWithNextToolStripMenuItem.Visible = false;
     toolStripSeparator11.Visible = false;
     toolStripMenuItemWaveformPlaySelection.Visible = false;
     toolStripSeparator24.Visible = false;
     contextMenuStripWaveform.Show(MousePosition.X, MousePosition.Y);
 }
Example #10
0
        private void MovePrevNext(AudioVisualizer.ParagraphEventArgs e, Paragraph beforeParagraph, int index)
        {
            int curIdx = FirstSelectedIndex;
            if (e.MovePreviousOrNext && curIdx >= 0)
            {
                if (e.MouseDownParagraphType == AudioVisualizer.MouseDownParagraphType.Start)
                {
                    var prev = _subtitle.GetParagraphOrDefault(index - 1);
                    if (prev != null)
                    {
                        Paragraph originalPrev = null;
                        if (_subtitleAlternate != null && SubtitleListview1.IsAlternateTextColumnVisible)
                            originalPrev = Utilities.GetOriginalParagraph(index - 1, prev, _subtitleAlternate.Paragraphs);

                        prev.EndTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds + (e.Paragraph.StartTime.TotalMilliseconds - beforeParagraph.StartTime.TotalMilliseconds);
                        SubtitleListview1.SetStartTimeAndDuration(index - 1, prev);
                        audioVisualizer.Invalidate();

                        if (originalPrev != null)
                        {
                            originalPrev.EndTime.TotalMilliseconds = prev.EndTime.TotalMilliseconds;
                        }

                        if (curIdx == index - 1)
                        {
                            var durationInSeconds = (decimal)(prev.Duration.TotalSeconds);
                            if (durationInSeconds >= numericUpDownDuration.Minimum && durationInSeconds <= numericUpDownDuration.Maximum)
                            {
                                SetDurationInSeconds((double)durationInSeconds);
                            }
                        }
                    }

                    else if (e.MouseDownParagraphType == AudioVisualizer.MouseDownParagraphType.End)
                    {
                        var next = _subtitle.GetParagraphOrDefault(index + 1);
                        if (next != null)
                        {
                            Paragraph originalNext = null;
                            if (_subtitleAlternate != null && SubtitleListview1.IsAlternateTextColumnVisible)
                                originalNext = Utilities.GetOriginalParagraph(index + 1, next, _subtitleAlternate.Paragraphs);

                            next.StartTime.TotalMilliseconds = next.StartTime.TotalMilliseconds + (e.Paragraph.EndTime.TotalMilliseconds - beforeParagraph.EndTime.TotalMilliseconds);
                            SubtitleListview1.SetStartTimeAndDuration(index + 1, next);
                            audioVisualizer.Invalidate();

                            if (originalNext != null)
                            {
                                originalNext.StartTime.TotalMilliseconds = next.StartTime.TotalMilliseconds;
                            }

                            if (curIdx == index + 1)
                            {
                                timeUpDownStartTime.TimeCode = next.StartTime;
                                var durationInSeconds = (decimal)(next.Duration.TotalSeconds);
                                if (durationInSeconds >= numericUpDownDuration.Minimum && durationInSeconds <= numericUpDownDuration.Maximum)
                                {
                                    SetDurationInSeconds((double)durationInSeconds);
                                }
                            }
                        }
                    }
                }
            }
        }