Play at.atmosynth.patch records in your browser or render them to WAV files atmosynth.at
README.md

atmosynth-audio-engine #

ATMOSYNTH's sound engine, for any web page to play a patch with: live, with keys, patterns and parameters, or rendered to a WAV file faster than real time.

A patch on ATMOSYNTH is an at.atmosynth.patch record in its creator's ATproto repository. This library takes one, from a file or fetched from the repository, and plays it with the engine every patch page on the site plays through, so it sounds here as it does there.

import { createPlayer } from 'atmosynth-audio-engine';

const record = await (await fetch('my-patch.json')).json();
const player = await createPlayer(record);

startButton.addEventListener('click', async () => {
  await player.start();        // the patch's patterns start playing
  player.noteOn(60);           // and a middle C over them
  setTimeout(() => player.noteOff(60), 500);
});

Rendering is one more thing to do with a patch:

import { renderPatch } from 'atmosynth-audio-engine';

const { wav, seconds } = await renderPatch(record);
const url = URL.createObjectURL(new Blob([wav], { type: 'audio/wav' }));

What it needs #

  • A browser. The engine is Web Audio, AudioWorklets included, and runs where those do. A module's code is DSP JS, played through an AudioWorklet, so it needs a secure context (https: or localhost) for the worklet, and a content security policy that allows the blob: scripts its code is loaded from and lets it connect to atmosynth.at, plc.directory and whichever PDS holds a module or a sample the patch uses.
  • atmosynth.at, for the built-ins. Built-in modules are read from https://atmosynth.at/asml, which publishes every version of each one along with the samples they come with, and answers any origin. Nothing about you or your page is sent.
  • The creator's account, for their samples. A slot the creator filled with a sample of their own is read from their PDS, found by resolving their DID (did:plc through https://plc.directory, did:web from its host), with com.atproto.sync.getBlob. The bytes are checked against the CID the patch names, and a sample that does not match is refused.
  • The author's account, for a module somebody published themselves. A version is read from its author's PDS with com.atproto.repo.getRecord, its record key being the version the patch pins, and the samples it comes with from whichever account holds them. One that can't be read is refused with a PatchError that names the block and says, in reason, whether it was deleted, notFound, unreachable, refused or unreadable (served, and not a module).
  • Somebody's code is yours to allow. A module carrying a dsp node is resolved like any other, marked codeBearing in the descriptor, and runsCommunityCode says whether any module that does is not a built-in. createPlayer and renderPatch play what they are handed, so a page that would ask first resolves the patch, reads that, and only then hands it on.
  • WebAssembly, for somebody's code. Before a source reaches the worklet the engine puts it through DSP JS's validator, compiled to WebAssembly, and a source it refuses is not played: the patch is refused as one whose code won't load. A built-in's source is known to pass and is let through by its hash, so a patch made only of built-ins never loads the validator. Any other needs 'wasm-unsafe-eval' in the page's script-src and fetches the validator once, about 450 KB gzipped; where it can't run, that module is refused rather than played unchecked. What validation can't settle, a loop that never ends or a constructor allocating without end, the validator writes a count into the source for, and the worklet holds the count to the budgets the plugin holds a module to: a module that runs past one is stopped and muted, and the rest of the patch plays on. A loop costs a little more for being counted: under 2% for most of the built-ins' shapes, about 7% for a reverb of many short loops. The audio-thread watchdog stops a patch whose thread stops keeping up anyway.

There are no dependencies and no build step: src/ is plain ES modules.

Reading a patch #

resolvePatch(input, options?) #

Reads every module the patch uses and finds every sample, and resolves to the descriptor the engine plays. input is a patch record or a repository entry around one ({ uri, cid, value }).

option default what it does
origin https://atmosynth.at where built-ins and their samples are read from
platformDid atmosynth.at's the account that origin names its built-ins under
plcDirectory https://plc.directory where a did:plc is resolved to the PDS holding its modules and samples
fetch the browser's used for every request

createPlayer and renderPatch both take a record and these options and resolve it themselves; resolve once and hand them the descriptor to do both, or several, without reading the modules again.

patchRecordIn(json) #

The patch record in a parsed file, or null.

Playing live #

createPlayer(input, options?) #

