Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generative SuperCollider files containing random patterns
/*
Generate SuperCollider file containing simple random pattern
*/
(
// Time stamp
~stamp = Date.getDate.stamp;
// This goes in the duration key of the pattern
~dur = "Pseq(%)".format(Array.rand(10, 0.1,10.0));
// The degree key
~degree = "Pwhite(%, %)".format(10.rand2, 10.rand2);
// The actual string that will be written to the file
~patternString = "
// Pattern generated %
Pbind(
\dur, %,
\degree, %
).play".format(~stamp, ~dur, ~degree);
// Path + filename
~path = "~/code/sc/gen_pat%.scd".format(~stamp).standardizePath;
// Open a file
~file = File(~path, "w");
// Write to it
~file.write(~patternString);
"Writing % to file %".format(~string, ~path).postln;
// Close the file
~file.close;
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment