Skip to content

Instantly share code, notes, and snippets.

@madskjeldgaard
Last active March 9, 2020 15:09
Show Gist options
  • Save madskjeldgaard/bb93f0dbb1c4926c0ef17fb481be0e74 to your computer and use it in GitHub Desktop.
Save madskjeldgaard/bb93f0dbb1c4926c0ef17fb481be0e74 to your computer and use it in GitHub Desktop.
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