mirror of https://github.com/odrling/Aegisub
Changes to VideoDisplay class to allow the new keyframe functionality to work
Originally committed to SVN as r573.
This commit is contained in:
parent
caba16ae8b
commit
dd1ed05e21
|
@ -232,7 +232,8 @@ void AudioDisplay::UpdateImage(bool weak) {
|
||||||
|
|
||||||
// Draw keyframes
|
// Draw keyframes
|
||||||
if (video->loaded && draw_boundary_lines) {
|
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));
|
dc.SetPen(wxPen(wxColour(255,0,255),1));
|
||||||
|
|
||||||
// Get min and max frames to care about
|
// Get min and max frames to care about
|
||||||
|
@ -241,7 +242,7 @@ void AudioDisplay::UpdateImage(bool weak) {
|
||||||
|
|
||||||
// Scan list
|
// Scan list
|
||||||
for (int i=0;i<nKeys;i++) {
|
for (int i=0;i<nKeys;i++) {
|
||||||
int cur = video->KeyFrames[i];
|
int cur = KeyFrames[i];
|
||||||
if (cur >= minFrame && cur <= maxFrame) {
|
if (cur >= minFrame && cur <= maxFrame) {
|
||||||
int x = GetXAtMS(VFR_Output.GetTimeAtFrame(cur,true));
|
int x = GetXAtMS(VFR_Output.GetTimeAtFrame(cur,true));
|
||||||
dc.DrawLine(x,0,x,h);
|
dc.DrawLine(x,0,x,h);
|
||||||
|
|
|
@ -501,7 +501,7 @@ void DialogTimingProcessor::Process() {
|
||||||
// Keyframe snapping
|
// Keyframe snapping
|
||||||
if (keysEnable->IsChecked()) {
|
if (keysEnable->IsChecked()) {
|
||||||
// Get keyframes
|
// Get keyframes
|
||||||
KeyFrames = grid->video->KeyFrames;
|
KeyFrames = grid->video->GetKeyFrames();
|
||||||
KeyFrames.Add(grid->video->length-1);
|
KeyFrames.Add(grid->video->length-1);
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
|
|
|
@ -290,8 +290,8 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) {
|
||||||
MenuBar->Enable(Menu_Video_AR_235,state);
|
MenuBar->Enable(Menu_Video_AR_235,state);
|
||||||
MenuBar->Enable(Menu_Video_AR_Custom,state);
|
MenuBar->Enable(Menu_Video_AR_Custom,state);
|
||||||
MenuBar->Enable(Menu_File_Close_VFR,VFR_Output.GetFrameRateType() == VFR);
|
MenuBar->Enable(Menu_File_Close_VFR,VFR_Output.GetFrameRateType() == VFR);
|
||||||
MenuBar->Enable(Menu_Video_Close_Keyframes,videoBox->videoDisplay->keyFramesLoaded);
|
MenuBar->Enable(Menu_Video_Close_Keyframes,videoBox->videoDisplay->OverKeyFramesLoaded());
|
||||||
MenuBar->Enable(Menu_Video_Save_Keyframes,videoBox->videoDisplay->keyFramesLoaded);
|
MenuBar->Enable(Menu_Video_Save_Keyframes,videoBox->videoDisplay->OverKeyFramesLoaded());
|
||||||
|
|
||||||
// Set AR radio
|
// Set AR radio
|
||||||
int arType = videoBox->videoDisplay->GetAspectRatioType();
|
int arType = videoBox->videoDisplay->GetAspectRatioType();
|
||||||
|
@ -888,21 +888,22 @@ void FrameMain::OnSnapToScene (wxCommandEvent &event) {
|
||||||
int prev = 0;
|
int prev = 0;
|
||||||
int next = 0;
|
int next = 0;
|
||||||
int frame = 0;
|
int frame = 0;
|
||||||
size_t n = videoBox->videoDisplay->KeyFrames.Count();
|
wxArrayInt keyframes = videoBox->videoDisplay->GetKeyFrames();
|
||||||
|
size_t n = keyframes.Count();
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (size_t i=0;i<n;i++) {
|
for (size_t i=0;i<n;i++) {
|
||||||
frame = videoBox->videoDisplay->KeyFrames[i];
|
frame = keyframes[i];
|
||||||
|
|
||||||
if (frame == curFrame) {
|
if (frame == curFrame) {
|
||||||
prev = frame;
|
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;
|
else next = videoBox->videoDisplay->length;
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frame > curFrame) {
|
if (frame > curFrame) {
|
||||||
if (i != 0) prev = videoBox->videoDisplay->KeyFrames[i-1];
|
if (i != 0) prev = keyframes[i-1];
|
||||||
else prev = 0;
|
else prev = 0;
|
||||||
next = frame;
|
next = frame;
|
||||||
found = true;
|
found = true;
|
||||||
|
@ -912,7 +913,7 @@ void FrameMain::OnSnapToScene (wxCommandEvent &event) {
|
||||||
|
|
||||||
// Last section?
|
// Last section?
|
||||||
if (!found) {
|
if (!found) {
|
||||||
if (n > 0) prev = videoBox->videoDisplay->KeyFrames[n-1];
|
if (n > 0) prev = keyframes[n-1];
|
||||||
else prev = 0;
|
else prev = 0;
|
||||||
next = videoBox->videoDisplay->length;
|
next = videoBox->videoDisplay->length;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,7 @@ VideoDisplay::VideoDisplay(wxWindow* parent, wxWindowID id, const wxPoint& pos,
|
||||||
PositionDisplay = NULL;
|
PositionDisplay = NULL;
|
||||||
loaded = false;
|
loaded = false;
|
||||||
keyFramesLoaded = false;
|
keyFramesLoaded = false;
|
||||||
|
overKeyFramesLoaded = false;
|
||||||
frame_n = 0;
|
frame_n = 0;
|
||||||
origSize = size;
|
origSize = size;
|
||||||
arType = 0;
|
arType = 0;
|
||||||
|
@ -172,9 +173,6 @@ void VideoDisplay::SetVideo(const wxString &filename) {
|
||||||
if (arType != 4) arValue = GetARFromType(arType); // 4 = custom
|
if (arType != 4) arValue = GetARFromType(arType); // 4 = custom
|
||||||
provider->SetDAR(arValue);
|
provider->SetDAR(arValue);
|
||||||
|
|
||||||
KeyFrames.Clear();
|
|
||||||
keyFramesLoaded = false;
|
|
||||||
|
|
||||||
// Why the hell was this disabled?
|
// Why the hell was this disabled?
|
||||||
// Read extra data from file
|
// Read extra data from file
|
||||||
bool mkvOpen = MatroskaWrapper::wrapper.IsOpen();
|
bool mkvOpen = MatroskaWrapper::wrapper.IsOpen();
|
||||||
|
@ -578,7 +576,7 @@ void VideoDisplay::UpdatePositionDisplay() {
|
||||||
|
|
||||||
// Position display update
|
// Position display update
|
||||||
PositionDisplay->SetValue(wxString::Format(_T("%01i:%02i:%02i.%03i - %i"),h,m,s,ms,frame_n));
|
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->SetBackgroundColour(Options.AsColour(_T("Grid selection background")));
|
||||||
PositionDisplay->SetForegroundColour(Options.AsColour(_T("Grid selection foreground")));
|
PositionDisplay->SetForegroundColour(Options.AsColour(_T("Grid selection foreground")));
|
||||||
}
|
}
|
||||||
|
@ -932,3 +930,40 @@ wxString VideoDisplay::GetTempWorkFile () {
|
||||||
}
|
}
|
||||||
return tempfile;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -71,6 +71,11 @@ private:
|
||||||
bool threaded;
|
bool threaded;
|
||||||
int nextFrame;
|
int nextFrame;
|
||||||
|
|
||||||
|
bool keyFramesLoaded;
|
||||||
|
bool overKeyFramesLoaded;
|
||||||
|
wxArrayInt KeyFrames;
|
||||||
|
wxArrayInt overKeyFrames;
|
||||||
|
|
||||||
clock_t PlayTime;
|
clock_t PlayTime;
|
||||||
clock_t StartTime;
|
clock_t StartTime;
|
||||||
wxTimer Playback;
|
wxTimer Playback;
|
||||||
|
@ -97,10 +102,13 @@ private:
|
||||||
void DrawTrackingOverlay( wxDC &dc );
|
void DrawTrackingOverlay( wxDC &dc );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VideoProvider *provider;
|
wxArrayInt GetKeyFrames();
|
||||||
|
void SetKeyFrames(wxArrayInt frames);
|
||||||
|
void SetOverKeyFrames(wxArrayInt frames);
|
||||||
|
void CloseOverKeyFrames();
|
||||||
|
bool OverKeyFramesLoaded();
|
||||||
|
|
||||||
bool keyFramesLoaded;
|
VideoProvider *provider;
|
||||||
wxArrayInt KeyFrames;
|
|
||||||
|
|
||||||
SubtitlesGrid *grid;
|
SubtitlesGrid *grid;
|
||||||
wxString videoName;
|
wxString videoName;
|
||||||
|
|
|
@ -189,14 +189,15 @@ void VideoSlider::OnMouse(wxMouseEvent &event) {
|
||||||
if (canDrag) {
|
if (canDrag) {
|
||||||
// Shift click to snap to keyframe
|
// Shift click to snap to keyframe
|
||||||
if (shift && Display) {
|
if (shift && Display) {
|
||||||
int keys = Display->KeyFrames.Count();
|
wxArrayInt KeyFrames = Display->GetKeyFrames();
|
||||||
|
int keys = KeyFrames.Count();
|
||||||
int clickedFrame = GetValueAtX(x);
|
int clickedFrame = GetValueAtX(x);
|
||||||
int closest = 0;
|
int closest = 0;
|
||||||
int cur;
|
int cur;
|
||||||
|
|
||||||
// Find closest
|
// Find closest
|
||||||
for (int i=0;i<keys;i++) {
|
for (int i=0;i<keys;i++) {
|
||||||
cur = Display->KeyFrames[i];
|
cur = KeyFrames[i];
|
||||||
if (abs(cur-clickedFrame) < abs(closest-clickedFrame)) {
|
if (abs(cur-clickedFrame) < abs(closest-clickedFrame)) {
|
||||||
closest = cur;
|
closest = cur;
|
||||||
}
|
}
|
||||||
|
@ -331,7 +332,8 @@ void VideoSlider::OnKeyDown(wxKeyEvent &event) {
|
||||||
// Prepare
|
// Prepare
|
||||||
int prevKey = 0;
|
int prevKey = 0;
|
||||||
int nextKey = Display->length-1;
|
int nextKey = Display->length-1;
|
||||||
int keys = Display->KeyFrames.Count();
|
wxArrayInt KeyFrames = Display->GetKeyFrames();
|
||||||
|
int keys = KeyFrames.Count();
|
||||||
int cur = Display->frame_n;
|
int cur = Display->frame_n;
|
||||||
int i;
|
int i;
|
||||||
int temp;
|
int temp;
|
||||||
|
@ -339,14 +341,14 @@ void VideoSlider::OnKeyDown(wxKeyEvent &event) {
|
||||||
// Find previous keyframe
|
// Find previous keyframe
|
||||||
// This algorithm does unnecessary loops, but it ensures it works even if keyframes are out of order.
|
// This algorithm does unnecessary loops, but it ensures it works even if keyframes are out of order.
|
||||||
for (i=0;i<keys;i++) {
|
for (i=0;i<keys;i++) {
|
||||||
temp = Display->KeyFrames[i];
|
temp = KeyFrames[i];
|
||||||
if (temp < cur && temp > prevKey) prevKey = temp;
|
if (temp < cur && temp > prevKey) prevKey = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find next keyframe
|
// Find next keyframe
|
||||||
for (i=0;i<keys;i++) {
|
for (i=0;i<keys;i++) {
|
||||||
temp = Display->KeyFrames[i];
|
temp = KeyFrames[i];
|
||||||
if (temp > cur && temp < nextKey) nextKey = Display->KeyFrames[i];
|
if (temp > cur && temp < nextKey) nextKey = KeyFrames[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (direction == -1) Display->JumpToFrame(prevKey);
|
if (direction == -1) Display->JumpToFrame(prevKey);
|
||||||
|
@ -421,9 +423,10 @@ void VideoSlider::DrawImage(wxDC &dc) {
|
||||||
int curX;
|
int curX;
|
||||||
if (Display && Options.AsBool(_T("Show keyframes on video slider"))) {
|
if (Display && Options.AsBool(_T("Show keyframes on video slider"))) {
|
||||||
dc.SetPen(wxPen(shad));
|
dc.SetPen(wxPen(shad));
|
||||||
int keys = Display->KeyFrames.Count();
|
wxArrayInt KeyFrames = Display->GetKeyFrames();
|
||||||
|
int keys = KeyFrames.Count();
|
||||||
for (int i=0;i<keys;i++) {
|
for (int i=0;i<keys;i++) {
|
||||||
curX = GetXAtValue(Display->KeyFrames[i]);
|
curX = GetXAtValue(KeyFrames[i]);
|
||||||
dc.DrawLine(curX,2,curX,8);
|
dc.DrawLine(curX,2,curX,8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue