I don't know why I wrote all this but here goes:
Note duration in MIDI
The way most synthesizers and samplers (and other similar instruments) work is constrained by the conceptual model behind the MIDI standard from 1982. In that model, there is (1) a controller keyboard (physical or virtual) and (2) a "synth", i.e. a sound-producing component (physical or virtual), which receives command messages from the keyboard. The keyboard can only say, "note on" and "note off". The keyboard cannot say, "play a note which should last for one second". Explicitly stating note lengths to synths is not a part of the MIDI command language, note lengths are implicitly derived from more elementary atoms: Note-Ons and Note-Offs. In MIDI, the length of a note is not known by the synth when it starts producing sound. Maybe the keyboard player never releases the key until the power runs out - the synth cannot know. This may seem like a minor detail, but a lot of things arise as a consequence from this conceptual model.
In a Digital Audio Workstation or DAW, there is an integrated sequencer, which acts as the keyboard player, sending commands to a synth. As long as the sequencer and synth are using a MIDI-like interface to communicate, not necessarily using physical MIDI connectors and cables, but using MIDI messages on a logical level, they have no choice but to operate within the conceptual model of MIDI. The DAW cannot tell the synth (external hardware synth or VST/AU/whatever instrument plugin) in advance, how long a note should last. There are other, different protocols and interfaces where this is possible, but not with plain old MIDI from 1982.
Depending on the type of desired sound and instrument behavior, not being able to explicitly say things about note duration might be irrelevant, or it can be a minor nuisance that can be worked around, or it can be a real problem. For example, imagine a speech/vocal synth that's able to sing syllables of different lengths. If commanded via MIDI note on/off messages, some kind of a hack-around has to be invented to let it sing each syllable with the appropriate speed. If the sounds of a syllable are the wrong lengths, it may change the whole meaning of the word, or at least it can sound silly. What to do? Maybe use different MIDI programs for each different length? Perhaps use a control change message to transmit the syllable speed information? Maybe use... aftertouch? Velocity? However it's done, it's basically application-specific and won't automatically work the same across MIDI devices.
To sum up the MIDI model of note durations:
- In MIDI, a short note = a chopped-off long note
If we have two identical MIDI synths with identical settings, and one of the synths is given a short note and the other a long note at the same time, they will output the exact same thing up until the short note is cut off.
For many instruments and types of sound, that sort of model is OK. But what you cannot do is the kind of audio time stretching you're used to in DAWs, in a note-length-dependent way. That cannot be done with MIDI notes.
Next I'll explain how to do it the MIDI way.
Sustaining and non-sustaining sounds
Sounds produced by MIDI synths can be categorized to two types: sustaining and non-sustaining sounds. The difference is in how the MIDI Note-Off message is handled.
- A sustaining sound keeps producing sound - or its envelope stays in a "sustain" phase - while a note (keyboard key) is held down. When the note is released, i.e. when the synth receives a Note-Off message, the sound stops or the envelope enters a "release" phase. Piano, organ, synth pad, guitar, bass, etc. are usually done as sustaining sounds.
- A non-sustaining sound starts at Note-On (keyboard key press), but its length or envelope stays the same regardless of when or if there is ever a corresponding Note-Off event. Drum sounds are typically non-sustaining. They are just triggered, fire and forget. When a Note-Off message comes, the synth basically doesn't react at all. Or at least it doesn't affect the envelope.
Sustaining sounds employ an envelope which has a sustaining phase. Envelopes are used most importantly to control the volume (gain/amplification) of a sound, starting from the Note-On moment. The final, ending phase of the envelope is called release. The envelope for a sustaining sound doesn't enter the release phase until it's told to do so, and that happens when the synth is sent a Note-Off message, i.e. when the keyboard key is released.
The envelope for a non-sustaining sound enters the release phase on its own, without waiting for any Note-Off message to arrive.
Here is an example where a non-sustaining drum sound sample is triggered, first by a short MIDI note and then by a long one. As you can see, the same sound output is produced for both the short and long note.
The waveform looks like this in the sampler.
Making a sustained sound from a drum sample
How can we make this a sustained sound? If we switch on a sustaining envelope for the drum sample, we get some difference in duration between the notes, but the sound produced by the long note is only very slightly longer than one produced by the short note:
The problem is, even though the envelope keeps saying "full volume!" until the Note-Off, it is only filtering/attenuating the sample, and as the drum sample's sound (waveform) fades out, so does the final output.
To create a really sustaining sound, the wave attenuated by the volume envelope has to be much longer, so the envelope has something to attenuate. For a synthesizer sound it works, because the volume envelope is getting a wave from an oscillator which produces an infinitely long sound all the time. For an acoustic piano or, say, Rhodes sample, this works, because a piano note can easily be 20 seconds long, which is practically infinitely long compared to the envelope, so the envelope has time to enter the sustain phase. But a typical drum sample is much shorter, for example 2 seconds. In order to have something for the envelope to process, we need to somehow make the drum sample significantly longer, in other words stretch it, as the OP suggests.
Because of the MIDI model of unknown note lengths, the most straight-forward way is to stretch the sample "enough", and then let the volume envelope cut the notes to the desired length. One way to stretch a sample infinitely is to loop it. Here is the 808 drum sample with a loop:
And the same waveform zoomed in to see the loop:
Now we can have the sound sustain for as long as we want:
But now it doesn't really sound like a drum. It's more like an organ, because the single-cycle loop is so steady and organ-like. To make it more like a drum again, we'd have to add more refined envelopes for the pitch and volume... but then it would be more like synthesizing a drum sound with an oscillator. Too bad we can't have sound here, so you'll just have to imagine what it sounds like, or try it out with a sampler.
However, what happens if we time-stretch the sample with Ableton Live's "tones" algorithm which tries to preserve the original tone somehow. Let's stretch it by 8x, so the 2-second sample gets close to 20 seconds.
Now it resembles a drum, but so that the length is noticeably controlled by MIDI Note-On and Note-Off messages.
However, what the OP seems to be asking is, how to get a different time-stretch factor for each and every note, so that the time stretch is precisely and automatically adjusted for each note length. Because of the limitations in the conceptual model of plain old MIDI, I don't think that's easily done with samplers. You could do it in a DAW with time-stretching facilities, manually stretching each note to the desired length. Or you could use an array of pre-stretched samples, with a different sample length for each desired note length. Or you could somehow use time stretching facilities which are meant for mangling audio loops. But in any case, you won't be able to do it with plain old MIDI notes, at least not easily and not in a way directly supported by the old standard. As far as I know.
There are some newer "post MIDI 1.0" interfaces and software systems which might directly and specifically support the concept of note length. In any such scenario, it must be assumed that the notes come from a sequencer or notation program, which knows the note lengths before playing the notes. In live realtime keyboard playing it cannot be done.
- Wallander NotePerformer. This is a synth, a sound-producing program which integrates with notation programs such as Sibelius, Finale and Dorico. Before starting to produce sound, it pre-reads the notation for a long segment of the whole piece and tries to take lengths, slurs, techniques, expressions, hairpins etc. into account, and translate all that into a musical performance resembling human players.
- Steinberg VST Expression? This is a beyond-MIDI protocol, intended for producing orchestrations in DAWs. At a quick glance it seems that there is some support for lengths of things.
- MIDI 2.0?? I don't know if this is possible with the new MIDI 2.0. Maybe, if note lengths can be transmitted to synths, then a sampler could use an appropriate time-stretch value depending on the note length.
- ... what else? I'm sure there are integrated DAW + synth combos out there, but this is what I could get off the top of my head.