Resolves to a Player. Takes a record, a repository entry or a descriptor, the options above, and latencyHint for the AudioContext: 'playback' suits a page that plays patterns and offers no keys, where a longer buffer is worth more than a short one.

Nothing sounds, and no AudioContext exists, until start() is called from a gesture: a click, a tap or a key. That is the browser's rule.

Player #

member what it does
start() starts the sound; every pattern, song and scene in the patch starts with it, as on its own page. Resolves to whether the sound is ready
state 'not-started', 'starting', 'ready' or 'failed'
problem why there is no sound, as { message } written for a person, or null
noteOn(note, { velocity, source }) strikes a MIDI note. Before start() it waits and plays once the sound is ready
noteOff(note, { source }) lets it go. A key struck again from the same source retriggers its voice, so two hands playing one note each need their own
setSustain(on) the sustain pedal
soundingNotes every note sounding now, a pattern's included
loopsPlaying, playLoops(), stopLoops() the patch's patterns, songs and automation lanes; playLoops starts them from the top
silence() stops every pattern and lets go of every key
parameters() every parameter a block exposes: instanceId, parameterId, label, min, max, values (a closed set), scale and the value it is at
setParameter(instanceId, parameterId, value) turns one, live, for what is sounding and what is still to come
tempo, setTempo(bpm) the patch's own tempo until it is set
level, setLevel(0…1), muted, setMuted(on) the output
enableMidi() lets MIDI devices play the patch too. The browser asks the visitor first, so it is never asked unless the page asks for it
close() stops the sound and closes the AudioContext; start() opens it again
engine the engine itself, an AudioEngine, for everything the above does not wrap

A Player is an EventTarget and sends statechange whenever anything about it moves: the sound starting or failing, a problem, a note sounding or ending.

The level, the mute and the tempo set are remembered in the page's localStorage, as the site remembers them: how a browser plays is the listener's, and never part of the patch. Pass remember: false to createPlayer and they start at the defaults and last as long as the player.

Rendering to a file #

renderPatch(input, options?) #

Renders a patch and resolves to { wav, channels, sampleRate, seconds, part, descriptor }. wav is a Uint8Array holding the file, and channels holds the samples, one Float32Array per channel. What comes out is the patch as the player plays it, and the same file the site's own Export as WAV writes. Takes a record, a repository entry or a descriptor, the options resolvePatch takes, and:

option default what it does
part 'all' 'all' plays the whole patch itself; a part's id from partsOf renders that pattern or song alone
ending 'ringOut' ringOut plays on until the tails are quiet, cut stops on the last bar line, seamless (a pattern only) is exactly one pass long, starting with what rings over from the pass before
tempo the patch's, or 120 beats a minute
seconds the longest part how long the whole patch plays for, before any tail
notes none MIDI notes struck at the start, as if by hand
hold 1 seconds until those notes are let go
velocity 100 1 to 127, for those notes
format 'pcm24' pcm16, pcm24 or float32
dither false triangular noise before rounding, worth having at 16 bits
onProgress none called with a fraction from 0 to 1 as the render goes

With part: 'all', every sequencer plays its pattern, every arranger its song and every scenes block the scene the record names, all together, as on the patch's page. A patch with nothing that plays itself gets a middle C held for a second, unless notes says otherwise.

A render is held in memory whole, so it can be at most ten minutes long.

What a module's DSP JS draws by chance comes from its seed, so a noise is the same noise on every render; a pattern's note that plays only some of the time is chosen afresh each render.

partsOf(descriptor) #

What can be rendered on its own, as { loops, songs }. Each part has an id to pass as part, a label such as "Drums · Pattern 1", and its length in ticks, 96 to the beat.

Also exported #

  • AudioEngine: the engine's class, as the site constructs it.
  • renderOffline(options): the engine's own offline entry point, for anything renderPatch does not cover.
  • encodeWav({ channels, sampleRate, format, dither }): samples to a WAV file.
  • PatchError, ExportRefusal and UnplayablePatchError: why a patch did not play or render, with a message written for a person. A PatchError about one block names it in instanceId, and one about a module that could not be read says what became of it in reason. RenderError is the name PatchError had before this library played live, and is the same class.

The examples #

example/ has two pages: one plays a patch file you choose, with keys, its patterns and a control for every parameter, and one renders it to a WAV file. Serve the repository root over HTTP and open them:

