Tagged: music
Part 1: A First Sound
Start loopcode, a live coding music app for the browser: set up a Vite project with TypeScript, get to know the Web Audio API as a graph of nodes, and play a first note with an oscillator and an envelope that keeps it from clicking.
Intermediate25 minPart 2: A Clock That Keeps Time
JavaScript's timers are too sloppy for music. Build a clock that counts in bars, schedules notes ahead of time on the exact clock of the audio context, and keeps its place when the tempo changes. A metronome lets you hear it.
Intermediate25 minPart 3: Drums From Oscillators and Noise
Build a drum machine without a single recording: a kick from a sine with a falling pitch, a snare and a clap from filtered noise, hi-hats from six square waves, and an open hi-hat that a closed one cuts off. Then play a beat written as sixteen steps of x and dots.
Intermediate30 minPart 4: Patterns Are Functions of Time
Replace the beat of x and dots with patterns: functions that are asked for a stretch of time and answer with the events that begin in it. Six small functions combine them into beats, and a beat can be swapped while it plays without losing the time.
Intermediate35 minPart 5: A Small Language for Rhythm
Write beats as text: bd [~ bd] sd ~ instead of nested function calls. A tokenizer, a parser and a compiler turn the text into the patterns of part 4, a mistake is marked at its place under the input, and a broken pattern leaves the last good one playing.
Intermediate40 minPart 6: Speed, Length and Chance
Seven additions to the mini-notation: * and / for speed, @ and _ for length, ! for repeats, ? for chance and (3,8) for euclidean rhythms. Steps get a weight, random numbers become a function of time, and an algorithm spreads hits evenly over a bar.
Intermediate40 minPart 7: Choices, Polymeter and Changing Speeds
Finish the mini-notation: a choice between several sequences that is made anew in every cycle, layers of different length that drift against each other, and speeds that change from cycle to cycle. The part ends with a reference of every symbol.
Intermediate20 minPart 8: A Synth for Bass and Lead
Build a mono synth for bass lines and leads: an oscillator, a low-pass filter and a gain that run the whole time, and notes that only move their settings. Note names become MIDI numbers, and two tags in the notation add accents and slides.
Intermediate30 minPart 9: Code That Makes Music
The inputs make way for an editor. Its code describes a song through a small API that is built from a schema, running the code gives a patch of plain data, and an engine turns the patch into units that play. CodeMirror and two keys complete the page.
Intermediate45 minPart 10: Change It While It Plays
Turn the app into a live coding app: the engine compares every run of the code with what is playing, keeps the units that are still there, creates the new ones and fades out the rest. The music changes without a gap.
Intermediate20 minPart 12: Chords and Pads
Build a poly synth that plays several notes at once: every note gets two detuned oscillators and an envelope of its own with attack, decay, sustain and release. Chords are written in the notation, and the new kind of unit takes a class, a schema entry and one line in the engine.
Intermediate30 minPart 13: Filter, Delay, Reverb and Distortion
Put effects between the instruments and the speakers: a filter, a delay whose echoes follow the tempo, a reverb made of decaying noise and a distortion that bends the wave. A limiter in front of the speakers catches what gets too loud.
Intermediate35 minPart 14: Movement With LFOs
Let slow waves turn the knobs: an LFO moves the cutoff, the pitch or the volume of another unit. It is a cable into an audio parameter, and its wave is worked out from the cycle, so it stays locked to the bars.
Intermediate30 minPart 15: Your Own Sounds
Add a sampler that plays recordings at the pitch of every note. Audio files are decoded, kept in IndexedDB and listed in a bar above the code, a bell is rendered with an OfflineAudioContext, and files can be dropped on the page.
Intermediate40 min