Add filter automation and kick-ducking sidechain to the DAWproject

Low-pass Equalizer band with automated cutoff on Saw Bass, Pad and Lead;
fader-ducking automation generated from the kick notes (DAWproject has no
sidechain routing). New --no-automation flag; READMEs updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
valknarandClaude Sonnet 5.5 committed 2026-11-25 10:39:10 +01:00
1 parent 3e3776a20d
commit fa33c7fd68
4 files changed
+196 -19

No files matched your search

+139 -6
View File
@@ -7,8 +7,9 @@ Generates (stdlib only, deterministic):
midi/full_arrangement.mid all tracks, one SMF type 1 file
midi/NN_<track>.mid one full-length MIDI file per track
Usage: python3 build_track.py [--devices]
--devices add instrument-device hints to each track (default: bare note tracks)
Usage: python3 build_track.py [--devices] [--no-automation]
--devices add instrument-device hints to each track
--no-automation leave out the filter automation and kick-ducking (bare note tracks)
"""
import os
import random
@@ -508,6 +509,105 @@ def write_midi(path, tracks):
f.write(header + b"".join(chunks))
# ---------------------------------------------------------------- automation
# Filter: a low-pass band on a standard DAWproject Equalizer, cutoff automated in Hz.
# Sidechain: DAWproject has no sidechain routing, so the kick "pump" is written as
# volume-ducking automation on the channel faders (synchronised to the kick notes).
FILTERS = { # track -> (Q, filter order)
"Saw Bass": (1.6, 4),
"Pad": (0.8, 2),
"Lead": (1.4, 2),
}
DUCK = { # track -> (depth = fraction of fader level at the kick hit, release in beats)
"Saw Bass": (0.45, 0.5),
"Pad": (0.25, 0.8),
"Lead": (0.45, 0.5),
}
def hold(pts, bar0, bar1, hz):
pts += [(bar0 * 4.0, hz), (bar1 * 4.0, hz)]
def sweep(pts, bar0, bar1, f0, f1):
"""Exponential (log-frequency) cutoff sweep, one breakpoint per bar."""
n = max(1, bar1 - bar0)
for i in range(n + 1):
pts.append(((bar0 + i) * 4.0, f0 * (f1 / f0) ** (i / n)))
def tidy(pts):
"""Make breakpoint times strictly increasing (a reset becomes a 1/16-beat snap)."""
pts = sorted(pts, key=lambda p: p[0])
for i in range(len(pts) - 2, -1, -1):
if pts[i][0] >= pts[i + 1][0]:
pts[i] = (pts[i + 1][0] - 0.0625, pts[i][1])
return pts
def filter_curves():
"""Cutoff breakpoints in Hz, as {track: [(beat, hz)]}; bars are 0-based."""
bass = []
hold(bass, 0, 48, 150)
sweep(bass, 48, 56, 180, 450) # Build 1: offbeat bass creeps in
sweep(bass, 56, 64, 450, 3200) # Build 1: rolling bass opens up
for i in range(8): # Drop 1: one sweep per 8-bar phrase, ever brighter
sweep(bass, 64 + 8 * i, 72 + 8 * i, 500 + 50 * i, 1500 + 150 * i)
hold(bass, 128, 136, 250) # Breakdown: dark drone ...
sweep(bass, 136, 160, 250, 1200) # ... slowly opening
hold(bass, 160, 172, 600)
sweep(bass, 172, 180, 350, 800) # Build 2: offbeat bass
sweep(bass, 180, 192, 800, 4200) # Build 2: rolling bass opens
for i in range(12): # Drop 2: sweeps get wider every phrase
sweep(bass, 192 + 8 * i, 200 + 8 * i, 900 + 60 * i, min(2200 + 250 * i, 5000))
sweep(bass, 288, 304, 3500, 1500) # Outro: closing down
sweep(bass, 304, 312, 1500, 400)
hold(bass, 312, 320, 400)
pad = []
hold(pad, 0, 128, 400)
sweep(pad, 128, 160, 400, 4500) # Breakdown: pad blooms
hold(pad, 160, 176, 1500)
sweep(pad, 176, 192, 1500, 6000) # Build 2: pad opens into the drop
for i in range(6): # Drop 2: breathing over 16 bars
sweep(pad, 192 + 16 * i, 200 + 16 * i, 2500, 4500)
sweep(pad, 200 + 16 * i, 208 + 16 * i, 4500, 2500)
hold(pad, 288, 320, 2500)
lead = []
hold(lead, 0, 128, 1200)
sweep(lead, 128, 160, 1200, 3500) # Breakdown: melody brightens
hold(lead, 160, 176, 900)
sweep(lead, 176, 192, 900, 7000) # Build 2: arp sweeps wide open
hold(lead, 192, 200, 7000)
for i in range(11): # Drop 2: alternate closing and opening
if i % 2 == 0:
sweep(lead, 200 + 8 * i, 208 + 8 * i, 7000, 3000)
else:
sweep(lead, 200 + 8 * i, 208 + 8 * i, 3000, 7000)
hold(lead, 288, 320, 3500)
return {"Saw Bass": tidy(bass), "Pad": tidy(pad), "Lead": tidy(lead)}
def duck_points(kick_notes, base, depth, release):
"""Fader automation: drop to base*depth on every kick, recover over `release` beats."""
ons = sorted({n[0] for n in kick_notes})
pts = []
ducked = False
if not ons or ons[0] > 0:
pts.append((0.0, base, "hold"))
for i, t in enumerate(ons):
if not ducked:
pts.append((t, base * depth, "linear"))
ducked = True
nxt = ons[i + 1] if i + 1 < len(ons) else None
if nxt is not None and nxt - t <= release + 0.05:
continue # next kick arrives before recovery: stay ducked (kick roll)
pts.append((t + release, base, "hold"))
ducked = False
return pts
# ---------------------------------------------------------------- DAWproject writer
def fmt(x):
return ("%.5f" % x).rstrip("0").rstrip(".")
@@ -529,8 +629,11 @@ def chunk_clips(notes):
return out
def build_dawproject(path, tracks, devices):
def build_dawproject(path, tracks, devices, automation=True):
q = quoteattr
kick = next(t[1] for t in tracks if t[0] == "Kick 808")
curves = filter_curves() if automation else {}
n_points = 0
x = ['<?xml version="1.0" encoding="UTF-8"?>',
'<Project version="1.0">',
' <Application name="build_track.py" version="1.0"/>',
@@ -542,9 +645,21 @@ def build_dawproject(path, tracks, devices):
for i, (name, notes, ch, color, vol, pan, dev) in enumerate(tracks):
x.append(' <Track contentType="notes" loaded="true" id="t%d" name=%s color=%s>' % (i, q(name), q(color)))
x.append(' <Channel role="regular" audioChannels="2" destination="c_master" id="c%d">' % i)
if devices:
has_filter = automation and name in FILTERS
if devices or has_filter:
x.append(' <Devices>')
x.append(' <BuiltinDevice deviceName=%s deviceRole=%s id="d%d"/>' % (q(dev[0]), q(dev[1]), i))
if devices:
x.append(' <BuiltinDevice deviceName=%s deviceRole=%s id="d%d"/>' % (q(dev[0]), q(dev[1]), i))
if has_filter:
fq, order = FILTERS[name]
x.append(' <Equalizer deviceName="Filter" deviceRole="audioFX" id="eq%d">' % i)
x.append(' <Band type="lowPass" order="%d">' % order)
x.append(' <Freq unit="hertz" value="%s" min="20" max="20000" id="flt%d"/>'
% (fmt(curves[name][0][1]), i))
x.append(' <Q unit="linear" value="%s" min="0.1" max="10" id="flq%d"/>' % (fmt(fq), i))
x.append(' <Enabled value="true" id="fle%d"/>' % i)
x.append(' </Band>')
x.append(' </Equalizer>')
x.append(' </Devices>')
x.append(' <Pan unit="normalized" value="%s" id="pan%d"/>' % (fmt(pan), i))
x.append(' <Volume unit="linear" value="%s" id="vol%d"/>' % (fmt(vol), i))
@@ -571,6 +686,22 @@ def build_dawproject(path, tracks, devices):
x.append(' </Notes>')
x.append(' </Clip>')
x.append(' </Clips>')
if automation and name in FILTERS:
x.append(' <Points id="auto_flt%d" unit="hertz" timeUnit="beats">' % i)
x.append(' <Target parameter="flt%d"/>' % i)
for t, hz in curves[name]:
x.append(' <RealPoint time="%s" value="%s" interpolation="linear"/>' % (fmt(t), fmt(hz)))
x.append(' </Points>')
n_points += len(curves[name])
if automation and name in DUCK:
depth, rel = DUCK[name]
dp = duck_points(kick, vol, depth, rel)
x.append(' <Points id="auto_duck%d" unit="linear" timeUnit="beats">' % i)
x.append(' <Target parameter="vol%d"/>' % i)
for t, v, interp in dp:
x.append(' <RealPoint time="%s" value="%s" interpolation="%s"/>' % (fmt(t), fmt(v), interp))
x.append(' </Points>')
n_points += len(dp)
x.append(' </Lanes>')
x.append(' </Lanes>')
x.append(' <Markers id="markers">')
@@ -586,6 +717,7 @@ def build_dawproject(path, tracks, devices):
with zipfile.ZipFile(path, "w", zipfile.ZIP_DEFLATED) as z:
z.writestr("metadata.xml", meta_xml)
z.writestr("project.xml", "\n".join(x) + "\n")
return n_points
def main():
@@ -597,11 +729,12 @@ def main():
slug = name.lower().replace(" ", "_")
write_midi(os.path.join(HERE, "midi", "%02d_%s.mid" % (i, slug)), [(name, ch, notes)])
out = os.path.join(HERE, "exit-progressive-emulation.dawproject")
build_dawproject(out, tracks, devices)
n_auto = build_dawproject(out, tracks, devices, automation="--no-automation" not in sys.argv)
secs = TOTAL_BARS * 4 * 60 / BPM
print("%s: %d bars @ %d BPM = %d:%02d" % (TITLE, TOTAL_BARS, BPM, secs // 60, secs % 60))
for name, notes, *_ in tracks:
print(" %-12s %5d notes" % (name, len(notes)))
print("automation breakpoints: %d" % n_auto)
print("wrote", out)