npx http-server .     # or any static server
open http://localhost:8080/example/

Working on the engine #

This repository is where the engine is written, twice: in JavaScript, which a browser plays through, and in Rust, which renders when it is asked to (a plugin's audio thread, an offline render), without allocating. The record types, the Lexicons they are written to, the built-in modules and the reference patches are here too, because both engines read them and are held to each other with them. ATMOSYNTH's site, its patch editor, its plugin and the ATMOSYNTH Groove DAW all play through it, so a change here is heard in all of them.

npm install                 # vitest, the one development dependency
npm test                    # the JavaScript engine, on node, in a few seconds
cargo test --workspace      # the Rust engine, the record types, the built-ins
cargo test -p atmosynth-engine --features compiled   # DSP JS's compiled tier, played beside the interpreter

cargo test needs node on the path (the Rust interpreter's DSP JS is held to what the JS reference host computes, the built-ins' programs among it) and checks the engine for wasm32-unknown-unknown where that target is installed.

GLOSSARY.md holds the words the engines, the spec and the editor share for notes, their wiring and the patterns a sequencer plays.

What is where #

path what it is
src/index.js the library's entry point: everything above
src/resolve.js, src/accounts.js a patch record to what the engine plays: built-ins from /asml, anybody else's modules and every chosen sample from the account holding it
src/player.js createPlayer and Player, around the engine
src/render.js renderPatch and partsOf, around the engine's offline render
src/audio/ the engine: engine.js plays live, offline.js renders, performance.js plays a performance again through its patch, live, and performance-render.js renders it, offline: its keys, its knobs, every change to the patch, every loop, song, scenes block and lane started or stopped and every scene taking over, each at its moment, whole or a piece at a time for one too long to hold, the pieces joining into the whole; performance-sound.js plays a published performance's sound, its pieces one after another with no gap; patch-diff.js is a patch changed while it plays, as the live calls that make it so, for the patch editor's edits and a performance's changes alike; and the rest is what they are made of (notes, voices, the patch graph, patterns, songs, scenes, lanes, MIDI, tuning, the clock)
src/records/numbers.js how a record's numbers are written, and read back
src/records/reference.js the key a module reference is addressed by. Nothing in src/records/ imports from outside it
src/editor/ the few things about notes, patterns, names and WAV export that the engine and the patch editor share
crates/records the record types, their validation, a patch's kind (kind), a patch's presentation and the split of a patch written before into the two records (presentation), and the Lexicons compiled in (atmosynth_records::lexicons)
crates/builtins the built-in modules and the reference patches, compiled in, and a patch made only of built-ins as a descriptor
crates/resolve a patch record made playable: its modules and sample slots resolved, through a Network the caller supplies
crates/engine the Rust engine: Blink's Web Audio nodes ported, and the JavaScript engine's orchestration file by file
crates/render atmo-render, a patch and a script to a WAV file, offline
crates/transport a room's transport: where a patch's patterns are in the room's own time, the changes queued to take effect, what a native client follows it with: a clock set to the server's, and which tick each frame is heard at; and the notes people play in a room, their frames and their cap (notes)
crates/tile a patch as a web tile, and Pcm, the FLAC encoder a tile's samples, a plyr.fm track and an arrangement's recordings are made with; atmo-tile behind the cli feature. The page is atmosynth-patch-editor's
lexicons/ the at.atmosynth.* Lexicons, and example records in examples/
assets/builtin-modules/ every version of every built-in, <moduleId>/<version>/module.json with its samples beside it
assets/default-patches/ the reference patches, made only of built-ins
fixtures/engine/ a patch, a script and what the JavaScript engine decided for them, which the Rust engine is held to
fixtures/transport/ a room's script and what its transport says, worked by hand, which both languages are held to
fixtures/patch-kind/ patches and the kind each is, an effect, a song, a sequence or an instrument, which src/audio/patch-kind.js and atmosynth_records::kind are both held to
fixtures/module-cycles/ feedback loops in a module and the one each is refused for, which atmosynth_records::validate and the editor's copy of the rule are both held to
fixtures/module-integers/ a module's whole-number fields holding something else, and whether the module is refused for it, which src/audio/validate.js and atmosynth_engine::patch::Descriptor::from_json are both held to
fixtures/numbers/ a number written as text in a record and what each reading makes of it, which src/records/numbers.js and atmosynth_records::number are both held to
fixtures/sanitised/ fields of a patch a reader sanitises rather than refuses, and what each engine plays of them, which src/audio/'s readers and atmosynth_records::patch::PatchRecord::read are both held to
fixtures/midi-clock/ windows of the count and what the MIDI clock says in each, written by the JavaScript clock (src/audio/midi-clock.js), which the Rust one (atmosynth_engine::midi_clock) is held to
fixtures/mpe/ a device's messages across a change of patch and what each means: the zone and bend ranges it set kept, what it was playing let go. Written by the JavaScript parser (src/audio/mpe.js), which the Rust one (atmosynth_engine::midi) is held to
tools/ trace-fixture.mjs; the parity cases and their comparison; content.mjs
test/ the JavaScript tests, one file to a subject; the Rust tests are in each crate
example/ the two example pages

Two engines, one set of decisions #

The JavaScript engine is the reference. fixtures/engine/ holds what it decides for a patch and a script, in trace mode (src/audio/trace.js): which voices a note builds, when each is let go, what a song, a scene and a lane are at given moments. test/conformance.test.js holds the JavaScript engine to those traces and crates/engine/tests/conformance.rs holds the Rust one to the same files. When what the JavaScript engine decides changes on purpose, the fixtures are written again, and the Rust test stays red until its engine follows:

ATMO_UPDATE_FIXTURES=1 npx vitest run conformance   # the traces, written by the JavaScript engine
cargo test -p atmosynth-engine --test conformance   # the Rust engine, held to them
node tools/trace-fixture.mjs one-shot               # what is decided for one, in seconds, ticks and beats

A script can edit the patch as it plays, in the fixtures called live- something: each edit is written as the record writes it and read as it would be on the page, and Rust hands it over through a Plan (crates/engine/src/play/plan.rs), the one place that says what can change with nothing compiled, so a fixture fails there where an edit would take a compile. A script can also make the patch a whole other one at a moment ({ at, patch }), as a performance's changed does: the JavaScript engine makes it by the live calls the difference implies (patch-diff.js), and Rust reads it by the Plan where it can and otherwise compiles it and goes on (Engine::carry_on), as a host does with an edit of what a patch is made of; live-patch-changed is one. A fixture can also say scenesTold, as a performance played again does, and tell a scene where it takes over ({ at, switched: {instanceId, scene, tick} }, the tick from the scenes block's downbeat): a scene the record chooses then waits for its telling rather than landing on a line of its own (Sequencer.takeScene, and Sequencer::take_scene in Rust); scene-told is one. A fixture can say polyphony, how many voices the JavaScript engine holds as it writes the trace, where what is decided turns on it, as a wide unison down many paths does (unison-many-paths); Rust holds thirty-two (MAX_VOICES), the page's until a player changes it, and fails a fixture written at any other number. One case is made by the Rust test itself and asked of both engines, since its trace would be thousands of lines: more of a loop's notes waiting to be let go at once than Rust keeps room for. The page has a lookahead of sound committed and Rust has none, so an edit stays further than that from a step. What such an edit does to what is already sounding no trace can say: crates/engine/tests/live.rs holds that to a null test, an edited render against one not edited, sample for sample.

