Fixed bug where wave form data would not match with actual video (sample rate problem)

Mousewheel will work in video player (also un-docked)


git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@220 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2011-01-04 19:12:27 +00:00
parent fe8896ab2a
commit 79dd4d1238
7 changed files with 86 additions and 59 deletions

View File

@ -11,7 +11,7 @@ Subtitle Edit Changelog
* Options to choose font color and background color (for list view/text-boxes)
* Can now import VobSub subtitles embedded in Matroska (.mkv) files (thx mosu for mkv info)
* Wave form position can be locked at center via new 'Center' button (thx Krystian)
* Can insert subtitle after a line in the list view via context menu
* Can insert (a whole) subtitle after a line in the list view via context menu
* IMPROVED:
* Main window: Video player will now automatically move up beside subtitle if waveform is
displayed + some resizing of controls allowed via splitters
@ -22,10 +22,11 @@ Subtitle Edit Changelog
* Moved video controls below subtitle preview (which now displays italic)
* Fix common ocr errors improed (thx aMvEL, sialivi, Alberto)
* FIXED:
* Wave form: Fix bug with unprecise data (only for some sample rates)
* OCR Fix Engine: Lines after "..." will no longer be changed to start with uppercase letter
* Missing line break in Sony Dvd Architecht w line numbers (thx Rosa)
* A minor bug in initialization of waveform (thx Frederic)
* A minor bug in Visual Sync, if end scene was after video length
* A minor bug in Visual Sync, if end scene was after video length (thx tsieberg)
* Fixed crash with wave form track bar (thx Christian)
* Fixed several bugs regarding 'large fonts' / higher dpi (thx Radbert)

View File

@ -3,15 +3,39 @@ using System.Drawing;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Logic.VideoPlayers;
using System.Text;
using System.Runtime.InteropServices;
namespace Nikse.SubtitleEdit.Controls
{
public sealed class VideoPlayerContainer : Panel
{
class RichTextBoxViewOnly : System.Windows.Forms.RichTextBox
{
public RichTextBoxViewOnly()
{
base.ReadOnly = true;
base.BorderStyle = BorderStyle.None;
base.TabStop = false;
base.SetStyle(ControlStyles.Selectable, false);
base.SetStyle(ControlStyles.UserMouse, true);
base.MouseEnter += delegate(object sender, EventArgs e) { this.Cursor = Cursors.Default; };
base.ScrollBars = RichTextBoxScrollBars.None;
base.Margin = new System.Windows.Forms.Padding(0);
base.TabStop = false;
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x204) return; // WM_RBUTTONDOWN
if (m.Msg == 0x205) return; // WM_RBUTTONUP
base.WndProc(ref m);
}
}
public event EventHandler OnButtonClicked;
public Panel PanelPlayer { get; private set; }
private Panel _panelSubtitle;
private RichTextBox _subtitleTextBox;
private RichTextBoxViewOnly _subtitleTextBox;
private string _subtitleText = string.Empty;
private VideoPlayer _videoPlayer;
public VideoPlayer VideoPlayer
@ -107,23 +131,48 @@ namespace Nikse.SubtitleEdit.Controls
PanelPlayer.MouseDown += PanelPlayer_MouseDown;
}
public void EnableMouseWheelStep()
{
AddMouseWheelEvent(this);
}
private void AddMouseWheelEvent(Control control)
{
control.MouseWheel += Control_MouseWheel;
foreach (Control ctrl in control.Controls)
AddMouseWheelEvent(ctrl);
}
void Control_MouseWheel(object sender, MouseEventArgs e)
{
int delta = e.Delta;
double newPosition = CurrentPosition - (delta / 256.0);
if (newPosition < 0)
newPosition = 0;
else if (newPosition > Duration)
newPosition = Duration;
CurrentPosition = newPosition;
}
private Control MakeSubtitlesPanel()
{
_panelSubtitle = new Panel { BackColor = _backgroundColor, Left = 0, Top = 0 };
_panelSubtitle.Height = SubtitlesHeight + 1;
_subtitleTextBox = new RichTextBox();
_subtitleTextBox = new RichTextBoxViewOnly();
_panelSubtitle.Controls.Add(_subtitleTextBox);
_subtitleTextBox.ReadOnly = true;
_subtitleTextBox.ScrollBars = RichTextBoxScrollBars.None;
_subtitleTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
_subtitleTextBox.Margin = new System.Windows.Forms.Padding(0);
_subtitleTextBox.BackColor = _backgroundColor;
_subtitleTextBox.ForeColor = Color.White;
_subtitleTextBox.Dock = DockStyle.Fill;
_subtitleTextBox.Font = new Font("Tahoma", 8, FontStyle.Bold);
_subtitleTextBox.MouseClick += SubtitleTextBox_MouseClick;
return _panelSubtitle;
}
void SubtitleTextBox_MouseClick(object sender, MouseEventArgs e)
{
TooglePlayPause();
}
private static string RemoveSubStationAlphaFormatting(string s)
{
int indexOfBegin = s.IndexOf("{");

View File

@ -996,19 +996,17 @@ namespace Nikse.SubtitleEdit.Controls
void WaveForm_MouseWheel(object sender, MouseEventArgs e)
{
int delta = e.Delta;
if (Locked)
{
if (Locked)
{
OnPositionSelected.Invoke(_currentVideoPositionSeconds + (-delta / 256.0), null);
}
else
{
StartPositionSeconds -= delta / 256.0;
if (_currentVideoPositionSeconds < StartPositionSeconds || _currentVideoPositionSeconds >= EndPositionSeconds)
OnPositionSelected.Invoke(StartPositionSeconds, null);
}
Invalidate();
OnPositionSelected.Invoke(_currentVideoPositionSeconds + (-delta / 256.0), null);
}
else
{
StartPositionSeconds -= delta / 256.0;
if (_currentVideoPositionSeconds < StartPositionSeconds || _currentVideoPositionSeconds >= EndPositionSeconds)
OnPositionSelected.Invoke(StartPositionSeconds, null);
}
Invalidate();
}
}

