Kasm Ableton WASM C++ (Max4Live + source code)
Manipulating live notes on-the-fly with C++/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 C++ 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 C++
C++ code calling Max4Live outlet function (C++ code plays chords offset by semitones pssed in from Max4Live)
Max console debug post() messages from inside C++ code
How does it work, what does "Kasm" do for me?
There are three primary layers working together to enable C++ execution within Max4Live/V8:
C++ 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 C++
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 C++ functions available to JavaScript
getStringFromWasm: Convert WASM memory strings into JavaScript strings, for Max Window console debugging
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 C++ code
Building and updating it is easy:
npm install
npm run build
This updates kasm_WASM_cpp.js which then compiles the WASM, you simply copy and paste that into any 'v8' Max4Live object
The example .amxd demonstrates the C++ functions being called and outlet and debugging messages from C++ code itself
kasm_midi_note_offset has two inlets and has one outlet simply offset the played note
kasm_midi_note_octave_hit shows how to generate chords and triggering MIDI events by calling the outlet() function from inside C++ and also debugging your code into Max4Live console using post()
C++/WebAssembly/JavaScript source code you can use to build a Ableton Live Max4Live .amxd supporting C++ code