Skip to content

Instantly share code, notes, and snippets.

@ryanlaws
Created November 4, 2021 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanlaws/2ecf087f46e30ff3a4bd7c6f41f6b1fb to your computer and use it in GitHub Desktop.
Save ryanlaws/2ecf087f46e30ff3a4bd7c6f41f6b1fb to your computer and use it in GitHub Desktop.
// each channel has its own trigger stream
// which is a slow Impulse and a faster CombN
// delay threshold is a regular trigger for an envelope
// the source is controlled by a Select (many:1)
// binary math takes triggers on several control channels
// and outputs the index of which channel was last triggered
(Ndef(\spaghettiArp, {|root=45, triggerThreshold=0.08, brightness=1.5, atk=0, dec=2.5|
var chord = [0,4,7,10,15,17];
var clockSpeed, clockPhase, clock;
var impulseDelay, triggerThreshold, switchTrigger, bits, switch;
var noteTrig, octaveJump, note;
var envTrig, env, osc, panPos;
clockSpeed = (0.1!chord.size).rrand(0.2);
clockPhase = (pi!chord.size).rand;
clock = Impulse.kr(clockSpeed, clockPhase);
impulseDelay = CombN.kr(clock, 0.5, (0.05!4).rrand(0.5), 5);
switchTrigger = (clock + impulseDelay) > triggerThreshold;
bits = 2 ** (1..chord.size);
switch = Mix.kr(switchTrigger * bits);
noteTrig = switch.sign;
octaveJump = Demand.kr(noteTrig, 0, Drand(0!5++(1..2)*12, inf));
note = Select.kr(switch.log2-1, chord+root);
note = octaveJump + Latch.kr(note, noteTrig);
note = note.lagud(0.01, 0.05);
envTrig = Mix.kr(switch.sign).lagud(0, atk*2) > 0.5;
env = envTrig.lagud(atk, dec) ** 2;
osc = Mix.ar(SinOscFB.ar((note + [0, 12.05]).midicps, env*brightness, env * 0.5));
panPos = Latch.kr(switch.log2*2-(chord.size+1)/(chord.size-1), switch.sign);
Pan2.ar(osc, panPos);
}).play)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment