brumm.club

Warning: physics How the pad thinks

The pad is a ground‑state search.

The pad is a free instrument plugin, VST3 and AU, open source, out 10 December: play any MIDI into it, one dot bends it, and it plays the result on its own sounds. This page is how it thinks.

You play a line into it. The pad scores every version of that line it could play: how wrong it sounds by the rules of music theory, plus how far it moved from what you played. The lowest score plays. Physicists call a score like that an energy, which makes the pad a search for the ground state. The dot only changes the prices.

E(line)=Ewrong(line)+Emoved(line)
(1)
T your line, as played the ground state: what plays Eevery version of the line →

Music theory, priced

Ask a musician what makes a line sound right and you get rules. They collide all the time: a note can break one and still be the best note in the bar, if it was played on purpose. A quantizer that snaps every note to the scale can't tell a deliberate F♯ from a slip, so it flattens both. The pad doesn't obey the rules. It prices them. These six are all the theory there is:

  1. Stay in the key. Notes from the scale sound like they belong; the others sound wrong unless they're placed with care. A minor's raised seventh, G♯, is almost free, because minor tunes borrow it all the time. K, eq. 5
  2. Don't rub a semitone against the bass. Two notes a semitone apart, or a minor ninth, grind, and every genre hears that as a mistake. A major seventh grinds a little less. X, eq. 6
  3. Where the ear rests, play the chord. Long notes and notes on the beat want to be tones of the bar's chord; quick notes in between may pass. Counterpoint teachers and jazz players agree on this one. C, eq. 7
  4. Tension is fine if it resolves by step. A rub that steps one or two semitones into its next note is mostly forgiven, and a quick off-beat note outside the key is fully forgiven when it steps back in. That's how counterpoint handles tension. L, eq. 9
  5. Keep the shape. Up stays up, down stays down. The contour is what makes a melody recognisable; change it and it's another tune. This one is a hard rule. L, eq. 9
  6. Change as little as you can, and least what was meant. Not theory: respect for the player. Long notes, notes on the beat and notes you play twice are ideas and resist being moved; a quick, quiet slip gives way. M and D, eq. 3, 4, 8

That's all of it. No parallel fifths, no style, no idea of what genre you're in: six rules that hold almost everywhere, each with a price. What a version breaks adds up to how wrong it sounds; what its changes cost adds up to how far it moved. The version with the lowest total plays. Physicists call such a total an energy and its lowest value the ground state; a soap bubble finds its shape the same way. Nothing here is learned from data: a few dozen numbers, set by Daniel's ears on his own hums. Trained on nobody.

line*=arg minlineE(line)
(2)

And the dot sets the prices. Far left, nothing is priced and the line plays as it came in. Move it right and breaking the rules gets dearer while changing your notes gets cheaper, so the line gives way to the theory, step by step.

Drag the dot. It's the real code.

This is Brumm's fit, the code the pad's fit is built from, compiled for your browser. Not a sketch of it, not a video. A two-bar line over Brumm's loop: 123 BPM, A minor, its bass on A. Outlines are the line as it came in, solid notes what plays, a thin line runs from each note to where it went. A coral cross is a note the energy deleted, a grey one a note the thinning took. Hatched rows are outside the key. Press play and, unless you take over, the demo walks the whole way: the dot from as played to a fresh dot in fourteen seconds and on to the far right, then the temperature up until the line melts. Touch the dot or the temperature and it's yours.

The demo runs the fit in your browser, so it needs JavaScript.

What counts as a version

Timing comes first, and it isn't part of the energy. Onsets are pulled to the 8th-note grid, swung at 56 % like the hats. Distances to a beat count three quarters, so a beat pulls harder than an offbeat: a note has to sit clearly off the beat to land between beats. Two notes played less than 1.6 sixteenths apart are a flam: one takes the 8th, the other the 16th beside it. Ends snap to 16ths. The dot fades all of this in, from the far left to 30 %.

Then every note gets options: stay, move one or two semitones up or down (up to four once the dot passes 30 %), or be deleted. Twelve notes with ten options each are 1012 versions. The pad doesn't sample them or guess. It finds the cheapest one exactly, as the next sections show.

The energy, term by term

Units are "one soft semitone move". First, every note gets a stiffness: how much it resists being changed.

si=2(12+ri)(1+ni)(0.7+0.3ℓi)bih(x)
(3)
ri
how confidently the note was sung, ranked within the line, 0 to 1. A keyboard can't be unsure: every played note ties at 0.
ni
how many other notes share its pitch class, up to 3. A note you play twice is an idea.
ℓi
its length in beats, up to 1.
bi
1.2 if it starts on a beat, else 1.
h(x)
the dot's weight on changing your notes (table below).

Moving a note by δ semitones costs its stiffness times a price that grows faster than the distance: one semitone 1, two 3, four 7.

Mi(δ)=si[c(|δ|)+12τi(δ)]c(1)=1, c(d)=2d−1, d≥2
(4)

The discount τi is zero or negative: moving toward where the voice actually was is cheaper than moving away. A hum sung 30 cents sharp goes up more easily than down. From a keyboard there's no voice, and it's zero.

A note outside the key (A minor here) costs more the longer it lasts and the stronger its beat:

Ki=2.5k(x)(12+min(1.5,di))miλi
(5)
di
the note's length in beats.
mi
1.3 on a beat, 1 on an 8th, 0.7 on a 16th.
λi
0.1 for G♯, the leading tone of A minor, the commonest colour note in minor tunes; 1 for the rest. Six G♯s once read as another key; now they're a tenth of a wrong note.

A rub against what else sounds, the bass or another melody, is the one thing that sounds like a mistake in any genre:

Xi=3mi∑jw(|pi−qj|)oij
(6)
w
1 for a semitone or a minor ninth, 0.6 for a semitone rub further apart, 0.5 for a major seventh inside the octave, 0 for everything else. Pitches as heard, after the octave rule puts the line on its instrument.
oij
how long the two overlap, in beats; under 40 ms doesn't count.

A note off the bar's chord costs only once the dot passes 30 %, and only as much as it's exposed:

Ci=3χ(x)σiσi=eimin(1.5,12+di)
(7)

where ei is 1 on a beat, 0.35 on an 8th and 0.15 on a 16th. A passing 16th can sit off the chord all day; a long note on the one can't. The chord is the bar's root with its third, fifth and seventh, here A, C, E and G; from 55 % the seventh no longer counts.

Deleting a note must never be the cheap way around the key or the chord, so it gets dearer as the chord pull grows. A note that looks like an accident is the exception: short and quiet, or short and seven semitones from both neighbours.

Di=6(1−ai)hi(1+χ(x))
(8)

Here ai runs from 0 to 1, how much the note looks like an accident, and keeping one costs 3ai.

Between neighbours, two terms. The contour guard: a step up stays up, a step down stays down, a repeat stays a repeat, with one exception, a semitone step may settle into a repeat, because voices overshoot and settle. And a rub that resolves by step is 60 % forgiven, a short off-beat passing note that steps into the key entirely.

