21 September 2008

SuperCollider Joystick Granulator


Joystick Granulator with SuperCollider3 from basementhum on Vimeo.

(
s=Server.local;
s.boot;
)


(
b = Buffer.alloc(s, 44100 * 3.0, 1);
SynthDef(\SimpleSine, { arg bufnum, warp=0.5, warpmult=1,grainsize=0.5,pitch=1, gate=1;
var wa=WarpIn.ar(SoundIn.ar(0), bufnum, warp*warpmult, pitch, grainsize, -1, 3, 0.01);
var en=Env.asr(0.002, 0.9, 0.002, 1, 'linear');
var eg=EnvGen.kr(en,gate,doneAction: 2);
Out.ar(0, wa*eg)
},[0,0.1,0.1,0.1,0.1]).send(s);


// detect logitech ATK3 joystick plugged into frontmost usb port on macbook.
HIDDeviceService.buildDeviceList;
HIDDeviceService.devices.do({arg dev;

[dev.manufacturer, dev.product, dev.vendorID, dev.productID, dev.locID].postln;

dev.elements.do({arg ele;

[ele.type, ele.usage, ele.cookie, ele.min, ele.max].postln;

});

});
HIDDeviceService.devices.at(0).queueDevice;
)


(
var pitchmult=1;
HIDDeviceService.action_({arg productID, vendorID, locID, cookie, val;
[productID, vendorID, locID, cookie, val].postln;
if (cookie==15,
{if(x.notNil,
{x.set(\warp,(1-(val/255)+0.01))}
)};
);
if (cookie==16,
{if(x.notNil,
{x.set(\grainsize,(val/255)+0.01)}
)};
);
if (cookie==17,
{if(x.notNil,{x.set(\pitch,((val/255)*4)-2)})};
);
if (cookie==4 && val==0,
{b.zero; x = Synth("SimpleSine",["gate",1,"buffnum",b])};
);
if (cookie==4 && val==1,
{if(x.notNil,{x.set(\gate,0)})};
);
if (cookie==6 && val==0,
{if(x.notNil,{x.set(\pitch,1)})};
);
if (cookie==5 && val==0,
{if(x.notNil,{x.set(\pitch,-1)})};
);
if (cookie==7 && val==0,
{if(x.notNil,{pitchmult=pitchmult+5;x.set(\pitch,pitchmult)})};
);
if (cookie==8 && val==0,
{if(x.notNil,{pitchmult=pitchmult-5;x.set(\pitch,pitchmult)})};
);

});

HIDDeviceService.runEventLoop;
)

/*
15 horizontal axis 0-255
16 vertical axis 0-255
17 +- wheel 0-255
4 index trigger 0-1
5 trigger2 0-1
6 trigger3 0-1
7 trigger4 0-1
8 trigger5 0-1
9 trigger6
10 trigger7
11 trigger8
12 trigger9
13 trigger10
14 trigger11
*/

0 comments: