Bar by Bar

A groovebox that writes its own house and techno. Every bar it tries a few hundred small edits to one part, keeps the best, and moves on when nothing beats it.

Press play to hear how this take was found.

Describe a track in a few words (a style, a tempo, a key, a mood, instruments), or roll one. Best on headphones or speakers with some bass. On an iPhone, switch silent mode off. Space plays and pauses, N rolls a new take, R turns the radio on and off, L likes the take.

The bar playing now

Sixteen steps, counted 1 e & a. Taller means louder. Click a step to change it; you hear the edit from the next bar.

ghost normal accent added by a fill

The whole performance

First the search, one part at a time, then the finished track. Click anywhere to jump there at the next bar line.

Rules

Each rule scores the pattern from 0 to 100%. The fit is their weighted average; the number after the × is the weight.

    The search

    Each dot is a pattern the search tried in that bar. The line is the best so far, which is the one you hear.

    Show as a table

    Key and chords

    chord bass lead in the scale

    Where each instrument sits

    Before the search, the page plays each instrument alone and measures how its energy is spread over ten octave bands. The mix rules use these figures.

    How it works

    1. Roll a take. The take number seeds every random choice: style, tempo, key, scale, the sound of each synth, and targets such as how many hats to play per bar. The same link always gives the same track. Pin the style, tempo, key or scale under the screen and the rest still rolls. Or describe what you want: the box looks for words it knows (styles, tempos, keys, moods, instruments, "no clap", "more hats"), pins those, and tells you which words it used and which it skipped. It matches words; it does not understand sentences, and it will not copy a named song.
    2. Measure the sounds. Each instrument is rendered on its own, silently, and its spectrum is measured.
    3. Search one part at a time. A part starts as a random scatter of roughly the right number of notes, which is why its first bar sounds rough. Every bar, the page scores every pattern that is one edit away: a note added, removed, moved, made louder or softer, raised or lowered. It also tries a few random double edits. Then it takes the best one. When no edit helps, it shakes the pattern three times and climbs again. If that fails too, the part locks and the next one starts on top of it.
    4. Mix pass. With all eight parts in place, five of them are searched once more with extra rules: leave other instruments their frequency bands, keep busy steps from getting crowded, and let the lead answer the chords.
    5. Arrange. The locked patterns are laid out as a track: intro, groove, breakdown, build, drop, and out again. Each take also rolls how it opens (on the drums, the chords, the bass line, the tune, a filtered loop, a breakdown, or straight into the groove) and how it closes. Fills close every four and eight bars. Filters sweep, risers climb, and there is one beat of silence before each drop.

    Radio. The radio skips the search and plays finished tracks back to back, each one a new take in the style, tempo, key and scale chosen under the screen. For every next song it rolls six takes and plays the one least like the song before, so two songs in a row do not share an opening, and seldom a style or a tempo. A track fades out over its last four bars and the next starts a moment later. It keeps going in a background tab.

    Playing from memory. Building every note at the moment it is due takes a lot of processor time, and a slow or busy device (a phone, a car's screen) can fall behind, which is heard as the music cutting in and out. So the radio renders each track eight bars at a time, a little ahead of where it is playing, and plays those recordings back. They are lined up as much as half a minute early, so the music carries on even if the page is frozen for a while. If a recording is not ready in time, those bars are played live and the status line says "catching up". While a recording plays, the height of the spectrum is still measured, and its colours are worked out from the notes being played.

    Likes. Like keeps a take under Most liked, in this browser. On barbybar.fm the like is also counted in a list everyone sees, which you can filter by style, scale, tempo and date. Two links that give the same track are counted as one.

    The search itself takes about a tenth of a second, so it is worked out the moment a take is rolled and then performed at the speed of the music. That is why you can jump around in it.

    Why takes differ. The targets change with every take, and many patterns tie for the best score. Why they stay musical. Every note comes from one scale, the kick is tuned to the key, and each rule encodes something producers do or listeners have been shown to prefer.

    Limits. The rule weights are set by hand, not learned from data. The rules simplify the research they cite. Timing offsets stay under 12 milliseconds, because larger ones lowered groove ratings in listening tests (Davies et al. 2013). Every sound is synthesised in your browser; there are no samples and no mastering engineer, so it will not match a released record.

    Sources

    • Butler 2006. Mark J. Butler, Unlocking the Groove: Rhythm, Meter, and Musical Design in Electronic Dance Music. Indiana University Press. How house and techno build tracks from interlocking loops.
    • Witek et al. 2014. Syncopation, Body-Movement and Pleasure in Groove Music. PLOS ONE 9(4). A medium amount of syncopation drew the strongest urge to move. Paper
    • Toussaint 2005. Godfried Toussaint, The Euclidean Algorithm Generates Traditional Musical Rhythms. BRIDGES conference. Spreading hits as evenly as possible reproduces rhythms from many traditions. PDF
    • Longuet-Higgins & Lee 1984. The Rhythmic Interpretation of Monophonic Music. Music Perception 1(4). The syncopation count used here. Paper
    • Lerdahl & Jackendoff 1983. A Generative Theory of Tonal Music. MIT Press. The grid of strong and weak beats.
    • Krumhansl & Kessler 1982. Tracing the Dynamic Changes in Perceived Tonal Organization in a Spatial Representation of Musical Keys. Psychological Review 89(4). Listeners hear the home note and its chord as the most stable. Paper
    • de Clercq & Temperley 2011. A Corpus Analysis of Rock Harmony. Popular Music 30(1). Which chord-to-chord moves are common in popular music. Paper
    • Tymoczko 2011. Dmitri Tymoczko, A Geometry of Music. Oxford University Press. Good chord changes move each voice a short distance.
    • Huron 2001. David Huron, Tone and Voice: A Derivation of the Rules of Voice-Leading from Perceptual Principles. Music Perception 19(1). Small steps keep a melody heard as one line. Paper
    • Huron 1996. David Huron, The Melodic Arch in Western Folksongs. Computing in Musicology 10. Phrases tend to rise and then fall.
    • von Hippel & Huron 2000. Why Do Skips Precede Reversals? The Effect of Tessitura on Melodic Structure. Music Perception 18(1). After a leap, melodies tend to head back toward the middle of their range. Paper
    • Plomp & Levelt 1965. Tonal Consonance and Critical Bandwidth. Journal of the Acoustical Society of America 38(4). Two tones close in pitch sound rough together. Paper
    • Caplin 1998. William E. Caplin, Classical Form. Oxford University Press. The two-part phrase in which the first half ends open and the second half closes.
    • Moore 2012. Brian C. J. Moore, An Introduction to the Psychology of Hearing, 6th edition. How one sound hides another that shares its frequency band.
    • Hafezi & Reiss 2015. Autonomous Multitrack Equalization Based on Masking Reduction. Journal of the Audio Engineering Society 63(5). Measuring how much the parts of a mix cover each other. Paper
    • Davies et al. 2013. The Effect of Microtiming Deviations on the Perception of Groove in Short Rhythms. Music Perception 30(5). Paper
    • Solberg & Dibben 2019. Peak Experiences with Electronic Dance Music. Music Perception 36(4). How listeners respond to the breakdown, build-up and drop. Paper
    • Wilson 2013. Chris Wilson, A Tale of Two Clocks. The scheduling method that keeps the beat steady in a browser. Article