Lij={∞turns around−0.6Xi−πiKisteps of 1–20otherwise
(9)

where πi is 1 for a short off-beat note (a quarter second or less) whose next note is in the key, else 0. Add it all up:

E=∑kept(Mi+Ki+Xi+Ci+3ai) +∑deletedDi+∑neighboursLij
(10)

How wrong it sounds is K+X+C+3a. How far it moved is M+D. The demo above shows both, live.

The dot sets the weights

The dot never picks notes. It moves three weights and a couple of switches, and the search does the rest. Up to 30 % the fit reads the dot as it is; from there 45 % reads as 0.4 and 60 % as 1, where the weights stop changing.

h(x)=41−2xk(x)=0.5+3x below 0.3, then 10χ(x)=3 clamp(x−0.30.1)
(11)
What the dot does to the weights (straight shape, Brumm's pad.ts)
Dotxh(x)stiffnessk(x)keyχ(x)chordmovesand
0–4 %–nothing is weighed: the line plays as it came in
15 %0.152.640.950±2timing half-way to the grid
29 %0.291.791.370±2a wrong note still costs little
30 %0.301.74100±4a fresh dot: in key, on the beat, every note kept
45 %0.401.32103±4exposed notes pulled onto the chord
55 %0.800.44103±4the chord is a triad now; half the thinning
60–100 %10.25103±4all the thinning, then the freedom moves

Look at the jump between 29 % and 30 %. Left of it a wrong note is a mild preference; from 30 % it costs ten times the base weight, which in practice is a rule. That's on purpose: people hum wrong notes into Brumm's silent loop, so a fresh dot starts at 30 % with every note in key and on the beat, and only the far left is exactly as played.

Solved exactly

Because every cost depends on one note or on two neighbours, the cheapest line is a shortest path through a graph whose nodes are (note, option) pairs. Dynamic programming walks it once:

Bj(o)=Uj(o)+min(D<j, mini<j,o′[Bi(o′)+Di<·<j+Lij])
(12)
Bj(o)
the cheapest way to play notes 1 to j with note j kept as option o.
Uj(o)
that note's own terms: M + K + X + C + 3a.
D…
the cost of deleting every note in between.

The work grows with the square of the note count: twelve notes with nine kept options each are about 5,000 links, thirty notes about 35,000. The demo tells you how long it took on your device.

Brumm runs the search twice. The first pass decides what you meant: how to read a hum sung between two semitones and, where the key may move, which key. It uses a fixed balance tuned on Daniel's hums, whatever the dot says. The second pass corrects inside that reading with the dot's weights. A line played on a keyboard leaves the first pass nothing to decide.

Temperature

At zero temperature the pad always plays the ground state. Same line, same dot, same notes, every time. That's what you want from an instrument most of the time, and it gets boring the rest of the time. A temperature draws a line instead of taking the best one:

P(line)=e−E(line)/TZZ=∑linese−E/T
(13)

Versions close to the ground state get a real chance, versions far above it practically none. The catch is that Z is a sum over 1012 lines, and nobody lists them. The same recursion does it, with the minimum replaced by a soft minimum:

minT(a,b,…)=−T ln(e−a/T+e−b/T+…)
(14)

That's a transfer matrix, the way statistical physics sums over a chain of spins. Run forward, it gives the partition function. Walk back from the end, drawing each step by its weight, and the line comes out with exactly its Boltzmann probability. No Markov chain, no burn-in. As T→0 the soft minimum becomes the minimum and the ground state is back.

The demo's keyboard line has a nice case at 30 %. Its C♯ can go to C or to D, and its F♯ to F or to G, all for exactly the same price: four ground states with one energy, which physicists call degenerate. At zero temperature the search keeps the first it finds, the step down each time. Any temperature above zero picks among the four with equal odds.

Quantum physics allows you to fall through your chair. Absurdly unlikely: paint one atom of the Earth red, pick an atom at random with your eyes closed, and hitting the red one is likelier than falling through your chair within a million years.

Daniel's favourite physics fact. “People don't appreciate that enough.”

The temperature works the same way. An unlikely line is never forbidden, only weighted. Turn it up a little and you get bolder lines a few units above the ground state. Turn it all the way and the many slightly wrong lines outnumber the few right ones: they win by count, not by energy. Physicists call that entropy. Musicians call it a jam that went on too long.

Like everything in the fit, the temperature only moves notes. It never touches the sound.

Not everything is physics

Two things happen after the fit, and they're rules, not energy. Past 50 % the weakest notes leave one at a time as the dot moves: off-beat and short notes first, the first note of each bar always stays, never more than half the line and never below six notes. They used to go as an energy choice, all at once; Daniel wanted them to leave one by one.

From 60 % the fit's weights stop changing, and the far right hands the line some freedom, in this order as the dot goes right: a passing note before a big leap, a repeat into a gap, a single note jumping an octave toward the middle of the phrase, a note on a beat pushed onto the offbeat. All of it deterministic. The energy in the demo is the fit's; the lines under it say what the rules did.

Where it's weak

  • It needs the whole phrase. The contour, the thinning and the freedom look at the line from first note to last, so the pad hears a loop once and bends it from its second pass.
  • Two modes. Natural minor and Dorian. A line in major reads as its relative minor, same notes, so the pitches come out right and the name is wrong.
  • One chord per bar. The chord pull knows a root per bar, no more.
  • Tuned on hums. A short, quiet note counts as an accident and is cheap to delete. Right for a hum's glitch, wrong for a ghost note you meant.
  • No rhythm in the energy. Timing is snapped first, then pitch is weighed. A version that moves a note in time is not a candidate.

None of that is a law of nature. Daniel's line on physics covers it: it's not truth, it's the best you have. He also says a formula that explained the universe exactly would be the universe itself. A formula that explained music exactly would be music, and nobody needs a plugin for that.

Mika lying on a wooden floor covered in printed pages, a guitar in the corner
Peer review, Neukölln style.

Who wrote it down

The idea of writing music theory down as an energy is Daniel Breyer's. He studied theoretical quantum physics and published a paper in Physical Review A, on light scattering in an optomechanical cavity coupled to a single atom. He has been writing everything down as an energy since. AI agents wrote the code; his ears set the numbers.

The demo runs Brumm's fit in its own setting, a two-bar loop at 123 BPM in A minor over Brumm's bass. In the pad, the tempo and the loop come from your DAW. The pad comes out on 10 December, free and open source under GPL-3, this energy included.

More about Daniel Learn: odd meters with a band