13
0

Simplify snap-to magnetic distance calc

This commit is contained in:
Robin Gareus 2020-04-05 20:09:42 +02:00
parent 6b9bdbf0ff
commit 14a2a50e93
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04

View File

@ -3020,22 +3020,18 @@ Editor::snap_to_internal (MusicSample& start, RoundMode direction, SnapPref pref
check_best_snap (presnap, post.sample, dist, best);
}
if (max_samplepos == best) {
return;
}
/* now check "magnetic" state: is the grid within reasonable on-screen distance to trigger a snap?
* this also helps to avoid snapping to somewhere the user can't see. (i.e.: I clicked on a region and it disappeared!!)
* ToDo: Perhaps this should only occur if EditPointMouse?
*/
int snap_threshold_s = pixel_to_sample (uic.get_snap_threshold());
if (ensure_snap) {
start.set (best, 0);
samplecnt_t snap_threshold_s = pixel_to_sample (uic.get_snap_threshold ());
if (!ensure_snap && ::llabs (presnap - best) > snap_threshold_s) {
return;
} else if (presnap > best) {
if (presnap > (best+ snap_threshold_s)) {
best = presnap;
}
} else if (presnap < best) {
if (presnap < (best - snap_threshold_s)) {
best = presnap;
}
}
start.set (best, 0);