Kasm Ableton WASM Rust (Max4Live + source code)
Manipulating live notes on-the-fly with Rust/WebAssembly (WASM)
This is a tutorial only (i.e. not an exciting new plugin) detailing a working example of how to manipulate MIDI data and potentially DSP audio signals using more efficient Rust code in Ableton Live 12.2 w/ Max4Live using WebAssembly in the newly added V8 Javascript engine
!! NOTE: this project needs Ableton Live 12.2 (or later) and Max4Live as it utilises the new V8 engine, i.e. you'll need Live 12.2 Suite or Standard + Max4Live add-in !!
Features includes:
Passing inlet parameters from JS into to Rust
Rust code calling Max4Live outlet function (Rust code plays chords offset by semitones pssed in from Max4Live)
Max console debug post() messages from inside Rust code
How does it work, what does "Kasm" do for me?
There are three primary layers working together to enable Rust execution within Max4Live/V8:
Rust Code Layer: Your MIDI/Audio DSP logic compiled as WebAssembly
JavaScript Bridge Layer: Handles WASM bytecode loading, setups parameter marshalling for Max4Live integration
Max4Live Layer: V8 JavaScript engine with an basic example .amxd device showing two way communication with Rust
Kasm then provides the base64-encoded WASM binary parts and compiles this as a blob for integration:
Base64 Decoding: Custom atob() implementation for Max4Live
WASM Compilation: Direct compilation from that decoded binary
Function Export: Cahing mapped Rust functions available to JavaScript
getStringFromWasm: Convert WASM memory strings into JavaScript strings
The example contains a heap of code comments, whilst you can figure it out from this it helps if you already know a bit about what WebAssembly is, Javascript and how to compile Rust code
Building and updating it is easy:
npm install
npm run build
This updates kasm_WASM_rust.js which then compiles the WASM, you simply copy and paste that into any 'v8' Max4Live object
The example .amxd demonstrates the Rust function being called and outlet and debugging messages from Rust code itself
kasm_midi_note_offset has two inlets and has one outlet
pub fn kasm_midi_note_offset(inlet_0: i32, inlet_1: i32) -> i32
kasm_midi_note_octave_hit shows how to generate chords and triggering MIDI events by calling the outlet() function from inside Rust and also debugging the Rust code into Max4Live console using post()
Rust/WebAssembly/JavaScript source code you can use to build a Ableton Live Max4Live .amxd supporting Rust code