Layered samples

Hi Jules,

would you consider adding a virtual function to Synthesizer in order to select samples based on velocity?

bool appliesToVelocity (const float /velocity/) { return true; }

in analogy to appliesToNote and appliesToChannel.

The lines
if (sound->appliesToNote (midiNoteNumber)
&& sound->appliesToChannel (midiChannel))

in void Synthesiser::noteOn(…)

should then be updated to

    if (sound->appliesToNote (midiNoteNumber)
         && sound->appliesToChannel (midiChannel)
    && sound->appliesToVelocity(velocity))

That’s all it takes.


TBH if I was going to add anything like that, I’d probably prefer to refactor the existing calls into something like “appliesTo (int noteNumber, int channel, float velocity)” to avoid lots of virtual calls.

Agree, I thought so myself initially, but that would break existing code.

It could be done in a way that doesn’t break existing code, by providing default implementations of virtual functions but I think Jules wouldn’t like it because the old routines would still exist.

Shouldn’t the velocity not rather be a range than a value?


Nope. For each sample you have a velocity range defined, and only when the played velocity falls into that range, it should sound. It’s exactly the same logic as for the midi note number.