Ok, four days into the Expo and I'd really love to introduce buffers into the code, the synths are ok, but could be improved with samples.
This is the code i'm running, I'm trying to get the analogin to chose the buffer number, but 'Index not integer' is my problem.
I found a crude way to change sounds on the fly without the bela exploding, but it means running the ugens for digitalin and analogin right in the synthdef.
arg atk=0, sus=0, rel=3, c1=1, c2=(-1),
buf=0, rate=1, spos=0, freq=440, rq=1, bpfmix=0,
pan=0, amp=1, out=0;
var sig, env, sound, sample,
buffersAvailable=[0,1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19];
sample = Select.ar( ((0.4).linlin(0.01, 1, 0, 19).nearestInList(buffersAvailable)), buffersAvailable);
sound = b[\drum_kit][1 * sample];
env = EnvGen.kr(Env([0,1,1,0], [atk, sus, rel], [c1,0,c2]), gate: 1 );
sig = PlayBuf.ar(1, sound, rate*BufRateScale.ir(sound), startPos:spos);
sig = XFade2.ar(sig, BPF.ar(sig, freq, rq, 1/rq.sqrt), bpfmix*2-1);
sig = sig * amp;
sig = Pan2.ar(sig, pan, amp);