Skip to content

Commit dd66f47

Browse files
corepunchclaude
andcommitted
dnb: seeded song forms, clip automation and a DAW-style arrangement strip
Every track draws its own form from the seed: how it reaches the first drop, what joins one drop to the next, how long each section runs (in whole phrases) and how each build winds up (snare roll, kick roll, filter build, or drums gone under the riser). Styles weight the choices, and the same seed gives each style different forms. Blocks carry automation: a level fade and a low-pass or high-pass sweep, played per voice by the Synth. A filter lane sweeps the whole mix. The shared producer pass staggers entries, pulls parts out before a phrase lands, teases the bass under builds and sheds parts through the outro. The strip merges lanes into tracks, shades its clips, draws their envelopes and drops the section ruler; rows are 25% taller. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent b63f685 commit dd66f47

20 files changed

Lines changed: 1292 additions & 197 deletions

File tree

‎apps/dnb/Controller.lua‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ local VIEWS = "apps/dnb/views/"
1818
-- modal menu) resumes the picture instead of leaping ahead.
1919
local PLAYBACK = {sampleRate = 44100, bufferSeconds = 0.3, frameInterval = 1 / 60, maxFrame = 0.1}
2020

21-
-- The arrangement strip's rows, ruler and lane-name column, in points.
22-
local TIMELINE = {rowHeight = 10, ruler = 10, labelWidth = 52, scale = 2}
21+
-- The arrangement strip's rows and track-name column, in points.
22+
local TIMELINE = {rowHeight = 17.5, labelWidth = 52, scale = 2}
2323

2424
local SECTION_TITLES = {intro = "Intro", build = "Build-up", drop = "Drop", breakdown = "Breakdown",
2525
outro = "Outro", halftime = "Half-time", blend = "Mixing in"}
@@ -224,7 +224,7 @@ function Controller:present(refs, stage)
224224
end
225225