The MIDI clock sent to outside gear is decided twice the same way: src/audio/midi-clock.js for a page and crates/engine/src/midi_clock.rs for a host that renders its own frames. fixtures/midi-clock/ holds windows of the count, the patterns running in each, and what the JavaScript clock says in it; test/midi-clock-fixtures.test.js and crates/engine/tests/midi_clock.rs hold each clock to it, and ATMO_UPDATE_FIXTURES=1 npx vitest run midi-clock-fixtures writes it again for a change that is meant.

A fixture's trace is in seconds and its patch in ticks, and a wrong sum between the two looks exactly like an engine bug: read trace-fixture.mjs's lines before believing the engine is wrong.

By ear, the two are compared on every case in tools/parity-cases.mjs: every reference patch, a patch around every version of every built-in that carries code, and every value a choice hands a node. tools/parity.mjs compares two renders the way a listener hears them. Rendering the JavaScript side needs a browser, which npm test does not start; test/parity-coverage.test.js fails here, without one, naming any choice no case plays.

A room's transport has no reference to trace: the server of a room counts it in Rust (crates/transport), a client reads what it says in either language (src/audio/room-transport.js and src/audio/netclock.js, or State, clock.rs and follower.rs in that crate), and fixtures/transport/ is worked by hand between them. numbers.json holds the tempo's default and range and the ticks to a beat, clock.json how a client measures its clock and walks its count, and each file in rooms/ is a script of what clients ask, the state said after each step, and where the patterns are at given moments. crates/transport/tests/fixtures.rs asks the transport and a Rust client for those, and test/transport-fixtures.test.js reads them through the engine's clock, a late-joining sequencer and everything that asks a room for a change. note-frames.json holds what a played note is on the socket, read and written in Rust (crates/transport/src/notes.rs) and JavaScript (src/audio/room-notes.js), with the cap's steps worked, which only Rust counts.

