[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sc-users] sound banks/velocities



Hi list,

I'm trying to load and trigger harpsichord sound banks in SC (3 different samples per key for note-ons and 3 different samples per key for note-offs (mechanical noise when a key is released), depending on the velocity). I firstly worked with MIDIResponders mapped to different velocity ranges.

1. I loaded the synths in arrays for SC to remember witch synth to release on note-off but when midi traffic was high, I got many held notes. For now I've got reliable results only by using Voicer (with NoteOffResponders to trigger note-off samples, with synths releasing automatically), but AFAIK I cannot map MIDIVoicerSockets to specific velocity ranges...
2. Since a note-off is a note-on with velocity = 0 (right?), I don't know how to map NoteOffResponders to different velocity ranges (I guess I have to switch between my different NoteOffResponders depending on the velocity of the previous note-on, but I can't really figure out how to write this...)

Here's my code, working with only one sound bank for noteons and one sound bank for noteoffs:

s = Server.local;
s.boot;

(
~>"sounds/harpsichord/onvel1/*.wav".pathMatch;
~offvel3 = "sounds/harpsichord/offvel3/*.wav".pathMatch;
)

(
~ { |path| Buffer.read(s, path)};
~offbuffers3 = ~offvel3.collect { |path| Buffer.read(s, path)};
)

(
SynthDef(\harpsichord,
{
arg trig = 0, sustain = 0.5, gate = 0, out = 0, buf = 0;
var env, sig;
env = EnvGen.ar(Env.asr(0.001, sustain, 0.01), gate, doneAction:2);
sig = PlayBuf.ar(2, buf, BufRateScale.kr(buf), trig, 0, 0) * env;
Out.ar(out, sig)
}).send(s);
)

(
SynthDef(\harpsichordrel,
{
arg trig = 0, lenght, gate = 0, out = 0, buf = 0;
var env, sig;
env = EnvGen.ar(Env.linen(0.001, lenght, 0.01, 1), gate, doneAction:2);
sig = PlayBuf.ar(2, buf, BufRateScale.kr(buf), trig, 0, 0) * env;
Out.ar(out, sig)
}).send(s);
)


~harps = Voicer(15, \harpsichord);


(
~noteon = ~onbuffers1.collect { |item, i|
VoicerMIDISocket([0, 0], ~harps, i+42, i+42).noteOnArgsPat = Pbind(\trig, Pkey(\velocity), \gate, Pkey(\velocity), \buf, item);
};


~noteoff = ~offbuffers3.collect { |item, i|
NoteOffResponder({ |src,chan,note,vel|
Synth(\harpsichordrel).set(\trig, 1, \gate, 1, \buf, item, \lenght, item.numFrames * 2.2675736961451e-05)}, 
0, 0, i+42, nil);
};
)

(
~onbuffers1.do(_.free);
~offbuffers3.do(_.free);
~noteon.do(_.free);
~noteoff.do(_.remove);
)


Thank you for your help,

c