var pitchsets, timepoints, patterndurations;
var lPat = Pseq( (8..12).mirror, inf).asStream;
var rPat = Pseq( (5..8).mirror/25, inf).asStream;
var length = lPat.next;
var cantus = (Pbrown(-6, 6, 3) ).asStream.nextN(length);
{ cantus[cantus.size.rand] = \r }.dup((~length * rPat.next).asInteger.postln);
~pitchsets = cantus.asSet.asArray.powerset.select{ | v | v.size == 3};
pitchsets = pitchsets.collect(_.scramble);
timepoints = pitchsets.collect({ | pset | ~computeDurs.(pset, cantus) });
patterndurations = timepoints.sum;
p = [ 3, 2, 1, 0, -1, -4, -5, -2 ];
sp = [-2, 0, 1];
occurrences = [7, 3, 2];
durations = [7, 4, 7]:
duration = 18;