Device Details


Overview

Name | Version: Kasm Counterpoint 1.12
Author: kevleyski
Device Type: MIDI Effect
Description: MIDI Live Looping with counterpoint harmony and scale detection

This is an example of Rust code running in Ableton doing some complex algorithms to record the midiin Max4Live data detect the played scale and run some sums and output fire off additional notes to midiout

To change the counterpoint algoriths this Ableton Max4Live MIDI device was built with source code available here:
https://maxforlive.com/library/device/12909/kasm-ableton-wasm-rust-source-code-example

!! NOTE: you need the latest Ableton 12.2 for this as it uses the new V8 jsinterp from Max9 !!

Kasm is WebAssembly so you can develop and test things in web browser too, try it out here:
https://pyrmontbrewery.com/kasm


For those interested, this is what the Bangaz Rust code (Ableton Live and Web version uses identical WebAssembly)...

pub fn kasm_emanator_chaos_game_harmony(
inlet_0_note: i32,
_inlet_1_semitone_offset: i32,
inlet_2_velocity: i32,
_inlet_3_enc1: i32,
_inlet_4_enc2: i32,
_time_step: i32,
_time_bar: i32,
) -> i32 {
let note = inlet_0_note;
let velocity = inlet_2_velocity;
let base_note = note.max(24).min(104); // Restrict to reasonable MIDI range
let base_velocity = velocity.max(1).min(127);
let harmony_voices = 4;
let mut x = base_note as f64;
let mut y = base_velocity as f64;
let delays = [0, 80, 160, 240];
let mut harmony_notes = Vec::new();

// Generate harmony notes using chaos game logic, keep close to root
for _i in 0..harmony_voices {
let r = ((note * 22 + velocity * 23) % 1000) as f64 / 1000.0; // Pseudo-random
if r < 0.25 {
x = (x + base_note as f64) / 2.0;
y = (y + base_velocity as f64) / 2.0;
} else if r < 0.5 {
x = (x + base_note as f64 + 7.0) / 2.0;
y = (y + base_velocity as f64 + 7.0) / 2.0;
} else if r < 0.75 {
x = (x + base_note as f64 - 5.0) / 2.0;
y = (y + base_velocity as f64 + 12.0) / 2.0;
} else {
x = (x + base_note as f64 + 3.0) / 2.0;
y = (y + base_velocity as f64 + 3.0) / 2.0;
}
let harmony_note = x.round() as i32;
let harmony_note = harmony_note
.max(base_note - 12)
.min(base_note + 12)
.max(24)
.min(104); // Keep close to root and in range
let harmony_vel = (y.round() as i32).max(40).min(127);
harmony_notes.push((harmony_note, harmony_vel));
}

// Set MIDI modulation wheel (CC 1) for expressive effect
let mod_value = (base_velocity as f32 * 0.7).max(0.0).min(127.0) as i32;
crate::send_cc(1, mod_value, 0);

// Send harmony notes as counterpoint
for (i, (note, vel)) in harmony_notes.iter().enumerate() {
crate::send_note(*note, *vel, delays[i], 220, 64 + (i as i32 * 12));
}
0
}

pub fn kasm_emanator_prime_harmony(
inlet_0_note: i32,
_inlet_1_semitone_offset: i32,
inlet_2_velocity: i32,
_inlet_3_enc1: i32,
_inlet_4_enc2: i32,
_time_step: i32,
_time_bar: i32,
) -> i32 {
let base_note = inlet_0_note;
let velocity = inlet_2_velocity;
let mut prime_idx = PRIME_INDEX.write().unwrap();
*prime_idx = (*prime_idx + 1) % PRIMES.len();

let prime = PRIMES[*prime_idx];

// Map primes to just intonation ratios avoiding dissonance
let interval = match prime {
2 => 12, // 2:1 octave
3 => 7, // 3:2 perfect fifth
5 => 4, // 5:4 major third
7 => 10, // 7:4 harmonic seventh (close to minor seventh)
11 => 6, // 11:8 augmented fourth (close to tritone, but we'll use dim fifth)
13 => 8, // 13:8 minor sixth
17 => 2, // 17:16 semitone (use major second)
19 => 3, // 19:16 minor third
_ => prime % 12, // Fallback to chromatic mapping
};

let harmony_note = (base_note + interval).min(127);

// Use 120 BPM timing for just intonation-inspired sequential harmony
let beat_ms = 500; // 120 BPM beat duration
let triplet_subdivision = (beat_ms / 3) as i32; // Triplet = 166.67ms at 120 BPM
send_note(harmony_note, velocity * 5 / 6, triplet_subdivision, 500, 1);

post!(&format!(
"Prime harmony: prime {} base {} + interval {} = {} (triplet delay: {}ms)",
prime, base_note, interval, harmony_note, triplet_subdivision
));

harmony_note
}

...

full source code is here https://maxforlive.com/library/device/12909/kasm-rust-ableton-wasm-source-code

Details

Live Version Used: 12.2
Max Version Used: 9.0
Date Added: Jul 24 2025 07:06:21
Date Last Updated: Jul 28 2025 12:27:46
Downloads: 118
License: None
Average Rating

Log in to rate this device

-n/a-

Files

Device File: Kasm Counterpoint.amxd
 


Comments

Hello. To run this, is there anything else needed except a compatible Ableton Live? Thanks!
(no, just needs 12.2 or newer it relies on the nee V8 integration, give it a go should work)

Login to comment on this device.

Browse the full library