How to MIDI map a samples start and end point?

It might not be sample perfect in all cirurcumstances, but works quite well imo.