Compose music in Vis as Strudel code. Play it live, layer by layer, and export WAV, MP3, FLAC, Ogg, Opus, M4A or AAC, as a mix or as one stem for each layer.
In py3, the music tools take the code or a file:
song = """setcpm(124/4)
drums: s("bd*4, [~ cp]*2, hh*8").bank("RolandTR909")
bass: note("<c2 c2 eb2 g1>*4").s("sawtooth").lpf(sine.range(400, 1600).slow(4)).gain(.5)
keys: n("<0 2 4 6>").scale("C:minor").s("piano").room(.4)
"""
await music.save("songs/acid", song) # songs/acid.strudel, only when it compiles
await music.play("songs/acid.strudel") # live, returns at once
await music.play("songs/acid.strudel", layers=["bass"]) # the bass alone, without a gap
await music.stop()
await music.export("songs/acid.strudel", "out/acid.mp3", cycles=16)
await music.export("songs/acid.strudel", "out/acid.wav", stems=True) # acid.drums.wav, ...Requires Vis (vis-agent) 0.8.0 or newer. See Runtimes for runtime requirements.
vis-agent extension install Blockether/vis-music --trustThen run /reload in Vis.
Vis uses the music implementation for your agent runtime.
- Python needs Python 3.12 or newer. It supplies Node.js as a Python
dependency and can use
lameencfor MP3. - Babashka needs standalone Node.js 22 or newer and
taronPATH. Install FFmpeg to export compressed audio. Babashka does not need Python. It uses the jailed shell service in Vis. If the host lacks this service, the music tools report an error.
Start a Babashka agent with vis-agent --runtime babashka, then use
(music/check "lead: note(\"c3 e3\").s(\"sine\")") to check a track.
Ten tracks in examples/. See Examples for the style and the layers of each one.
| Tool | Does |
|---|---|
music.check(track) |
Compiles the track; lists layers, tempo and unknown sounds. |
music.save(path, code) |
Checks, then writes a .strudel file. |
music.play(track, layers=(), cps=0) |
Plays live until music.stop(); a new play replaces the old one on time. |
music.stop(shutdown=False) / music.status() |
Stops the sound / tells what plays. |
music.events(track, begin=0, end=1) |
The notes of a span, to read a pattern without listening. |
music.export(track, out, cycles=0, seconds=0, stems=False) |
Renders offline, faster than real time. Vis shows a player. |
music.sounds(filter) |
Sample names, drum machine banks and synths. |
music.export writes WAV, MP3, FLAC, Ogg, Opus, M4A, and AAC. All compressed
formats use ffmpeg on PATH. The Python implementation can use lameenc
for MP3 instead.
A track is a file path or the code itself. See Examples for the layer labels, _ mute and S solo.
See Limitations for the sound engine, the render paths and the known gaps.
py3 calls the tools as await music.export("examples/acid.strudel", "out/acid.mp3"). The SDK calls are synchronous and work inside a Vis extension callback:
from blockether import vis
class Jukebox:
"""Render Strudel tracks without the live sound engine."""
def render(self, track: str, out: str, cycles: int = 0) -> list[str]:
"""Render a track offline. Returns the files that it wrote."""
song = vis.tools.music.export(track, out, cycles=cycles)
return [file.path for file in song.files]
ext = vis.Extension("jukebox", description="Offline Strudel renders.")
ext.expose(Jukebox(), name="jukebox")vis.tools.music raises vis.errors.NoCall in code that Vis does not call, and vis.errors.NotBound outside Vis.
uv sync
VIS_EXTENSION_SCHEMA_DIR=/path/to/vis-contract/schema uv run pytest
(cd babashka && bb test) # standalone Node.js, FFmpeg, and the test host
python scripts/build.py # after a change in js/
vis-agent extension install . --trust --global --saveOn a machine without an audio device, music.play fails with a clear error and
music.export still works. Set VIS_MUSIC_NO_AUDIO=1 there: the tests then
check that error instead of live playback.
AGPL-3.0-or-later. See LICENSE and NOTICE.md.