var grainBuffer, grainBus, grainGroup, grainArray; var window; var openDialog, startButton, addButton, removeButton, grainNumber, fileString; var positionSlider, densitySlider, lengthSlider; var slopeSlider, rateSlider, ampSlider; var channels, synthDefArray; synthDefArray = ["GrainularMono", "GrainularStereo"]; SynthDef("GrainularMono", { arg bus, buffer, length, lengthVar, density, densityVar, amp, ampVar, frq, frqVar, ofs, ofsVar, slp, slpVar; var clock, env, sound; var lengthValue, densityValue; length = length + (LFNoise1.kr(10,0.5,0.5) * (lengthVar - length)); lengthValue = length * 0.09 + 0.01; density = density + (LFNoise1.kr(10,0.5,0.5) * (densityVar - density)); densityValue = density * 3 + 1; clock = LFPulse.kr(1 / (densityValue * lengthValue), 0, (1 - density)); amp = TRand.kr(amp, ampVar, clock); frq = TRand.kr(frq, frqVar, clock); ofs = TRand.kr(ofs, ofsVar, clock); slp = TRand.kr(slp, slpVar, clock); env = EnvGen.kr(Env.new([0,1,1,0], [slp * 0.5, 1 - slp, slp * 0.5]), clock, amp, timeScale:lengthValue); sound = PlayBuf.ar(1, buffer, frq * 2, clock, ofs * BufFrames.kr(buffer)) * env; Out.ar(bus, [sound, sound]); }).writeDefFile; s.sendSynthDef("GrainularMono"); SynthDef("GrainularStereo", { arg bus, buffer, length, lengthVar, density, densityVar, amp, ampVar, frq, frqVar, ofs, ofsVar, slp, slpVar; var clock, env, sound; var lengthValue, densityValue; length = length + (LFNoise1.kr(10,0.5,0.5) * (lengthVar - length)); lengthValue = length * 0.09 + 0.01; density = density + (LFNoise1.kr(10,0.5,0.5) * (densityVar - density)); densityValue = density * 3 + 1; clock = LFPulse.kr(1 / (densityValue * lengthValue), 0, (1 - density)); amp = TRand.kr(amp, ampVar-amp, clock); frq = TRand.kr(frq, frqVar, clock); ofs = TRand.kr(ofs, ofsVar-ofs, clock); slp = TRand.kr(slp, slpVar-slp, clock); env = EnvGen.kr(Env.new([0,1,1,0], [slp * 0.5, 1 - slp, slp * 0.5]), clock, amp, timeScale:lengthValue); sound = PlayBuf.ar(2, buffer, frq * 2, clock, ofs * BufFrames.kr(buffer)) * env; Out.ar(bus, sound); }).writeDefFile; s.sendSynthDef("GrainularStereo"); grainBus = Bus.new; grainArray = Array.new; grainGroup = Group.new; window = SCWindow("Grain Potter", Rect(0,0,100, 315), false); window.view.background_(Color.new(0.3,0.3,0.3)); //window.view.decorator = f = FlowLayout(window.view.bounds); window.onClose = { if (grainGroup != nil, {grainGroup.free}); if (grainBuffer != nil, {grainBuffer.free}); if (grainBus != nil, {grainBus.free}); }; window.front; openDialog = SCButton(window, Rect(10, 10, 80, 15)); openDialog.states = [["Open", Color.black, Color.new(0.8,0.8,0.8)]]; openDialog.action = { CocoaDialog.getPaths({ arg paths; var sf; sf = SoundFile.new; sf.openRead(paths.at(0)); channels = sf.numChannels; sf.close; if (grainBuffer != nil, {grainBuffer.free}); grainBuffer = Buffer.read(s, paths.at(0)); fileString.string_(" " ++ PathName(paths.at(0)).fileName); }, {"Canceled".postln}, 1); }; fileString = SCStaticText(window, Rect(10, 30, 80, 15)).string_(" empty") .background_(Color.new(0.8, 0.8, 0.8)); addButton = SCButton(window, Rect(10,50, 15,15)); addButton.states = [["+", Color.black, Color(0.3, 0.3, 0.3)]]; addButton.action = { grainArray = grainArray.add(Synth(synthDefArray.at(channels - 1), [ "bus", grainBus.index, "buffer", grainBuffer.bufnum, "length", lengthSlider.lo, "lengthVar", lengthSlider.hi, "density", densitySlider.lo, "densityVar", densitySlider.hi, "amp", \amp.asSpec.map(ampSlider.lo), "ampVar", \amp.asSpec.map(ampSlider.hi), "frq", rateSlider.value, "frqVar", rateSlider.value, "ofs", positionSlider.lo, "ofsVar", positionSlider.hi, "slp", slopeSlider.lo, "slpVar", slopeSlider.hi ], grainGroup)); grainNumber.value_(grainArray.size); }; removeButton = SCButton(window, Rect(30,50,15,15)); removeButton.states = [["-", Color.black, Color(0.3, 0.3, 0.3)]]; removeButton.action = { grainArray.pop.free; grainNumber.value_(grainArray.size); }; grainNumber = SCNumberBox(window, Rect(50, 50, 40, 15)); SCStaticText(window, Rect(10, 70, 80, 15)).string_("Position"); positionSlider = SCRangeSlider(window, Rect(10, 90, 80, 15)); positionSlider.lo_(0.0).hi_(0.4); positionSlider.action = { grainGroup.set("ofs", positionSlider.lo, "ofsVar", positionSlider.hi); }; SCStaticText(window, Rect(10, 110, 80, 15)).string_("Density"); densitySlider = SCRangeSlider(window, Rect(10, 130, 80, 15)); densitySlider.lo_(0.3).hi_(0.7); densitySlider.action = { grainGroup.set("density", densitySlider.lo, "densityVar", densitySlider.hi); }; SCStaticText(window, Rect(10, 150, 80, 15)).string_("Length"); lengthSlider = SCRangeSlider(window, Rect(10, 170, 80, 15)); lengthSlider.lo_(0.0).hi_(1.0); lengthSlider.action = { grainGroup.set("length", lengthSlider.lo, "lengthVar", lengthSlider.hi); }; SCStaticText(window, Rect(10, 190, 80, 15)).string_("Slope"); slopeSlider = SCRangeSlider(window, Rect(10, 210, 80, 15)); slopeSlider.lo_(0.4).hi_(0.6); slopeSlider.action = { grainGroup.set("slp", slopeSlider.lo, "slpVar", slopeSlider.hi); }; SCStaticText(window, Rect(10, 230, 80, 15)).string_("Rate"); rateSlider = SCNumberBox(window, Rect(10, 250, 80, 15)); rateSlider.value_(1); rateSlider.action = { grainGroup.set("frq", rateSlider.value, "frqVar", rateSlider.value); }; SCStaticText(window, Rect(10, 270, 80, 15)).string_("Amp"); ampSlider = SCRangeSlider(window, Rect(10, 290, 80, 15)); ampSlider.lo_(0.0).hi_(1.0); ampSlider.action = { grainGroup.set("amp", \amp.asSpec.map(ampSlider.lo), "ampVar", \amp.asSpec.map(ampSlider.hi)); }; SCStaticText(window, Rect(5,5,90,305)) .string_(" ") .background_(Color.grey);/* authors so far: casey basichis */ |