witw/sc/witw.scd

247 lines
6.5 KiB
Plaintext

/*RUN*/
// initial settings .....................................
s.options.numInputBusChannels = 4;
s.options.numOutputBusChannels = 4;
~dataPath = "/home/rizoma/witw/data/"; // CHANGE THIS TO RELATIVE PATH
~devices = ["D7:80:BE:2C:63:BD", "F1:CC:C3:0B:7F:5C"];
s.waitForBoot{
// create 8 control busses to pass data between synths
~ctrlBus = 8.collect({arg i; Bus.control(s,1); });
// initial settings .....................................
// define synths
SynthDef(\sgrain, { | out=0, atk=0.01, dcy=0.01, freq=100, pan=0, amp=1|
var sig, env;
env = EnvGen.ar(Env.perc(atk, dcy), doneAction: 2);
sig = FSinOsc.ar(freq);
sig = sig * (env * amp);
sig = Pan2.ar(sig, pan);
Out.ar(out, sig);
Out.kr(~ctrlBus[0],freq);
}).add;
SynthDef(\sslew, {
| out = 0, freq=100, amp = 0.7, slewrate = 1|
var sig, z;
// add slew rate on frequency
z = Slew.kr(freq, slewrate, slewrate);
sig = BPF.ar(PinkNoise.ar(), z, 6 );
//sig = Blip.ar(z, 5, amp).dup;
Out.ar(out, sig)
}).add;
SynthDef.new(\sine, {
arg freq=440, panfreq=0.3, panphase=0.5, rel=0.5, gate=0, amp=0.0001;
var sig;
sig = SinOsc.ar(freq);
sig = sig * EnvGen.kr(Env.perc(0.04,rel), doneAction:2);
sig = Pan2.ar(sig, FSinOsc.kr(panfreq, panphase));
sig = sig * amp;
Out.ar(0, sig);
}).add;
// initial settings .....................................
// load and process the data source /////////////////////////////////
~csvFile=CSVFileReader.read(~dataPath ++ ~devices[0] ++ "/" ++ "sensor_data.csv",true,true);
// flatten ~data from 2D Array to regular array (per column);
~data = ( ~csvFile[0].size ).collect({ arg itt;
Array.fill( ~csvFile.size-1,{ arg i;
~csvFile.at(i+1).asArray.at(itt)}); // +1 to skip the column name
});
~data[2]; // Temperature C
~data[3]; // F
~data[10]; // wind speed MPH
~data[11]; // wind direction
~data[13]; // wind gusts MPH
~data[5]; // rain bucket capacity
~data[6]; // rain bucket tips per minute?
~data[20]; // LON
~data[21]; // LAT
// normalize data ranges //////
~date=~data[0];
~freq=~data[2].asFloat.normalize(0, 400);
~atk=~data[4].asFloat.normalize(0.02, 0.04);
~dcy=~data[2].asFloat.normalize(0.05, 0.1);
~dur=~data[2].asFloat.normalize(0.1, 0.1);
~level=~data[2].asFloat.normalize(0, 0);
//start the slewing synth /////////////////////////////
//~sslew1 = Synth(\sslew,[\out,0,\freq,220,\amp,0,\slewrate,1000]);
//~sslew1.map(\freq, ~ctrlBus[0]); // map control bus to freq parameter
//o = OSCFunc({ |msg| msg.postln }, '/tr', s.addr);
~ce = Array.new(maxSize: 20);
// first synth test /////////////////////
/* ( p = Pbind(\instrument, \sgrain,
\freq, Pseq(~freq.round(30),1),
\atk, Pseq(~atk,1).poll,
\dcy, Pseq(~dcy,1),
\pan, Pseq([0,1], inf),
\dur, Pseq(~dur,1),
\amp, Pseq(~level, 1),
\date, Pseq(~date, 1 )
).collect{ arg i; i.postln; });*/
// initial settings .....................................
~gr = Group.new;
~pitchset = [20,40,60,80].midicps;
Pdef(\c,
Pspawner({ | sp |
8.do { | i |
sp.par(
// Pdefn (~ce[i],
Pbind( *[
\instrument, \sine,
\dur, Pseq(Array.geom(30, rrand(1,1.5), rrand(0.98,0.99)).mirror,inf),
\freq, exprand(~pitchset[0],~pitchset[0]*100).round(~pitchset[0]),
\panfreq, rrand(0.1, 2.2),
\amp, 0.05,
\panphase, rrand(-1.0,1.0),
\rel, exprand(1.5,3.35),
//\gate, 0,
\group, ~gr
]);
//)
);
sp.wait(1);
};
});
).play;
// initial settings .....................................
~dur = PatternProxy.new;
~deg = PatternProxy.new;
~oct = PatternProxy.new;
~voc = PatternProxy.new;
~amp = PatternProxy.new;
~sca = PatternProxy.new;
~rel = PatternProxy.new;
~dur.source = Pseq(Array.geom(30, rrand(1,1.5), rrand(0.98,0.99)).mirror,inf);
~deg.source = Prand([0,5,7],inf);
~oct.source = Prand([2,3,4],inf);
~voc.source = 4;
~amp.source = Pwhite(0.001, 0.1,inf);
~sca.source = Scale.harmonicMinor;
~rel.source = Pexprand(1.5,3.35, inf);
// initial settings .....................................
Pdef(\c, Pspawner({ | sp | 8.do { | i | sp.par(
Pbind( *[
\instrument, \sine,
\dur, ~dur,
\scale, ~sca,
\degree, ~deg,
\octave, ~oct,
//\freq, exprand(~pitchset[0],~pitchset[0]*80).round(100),
\panfreq, rrand(0.1, 2.2),
\amp, ~amp,
\panphase, rrand(-1.0,1.0),
\rel, ~rel,
//\rel, exprand(1.5,3.35),
\group, ~gr
]);
); sp.wait(1); }}); ).play;
}; // closes s.waitForBoot .....................................
// initial settings .....................................
~dur.source = Pseq(Array.geom(30, rrand(1,1.5), rrand(0.96,0.97)).mirror,inf);
~oct.source = Prand([3,4,5],inf);
~deg.source = Prand([0,1,2,3,4,5],inf);
~sca.source = Scale.chromatic;
~rel.source = Pexprand(1.1,4.5, inf);
~amp.source = Pwhite(0.001, 0.1,inf);
/////////////////////////////////////////////////////////
// temporal structure of wind controled layer ///////////
// .....................................
~temperature=~data[2];//.asFloat; //.normalize(0, 11);
(
r = Routine { arg inval;
var i = 0;
loop {
i = i + 1;
postln(~temperature[i]); postf("beats: % seconds: % time: % \n",
thisThread.beats, thisThread.seconds, Main.elapsedTime
);
~deg.source = Prand([0,1,2,3,5,8],inf); postln("line 1");
~oct.source = Prand([4,5],inf);
~dur.source = Pseq(Array.geom(30, rrand(2,4), rrand(0.96,0.97)).mirror,inf);
~rel.source = Pexprand(1.1,5.5, inf);
20.wait;
~deg.source = Prand([0,3,5,8],inf); postln("line 2");
~oct.source = Prand([3,4,5],inf);
~dur.source = Pseq(Array.geom(30, rrand(1,2.5), rrand(0.96,0.97)).mirror,inf);
20.wait;
~deg.source = Prand([6,7,8,9,10,11],inf);postln("line 3");
~oct.source = Prand([3,4,5,6],inf);
~rel.source = Pexprand(3,6, inf);
~dur.source = Pseq(Array.geom(30, rrand(1,1.5), rrand(0.96,0.97)).mirror,inf);
20.wait;
~deg.source = Prand([0,2,4,6,8,10],inf);postln("line 4");
~oct.source = Prand([2, 3,4,5],inf);
20.wait;
~deg.source = Prand([0,2,4,6,8,10],inf);postln("line 5");
~oct.source = Prand([3,4,5],inf);
~dur.source = Pseq(Array.geom(30, rrand(0.5,0.6), rrand(0.98,0.99)).mirror,inf);
~rel.source = Pexprand(0.5,6, inf);
20.wait;
~deg.source = Prand([0,7,5],inf);postln("line 6");
~oct.source = Prand([2,3],inf);
~dur.source = Pseq(Array.geom(30, rrand(0.5,1.6), rrand(0.98,0.99)).mirror,inf);
~rel.source = Pexprand(3,6, inf);
10.wait;
~deg.source = Prand([0,7,5],inf);postln("line 6");
~oct.source = Prand([2,3,4,5],inf);
~dur.source = Pseq(Array.geom(30, rrand(1,1.5), rrand(0.98,0.99)).mirror,inf);
~rel.source = Pexprand(6,10, inf);
20.wait;
};
}.play;
);
r.stop;