{
   "author" : "tom.dugovic",
   "name" : "Re: sloth canons [Pattern Extension]",
   "ancestor_list" : [
      "1-5fU"
   ],
   "description" : "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.\r\n\r\nI didn't persist the use cases, as this should be saved as a `.sc` file. Please refer to the ancestor code for usage.\r\n\r\nMemory/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.",
   "labels" : [
      "code fork",
      "sloth canon"
   ],
   "is_private" : null,
   "id" : "1-5g3",
   "code" : "Psloth {\r\n    var seed, repeats;\r\n\r\n    *new { arg seed, repeats=1;\r\n        ^super.newCopyArgs(seed, repeats);\r\n    }\r\n\r\n    storeArgs{^[seed, repeats]}\r\n\r\n    embedInStream { arg inval;\r\n        var size=seed.size;\r\n        var pointers=List[];\r\n        repeats.value(inval).do({ arg j;\r\n            j = j+1;\r\n            if(j == j.nextPowerOf(size),{ pointers.add(0); });\r\n            pointers.collect{|i| seed.at(i)}.sum.embedInStream(inval);\r\n            pointers.do{|x, i|\r\n                if((i==0) || (pointers[0..(i-1)].sum==0), {pointers[i] = ((x+1)%size);})\r\n            };\r\n        });\r\n        ^inval\r\n    }\r\n}"
}
