From dd1ed05e21778ad07175d0bc96bde0b16ebfd08e Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Mon, 18 Dec 2006 04:53:40 +0000 Subject: [PATCH] Changes to VideoDisplay class to allow the new keyframe functionality to work Originally committed to SVN as r573. --- core/audio_display.cpp | 5 ++-- core/dialog_timing_processor.cpp | 2 +- core/frame_main_events.cpp | 15 +++++------ core/video_display.cpp | 43 +++++++++++++++++++++++++++++--- core/video_display.h | 14 ++++++++--- core/video_slider.cpp | 19 ++++++++------ 6 files changed, 73 insertions(+), 25 deletions(-) diff --git a/core/audio_display.cpp b/core/audio_display.cpp index fff6d1dd6..fc6caf630 100644 --- a/core/audio_display.cpp +++ b/core/audio_display.cpp @@ -232,7 +232,8 @@ void AudioDisplay::UpdateImage(bool weak) { // Draw keyframes if (video->loaded && draw_boundary_lines) { - int nKeys = (int)video->KeyFrames.Count(); + wxArrayInt KeyFrames = video->GetKeyFrames(); + int nKeys = (int)KeyFrames.Count(); dc.SetPen(wxPen(wxColour(255,0,255),1)); // Get min and max frames to care about @@ -241,7 +242,7 @@ void AudioDisplay::UpdateImage(bool weak) { // Scan list for (int i=0;iKeyFrames[i]; + int cur = KeyFrames[i]; if (cur >= minFrame && cur <= maxFrame) { int x = GetXAtMS(VFR_Output.GetTimeAtFrame(cur,true)); dc.DrawLine(x,0,x,h); diff --git a/core/dialog_timing_processor.cpp b/core/dialog_timing_processor.cpp index 3e6f4a977..99fbebc23 100644 --- a/core/dialog_timing_processor.cpp +++ b/core/dialog_timing_processor.cpp @@ -501,7 +501,7 @@ void DialogTimingProcessor::Process() { // Keyframe snapping if (keysEnable->IsChecked()) { // Get keyframes - KeyFrames = grid->video->KeyFrames; + KeyFrames = grid->video->GetKeyFrames(); KeyFrames.Add(grid->video->length-1); // Variables diff --git a/core/frame_main_events.cpp b/core/frame_main_events.cpp index 6108f5f8b..6d1d59e24 100644 --- a/core/frame_main_events.cpp +++ b/core/frame_main_events.cpp @@ -290,8 +290,8 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) { MenuBar->Enable(Menu_Video_AR_235,state); MenuBar->Enable(Menu_Video_AR_Custom,state); MenuBar->Enable(Menu_File_Close_VFR,VFR_Output.GetFrameRateType() == VFR); - MenuBar->Enable(Menu_Video_Close_Keyframes,videoBox->videoDisplay->keyFramesLoaded); - MenuBar->Enable(Menu_Video_Save_Keyframes,videoBox->videoDisplay->keyFramesLoaded); + MenuBar->Enable(Menu_Video_Close_Keyframes,videoBox->videoDisplay->OverKeyFramesLoaded()); + MenuBar->Enable(Menu_Video_Save_Keyframes,videoBox->videoDisplay->OverKeyFramesLoaded()); // Set AR radio int arType = videoBox->videoDisplay->GetAspectRatioType(); @@ -888,21 +888,22 @@ void FrameMain::OnSnapToScene (wxCommandEvent &event) { int prev = 0; int next = 0; int frame = 0; - size_t n = videoBox->videoDisplay->KeyFrames.Count(); + wxArrayInt keyframes = videoBox->videoDisplay->GetKeyFrames(); + size_t n = keyframes.Count(); bool found = false; for (size_t i=0;ivideoDisplay->KeyFrames[i]; + frame = keyframes[i]; if (frame == curFrame) { prev = frame; - if (i < n-1) next = videoBox->videoDisplay->KeyFrames[i+1]; + if (i < n-1) next = keyframes[i+1]; else next = videoBox->videoDisplay->length; found = true; break; } if (frame > curFrame) { - if (i != 0) prev = videoBox->videoDisplay->KeyFrames[i-1]; + if (i != 0) prev = keyframes[i-1]; else prev = 0; next = frame; found = true; @@ -912,7 +913,7 @@ void FrameMain::OnSnapToScene (wxCommandEvent &event) { // Last section? if (!found) { - if (n > 0) prev = videoBox->videoDisplay->KeyFrames[n-1]; + if (n > 0) prev = keyframes[n-1]; else prev = 0; next = videoBox->videoDisplay->length; } diff --git a/core/video_display.cpp b/core/video_display.cpp index 4ce2cfc37..10f049e60 100644 --- a/core/video_display.cpp +++ b/core/video_display.cpp @@ -100,6 +100,7 @@ VideoDisplay::VideoDisplay(wxWindow* parent, wxWindowID id, const wxPoint& pos, PositionDisplay = NULL; loaded = false; keyFramesLoaded = false; + overKeyFramesLoaded = false; frame_n = 0; origSize = size; arType = 0; @@ -172,9 +173,6 @@ void VideoDisplay::SetVideo(const wxString &filename) { if (arType != 4) arValue = GetARFromType(arType); // 4 = custom provider->SetDAR(arValue); - KeyFrames.Clear(); - keyFramesLoaded = false; - // Why the hell was this disabled? // Read extra data from file bool mkvOpen = MatroskaWrapper::wrapper.IsOpen(); @@ -578,7 +576,7 @@ void VideoDisplay::UpdatePositionDisplay() { // Position display update PositionDisplay->SetValue(wxString::Format(_T("%01i:%02i:%02i.%03i - %i"),h,m,s,ms,frame_n)); - if (KeyFrames.Index(frame_n) != wxNOT_FOUND) { + if (GetKeyFrames().Index(frame_n) != wxNOT_FOUND) { PositionDisplay->SetBackgroundColour(Options.AsColour(_T("Grid selection background"))); PositionDisplay->SetForegroundColour(Options.AsColour(_T("Grid selection foreground"))); } @@ -932,3 +930,40 @@ wxString VideoDisplay::GetTempWorkFile () { } return tempfile; } + + +///////////////// +// Get keyframes +wxArrayInt VideoDisplay::GetKeyFrames() { + if (OverKeyFramesLoaded()) return overKeyFrames; + return KeyFrames; +} + + +///////////////// +// Set keyframes +void VideoDisplay::SetKeyFrames(wxArrayInt frames) { + KeyFrames = frames; +} + + +///////////////////////// +// Set keyframe override +void VideoDisplay::SetOverKeyFrames(wxArrayInt frames) { + overKeyFrames = frames; +} + + +/////////////////// +// Close keyframes +void VideoDisplay::CloseOverKeyFrames() { + overKeyFrames.Clear(); + overKeyFramesLoaded = false; +} + + +////////////////////////////////////////// +// Check if override keyframes are loaded +bool VideoDisplay::OverKeyFramesLoaded() { + return overKeyFramesLoaded; +} diff --git a/core/video_display.h b/core/video_display.h index 1a5be1995..71a32094c 100644 --- a/core/video_display.h +++ b/core/video_display.h @@ -71,6 +71,11 @@ private: bool threaded; int nextFrame; + bool keyFramesLoaded; + bool overKeyFramesLoaded; + wxArrayInt KeyFrames; + wxArrayInt overKeyFrames; + clock_t PlayTime; clock_t StartTime; wxTimer Playback; @@ -97,10 +102,13 @@ private: void DrawTrackingOverlay( wxDC &dc ); public: - VideoProvider *provider; + wxArrayInt GetKeyFrames(); + void SetKeyFrames(wxArrayInt frames); + void SetOverKeyFrames(wxArrayInt frames); + void CloseOverKeyFrames(); + bool OverKeyFramesLoaded(); - bool keyFramesLoaded; - wxArrayInt KeyFrames; + VideoProvider *provider; SubtitlesGrid *grid; wxString videoName; diff --git a/core/video_slider.cpp b/core/video_slider.cpp index a213113d5..c9eff6c5d 100644 --- a/core/video_slider.cpp +++ b/core/video_slider.cpp @@ -189,14 +189,15 @@ void VideoSlider::OnMouse(wxMouseEvent &event) { if (canDrag) { // Shift click to snap to keyframe if (shift && Display) { - int keys = Display->KeyFrames.Count(); + wxArrayInt KeyFrames = Display->GetKeyFrames(); + int keys = KeyFrames.Count(); int clickedFrame = GetValueAtX(x); int closest = 0; int cur; // Find closest for (int i=0;iKeyFrames[i]; + cur = KeyFrames[i]; if (abs(cur-clickedFrame) < abs(closest-clickedFrame)) { closest = cur; } @@ -331,7 +332,8 @@ void VideoSlider::OnKeyDown(wxKeyEvent &event) { // Prepare int prevKey = 0; int nextKey = Display->length-1; - int keys = Display->KeyFrames.Count(); + wxArrayInt KeyFrames = Display->GetKeyFrames(); + int keys = KeyFrames.Count(); int cur = Display->frame_n; int i; int temp; @@ -339,14 +341,14 @@ void VideoSlider::OnKeyDown(wxKeyEvent &event) { // Find previous keyframe // This algorithm does unnecessary loops, but it ensures it works even if keyframes are out of order. for (i=0;iKeyFrames[i]; + temp = KeyFrames[i]; if (temp < cur && temp > prevKey) prevKey = temp; } // Find next keyframe for (i=0;iKeyFrames[i]; - if (temp > cur && temp < nextKey) nextKey = Display->KeyFrames[i]; + temp = KeyFrames[i]; + if (temp > cur && temp < nextKey) nextKey = KeyFrames[i]; } if (direction == -1) Display->JumpToFrame(prevKey); @@ -421,9 +423,10 @@ void VideoSlider::DrawImage(wxDC &dc) { int curX; if (Display && Options.AsBool(_T("Show keyframes on video slider"))) { dc.SetPen(wxPen(shad)); - int keys = Display->KeyFrames.Count(); + wxArrayInt KeyFrames = Display->GetKeyFrames(); + int keys = KeyFrames.Count(); for (int i=0;iKeyFrames[i]); + curX = GetXAtValue(KeyFrames[i]); dc.DrawLine(curX,2,curX,8); } }