From 5a4e03312a12e5b882064cbedb7af6bbad845cfd Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sat, 2 Jun 2007 13:48:36 +0000 Subject: [PATCH] If Ctrl is held when video playback is started, no audio resync is attempted during that playback. Originally committed to SVN as r1201. --- aegisub/video_box.cpp | 8 ++++++-- aegisub/video_context.cpp | 5 +++-- aegisub/video_context.h | 3 +++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/aegisub/video_box.cpp b/aegisub/video_box.cpp index ed9c44bf8..773863bea 100644 --- a/aegisub/video_box.cpp +++ b/aegisub/video_box.cpp @@ -196,14 +196,18 @@ END_EVENT_TABLE() ////////////// // Play video void VideoBox::OnVideoPlay(wxCommandEvent &event) { - VideoContext::Get()->Play(); + VideoContext *ctx = VideoContext::Get(); + ctx->EnableAudioSync(wxGetMouseState().ControlDown() == false); + ctx->Play(); } /////////////////// // Play video line void VideoBox::OnVideoPlayLine(wxCommandEvent &event) { - VideoContext::Get()->PlayLine(); + VideoContext *ctx = VideoContext::Get(); + ctx->EnableAudioSync(wxGetMouseState().ControlDown() == false); + ctx->PlayLine(); } diff --git a/aegisub/video_context.cpp b/aegisub/video_context.cpp index feddfed46..16948c8b1 100644 --- a/aegisub/video_context.cpp +++ b/aegisub/video_context.cpp @@ -114,6 +114,7 @@ VideoContext::VideoContext() { arValue = 1.0; isPlaying = false; nextFrame = -1; + keepAudioSync = true; // Threads threaded = Options.AsBool(_T("Threaded Video")); @@ -723,7 +724,7 @@ void VideoContext::OnPlayTimer(wxTimerEvent &event) { if (nextFrame == frame_n) return; // Next frame is before or over 2 frames ahead, so force audio resync - if (nextFrame < frame_n || nextFrame > frame_n + 2) audio->player->SetCurrentPosition(audio->GetSampleAtMS(VFR_Output.GetTimeAtFrame(nextFrame))); + if (keepAudioSync && (nextFrame < frame_n || nextFrame > frame_n + 2)) audio->player->SetCurrentPosition(audio->GetSampleAtMS(VFR_Output.GetTimeAtFrame(nextFrame))); // Jump to next frame playNextFrame = nextFrame; @@ -731,7 +732,7 @@ void VideoContext::OnPlayTimer(wxTimerEvent &event) { JumpToFrame(nextFrame); // Sync audio - if (nextFrame % 10 == 0) { + if (keepAudioSync && nextFrame % 10 == 0) { __int64 audPos = audio->GetSampleAtMS(VFR_Output.GetTimeAtFrame(nextFrame)); __int64 curPos = audio->player->GetCurrentPosition(); int delta = int(audPos-curPos); diff --git a/aegisub/video_context.h b/aegisub/video_context.h index 9664cbc8b..94d3b7458 100644 --- a/aegisub/video_context.h +++ b/aegisub/video_context.h @@ -103,6 +103,7 @@ private: bool loaded; bool isInverted; bool isPlaying; + bool keepAudioSync; float texW,texH; int w,h; @@ -146,6 +147,8 @@ public: bool IsPlaying() { return isPlaying; } bool IsInverted() { return isInverted; } + void EnableAudioSync(bool sync = true) { keepAudioSync = sync; } + int GetWidth() { return w; } int GetHeight() { return h; } int GetLength() { return length; }