External sample pattern timed

Hi everyone, at first glace, I couldn’t find anyone that posted a play_pattern_timed function for external samples, so I thought I’ld share the one I came up with.

g84 = "C:/S/C5.wav"
g85 = "C:/S/C#5.wav"
g86 = "C:/S/D5.wav"
g87 = "C:/S/D#5.wav"
g88 = "C:/S/E5.wav"
g89 = "C:/S/F5.wav"
g90 = "C:/S/F#5.wav"
g91 = "C:/S/G5.wav"
g92 = "C:/S/G#5.wav"
g93 = "C:/S/A5.wav"
g94 = "C:/S/A#5.wav"
g95 = "C:/S/B5.wav"
g96 = "C:/S/C6.wav"

n1 = [g85,g85,g87,g82]
d1 = [3,3,3,2]

 define :sample_pattern_lead do
  live_loop :lead do
    if x != n1.length
      sample n1[i], amp: 1.2
      d1[i].times do
        sleep 1
        use_bpm tempo
      end
      i = i + 1
      x = x + 1
      print x
    else
      stop
    end
  end
end

sample_pattern_lead

It loops through every instance of sleep, and then resets the tempo, so you can write another function to control the tempo. That way you can change the tempo across several functions without them going out of sync.
If anyone has any ideas how to optimize it, or write it shorter, shoot :slight_smile: