«Re: sloth canons [Pattern Extension]» by tom.dugovic

on 23 Apr'22 22:21 in code forksloth canon

Save this as an extension and recompile class library. You can now use Psloth([0,1,0], 10), for example, instead of declaring a new routine for each pattern.

I didn't persist the use cases, as this should be saved as a .sc file. Please refer to the ancestor code for usage.

Memory/CPU usage will grow over time, but at a decreasing rate. This can be used for a large amount of repeats. Extensive testing has not been done on this though.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Psloth {
    var seed, repeats;

    *new { arg seed, repeats=1;
        ^super.newCopyArgs(seed, repeats);
    }

    storeArgs{^[seed, repeats]}

    embedInStream { arg inval;
        var size=seed.size;
        var pointers=List[];
        repeats.value(inval).do({ arg j;
            j = j+1;
            if(j == j.nextPowerOf(size),{ pointers.add(0); });
            pointers.collect{|i| seed.at(i)}.sum.embedInStream(inval);
            pointers.do{|x, i|
                if((i==0) || (pointers[0..(i-1)].sum==0), {pointers[i] = ((x+1)%size);})
            };
        });
        ^inval
    }
}
raw 623 chars (focus & ctrl+a+c to copy)
reception
comments
eli.rosenkim user 28 Apr'22 01:25

this is rad!