mirror of https://github.com/odrling/Aegisub
Fixed (I hope?) boundary snapping.
Originally committed to SVN as r728.
This commit is contained in:
parent
2d7af197ee
commit
71828a2df5
|
@ -1543,7 +1543,7 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
|
||||||
if (leftIsDown && x != lastX) {
|
if (leftIsDown && x != lastX) {
|
||||||
selStart = lastX;
|
selStart = lastX;
|
||||||
selEnd = x;
|
selEnd = x;
|
||||||
curStartMS = GetMSAtX(GetBoundarySnap(lastX,event.ShiftDown()?0:10));
|
curStartMS = GetBoundarySnap(GetMSAtX(lastX),event.ShiftDown()?0:10,true);
|
||||||
curEndMS = GetMSAtX(x);
|
curEndMS = GetMSAtX(x);
|
||||||
hold = 2;
|
hold = 2;
|
||||||
}
|
}
|
||||||
|
@ -1554,7 +1554,8 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
|
||||||
if (hold == 1 && buttonIsDown) {
|
if (hold == 1 && buttonIsDown) {
|
||||||
// Set new value
|
// Set new value
|
||||||
if (x != selStart) {
|
if (x != selStart) {
|
||||||
selStart = GetBoundarySnap(x,event.ShiftDown()?0:10);
|
int snapped = GetBoundarySnap(GetMSAtX(x),event.ShiftDown()?0:10,true);
|
||||||
|
selStart = GetXAtMS(snapped);
|
||||||
if (selStart > selEnd) {
|
if (selStart > selEnd) {
|
||||||
int temp = selStart;
|
int temp = selStart;
|
||||||
selStart = selEnd;
|
selStart = selEnd;
|
||||||
|
@ -1572,7 +1573,9 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
|
||||||
if (hold == 2 && buttonIsDown) {
|
if (hold == 2 && buttonIsDown) {
|
||||||
// Set new value
|
// Set new value
|
||||||
if (x != selEnd) {
|
if (x != selEnd) {
|
||||||
selEnd = GetBoundarySnap(x,event.ShiftDown()?0:10);
|
int snapped = GetBoundarySnap(GetMSAtX(x),event.ShiftDown()?0:10,false);
|
||||||
|
selEnd = GetXAtMS(snapped);
|
||||||
|
//selEnd = GetBoundarySnap(x,event.ShiftDown()?0:10,false);
|
||||||
if (selStart > selEnd) {
|
if (selStart > selEnd) {
|
||||||
int temp = selStart;
|
int temp = selStart;
|
||||||
selStart = selEnd;
|
selStart = selEnd;
|
||||||
|
@ -1665,18 +1668,26 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
|
||||||
|
|
||||||
////////////////////////
|
////////////////////////
|
||||||
// Get snap to boundary
|
// Get snap to boundary
|
||||||
int AudioDisplay::GetBoundarySnap(int x,int range) {
|
int AudioDisplay::GetBoundarySnap(int ms,int rangeX,bool start) {
|
||||||
// Range?
|
// Range?
|
||||||
if (range <= 0) return x;
|
if (rangeX <= 0) return ms;
|
||||||
|
|
||||||
|
// Convert range into miliseconds
|
||||||
|
int rangeMS = rangeX*samples*1000 / provider->GetSampleRate();
|
||||||
|
|
||||||
// Find the snap boundaries
|
// Find the snap boundaries
|
||||||
wxArrayInt boundaries;
|
wxArrayInt boundaries;
|
||||||
if (video->KeyFramesLoaded() && Options.AsBool(_T("Audio Draw Secondary Lines"))) {
|
if (video->KeyFramesLoaded() && Options.AsBool(_T("Audio Draw Secondary Lines"))) {
|
||||||
__int64 keyX;
|
__int64 keyMS;
|
||||||
wxArrayInt keyFrames = video->GetKeyFrames();
|
wxArrayInt keyFrames = video->GetKeyFrames();
|
||||||
|
int frame;
|
||||||
for (unsigned int i=0;i<keyFrames.Count();i++) {
|
for (unsigned int i=0;i<keyFrames.Count();i++) {
|
||||||
keyX = GetXAtMS(VFR_Output.GetTimeAtFrame(keyFrames[i],true));
|
frame = keyFrames[i];
|
||||||
if (keyX >= 0 && keyX < w) boundaries.Add(keyX);
|
if (!start) frame--;
|
||||||
|
if (frame < 0) frame = 0;
|
||||||
|
keyMS = VFR_Output.GetTimeAtFrame(frame,start);
|
||||||
|
//if (start) keyX++;
|
||||||
|
if (GetXAtMS(keyMS) >= 0 && GetXAtMS(keyMS) < w) boundaries.Add(keyMS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1705,24 +1716,24 @@ int AudioDisplay::GetBoundarySnap(int x,int range) {
|
||||||
// Get coordinates
|
// Get coordinates
|
||||||
shadeX1 = GetXAtMS(shade->Start.GetMS());
|
shadeX1 = GetXAtMS(shade->Start.GetMS());
|
||||||
shadeX2 = GetXAtMS(shade->End.GetMS());
|
shadeX2 = GetXAtMS(shade->End.GetMS());
|
||||||
if (shadeX1 >= 0 && shadeX1 < w) boundaries.Add(shadeX1);
|
if (shadeX1 >= 0 && shadeX1 < w) boundaries.Add(shade->Start.GetMS());
|
||||||
if (shadeX2 >= 0 && shadeX2 < w) boundaries.Add(shadeX2);
|
if (shadeX2 >= 0 && shadeX2 < w) boundaries.Add(shade->End.GetMS());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// See if x falls within range of any of them
|
// See if ms falls within range of any of them
|
||||||
int minDist = range+1;
|
int minDist = rangeMS+1;
|
||||||
int bestX = x;
|
int bestMS = ms;
|
||||||
for (unsigned int i=0;i<boundaries.Count();i++) {
|
for (unsigned int i=0;i<boundaries.Count();i++) {
|
||||||
if (abs(x-boundaries[i]) < minDist) {
|
if (abs(ms-boundaries[i]) < minDist) {
|
||||||
bestX = boundaries[i];
|
bestMS = boundaries[i];
|
||||||
minDist = abs(x-boundaries[i]);
|
minDist = abs(ms-boundaries[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return best match
|
// Return best match
|
||||||
return bestX;
|
return bestMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,7 @@ private:
|
||||||
void GetKaraokePos(__int64 &start,__int64 &end,bool cap);
|
void GetKaraokePos(__int64 &start,__int64 &end,bool cap);
|
||||||
void UpdatePosition(int pos,bool IsSample=false);
|
void UpdatePosition(int pos,bool IsSample=false);
|
||||||
|
|
||||||
int GetBoundarySnap(int x,int range);
|
int GetBoundarySnap(int x,int range,bool start=true);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AudioProvider *provider;
|
AudioProvider *provider;
|
||||||
|
|
Loading…
Reference in New Issue