226226
-- The arrangement strip around set bar `n` of `composer`, the playhead
227-
-- `fraction` into it and moving at `barsPerSecond`. Rows and blocks change
227+
-- `fraction` into it and moving at `barsPerSecond`. Rows and clips change
228228
-- only when another track comes into view; the playhead moves every frame.
229229
function Controller:showTimeline(composer, n, fraction, barsPerSecond)
230230
local timeline = self.timeline
@@ -237,7 +237,7 @@ function Controller:showTimeline(composer, n, fraction, barsPerSecond)
237237
self.timelineKey = key
238238
self.timelineRows = Timeline.rows(plans)
239239
refs = select(2, timeline:update({rows = self.timelineRows, headline = headline,
240-
rowHeight = TIMELINE.rowHeight, ruler = TIMELINE.ruler, labelWidth = TIMELINE.labelWidth}))
240+
rowHeight = TIMELINE.rowHeight, labelWidth = TIMELINE.labelWidth}))
241241
local data = Timeline.instances(plans, self.timelineRows)
242242
refs.timelineCanvas.draws = {{vertex = "timelineBlockVertex", fragment = "timelineBlockFragment",
243243
count = 6, instances = #data // Timeline.stride, data = data, blend = "alpha"}}
@@ -246,7 +246,6 @@ function Controller:showTimeline(composer, n, fraction, barsPerSecond)
246246
end
247247
local rows = #self.timelineRows
248248
local values = Timeline.values(n + fraction, barsPerSecond, rows)
249-
table.insert(values, TIMELINE.ruler / (TIMELINE.ruler + rows * TIMELINE.rowHeight))
250249
table.insert(values, self.window and self.window.backingScaleFactor or TIMELINE.scale)
251250
refs.timelineCanvas.values = values
252251
end

‎apps/dnb/Model.lua‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Model.partGroups = {
1414
{family = "bass", parts = {"sub", "reese"}},
1515
{family = "chords", parts = {"pads", "keys", "stabs"}},
1616
{family = "melody", parts = {"arp", "lead"}},
17-
{family = "structure", parts = {"fills", "risers", "halftime", "throws", "chops"}},
17+
{family = "structure", parts = {"fills", "risers", "filter", "halftime", "throws", "chops"}},
1818
}
1919
Model.parts, Model.family = {}, {}
2020
for _, group in ipairs(Model.partGroups) do
@@ -24,6 +24,27 @@ for _, group in ipairs(Model.partGroups) do
2424
end
2525
end
2626

27+
-- The timeline's tracks, as an arrange window groups them: a track shows
28+
-- the blocks of its parts as clips and their notes inside. The switches
29+
-- (half-time, throws, chops) have no track; they show in the notes they
30+
-- change.
31+
Model.tracks = {
32+
{id = "kick", parts = {"kick"}},
33+
{id = "snare", parts = {"snare", "ghosts"}},
34+
{id = "hats", parts = {"hats", "ride"}},
35+
{id = "percussion", parts = {"percussion"}},
36+
{id = "break", parts = {"amen"}},
37+
{id = "bass", parts = {"sub", "reese"}},
38+
{id = "pads", parts = {"pads"}},
39+
{id = "keys", parts = {"keys"}},
40+
{id = "stabs", parts = {"stabs"}},
41+
{id = "arp", parts = {"arp"}},
42+
{id = "lead", parts = {"lead"}},
43+
{id = "fills", parts = {"fills"}},
44+
{id = "fx", parts = {"risers"}},
45+
{id = "filter", parts = {"filter"}},
46+
}
47+
2748
-- `format` renders the value label beside each slider.
2849
local function percent(v) return string.format("%d%%", math.floor(v * 100 + 0.5)) end
2950
Model.controlGroups = {

‎apps/dnb/README.md‎

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ mix between, each new intro mixed under the outgoing tune.
2020
The visualizer fills the window, running under the Liquid Glass toolbar;
2121
the now-playing cards, the arrangement strip and the Groove, Sound and Mix
2222
sliders float over it in glass. Each track is arranged before it plays, like
23-
the arrange window of Cubase or MTV Music Generator: a ruler of sections and
24-
one lane of blocks per part. The strip scrolls those blocks right to left
25-
past a fixed playhead, brightens the ones playing and shows the next section
26-
change coming. The style decides which parts its songs play; the listener shapes
23+
the arrange window of Cubase or MTV Music Generator: sections, and one lane
24+
of blocks per part. The strip draws them as an arrange window
25+
does, one track per instrument (Snare holds the ghosts, Hats the ride, Bass
26+
the sub and the reese) with softly shaded clips that show the fade or filter
27+
sweep riding them. It scrolls right to left past a fixed playhead, lights
28+
the clips that sound and shows the next section change coming. The style decides which parts its songs play; the listener shapes
2729
them with the sliders, and the Mix faders (Drums, Bass, Chords, Melody)
2830
scale the style's own balance. The Style menu switches genre on the next bar
2931
line. The Scene menu pins one visualizer scene
@@ -55,13 +57,35 @@ The host's [`Composer`](host/Composer.lua) builds each track's
5557
bar n from the blocks under it. Energy and Complexity shape the patterns bar
5658
by bar. Blocks are plain data, never overlap in a lane, and point at
5759
patterns by id; structure moves (fills, risers, half-time, throws, chops)
58-
are lanes too, so tests read the plan instead of rendering audio. The kit
60+
are lanes too, so tests read the plan instead of rendering audio. A block
61+
may carry automation, as a clip does: `level` fades it and `filter` sweeps
62+
a low-pass or a high-pass over it. The composer marks every note with its
63+
block's automation where the note starts, and the Synth plays each voice
64+
through it. A style arranges section by section and ends with
65+
`kit.produce(lanes, track)`, the producer's moves drawn from the track's
66+
seed: parts join a phrase or two late and leave early, the bar before a
67+
phrase lands pulls the kick and bass or the drums out, the drums open
68+
through the intro, the tops thin through a build while the reese is teased
69+
under it, and the outro sheds parts for the next track to mix over. The
70+
`filter` lane sweeps the whole mix, the way an effect machine has patterns
71+
of its own in Jeskola Buzz's sequence.
72+
73+
No two tracks take the same road. Each draws its form from the seed: how it
74+
reaches the first drop (a build, straight out of the intro, or by way of a
75+
melodic passage), what joins one drop to the next (a breakdown and a build,
76+
a build alone, a breakdown the drop slams out of, or nothing: a double
77+
drop), and how long each section runs, in whole eight-bar phrases so that
78+
tracks still line up in the mix. A build winds up in one of four ways: a
79+
snare roll, a kick roll, the drop's groove opening through a filter, or the
80+
drums gone under the riser. A style weights these in its set's `form`
81+
(Trance always breaks down and builds; Techno prefers cold opens and kick
82+
rolls), and the same seed gives each style different forms. The kit
5983
([`host/StyleKit.lua`](host/StyleKit.lua)) is the shared functionality:
6084
seeded randomness, modes, voice-led chords, a drum kit for every track
6185
(a snare character from the flavour's `snares` — tight, fat, rimshot,
6286
roomy, crunchy, layered with a clap, vintage — and a retuned kick, hats and
6387
clap), a call-and-response melody writer, the DJ set that sequences tracks and sections, the bar score with
64-
humanized hits, the lane builder, the shared punctuation (crashes, risers,
88+
humanized hits, the lane builder (`add`, `cut`, `automate`), the shared punctuation (crashes, risers,
6589
build rolls, throws), the blend into a new track, and the Amen break. Adding a genre is one folder and
6690
one line in [`host/Styles.lua`](host/Styles.lua).
6791

@@ -91,15 +115,15 @@ stage rather than the window, and the picture continues behind the panels.
91115

92116
| File | Role |
93117
|---|---|
94-
| `Model.lua` | Lanes by family (the timeline's rows and order), controls (the single source for the sliders), the current style's ranges and which lanes sound |
118+
| `Model.lua` | Lanes by family, the timeline's tracks and the parts each gathers, controls (the single source for the sliders), the current style's ranges and which lanes sound |
95119
| `Controller.lua` | Window, transport, Style and Scene menus, the mini player, and the 60 Hz display loop |
96120
| `host/Styles.lua`, `host/StyleKit.lua` | The style extension point and its host API, with the lane builder and the shared patterns |
97121
| `host/Arrangement.lua`, `host/Composer.lua` | A track's plan of sections and lanes, checked and searchable; the composer every style shares, which arranges tracks and renders bars from their blocks |
98122
| `host/Visualizers.lua` | The visualizer extension point, the program it links and the draws that show a scene on a layer |
99123
| `plugins/styles/*` | Drum & Bass, Techno, House, Trance, Dubstep, Breakbeat, UK Garage |
100124
| `plugins/visualizers/*` | Synthwave Horizon, Valley Flight, Solar System, Liquid Chrome, Light Trails, Tunnel, Crystals |
101-
| `models/Timeline.lua`, `views/Timeline.etlua`, `shaders/Timeline.metal` | The arrangement strip: rows, instanced block data and the headline; lane names; blocks scrolling past the playhead |
102-
| `models/Synth.lua` | Sample-accurate synthesis: kicks, snares, claps and hats designed per style and voiced anew for every track, shared cymbals and percussion, the Amen loop and its slice sampler, reese/acid/wobble bass with resonance, filter envelope, accents and retriggered LFO, sub, pads, FM electric piano, stabs, arp plucks, a gliding lead, risers, ping-pong delay with throws, reverb, sidechain pump, soft clip |
125+
| `models/Timeline.lua`, `views/Timeline.etlua`, `shaders/Timeline.metal` | The arrangement strip: tracks, instanced clips and the headline; track names; clips scrolling past the playhead |
126+
| `models/Synth.lua` | Sample-accurate synthesis: kicks, snares, claps and hats designed per style and voiced anew for every track, shared cymbals and percussion, the Amen loop and its slice sampler, reese/acid/wobble bass with resonance, filter envelope, accents and retriggered LFO, sub, pads, FM electric piano, stabs, arp plucks, a gliding lead, risers, per-voice fades and filter sweeps from the arrangement, ping-pong delay with throws, reverb, sidechain pump, soft clip |
103127
| `models/Amen.lua` | The recreated Amen break's four-bar pattern and slice bookkeeping |
104128
| `models/Visuals.lua` | Spectrum smoothing, peak holds, kick and snare flashes, the scene director with crossfades, and the shader value layout |
105129
| `services/AudioOutput.lua` | Speaker output through [AudioStream](../../src/plugins/audio/README.md) |
@@ -118,6 +142,9 @@ synthesis costs about a fifth of one core at its busiest.
118142

119143
Tests: `tests/dnb.test.lua` (the drum & bass set, composition, synthesis,
120144
visuals, the controller with a fake output, the native plugin),
145+
`tests/dnb_arrangement.test.lua` (clip automation, cuts and rides, the
146+
producer's moves in every style, forms and build kinds, filtered voices,
147+
the whole-mix sweep, timeline clips),
121148
`tests/dnb_plugins.test.lua` (the contract every style plugin keeps, style
122149
switching, scene pinning, the mini player), `tests/plugins.test.lua` (the
123150
framework), `tests/shader_view.test.lua`, `tests/window_chrome.test.lua`,

‎apps/dnb/host/Arrangement.lua‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,28 @@
44
--
55
-- {track = 3, start = 1040, length = 176, -- set bar of its first bar; bars
66
-- sections = {{id = "intro", start = 0, length = 16, cycle = 0}, ...},
7-
-- lanes = {{part = "kick", blocks = {{start = 8, length = 16, pattern = "kick.intro"}, ...}}, ...}}
7+
-- lanes = {{part = "kick", blocks = {{start = 8, length = 16, pattern = "kick.intro",
8+
-- filter = {kind = "lowpass", from = 0.3, to = 1}}, ...}}, ...}}
89
--
910
-- Section and block starts count bars from the track's first bar. Blocks are
1011
-- pure data (numbers and strings), so the composer, the timeline, tests and a
1112
-- future editor all read the same plan; patterns hold the only code. Within
1213
-- a lane blocks never overlap, and silence is the absence of a block.
14+
--
15+
-- A block may carry automation, as a clip does in an arrange window: `level`
16+
-- {from, to} fades it and `filter` {kind, from, to} sweeps a low-pass or a
17+
-- high-pass over it, both 0…1 with 1 wide open. A block split from a longer
18+
-- one plays on from `offset` bars into the `whole`.
1319
local Arrangement = {}
1420
Arrangement.__index = Arrangement
1521

22+
Arrangement.filters = {lowpass = true, highpass = true}
23+
24+
local function isEnvelope(envelope)
25+
return type(envelope) == "table" and type(envelope.from) == "number" and type(envelope.to) == "number"
26+
and math.min(envelope.from, envelope.to) >= 0 and math.max(envelope.from, envelope.to) <= 1
27+
end
28+
1629
local function isData(value)
1730
local kind = type(value)
1831
if kind == "number" or kind == "string" or kind == "boolean" then return true end
@@ -55,6 +68,9 @@ function Arrangement.new(fields, patterns, order)
5568
local pattern = patterns[block.pattern]
5669
assert(pattern, name .. " plays unknown pattern " .. tostring(block.pattern))
5770
assert(pattern.part == part, name .. " plays " .. block.pattern .. ", a " .. pattern.part .. " pattern")
71+
assert(block.level == nil or isEnvelope(block.level), name .. " fades between levels of 0…1")
72+
assert(block.filter == nil or (isEnvelope(block.filter) and Arrangement.filters[block.filter.kind]),
73+
name .. " sweeps a lowpass or highpass between 0…1")
5874
stop = block.start + block.length
5975
end
6076
end
@@ -109,4 +125,16 @@ function Arrangement:plays(part, i)
109125
return false
110126
end
111127

128+
129+
--- A block's automation `at` (0…1) of the way through it: its level, and
130+
--- its filter's kind and opening, or no kind while the filter is wide open.
131+
function Arrangement.automation(block, at)
132+
local level, filter = block.level, block.filter
133+
local gain = level and level.from + (level.to - level.from) * at or 1
134+
if not filter then return gain end
135+
local opening = filter.from + (filter.to - filter.from) * at
136+
if opening >= 1 then return gain end
137+
return gain, filter.kind, opening
138+
end
139+
112140
return Arrangement

‎apps/dnb/host/Composer.lua‎

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ local Arrangement = require("apps.dnb.host.Arrangement")
1111

1212
local kit = Plugins.readonly(StyleKit)
1313

14+
-- The lists of a bar that hold notes, which take their block's automation.
15+
local NOTES = {"hits", "breaks", "bass", "stabs", "keys", "arp", "lead"}
16+
1417
-- Structure lanes render first: they leave the flags (a fill, a throw,
1518
-- half-time, chops) the instruments read. Then the instruments, in lane order.
1619
local RENDER_ORDER = {}
@@ -42,10 +45,20 @@ local function library(style)
4245
return patterns
4346
end
4447

48+
-- A style's own number, from its title: two styles given one seed draw
49+
-- different forms.
50+
local function salt(style)
51+
local sum = 0
52+
for i = 1, #style.title do sum = sum * 31 + style.title:byte(i) end
53+
return sum
54+
end
55+
4556
function Composer.new(style, seed)
57+
local spec = {salt = salt(style)}
58+
for k, v in pairs(style.set) do spec[k] = v end
4659
return setmetatable({
4760
style = style, seed = seed, kit = kit,
48-
set = StyleKit.newSet(seed, style.set),
61+
set = StyleKit.newSet(seed, spec),
4962
patterns = library(style),
5063
barsPerChord = style.barsPerChord or 2,
5164
plans = {},
@@ -73,7 +86,8 @@ function Composer:arrangement(k)
7386
for i = 0, track.cycles - 1 do cycles[i] = self:cycle(track, i) end
7487
local sections = {}
7588
for i, section in ipairs(track.sections) do
76-
sections[i] = {id = section.id, start = section.start, length = section.length, cycle = section.cycle}
89+
sections[i] = {id = section.id, start = section.start, length = section.length, cycle = section.cycle,
90+
kind = section.kind}
7791
end
7892
plan = Arrangement.new({track = k, start = track.start, length = track.length, sections = sections,
7993
lanes = self.style.arrange(kit, track, cycles)}, self.patterns, Model.parts)
@@ -131,14 +145,40 @@ function Composer:bar(n, settings)
131145
return self:chord(previous, last, n), kit.keyName(self:tonic(previous, last), previous.mode)
132146
end
133147
local blocks = plan:blocksAt(pos)
148+
local counts = {}
134149
for _, part in ipairs(RENDER_ORDER) do
135150
local block = blocks[part]
136151
if block and settings:plays(part) then
137152
local pattern = self.patterns[block.pattern]
138-
ctx.block, ctx.variant = block, block.variant
139-
ctx.barInBlock = pos - block.start
153+
local inBlock = pos - block.start
154+
ctx.block, ctx.blockLength = block, block.whole or block.length
155+
ctx.barInBlock = inBlock + (block.offset or 0)
140156
ctx.loopBar = ctx.barInBlock % pattern.bars
157+
-- The block's level and filter at a step of this bar.
158+
function ctx.automation(step)
159+
return Arrangement.automation(block, (inBlock + step / StyleKit.stepsPerBar) / block.length)
160+
end
161+
for _, list in ipairs(NOTES) do counts[list] = #bar[list] end
141162
pattern.render(bar, ctx)
163+
-- Every note the pattern wrote belongs to its part and rides the
164+
-- block's automation from where it starts.
165+
for _, list in ipairs(NOTES) do
166+
local notes = bar[list]
167+
for i = counts[list] + 1, #notes do
168+
local note = notes[i]
169+
local level, kind, filter = ctx.automation(note.step)
170+
note.part = part
171+
if level ~= 1 then note.level = level end
172+
if kind then note[kind] = filter end
173+
end
174+
end
175+
-- Held voices (a pad) ride it through the bar.
176+
if block.level or block.filter then
177+
local level, kind, from = ctx.automation(0)
178+
local levelTo, kindTo, to = ctx.automation(1)
179+
bar.automation[part] = {level = {from = level, to = levelTo}, kind = kind or kindTo,
180+
filter = {from = from or 1, to = to or 1}}
181+
end
142182
end
143183
end
144184
return bar

0 commit comments

Comments
 (0)