Apply swing to drum hits — offbeats shift with the groove

Drum hits on fractional beat positions now get pushed later by
the score's swing amount. Everything locks into the same pocket.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-25 21:48:31 -04:00
parent f4c3b2dd88
commit a77db557f3
+11 -3
View File
@@ -1614,12 +1614,20 @@ def render_score(score):
# Drum hits — render to separate buffer for sidechain trigger
drum_buf = numpy.zeros(total_samples, dtype=numpy.float32)
drum_swing = score.swing
for hit in score._drum_hits:
pos = hit.position
# Apply swing: hits on offbeats get pushed later
if drum_swing > 0:
beat_frac = pos % 1.0
# Offbeat = not on a downbeat (0.0) — shift 8th note upbeats
if 0.1 < beat_frac < 0.9:
pos += drum_swing * 0.15 # subtle swing on drum hits
if has_tempo_changes:
start = _beat_to_sample(hit.position, tempo_map)
start = _beat_to_sample(pos, tempo_map)
else:
start = int(hit.position * samples_per_beat)
if start >= total_samples:
start = int(pos * samples_per_beat)
if start >= total_samples or start < 0:
continue
remaining = total_samples - start
hit_len = min(int(SAMPLE_RATE * 0.5), remaining)