Hi guys,
it has been some month I’m working on this sampler synth of mine and I’m improving and testing it day by day also thanks to your precious help (Dictionary and array inside patterns, Orchetral Texture v1).
Now I want to add a new feature: I want it to be played in a polyphonic way.
I now that if I evaluate the following code (I’m using the SSO samples here) I obtain a chord:
(
Pbindef(
\test,
\instrument, \default,
\degree, Pseq([[0,4,7]], inf),
\dur, 1,
\amp, 0.25
);
)
Pbindef(\test).play;
but if I do the same with my code I get an error.
(
// create data structure to load samples
~loadfunc;
if (~samples.notNil) {
~samples.do({
|key|
if (~samples[key].notNil) {
~samples[key][\buffers].do({
| buffer |
if (buffer.notNil) {
buffer.free;
};
});
};
});
};
~samples = ();
// add function to load samples
~loadfunc = {
// loaded samples will be stored under samples[key]
| key, relpath, namefilter, destination, basepath="/path/to/your/SSO/samples" |
var path = PathName(basepath +/+ relpath);
var tmp_buffers = path.entries.removeAllSuchThat({|item| item.fileName.contains(namefilter); });
var tmp_array = tmp_buffers.collect({
| item, index |
var d = ();
var string = item.fileNameWithoutExtension;
var output = string.findRegexp("[abcdefgABCDEFG]#?[0123456789]");
var noteNameAll = output[0][1];
var octNumber = noteNameAll.rotate(1)[0].asString.asInteger;
var noteName = noteNameAll[0].asString;
var isSharp = noteNameAll.contains("#"); // boolean
var midiNumber = (octNumber +1) * 12;
switch( noteName,
"c", { midiNumber = midiNumber+0; },
"d", { midiNumber = midiNumber+2; },
"e", { midiNumber = midiNumber+4; },
"f", { midiNumber = midiNumber+5; },
"g", { midiNumber = midiNumber+7; },
"a", { midiNumber = midiNumber+9; },
"b", { midiNumber = midiNumber+11; },
);
if (isSharp) {midiNumber = midiNumber + 1;};
[noteNameAll, noteName, isSharp, octNumber, midiNumber];//.debug("[fullname, note, sharp, octave, midinum]");
d[\midi] = midiNumber.asInteger;
d[\note] = noteNameAll;
d[\buffer] = Buffer.readChannel(s, item.fullPath.debug("reading file"), channels:0);
d;
});
key.debug("loading");
tmp_array.sortBy(\midi);
destination[key] = ();
destination[key][\buffers] = tmp_array.collect({|item| item[\buffer]; });
destination[key][\midinotes] = tmp_array.collect({|item| item[\midi]; });
destination;
// TODO: add here a check evaluation function in order to check if the samples array
// has been succesfully filled or not
};
)
~samples = ~loadfunc.(\celli_pizz, "Celli", "celli-piz-rr1-", ~samples);
(
SynthDef(\oneshot_player, {
|
out=0, amp=0.5, gate=1, buf, rate=1.0, pan=0.0
|
var sig;
sig = PlayBuf.ar(1, buf, BufRateScale.ir(buf)*rate, 1, doneAction:2);
sig = sig * amp;
Out.ar(out, Pan2.ar(sig, pan));
}).add;
);
(
Pbindef(
\celli,
\instrument, \oneshot_player,
\scale, Scale.major,
\root, Pfunc({~root}),
\octave, 5,
\degree, Pseq([[0,4,7]],inf),
\index, Pfunc({ |e| ~samples[\celli_pizz][\midinotes].indexIn( e.use{ ~midinote.()} ) }),
\buf, Pindex(~samples[\celli_pizz][\buffers], Pkey(\index)),
\rate, (Pfunc{ |e| e.use {~midinote.()}} - Pindex(~samples[\celli_pizz][\midinotes], Pkey(\index))).midiratio,
\amp, 0.9,
\dur, 1,
\out, 0,
);
)
Pbindef(\celli).play;
How to solve it? I think is something related to simultaneous events to be created by the event pattern but I don’t know how can I change it in order to scale it up to play both single notes and chords.
Thank you very much for your support