A built-in is never changed #

A patch pins the version of each module it uses, and a version is what it was the day it was published. To change a built-in, add <moduleId>/<version+1>/ and leave the old one alone. assets/builtin-modules.lock hashes every version directory, and crates/builtins/tests/lock.rs fails on an edited version as on an unrecorded new one; once a new version is meant, ATMO_UPDATE_BUILTIN_LOCK=1 cargo test -p atmosynth-builtins --test lock writes the lock, and node tools/dsp-builtin-sources.mjs the hashes of the built-ins' sources a page lets through without the validator (test/dsp-vet.test.js fails until it is run). A module's NOTICE, beside its versions, licenses what they carry of somebody else's.

Depending on it #

At a pinned commit, as anything else is: the crates as git dependencies (Cargo finds each by its name, atmosynth-records, -builtins, -resolve, -engine, -render, -transport, -tile), and the package as a git dependency of npm. Nothing needs this repository's checkout beside it:

  • the Lexicons are in atmosynth_records::lexicons, every description and example as committed;
  • the built-ins and the reference patches are in atmosynth_builtins (Builtins::load, reference_patches, lock_lines);
  • for a program on node, atmosynth-audio-engine/content says where the built-ins, the reference patches, the Lexicons and the test samples are, and atmosynth-audio-engine/parity-cases and /parity are the parity cases and their comparison. An installed package carries no Rust, so a program rendering the parity cases builds atmo-render itself and hands renderInRust the binary.

Playing it from Rust #

A host prepares a patch off the audio thread as a Loaded, hands it to Engine::load, and renders it with Engine::process, which allocates nothing. Engine::drain_changes says what a macro or a bound controller moved, for the host's own copy of the patch.

Engine::load lets go of what sounds and fades across. An edit that changes what a patch plays and nothing it is built from needs neither: CompiledPatch::plan hands out a Plan that goes to another thread, Plan::played reads a record off it, answering None where hearing that record takes a compile, and Engine::play_as swaps what it read in between two blocks and hands back what it replaced, to be dropped off the audio thread. Every voice, the transport and whatever is waiting to be let go carry on. That is patterns and lanes, songs and scenes, a sequencer's unison and glide, pattern routes, tempo, time signature, concert pitch and tuning, and what a note reaches: note routes, input routes, thru, ranges, transposes, assigned notes and one-shots' lengths. A setting of an ordinary block is set_parameter's, and a Plan passes over it. A note held keeps its pitch through a concert pitch or a tuning until something writes its pitch again, as a wheel does on either engine, and as what is left of a pattern's recorded bend does here, where the page wrote all of it as the note was struck.

A voice knows what it was built of by its part's place, so every plan of one compile reads on from the same parts, appending what a note reaches now and moving nothing: a held voice keeps what it was built with through as many edits as come, and the next note asks afresh. An edit that comes back to what was read before adds nothing. PARTS_KEPT bounds what is added: past it Plan::played answers None, and a compile starts afresh. Engine::play_as turns down what another compile's plan read, and a reading overtaken by the one it hands back, since neither holds what a voice may stand on. A route needing an origin the compile did not make also takes a compile (a sequencer wired for the first time has no place on the transport until then), and so does one a compile would refuse.

