mirror of https://github.com/odrling/Aegisub
Timecodes and keyframes are always sorted, so fix some code that assumed they could be unsorted
Originally committed to SVN as r5083.
This commit is contained in:
parent
17c07cc131
commit
4fdad923ad
|
@ -92,7 +92,6 @@ class AudioMarkerProviderKeyframes : public AudioMarkerProvider {
|
|||
keyframe_samples.push_back(AudioMarkerKeyframe(
|
||||
controller->SamplesFromMilliseconds(vc->TimeAtFrame(raw_keyframes[i]))));
|
||||
}
|
||||
std::sort(keyframe_samples.begin(), keyframe_samples.end());
|
||||
AnnounceMarkerMoved();
|
||||
}
|
||||
|
||||
|
|
|
@ -199,46 +199,20 @@ void MatroskaWrapper::Parse() {
|
|||
}
|
||||
}
|
||||
|
||||
// Copy raw
|
||||
for (std::list<MkvFrame>::iterator cur=frames.begin();cur!=frames.end();cur++) {
|
||||
rawFrames.push_back(*cur);
|
||||
}
|
||||
rawFrames.reserve(frames.size());
|
||||
std::copy(frames.begin(), frames.end(), std::back_inserter(rawFrames));
|
||||
|
||||
bool sortFirst = true;
|
||||
if (sortFirst) {
|
||||
// Process timecodes and keyframes
|
||||
frames.sort();
|
||||
MkvFrame curFrame(false,0,0);
|
||||
int i = 0;
|
||||
for (std::list<MkvFrame>::iterator cur=frames.begin();cur!=frames.end();cur++) {
|
||||
curFrame = *cur;
|
||||
if (curFrame.isKey) keyFrames.push_back(i);
|
||||
bytePos.Add(curFrame.filePos);
|
||||
timecodes.push_back(curFrame.time);
|
||||
if (cur->isKey) keyFrames.push_back(i);
|
||||
bytePos.Add(cur->filePos);
|
||||
timecodes.push_back(cur->time);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
// Process keyframes
|
||||
MkvFrame curFrame(false,0,0);
|
||||
int i = 0;
|
||||
for (std::list<MkvFrame>::iterator cur=frames.begin();cur!=frames.end();cur++) {
|
||||
curFrame = *cur;
|
||||
if (curFrame.isKey) keyFrames.push_back(i);
|
||||
bytePos.Add(curFrame.filePos);
|
||||
i++;
|
||||
}
|
||||
|
||||
// Process timecodes
|
||||
frames.sort();
|
||||
for (std::list<MkvFrame>::iterator cur=frames.begin();cur!=frames.end();cur++) {
|
||||
curFrame = *cur;
|
||||
timecodes.push_back(curFrame.time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int mkv_round(double num) {
|
||||
return (int)(num + .5);
|
||||
}
|
||||
|
|
|
@ -346,26 +346,14 @@ void VideoSlider::OnKeyDown(wxKeyEvent &event) {
|
|||
// Snap to keyframe
|
||||
if (shift && !ctrl && !alt) {
|
||||
if (direction != 0) {
|
||||
// Prepare
|
||||
int prevKey = 0;
|
||||
int nextKey = max;
|
||||
int keys = keyframes.size();
|
||||
std::vector<int>::iterator pos = std::lower_bound(keyframes.begin(), keyframes.end(), val);
|
||||
|
||||
// Find previous keyframe
|
||||
// This algorithm does unnecessary loops, but it ensures it works even if keyframes are out of order.
|
||||
for (int i=0;i<keys;i++) {
|
||||
int temp = keyframes[i];
|
||||
if (temp < val && temp > prevKey) prevKey = temp;
|
||||
}
|
||||
if (direction < 0 && val != 0 && (pos == keyframes.end() || *pos == val))
|
||||
--pos;
|
||||
if (direction > 0 && pos != keyframes.end())
|
||||
++pos;
|
||||
|
||||
// Find next keyframe
|
||||
for (int i=0;i<keys;i++) {
|
||||
int temp = keyframes[i];
|
||||
if (temp > val && temp < nextKey) nextKey = temp;
|
||||
}
|
||||
|
||||
if (direction == -1) VideoContext::Get()->JumpToFrame(prevKey);
|
||||
if (direction == 1) VideoContext::Get()->JumpToFrame(nextKey);
|
||||
VideoContext::Get()->JumpToFrame(pos == keyframes.end() ? max : *pos);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue