Oh I just reread your original question and maybe you don’t need MIDI playability… if you want to play with patterns, much easier, but you need to turn the rate argument into a freq argument:
(
SynthDef(\sample_mono_pat, { |out, buf, startSec, freq, baseFreq = 220, gate = 1, amp = 0.1, pan|
var env = Env.adsr(0.1, 1, 0.2, 1.0).ar(Done.freeSelf, gate);
var rate = freq / baseFreq;
var startPos = startSec * BufSampleRate.kr(buf);
var sig = PlayBuf.ar(1, buf, BufRateScale.kr(buf) * rate, startPos: startPos);
Out.ar(out, Pan2.ar(sig * env * amp, pan));
}).add;
)
(
Pbind(
\instrument, \sample_mono_pat,
\buf, Pfunc { ~buf },
\scale, Scale.chromatic('pythagorean'),
\degree, Pseq([0, 2, 7, 9], inf),
\octave, Prand([3, 4], inf),
\dur, 0.2
).play;
)