An edit of what a patch is built from compiles, off the audio thread, and need not be heard either. Plan::carried makes a Loaded of what was compiled ready to go on from the patch that plan is of, and Engine::carry_on swaps it in between two blocks with nothing let go of and nothing faded: the clock every param's timeline is on, every voice in its slot, the transport, the keyboards and whatever each block holds move across, and the old patch comes back from take_retired. A block goes on where its id, its module, its scope and whether it is on are the same, and then its copies line up slot for slot and their nodes by ordinal. One played per note whose samples changed goes on too, its nodes paired by the module's node id since a pad with no sample is not built, less the nodes whose slots now hold another sample, which start anew: a Multisampler given a sample on one key rings on with every note it is playing on the others. A shared block filled otherwise starts anew, as it is started only once. A compile stays the one reader of a record, so a wire, an output, a block added, taken out, replaced, switched, rescoped or refilled are all one path, and a voice held hears a rewire at once, where on the page it keeps its old wiring until its note ends. What the edit touches starts anew, and a closed copy a held voice's part has come to hold is woken for that voice alone, or a block wired into its chain would be silence. A voice built on a block taken out or replaced is let go of, as on the page; so is one whose origin has gone. A delay whose width moved starts empty, its lines being as many as its input was wide. A setting the record moved in that edit travels there, and one a host moved since the compile stays.

Only what a voice stands on is read over into the new compile's parts, after all it reaches of its own, so a compile empties what PARTS_KEPT counts. What stands on what is told off the audio thread with no lock, and a voice struck after that was asked asks afresh, as the next note does, and still goes with a block it was built on. What the hands played through no block goes to the first Keyboard block to arrive, which their key-ups go to. An origin that has lost its routes stays, reaching nothing, for what it holds. Everything is moved by value, kernels included, once for each shared node and each node of an open copy.

carry_on answers whether it went on. With a fade under way, a Loaded made over another compile, or one that shares no block with what plays (Plan::carried makes no table for that), it is Engine::load. Loaded::origin_went_to and Loaded::block_went_to say where things went, for a host that keeps notes or settings by them, and Loaded::arpeggiator_went that a block's arpeggiator at work went with its block. crates/engine/tests/carry_time.rs measures what it takes.

A control binding is the player's, not the patch's (docs/adr/0005-a-control-binding-is-the-players.md), so neither engine reads one off a record. A host keeps its player's bindings where it keeps their other settings and hands them over as ControlBindings, each an instance id, a parameter id, a control number and the sweep's ends: Plan::bindings reads them for one compile, Loaded::bind gives them to a Loaded before it plays, and Engine::rebind swaps them in between two blocks while it does, handing back what it replaced. A Loaded binds nothing until told, so a host binds every one it prepares, Plan::carried's included. On the page the engine keeps them itself, with how the browser plays (settings.js's bindings, by patch and then by instance id), through setMidiControls and midiControls. Instance ids repeat from one patch to the next, so the host names the patch as a work with setBindingScope, and carryBindings gives a draft's or a room's to the patch it is published as. A Keyboard block's settings (keyboardSettings, setKeyboard) are kept under the same name and carried the same way. A scope nothing opens again is the host's to say: setBindingScope(scope, { kept: false }) keeps a page's own unsaved patch for the page alone, carryBindings(from, to, { move: true }) forgets a draft once it is published, and forgetBindingScopes drops what an earlier build left. Every write changes only what it set, in what is stored at that moment (storeSettings), and a page takes up what another tab of the browser learnt on its storage event, so two tabs never write over each other's bindings. Both engines read a binding as a player could have made it: one per parameter, the last said winning, none on a control MIDI keeps for itself (bindingsAsBound, Plan::bindings). A record written when bindings were kept in the patch may still carry midiControls; record_bindings and recordBindings read them, for a host to hand once to whoever made the patch, and nothing plays them.

A Keyboard someone else adds does not take your hands (docs/adr/0006-a-keyboard-someone-else-adds-does-not-take-your-hands.md). Alone a player plays every Keyboard block; in a room (followRoom), only those they added or chose, setKeyboard(id, {plays: true}), which a host says as a block is added, before the patch holds it. keyboardSettings answers played, whether this player plays the block now, and playedKeyboards lists them for the room's presence. A key that reaches no block because none is played is told as keysunheard, for a page to offer the patch's Keyboards. Settings kept by instance id alone, before they were kept per patch, are still read for a block its patch keeps nothing for, as chosen, and never written.

