A music visualizer engine in Rust that plays MilkDrop-format (.milk) presets,
including MilkDrop 2 presets with pixel shaders and MilkDrop 3 double presets
(.milk2).
tidewarp draws into a pixel buffer that you own. It opens no window, reads no files and owns no audio device, so it fits inside a terminal UI, a GUI or a web page.
Photosensitivity warning. MilkDrop presets can contain flashing lights and fast patterns. If you show them to other people, tell them so, and offer
ComfortMode::Photosensitive. That mode reduces flashing; it cannot promise that no image triggers a reaction.
cargo run --release --example terminal
cargo run --release --example terminal -- --photosensitive --size 120x40The example draws the built-in presets in a truecolor terminal and plays a synthetic beat. To use real music, pipe raw audio into it:
ffmpeg -re -i song.mp3 -f f32le -ac 2 -ar 44100 - | cargo run --release --example terminal -- --stdinTo see shader presets, render a grid of presets from a folder into one PNG
(this needs the gpu feature):
cargo run --release --features gpu --example contact_sheet -- path/to/presets sheet.png
cargo run --release --features gpu,textures --example contact_sheet -- path/to/presets sheet.png --textures path/to/texturesWhen a shader preset does not translate or looks wrong, print the HLSL that tidewarp gives wgslift. The wgslift CLI and its playground translate this file as tidewarp does:
cargo run --release --features gpu --example shader_source -- preset.milk warp > warp.hlsl
wgslift warp.hlsl --entry shader_body --loop-limit 1024 --validateuse tidewarp::{ComfortMode, Config, Engine, Transition, presets};
let mut engine = Engine::new(Config {
width: 320,
height: 180,
comfort: ComfortMode::Off,
..Config::default()
});
let id = engine.load_preset(presets::ALL[0].text)?;
engine.switch_to(id, Transition::Blend(3.0))?;
let mut rgba = vec![0u8; 320 * 180 * 4];
// For each frame: push the audio you have, then render.
engine.push_pcm(&samples, 2, 44_100);
let info = engine.render_into(seconds_since_start, &mut rgba, 320 * 4)?;- The simulation runs at a fixed 60 steps per second, whatever your frame rate.
push_pcmtakes interleavedf32samples at any sample rate.load_presettakes the text of a.milkfile, or of a MilkDrop 3.milk2double preset. Reading files is up to you.- A statement of preset code that does not compile is left out, and the rest of its
block still runs.
skippedlists what a preset left out.
Most MilkDrop 2 presets have warp and composite pixel shaders. With the gpu cargo
feature, Engine::with_gpu renders them with wgpu and reads the
image back into your buffer:
tidewarp = { version = "0.4", features = ["gpu"] }let mut engine = Engine::with_gpu(Config::default())?;
println!("rendering on {}", engine.gpu_name().unwrap_or("?"));The shaders are translated from HLSL to WGSL at load time by
wgslift. Without the gpu feature the
engine renders on the CPU and needs no graphics stack; shader presets then fail to
load with Error::NeedsShaders, or render without their shaders when
Config::allow_shader_presets is set. On a GPU engine, a preset whose shader does not
translate fails with Error::Shader, or renders without its shaders when that flag is set.
Preset shaders run with a budget of 1024 loop passes per pixel, so a loop that never
ends cannot hang the GPU. When the GPU device is lost or a GPU operation fails,
render_into returns Error::Gpu; make a new engine then, or fall back to
Engine::new.
Many MilkDrop 2 shaders sample images by name, such as sampler_clouds or
sampler_worms. The engine reads no files, so you supply them:
- Offer the names you have with
Engine::set_texture_names, for example the file stems of a texture folder.sampler_rand00tosampler_rand15pick from these names, andsampler_rand00_smalltiledpicks only names that start withsmalltiled. - After
load_preset, asktextures_neededwhich ones the preset uses. - Add each one with
add_texturebeforeswitch_to.
A texture you do not add samples mid-grey. texsize_<name> reports the size of the
image you added. A running preset keeps its textures after remove_texture.
use tidewarp::TextureImage;
engine.set_texture_names(stems); // for example ["clouds", "worms", ...]
let id = engine.load_preset(&text)?;
for name in engine.textures_needed(id) {
let bytes = read_texture_file(&name); // your file lookup
engine.add_texture(&name, TextureImage::decode(&bytes)?)?;
}
engine.switch_to(id, Transition::Blend(3.0))?;TextureImage::decode reads JPEG, PNG and TGA files and needs the textures cargo
feature:
tidewarp = { version = "0.4", features = ["gpu", "textures"] }With your own decoder, pass RGBA8 pixels to TextureImage::new. Images larger than
4096 pixels on a side are refused.
With the textures feature, TextureFolder does the file part: it finds the images
under some folders by file stem (folders whose name starts with _ are skipped) and
decodes the ones a preset needs.
use tidewarp::TextureFolder;
let textures = TextureFolder::scan(["path/to/presets", "path/to/textures"]);
engine.set_texture_names(textures.names());
let id = engine.load_preset(&text)?;
let added = textures.add_needed(&mut engine, id);
engine.switch_to(id, Transition::Blend(3.0))?;
for name in &added {
engine.remove_texture(name); // the running preset keeps its copy
}A MilkDrop 3 .milk2 file holds two presets and a blend pattern stopped at one point.
load_preset reads it like a .milk file and gives one id: both presets run, and the
pattern decides which of the two each pixel shows. On the GPU the two are mixed before
the frame is read back, so a double preset costs one readback, like a single one.
The same patterns can change presets:
use tidewarp::{BlendPattern, Transition};
engine.switch_to(
id,
Transition::Pattern {
pattern: BlendPattern::Plasma,
seconds: 3.0,
inward: true,
},
)?;BlendPattern::ALL lists the 30 patterns, and BlendPattern::from_name reads the names
that .milk2 files use. inward turns Cercle, Triangle, Patches and Corner
around, as blending_direction=-1 does; the other patterns have one direction. In
ComfortMode::Photosensitive a pattern change is a slow cross-fade instead.
The patterns are measured on captures of MilkDrop 3.37, with a black and a white preset
as the two halves: where each pattern puts the second preset at a given progress, how
wide its soft edge is, and what the five random_n values and the direction of a
.milk2 file change. Like MilkDrop 3, tidewarp sets the weight at the 32 by 24 vertices
of a mesh that is finer toward the middle, so a thin shape shows the mesh. The patterns
follow the shape of the image as they do there, measured in wide, square and upright
windows; MilkDrop 3 measures both sides of the image rounded up to a multiple of 16, and
so does tidewarp. In an upright image MilkDrop 3 moves the four straight wipes off the
middle; tidewarp keeps them in the middle. plasma3 is measured in part only and drawn like plasma2.
MilkDrop 3 presets can also draw sprites: images with a place, a size, a blend mode and
code. A sprite image is a texture like the others: textures_needed lists it by its
file stem (sprites\Mandala1.png is mandala1), and the sprite is drawn once you have
added it. Sprites are drawn on the GPU only.
The sprite blend modes 5 to 10 and the meaning of the Sprite* keys are worked out
from the preset files and the public MilkDrop 3 notes, without MilkDrop 3 as a
reference, so they can look different from MilkDrop 3.
tidewarp-term encodes the frames for terminals with the Kitty graphics protocol or Sixel, fast enough for 60 frames per second:
tidewarp-term = "0.4"- The
.milkformat: settings, per-frame, per-vertex and init code. - The EEL expression language with
megabuf,gmegabuf,loopandwhile. - The warp mesh and feedback, the eight built-in waveforms, and custom waves and shapes (instanced and textured).
- Borders, motion vectors, video echo, gamma and the color filters.
- Warp and composite shaders, with the blur levels, noise textures and the per-frame
shader values (feature
gpu), and MilkDrop 3'sget_fft(pos)andget_fft_hz(freq)with theFFTAttackandFFTDecaykeys. - Disk textures by name and the
sampler_rand00tosampler_rand15samplers, from images the host adds (featuregpu; decoding with featuretextures). - MilkDrop 3 double presets (
.milk2) with its 30 blend patterns, measured on MilkDrop 3. - MilkDrop 3 sprites in
.milkand.milk2files (featuregpu). - Blends between presets, as a cross-fade or through a blend pattern.
ComfortMode::Off(the default: presets as written) andComfortMode::Photosensitive(slow brightness changes, dimmed peaks, slow blends).
tidewarp is its own implementation, not a port. Its behaviour is checked against
MilkDrop 2 by comparing rendered output; most presets look the same, some details
(the warp wobble) still differ.
tidewarp ships nine presets of its own, under CC0:
- six in
tidewarp::presets::ALL, which every engine plays; - three in
tidewarp::presets::SHADER(Tidewarp Sunrise, Tidewarp Lasers and Tidewarp Dancer), which needEngine::with_gpu. Each kick moves the whole scene, and each lead note between the kicks draws its own beam, fan or ring of petals, placed and colored by the note's pitch throughget_fft.
No third-party preset pack has a licence that permits redistribution, so load your own preset files for more.
tidewarp is not affiliated with Nullsoft, Winamp or the authors of MilkDrop.
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.