fix S10 code-review findings: WM_CAPTURECHANGED, proportional drag, paintSetup root source, Add Zone dedup, strip-area helpers

This commit is contained in:
2026-07-26 20:53:31 -04:00
parent 7151e19432
commit b9ad1ee18f
3 changed files with 90 additions and 25 deletions
+14 -6
View File
@@ -106,12 +106,20 @@ int resolveDragNote(const StripLayout& layout, int startNote, int dxPixels) {
if (dxPixels == 0) return clampNote(startNote);
const int bandWidth = std::max(0, layout.keys.width());
if (bandWidth <= 0) return clampNote(startNote); // zero-width -> no motion
// Key width in pixels (>= 1 via the max). Round the delta to the nearest key so a
// half-key drag flips at the key centre: add/subtract half a key before the divide.
const int keyW = std::max(1, bandWidth / kStripKeyCount);
const int half = keyW / 2;
const int shift = dxPixels >= 0 ? (dxPixels + half) / keyW
: -((-dxPixels + half) / keyW);
// Proportional shift: same linear mapping as keyAtPoint/keyEdgeToX so click and drag
// agree across the full strip, even on non-divisible-by-128 widths. The proportional
// key width is (bandWidth / kStripKeyCount) in exact rational arithmetic; rounding to
// the nearest key (half-key drag flips at the key centre) is achieved by adding
// bandWidth/2 to the absolute pixel delta before dividing — identical to the old
// formula except keyWidth is now derived from the same linear map (exact rational)
// rather than the truncated-integer bandWidth/128 that caused drift at the far end.
const int half = bandWidth / 2;
int shift;
if (dxPixels > 0) {
shift = (dxPixels * kStripKeyCount + half) / bandWidth;
} else {
shift = -(((-dxPixels) * kStripKeyCount + half) / bandWidth);
}
return clampNote(startNote + shift);
}