Engine::set_keyboard allocates nothing and is said between blocks. Switching a block's arpeggiator, its glide or its unison, or which channels reach it, lets go of what its keys hold; anything else answers the next note and leaves what sounds alone.

A held parameter is one a host has taken away from its player's control bindings for now, because something else moves it, as a DAW's automation does. The word is always held parameter: held alone already means a key held down. Loaded::hold_parameter(instance, parameter) holds one, named as MacroSlot and Change name it, and let_go_of_held_parameter and let_go_of_held_parameters let go of one or of all. A control bound to a held parameter moves nothing, records no Change and strikes no block on the canvas. Let go, the next control change moves it, an endless knob stepping from the value it has then. None of this rebuilds the patch or allocates, so a host may say it between any two blocks. It belongs to the Loaded, so a new patch has no held parameter: a host says it again, on the Loaded it prepares if that is to count through the fade. It is how a host plays and no record says it (playing-is-not-the-record), and only the Rust engine has it, so the traces in fixtures/engine/ know nothing of it.

Importing the engine's own modules #

Besides the entry point, every module of src/audio/, src/records/ and src/editor/ is exported at its own path, for a program that needs more of the engine than the player and the render:

import { AudioEngine } from 'atmosynth-audio-engine/audio/engine.js';
import { loopTicks } from 'atmosynth-audio-engine/audio/pattern.js';
import { decodeDescriptor } from 'atmosynth-audio-engine/records/numbers.js';

These are the engine's insides rather than a promise: they change when the engine does, so pin a commit.

Rules #

  • No dependencies, no build step. Every module in src/ imports only other modules in src/, by a relative path. A bare import, or a path out of src/, fails test/no-dependencies.test.js; a name gone from the entry point fails test/index.test.js.
  • Nothing site-specific. The engine knows no endpoint of ATMOSYNTH's but /asml, which answers any origin, and nothing of any page: where it needs something of its host (how a sample is fetched, whether the level is remembered, whether MIDI is asked for) it is handed it.
  • No I/O, no thread, no clock and no allocation on the Rust engine's render path. It builds for WebAssembly, and crates/engine/tests/wasm.rs says so.
  • A patch sounds as it does on the site, because this is the site's engine. Both hold thirty-two voices at once, and a note past them lets go of the oldest held. On the page that number is the player's to change (DEFAULT_POLYPHONY in src/audio/voices.js); the Rust engine always holds thirty-two (MAX_VOICES), so where a player has changed it the two part at the note past the smaller number.
  • Every path a comment names is here. One that is not fails test/named-paths.test.js.

Comments cite these by name:

name what it holds
playing-is-not-the-record how this browser plays (level, latency, tempo, which sequencers are stopped, which knob moves what and how each MIDI control counts, a Keyboard's arpeggiator and glide) stays in the browser and is never written to a record
nothing-between-patch-and-speakers from a patch to the speakers there is the player's gain and nothing else: no limiter, compressor or clipper; the meter is a tap
shared-inputs-never-close every input of a shared instance has silence joined to it for as long as it stands, and is held at the most channels that can ever reach it (src/audio/widths.js, the Rust engine's widths), so no voice coming or going changes what Chrome feeds a filter behind it
state-flows-engine-to-keyboard the engine knows what is sounding; the keyboard draws it and sends input, and holds none of it
versions-never-change a published module version is what it was the day it was published; a change is a new version
the-vocabulary-is-closed a module is built of a closed set of node kinds, and a reader refuses a kind it does not know by naming it
every-read-has-an-outcome a read resolves to a typed outcome and never fails as a whole: deleted, missing, unreachable and withheld stay apart

This repository was called atmosynth-offline-renderer while rendering was all it did. Issues are welcome.

License #

MIT, but for four things that are other people's work, each with its notice beside it: the Rust engine's nodes are ports of Blink's Web Audio implementation (crates/engine/NOTICE, BSD 3-Clause), the reverb's impulse response is from the Aachen Impulse Response Database (assets/builtin-modules/reverb/NOTICE, MIT), the eight 808- voices are ported from io-808's Web Audio graphs (assets/builtin-modules/808-bass-drum/NOTICE and the seven beside it, MIT), and the tile crate compiles in the flacenc FLAC encoder (crates/tile/NOTICE, Apache-2.0).