Dear Giulio,
thank you so much for your prompt response. I did a quick try by uploading 12 wave files (36.wav, 37.wav, ..., 48.wav) corresponding to 12 samples in the same directory where I have the .scd file.
I then wrote the following code:
// starting server
s = Server.default;
//audio options
s.options.numAnalogInChannels = 8;
s.options.numAnalogOutChannels = 8;
s.options.numDigitalChannels = 16;
s.options.blockSize = 16;
s.options.numInputBusChannels = 2;
s.options.numOutputBusChannels = 2;
s.options.postln;
// main code
s.waitForBoot({
~samples = Array.new;
~folder = PathName.new("./");
// load samples
(
~folder.entries.do({
arg path;
~samples = ~samples.add(Buffer.read(s, path.fullPath));
});
);
// create basic instrument: play sample with a simple envelope
(
SynthDef.new("harp", {
arg buf, vel=64, gate=0, rate=1;
var sig, env, amp;
env = EnvGen.kr(Env.asr(), gate, doneAction:2);
sig = PlayBuf.ar(2, buf, rate*BufRateScale.ir( buf ));
amp = LinExp.kr(vel, 1, 127, 0.01, 1);
sig = sig * env * amp;
Out.ar(0, sig);
}).add;
);
// Read AnalogIn (channel 0) and map values to 36-48 (the notes available, through samples 36.wav ... 48.wav).
(
SynthDef("play_harp",{ arg out=0;
Out.ar(out,
Synth("harp", [\buf, ~samples[AnalogIn.ar( DC.ar( 0 ) ).range( 36, 48 )].bufnum,\vel, 63,\gate, 1]);
)
}).send(s);
);
s.sync;
Synth.new("play_harp", target: s);
});
Unfortunately the compiler fails with the following error:
....
^^ The preceding error dump is for ERROR: Primitive '_BasicAt' failed.
Index not an Integer
RECEIVER: [ Buffer(0, nil, nil, nil, ./36.wav), Buffer(1, nil, nil, nil, ./37.wav), Buffer(2, nil, nil, nil, ./38.wav), Buffer(3, nil,
nil, nil, ./39.wav), Buffer(4, nil, nil, nil, ./_main.scd), Buffer(5, nil, nil, nil, ./settings.json) ]
So sorry to keep troubling you, do you think is there anything clearly wrong?
A huge thank-you!
Dom