Sunday, November 18, 2007

Super Collider

Dear ligs

For those who are interested here is my super collider code and mp3. Enjoy!

// Buffer

b = Buffer.read(s, "Sounds/Soprano Piano.wav");
c = Buffer.read(s, "Sounds/Techno.wav");

// Synthdef 1

(
SynthDef(\bufGrain,{ arg out = 0, bufnum, rate=1.0, amp = 0.1, dur = 10, freq = 10, pPos = 0.5, startPos=0, reverb = 0;
var signal;
signal = PlayBuf.ar(1, bufnum, rate, startPos) * EnvGen.kr(Env.sine(dur, amp), doneAction: 2);

OffsetOut.ar(out, ({CombC.ar(signal * 0.2, 0.01, XLine.kr(1, 0.01, 0.001), reverb)}) ! 2)
}).load(s)
)



// -------------------------------------------------------------------------------
// GUI & GRAIN CREATION
// -------------------------------------------------------------------------------
(
// Variables
var win,
sliderData,
controlArr,
time = 0, // Start Time
totalTime = 100, // Total Time
thisGrainDur, // Grain Duration
message, // SynthDef Message
wait,
sf,
offset,
activity,
deviationmult,
dutycycle; // Interval

// Build Slider Data
sliderData = [
// Label Min Max Init Param
["Grain Rate", [-1.0,25.0], 1.0, \rate],
["Grain Amplitude", [0.0, 1.0], 0.1, \amp],
["Grain Duration", [0.0, 3.0], 0.5, \dur],
["Grain Start Position", [0.0, 100000.0], 0.1, \startPos],
["Grain Decay", [0.0, 5.0], 0.0, \reverb]
];

// Build Control Data Array for Temporary GUI Information
controlArr = Array.fill(sliderData.size, {Array.newClear(5)});

// Window Setup
win = SCControlWindow(
name: "Granular Synth 1",
bounds: Rect(64,0,600,400)
).front;



offset=DDSlider( win, Rect.new(50,240,200,40), "offset", 0.0, 10.0, 'linear', 0.01, 0.0);
activity=DDSlider( win, Rect.new(50,310,200,40), "activity", 0.0, 5.0, 'linear', 0.01, 0.0);
deviationmult=DDSlider( win, Rect.new(280,240,200,40), "deviationmult", 0.0, 5.0, 'linear', 0.01, 1.0);
dutycycle =DDSlider( win, Rect.new(280,310,200,40), "dutycycle",0.0, 2.0, 'linear', 0.01, 1.0);
// Build Control consisting of Label, Min NumBox, Range Slider, Max NumBox,
sliderData.do({

// Arguments
arg val,
idx;

// Feedback
val[1].postln;

// Variables
m = idx * 30; // Multiplier to layout GUI

// Label
SCStaticText(
parent: win,
bounds: Rect(5, m, 100, 20)
).string =val[0];

// Min Number Box
controlArr[idx][0] = SCNumberBox(
parent: win,
bounds: Rect(110, m, 50, 20)
).value_(val[1][0]);

// Max Number Box
controlArr[idx][1] = SCNumberBox(
parent: win,
bounds: Rect(480, m, 50, 20)
).value_(val[1][1]);

// Create Button

(p = SCButton(win,Rect(20,168,220,50));
p.states = [
["Pick a Granulation File"],
["Pick a Granulation File", Color.white,Color.black]];
p.action = {

(
CocoaDialog.getPaths({ arg paths;
paths.do({ arg u;
b = Buffer.read(s, u);

u.postln;
})
},{
"cancelled".postln;
});
)

});

// BBCUT!


sf = BBCutBuffer("sounds/Electro.wav",16);

// Button 2

(p = SCButton(win,Rect(290,168,220,50));
p.states = [
["Pick a BBCut File"],
["Pick a BBCut File", Color.white,Color.black]];
p.action = {
(
CocoaDialog.getPaths({ arg paths;
paths.do({ arg t;
Routine.run({

sf = BBCutBuffer(t ,16);

s.sync;
// 3.33bps= 200 bpm
BBCut2(CutBuf2(sf, offset, deviationmult, dutycycle),SQPusher1(activity)).play(3.33);

});
t.postln;
})

},{
"cancelled".postln;
});

)});

// Create Range Slider
controlArr[idx][2] = SCRangeSlider(
parent: win,
bounds: Rect(170, m, 300, 20)
);

// Slider remapping from 0.0 - 1.0 to .. - ..
controlArr[idx][3] = val[1].asArray.asSpec;

// Slider Action
controlArr[idx][2].action_({

// Change Number Box Value
controlArr[idx][0].value_(controlArr[idx][3].map(controlArr[idx][2].lo.value));
controlArr[idx][1].value_(controlArr[idx][3].map(controlArr[idx][2].hi.value));

});

});

// Routine
r = Routine.new({

// Do function
inf.do{
// Arguments
arg item;

// Variable
// [controlArr[0][0].value, controlArr[0][1].value].postln;

message = [
\freq, rrand(controlArr[0][0].value, controlArr[0][1].value),
\amp, rrand(controlArr[1][0].value, controlArr[1][1].value),
\dur, thisGrainDur = rrand(controlArr[2][0].value, controlArr[2][1].value),
\pPos, rrand(controlArr[3][0].value, controlArr[3][1].value)
];

// Instance
(

Synth(\bufGrain, [ \bufnum, b.bufnum,
\rate, rrand(controlArr[0][0].value, controlArr[0][1].value),
\amp, rrand(controlArr[1][0].value, controlArr[1][1].value),
\dur, thisGrainDur = rrand(controlArr[2][0].value, controlArr[2] [1].value),
\startPos, rrand(controlArr[3][0].value, controlArr[3][1].value),
\reverb, rrand(controlArr[4][0].value, controlArr[4][1].value)

]));


// Duration and Interval
wait = thisGrainDur * rrand(0.1,0.2);
wait.wait;
};
});
AppClock.play(r);
)



Mp3 is here:



http://www.box.net/shared/68s8dx9k92

No comments: