let harmony = Engine.new(Palestrina);
fn detect_pitch(buf) -> Note
const MAX_VOICES: usize = 4;
voice_leading.reject_parallels()
struct GuitarInput { onset }
engine.harmonize(note, scale)
fn detect_pitch(
  buf: &[f32]
) -> Option<Note>
let voices =
  counterpoint::
    generate(line, mode);
if interval == Fifth
  && motion == Parallel
  { reject() }
#[inline(always)]
fn onset(
  frame: &Frame
) -> bool
block_size: 128
sample_rate: 48_000
latency_ms: 7.2
// Palestrina
// counterpoint
// rules.rs
CONTRAPUNK WEEKEND JAM·WK 01·Koji Kondo· STARTS IN 2DAYS→ /jam
ENGINE INTERNALS

HOW IT WORKS.

Six stages, one audio thread, no allocations in the hot path.

01 AUDIO IN

CPAL captures guitar audio at 48kHz in 128-sample blocks, ring-buffered to the DSP thread. MIDI input from any controller also lands here.

let stream = cpal::default_host()
  .default_input_device()?
  .build_input_stream(&cfg, …)?;
02 PITCH

McLeod autocorrelation + single-cycle refinement. Onset via spectral flux. Pitch voting smooths jitter. Sub-3ms per buffer.

let note = pitch_detection::
  mcleod_pitch(
    &buf, 48_000.0
  )?;
03 HARMONY

HarmonyEngine resolves the note against the current Scale and HarmonyMode. Stateful modes (Contrary, Strict CP) advance their internal history.

let line = engine
  .harmonize_note_on(note)?;
04 VOICING

VoiceLeadingProcessor places each harmony pitch-class into Soprano / Alto / Tenor / Bass, cartesian-products the combinations, scores them, picks the best.

let chord = solver
  .revoice_chord(line, prev)?;
05 HUMANIZE

Jitter, velocity, swing, duration. A per-note record ties Note-Off to its Note-On so releases stay coherent.

let humanized = humanizer
  .humanize_note_on(note, vel);
06 MIDI OUT

Virtual MIDI (CoreMIDI / WinMM / ALSA) to your DAW, or straight into a CLAP plugin hosted inside Contrapunk via clack-host.

midi_out.send(NoteOn {
  ch, note, vel
})?;
◆ ◇ ◆ ◇ ◆ WATCH IT
demo · contrapunk.mp4 · live take
LIVE GUITAR TAKE · PALESTRINA MODE · SUB-10MS PLUCK→NOTE · NO EDITING
◆ ◇ ◆ ◇ ◆ HOST A PLUGIN
CLAP PLUGIN HOST · clack-host
SLOT 01 · INSTRUMENT
VITAL.clap
wavetable · 2 in · 2 out
HARMONY
→ MIDI →
PLUGIN
→ AUDIO →
OUT
CLAP ABI · SAFE WRAPPER · GUI, LOG, AUDIO-PORTS, NOTE-PORTSROUTING HARMONY → INSTRUMENT