How can I line up "end" of sample to a beat?

It is quite easy to arrange sample sounds into patterns where the “start” of the sample plays at the time I want it to. However I am wondering if there is a way I can make the “end” point of my sample line up with the beat.

This is a common technique in dubstep drum patterns where there is a short reverse snare directly followed by a forwards playing snare sample. So if I reverse a snare sound of an arbitrary length, is there a way that I can have the reverse snare line up so it ends when the forward snare starts.

So my end resulting pattern would be:
Kick - Reverse Snare - Snare - Kick - Snare
*Where the kicks and snares are evenly spread along a bar and the reverse snare plays into the snare no matter it’s length.

Not sure if it fits exactly what you’re after, but a while ago I made a composition where I had the end of a reversed sample line up with the start of a new bar or song section. Perhaps it might lead in the right direction?

Very old thread but I will provide the solution I used in case it may help someone looking it up in the future.

sn = :drum_snare_soft
info = {amp: 0.45,start: 0.1, finish: 0.98, release: 0.1}
length = sample_duration sn, info
timeShift = 1-length
time_warp timeShift do
  sample sn, info
end

So if the sample has a length less than 1 beat, timeShift will be positive, pushing the sample to the end of the beat. And vice versa for a sample longer than 1 beat, it will happen slightly earlier.

Due to the added logic, I’ve been putting the code for the sample into its own function. You would also need to use set_sched_ahead_time! if you are going to have a negative time_warp.

With those two things in mind, I end up with something a bit like this:

use_bpm 125
set_sched_ahead_time! bt(4)

define :snare do
  sn = :drum_snare_soft
  info = {amp: 0.45,start: 0.1, finish: 0.98, release: 0.1}
  length = sample_duration sn, info
  timeShift = 1-length
  time_warp timeShift do
    sample sn, info
  end
end

define :kick do
  sample :drum_heavy_kick, amp: 0.6
end

live_loop :drums do
  4.times do
    kick
    snare
    sleep 1
  end
end