Changes to VideoDisplay class to allow the new keyframe functionality to work

Originally committed to SVN as r573.
This commit is contained in:
Rodrigo Braz Monteiro 2006-12-18 04:53:40 +00:00
parent caba16ae8b
commit dd1ed05e21
6 changed files with 73 additions and 25 deletions

View file

@ -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;i<nKeys;i++) {
int cur = video->KeyFrames[i];
int cur = KeyFrames[i];
if (cur >= minFrame && cur <= maxFrame) {
int x = GetXAtMS(VFR_Output.GetTimeAtFrame(cur,true));
dc.DrawLine(x,0,x,h);

View file

@ -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

View file

@ -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;i<n;i++) {
frame = videoBox->videoDisplay->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;
}

View file

@ -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;
}

View file

@ -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;

View file

@ -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;i<keys;i++) {
cur = Display->KeyFrames[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;i<keys;i++) {
temp = Display->KeyFrames[i];
temp = KeyFrames[i];
if (temp < cur && temp > prevKey) prevKey = temp;
}
// Find next keyframe
for (i=0;i<keys;i++) {
temp = Display->KeyFrames[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;i<keys;i++) {
curX = GetXAtValue(Display->KeyFrames[i]);
curX = GetXAtValue(KeyFrames[i]);
dc.DrawLine(curX,2,curX,8);
}
}