View File

@ -1,17 +1,12 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Logic;
namespace Nikse.SubtitleEdit.Forms
{
public partial class AddWareForm : Form
public sealed partial class AddWareForm : Form
{
public string SourceVideoFileName { get; private set; }
private bool _cancel = false;
@ -118,7 +113,12 @@ namespace Nikse.SubtitleEdit.Forms
private void ReadWaveFile(string targetFile)
{
WavePeakGenerator waveFile = new WavePeakGenerator(targetFile);
waveFile.GeneratePeakSamples(128); // samples per second - SampleRate
int sampleRate = 126;
while (!(waveFile.Header.SampleRate % sampleRate == 0) && sampleRate < 1000)
sampleRate++; // old sample-rate / new sample-rate must have rest = 0
waveFile.GeneratePeakSamples(sampleRate); // samples per second - SampleRate
WavePeak = waveFile;
waveFile.Close();
}

View File

@ -101,7 +101,7 @@ namespace Nikse.SubtitleEdit.Forms
if (versionInfo.Length >= 3 && versionInfo[2] != "0")
_title += "." + versionInfo[2];
}
return _title + " Beta";
return _title + " Beta 2";
}
}

View File

@ -32,6 +32,11 @@ namespace Nikse.SubtitleEdit.Forms
Text = title;
}
void VideoPlayerContainer_MouseWheel(object sender, MouseEventArgs e)
{
MessageBox.Show("Test");
}
private void VideoPlayerUnDocked_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing && panelContainer.Controls.Count > 0)
@ -54,36 +59,9 @@ namespace Nikse.SubtitleEdit.Forms
WindowState = FormWindowState.Maximized;
e.SuppressKeyPress = true;
}
else if (_videoPlayerContainer.VideoPlayer != null)
else
{
if (e.Modifiers == Keys.None && e.KeyCode == Keys.Space)
{
if (_videoPlayerContainer.VideoPlayer.IsPlaying)
_videoPlayerContainer.VideoPlayer.Pause();
else
_videoPlayerContainer.VideoPlayer.Play();
e.SuppressKeyPress = true;
}
else if (e.KeyCode == Keys.Right && e.Modifiers == Keys.Control)
{
_videoPlayerContainer.CurrentPosition += 0.10;
e.SuppressKeyPress = true;
}
else if (e.KeyCode == Keys.Left && e.Modifiers == Keys.Control)
{
_videoPlayerContainer.CurrentPosition -= 0.10;
e.SuppressKeyPress = true;
}
else if (e.KeyCode == Keys.Right && e.Modifiers == Keys.Alt)
{
_videoPlayerContainer.CurrentPosition += 0.5;
e.SuppressKeyPress = true;
}
else if (e.KeyCode == Keys.Left && e.Modifiers == Keys.Alt)
{
_videoPlayerContainer.CurrentPosition -= 0.5;
e.SuppressKeyPress = true;
}
_mainForm.Main_KeyDown(sender, e);
}
}
}

View File

@ -1157,6 +1157,7 @@ namespace Nikse.SubtitleEdit.Logic
videoPlayerContainer.VideoPlayer.Initialize(videoPlayerContainer.PanelPlayer, fileName, onVideoLoaded, onVideoEnded);
videoPlayerContainer.ShowStopButton = Configuration.Settings.General.VideoPlayerShowStopButton;
videoPlayerContainer.Volume = Configuration.Settings.General.VideoPlayerDefaultVolume;
videoPlayerContainer.EnableMouseWheelStep();
}
catch (Exception exception)
{