Skip to content

Instantly share code, notes, and snippets.

@catfact
Last active March 23, 2021 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catfact/ddcc63d78e8d2de9dc6054bd5fbd5bef to your computer and use it in GitHub Desktop.
Save catfact/ddcc63d78e8d2de9dc6054bd5fbd5bef to your computer and use it in GitHub Desktop.
supercollider graph wrapping
Routine {
s = Server.default;
~make_def = {
arg name, path;
// assume path refers to a .scd, returning a function, returning a ugen graph
// Hz is argument to function
f = this.executeFile(path);
f.postln;
SynthDef.new(name.asSymbol, {
arg out=0, amp=0.5, hz = 110.0, hzlag = 0.02;
var graph;
graph = f.value(Lag.kr(hz, hzlag));
Out.ar(out, (graph * amp).dup);
}).send(s);
};
// manage paths and stuff
~load_helper = {
arg name; // the graph filename, without location or extension
var path;
path = PathName(Document.current.path).pathOnly ++ name ++ ".scd";
~make_def.value(name, path);
};
~load_helper.value("sine");
s.sync;
x = Synth.new(\sine);
~change_def = { arg newname;
Routine {
~load_helper.value(newname);
s.sync;
if (x.notNil && x.class == Synth, {
x.get(\hz, { arg hz;
hz.postln;
x.free;
x = Synth.new(newname.asSymbol, [\hz, hz]);
});
});
}.play;
};
// play some nonsense
// try changing these
~imul = 13;
~imod = 6;
~jmul = 13;
~jmod = 7;
~geowrap = { arg x, min, max, ratio=2;
var y = x;
while ({y<min}, {y = y * ratio});
while ({y>max}, {y = y / ratio});
y
};
{
var dt = 0.125;
var root = 220;
var rate_max = 2**6;
var rate_min = 2**(-3);
var dt_max = 0.25;
var dt_min = 1/16;
var hz_max = 2000;
var hz_min = 100;
var rate = 1;
var i = 1;
var j = 1;
var hz = root;
s.sync;
inf.do {
hz = ~geowrap.value(root * rate, hz_min, hz_max);
i = (i*~imul)%~imod + 1;
j = (j*~jmul)%~jmod + 1;
rate = ~geowrap.value(rate * i / j, rate_min, rate_max);
dt = ~geowrap.value(dt * rate, dt_min, dt_max);
//hz.postln;
x.set(\hz, hz);
dt.wait;
}
}.value;
}.play;
// swap DroneZones:
/*
~change_def.value("lpsaw");
~change_def.value("sine");
*/
{
arg hz;
LPF.ar(Saw.ar(hz), hz * 4)
}
{
arg hz;
SinOsc.ar(hz)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment