I have managed, to implement the above into a simpler version. Although this is working as it is supposed to be, I am not sure the sounding aspect is the most representable, if any can suggest some things to make it sound better, that would be great, right now I get only some clicks/cracks sounds. Am I sure this can be improved with some buffer writing management maybe, or is this the best it can do based on my approaches at hand.
// =====================================================================
// SuperCollider Workspace
// =====================================================================
HID.findAvailable[0];
~gamepad = HID.open(1356, 2508); //or something based on connected devices.
c = {Bus.control(s, 1)}!4;
b = {Buffer.alloc(s, 2 * 44100, 1)}!4;
(
[14, 15, 16, 17].collect{
|el, i|
~gamepad.elements[el].action = {|...args|
c[i].set(args[0].range(-1.0, 1.0).postln);
};
}
)
//run bellow if no controller is available.
(
Ndef(\c1, {Out.kr(c[0].index, LFNoise1.kr(1).range(-1, 1)) });
Ndef(\c2, {Out.kr(c[1].index, LFNoise1.kr(1).range(-1, 1)) });
Ndef(\c3, {Out.kr(c[2].index, LFNoise1.kr(1).range(-1, 1)) });
Ndef(\c4, {Out.kr(c[3].index, LFNoise1.kr(1).range(-1, 1)) });
)
(
SynthDef(\record_buf, { arg out=0, input=0, bufnum=0, gate = 0, dur = 2;
var in;
in = In.kr(input, 1);
EnvGen.kr( Env.sine, gate, dur ) * RecordBuf.kr(in, bufnum, 0, 0.5, 0.5, doneAction: Done.freeSelf, loop: 1);
}).add;
)
(
SynthDef(\play_buf, { arg out = 0, bufnum = 0, rate = 1;
var playbuf;
playbuf = PlayBuf.ar(1, bufnum, BufRateScale.ir(bufnum) * rate, 1, loop:1);
Out.ar(out, playbuf);
}).add;
)
(
[0, 1, 2, 3].collect{ |i|
Synth(\record_buf, [\input, c[i].index, \bufnum, b[i].bufnum]);
Synth(\play_buf, [\out, 0, \bufnum, b[i].bufnum, \rate, 1]);
b[i].plot; //test something is written in the buffs.
}
)
~gamepad.close;