Expand description
MilkDrop engine: preset + expressions + audio + shaders driving lactea-render.
Embeddable into any wgpu host: bytes in (presets, textures, PCM), a host-provided
wgpu::Device / Queue and target view out. No windows, no audio devices, no filesystem.
This crate is the CPU side of MilkDrop 2’s RenderFrame (milkdropfs.cpp + state.cpp),
behaving like projectM where projectM and MilkDrop 2 differ (projectM is the reference;
docs/divergences.md, docs/engine.md).
use lactea::{Engine, EngineConfig, FrameClock, Transition};
let mut engine = Engine::new(device, queue, EngineConfig::default()).unwrap();
let report = engine.load_preset(milk, "my preset", Transition::Cut).unwrap();
for frame in 0..60u32 {
engine.push_pcm_f32(pcm, 2);
let mut enc = device.create_command_encoder(&Default::default());
engine.render(&mut enc, target, FrameClock { time: frame as f64 / 60.0, frame });
queue.submit(Some(enc.finish()));
}Preset changes: Transition::Cut replaces the preset at once, Transition::Soft blends the
old and the new preset over a number of seconds (both keep running: projectM’s shader
transitions by default, MilkDrop 2’s per-vertex blend with Compat::MilkDrop2); see
docs/engine.md.
Modules§
- auto_
cut - MilkDrop 3
AutoHardCutMode0..7 (MD3 3.37,docs/md3.md“Auto hard cuts”): beat-driven preset changes and composite-shader effect injection.
Structs§
- Anim
Frame - One frame of an animated image.
- Animated
Image - An animated image (a GIF): every frame is a full canvas.
- Audio
Frame - Everything the renderer needs for one frame.
- Ctrl
Keys - The arrow keys held together with Ctrl (
ctrllt ctrlrt ctrldn ctrlup): BeatDrop sets them from Ctrl + arrow key events. The host reports the current state; the engine samples it once per rendered frame. - Date
Time - The wall clock BeatDrop reads with
GetLocalTime. The engine never looks at the system clock (a library must be deterministic); until the host callscrate::Engine::set_date_timeit derives the time of day from the frame clock instead (seecrate::Engine::set_date_time). - Debug
Image - A rendered stage read back from the GPU: RGBA8, row 0 = top.
- Double
Preset Info - What the host can show about the double preset on screen (
crate::Engine::double_preset_info). - Engine
- The MilkDrop engine. See the crate docs.
- Engine
Config - Engine construction parameters.
- Filter
- The playlist’s include/exclude list (
projectm_playlist_set_filter). - Forced
Frame - Oracle state to impose on the next rendered frame (
crate::Engine::force_next_frame). - Frame
Clock - Time of the frame about to be rendered.
- Hook
- An optional callback taking
&A. Clones share the same underlying callback. - Image
- A decoded texture: RGBA8, row 0 = top.
- Load
Request - What the host’s loader is asked to do (
projectm_playlist_preset_load_event). - Md3Locks
- The user locks of the random block (
forcePattern,forceProgress,dirLock), all off by default. - Md3Pattern
Instance - Everything a generator needs: the values of the
.milk2header keys. - Media
Files - Index of the media files a host can read, with the lookups of MilkDrop 3.
- Mouse
State - The host’s mouse, as MD3’s
_c14shader constant (mouse,mouse_x.. of the shader prelude) sees it. Preset expressions cannot read it: MD3’s expression grammar has no dotted identifiers, somouse.xdoes not compile there. - Playlist
- An ordered preset list with projectM’s navigation rules. See the module docs.
- Preset
Control - projectM’s timing + switch-request state. Deterministic: the easter-egg duration sampling is seeded from the run seed.
- Preset
Report - What
Engine::load_presetfound. - Renderer
- The MilkDrop 2 frame renderer. See the crate docs for the pass order.
- Shader
Fallback - A shader that was replaced by a default one.
- Shader
Override - User-supplied HLSL for a locked MilkDrop 3 preset (see
EngineConfig::shader_overrides). - Switch
Failure - A failed preset load (
projectm_preset_switch_failed_event): the preset’s name and the error text. The previously loaded preset keeps running. - Switch
Request - The host should load another preset (
projectm_preset_switch_requested_event). - Transition
Info - The soft cut in progress (
Engine::transition_info).
Enums§
- Compat
- Which reference behaviour the renderer follows where MilkDrop 2 (
third_party/md2) and projectM differ. Default: projectM. - Double
Mode - Where a double preset is in its life (
DoublePresetInfo::mode). - Engine
Error - Errors from
Engine::load_preset. - Md3Pattern
- The 30 MD3 blend patterns, in MD3’s order (
index()is the discriminant). - Media
- What a
TextureProviderfound for an MD3 resource. - Pass
Kind - Which pass a translated shader runs in.
- Shader
Outcome - How a warp / composite shader slot ended up.
- Sort
Order - Sort direction for
Playlist::sort. - Sort
Predicate - What
Playlist::sortcompares. - Stage
- Which intermediate or final image a dump frame holds.
- Touch
Type projectm_touch_type(types.h:68-79): the waveform a touch asks for.- Transition
- How
Engine::load_presetreplaces the current preset. - Transition
Kind - The six built-in transition shaders, in projectM’s
TransitionShaderManagerorder.
Constants§
- DEFAULT_
RETRY_ COUNT - Default number of failed loads in a row before the failure event is raised.
- HARD_
CUT_ MIN_ FRAMES - A hard cut needs more than this many rendered frames first (
m_frameCount > 50). - IDLE_
PRESET .milksource of the idle preset.- IDLE_
PRESET_ NAME - Display name the idle preset is loaded under (
Engine::preset_name). - INSERT_
AT_ END - Pass as
indexto insert at the end (Playlist::InsertAtEnd). - MAX_
HISTORY - Maximum entries of the playback history (
Playlist::MaxHistoryItems). - TEXTURE_
EXTENSIONS - Extensions MD3 looks for when a shader names a texture, in its order (
.jpegis accepted right after.jpg). - VCS_
VERSION git describe --always --dirtyof the source this crate was built from;"unknown"for a build outside a git checkout of it (a published crate). projectM’sprojectm_get_vcs_version_string.
Traits§
- Texture
Provider - Source of user textures (
sampler_<name>in preset shaders).
Functions§
- compat_
for_ preset - The compatibility mode
EngineConfig::auto_compatpicks for a preset file:Compat::MilkDrop3whenlactea_preset::detect_compatfinds evidence of a MilkDrop 3 feature, otherwiseCompat::ProjectM(MilkDrop 2 files are indistinguishable from projectM ones, so this never returns it;Engine::load_presetreaches it only by retrying a preset projectM rejects with a compile error). Pure on the bytes; the evidence itself islactea_preset::detect_compat. - decode_
gif - Decode a GIF into full-canvas frames.
- default_
enabled_ patterns - The 13 patterns random soft cuts may pick when
settings.inihas no[transitions]section. - md3_
draw_ progress - The progress of a double preset drawn for
pattern:round((rand() / 32767 * A + B) * 100) / 100. - md3_
fill_ vertinfo - Fill the
(gx + 1) * (gy + 1)meshvi(vi[y * (gx + 1) + x] = (a, c)) with the pattern.aspectis(m_fAspectX, m_fAspectY). Pure: the same instance gives the same mesh, nothing is read fromvi. - md3_
random_ instance - The random block of
RandomizeBlendPattern, once per preset change: draws, in this order, the pattern (a uniform element ofenabled,{zoom}if empty), the direction (+-1, unless locked),r1..r5and, in double-preset mode, the pattern again ifauto_hardcut(one of the first six patterns, ignoringenabled) and the progress. Ordinary soft cuts haveprogress = 1.
Type Aliases§
- Failed
Fn - Callback of
Playlist::set_preset_switch_failed_callback:(filename, message). - Switched
Fn - Callback of
Playlist::set_preset_switched_callback:(is_hard_cut, index).