Skip to content

Instantly share code, notes, and snippets.

@pgblu
Last active March 7, 2017 18:55
Show Gist options
  • Save pgblu/6e5bd41734813684d7db to your computer and use it in GitHub Desktop.
Save pgblu/6e5bd41734813684d7db to your computer and use it in GitHub Desktop.
Command line timer with just-intonation pulse generator
# add this to your .bash_profile
# pomo() takes 0,1, or 3 arguments
# 1st is a time in minutes (default 25)
# 2nd and 3rd are a just-intonation ratio x:y (default 4:3)
# End the process with ctrl-C.
function pomo() {
case $# in
[0]*)
chuck ~/Documents/ChucK/pomo.ck
;;
[1]*)
chuck ~/Documents/ChucK/pomo.ck:"$1"
;;
[3]*)
chuck ~/Documents/ChucK/pomo.ck:"$1":"$2":"$3"
;;
*)
echo "illegal number of arguments (expecting 0,1, or 3)"
esac
}
// Download ChucK's command line interface at chuck.cs.princeton.edu
// Place this file in your ~/Documents/ChucK folder
// This script will be called from the command line using pomo and 0, 1, or 3 args
5 => int sizer;
// 5 is about the maximum that it can handle, 6 creates some
// bit-crashing, and 7 is completely distorted (but is also kind of nice).
// 1=>8, 2=>24, 3=>48, 4=>80, 5=>120, 6=>168, 7=>224 (x^2 + 4x+ 4) shreds
float num;
int denom;
if (me.args() > 1) {
Std.atof(me.arg(1)) => num;
Std.atoi(me.arg(2)) => denom;
} else {
4.0 => num;
3 => denom;
}
//first fundamental
250.0 * Math.pow(0.5,0.166667) => float x;
//Intervall determination for second fundamental.
x*(num/denom) => float y;
//Endpoints of the probe line
5.0 => float a1;
-3.0 => float b1;
4.0 => float a2;
-5.0 => float b2;
// countdown duration
dur T;
if (me.args() != 0)
Std.atoi(me.arg(0))::minute => T;
else 25::minute => T;
// remember
now => time start;
now + T => time later;
// wait
while( now < later )
{
<<< (T - (now - start)) / second, "left..." >>>;
1.0::second => now;
}
fun void iGen(int i1, int j1) {
Math.random2(0,9000)::ms=>now;
SinOsc s => ADSR e => dac;
while(true) {
Euclid(i1,j1,a1,b1) + Euclid(i1,j1,a2,b2) => float dist;
Math.pow(0.85,dist) * 0.9 => s.gain;
i1*x + j1*y => s.freq;
Math.random2(0,4) => int t;
e.set(75::ms, 8::ms, .2, (10*Math.pow(5,t))::ms);
e.keyOn();
300::ms => now;
e.keyOff();
1+Math.pow(2.0,-0.2*(Euclid(a1,b1,a2,b2))) => float prlen;
(440*Math.pow(prlen,dist))::ms => now;
}
}
fun float Euclid(float p, float q, float r, float s) {
return Math.sqrt(Math.pow((p-r),2) + Math.pow((q-s),2));
}
for(-(sizer) => int i; i<(sizer+1); i++) {
for (-(sizer) => int j; j<(sizer+1); j++) {
if (i != 0 || j != 0)
spork ~ iGen(i,j);
}
}
while (x != y) {
500::ms=>now;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment