// Quantizer: snaps a control voltage to semitones or the major pentatonic scale. module quant "Quantizer" { desc de "Quantisierer: rundet V/Oct auf Halbtöne oder die Dur-Pentatonik; mit Trigger hält er den Ton bis zum nächsten Takt." desc en "Quantizer: rounds V/Oct to semitones or the major pentatonic scale; with a trigger it holds the note until the next clock." switch scale "SCALE" "CHR" "PEN" = 0 in x "IN" pitch in clk "TRIG" gate out y "OUT" pitch out g "GATE" gate process { s = semi(x) // Pentatonic: round the semitone within the octave down to 0, 2, 4, 7 or 9. oct = floor(s) n = round((s - oct) * 12) pen = n >= 9 ? 9 : n >= 7 ? 7 : n >= 4 ? 4 : n >= 2 ? 2 : 0 q = scale == 0 ? s : oct + pen / 12 y = connected(clk) ? sah(q, rise(clk)) : q g = gate(pulse(changed(y), 5)) } }