Accurate Happy Birthday

use_bpm 110

define :plax do |n, x = 1|
  t = rrand(-1,0)
  ##| use_synth :saw
  ##| play n + t, attack: 0.01 * x, sustain: 0.2 * x, release: 0.1 * x, amp: 0.25
  ##| use_synth :tri
  ##| play n + t, attack: 0.01 * x, sustain: 0.2 * x, release: 0.1 * x, amp: 0.25
  use_synth :blade
  play n + t, attack: 0.01 * x, sustain: 0.2 * x, release: 0.1 * x#, amp: 0.5
  sleep 0.25 * x
end

in_thread do
  g = rrand(0.99, 1/0.99)
  plax 63 + rrand(-0.1, 0.1), 2.5 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 63 + rrand(-0.1, 0.1), 1.5 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 65 + rrand(-0.1, 0.1), 4 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 63 + rrand(-0.1, 0.1), 4 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 68 + rrand(-0.1, 0.1), 4 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 67 + rrand(-0.1, 0.1), 7.9 * g
  g = 1/g * rrand(0.99, 1/0.99)
  sleep 0.1 * g
  g = 1/g * rrand(0.99, 1/0.99)
end


in_thread do
  i = rrand(0.995, 1/0.995)
  plax 63 + rrand(-0.025, 0.025), 2.5 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 63 + rrand(-0.025, 0.025), 1.5 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 65 + rrand(-0.025, 0.025), 4 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 63 + rrand(-0.025, 0.025), 4 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 68 + rrand(-0.025, 0.025), 4 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 67 + rrand(-0.025, 0.025), 7.9 * i
  i = 1/i * rrand(0.995, 1/0.995)
  sleep 0.1 * i
  i = 1/i * rrand(0.995, 1/0.995)
end

in_thread do
  h2 = rrand(0, 2)
  sleep h2
  h = rrand(0.99, 1/0.99)
  plax 63-7 + rrand(-0.2, 0.2), 2.5 * h - h2
  h = 1/h * rrand(0.99, 1/0.99)
  plax 63-7 + rrand(-0.2, 0.2), 1.5 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 65-7 + rrand(-0.2, 0.2), 4 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 63-7 + rrand(-0.2, 0.2), 4 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 68-7 + rrand(-0.2, 0.2), 4 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 67-7 + rrand(-0.2, 0.2), 7.9 * h
  h = 1/h * rrand(0.99, 1/0.99)
  sleep 0.1 * h
  h = 1/h * rrand(0.99, 1/0.99)
end



j2 = rrand(0, 0.5)
sleep j2
j = rrand(0.99, 1/0.99)
plax 63 + rrand(-0.25, 0.25), 2.5 * j - j2
j = 1/j * rrand(0.99, 1/0.99)
plax 63 + rrand(-0.25, 0.25), 1.5 * j
j = 1/j * rrand(0.99, 1/0.99)
plax 65 + rrand(-0.25, 0.25), 4 * j
j = 1/j * rrand(0.99, 1/0.99)
plax 63 + rrand(-0.25, 0.25), 4 * j
j = 1/j * rrand(0.99, 1/0.99)
plax 68 + rrand(-0.25, 0.25), 4 * j
j = 1/j * rrand(0.99, 1/0.99)
plax 67 + rrand(-0.25, 0.25), 7.9 * j
j = 1/j * rrand(0.99, 1/0.99)
sleep 0.1 * j
j = 1/j * rrand(0.99, 1/0.99)



in_thread do
  g = rrand(0.99, 1/0.99)
  plax 63 + rrand(-0.1, 0.1), 2.5 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 63 + rrand(-0.1, 0.1), 1.5 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 65 + rrand(-0.1, 0.1), 4 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 63 + rrand(-0.1, 0.1), 4 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 70 + rrand(-0.1, 0.1), 4 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 68 + rrand(-0.1, 0.1), 7.9 * g
  g = 1/g * rrand(0.99, 1/0.99)
  sleep 0.1 * g
  g = 1/g * rrand(0.99, 1/0.99)
end


in_thread do
  i = rrand(0.995, 1/0.995)
  plax 63 + rrand(-0.025, 0.025), 2.5 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 63 + rrand(-0.025, 0.025), 1.5 * i
  i = 1/i * rrand(0.995, 1/0.959)
  plax 65 + rrand(-0.025, 0.025), 4 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 63 + rrand(-0.025, 0.025), 4 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 70 + rrand(-0.025, 0.025), 4 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 68 + rrand(-0.025, 0.025), 7.9 * i
  i = 1/i * rrand(0.995, 1/0.995)
  sleep 0.1 * i
  i = 1/i * rrand(0.995, 1/0.995)
end


in_thread do
  h = rrand(0.99, 1/0.99)
  plax 63-7 + rrand(-0.2, 0.2), 2.5 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 63-7 + rrand(-0.2, 0.2), 1.5 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 65-7 + rrand(-0.2, 0.2), 4 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 63-7 + rrand(-0.2, 0.2), 4 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 70-7 + rrand(-0.2, 0.2), 4 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 68-7 + rrand(-0.2, 0.2), 7.9 * h
  h = 1/h * rrand(0.99, 1/0.99)
  sleep 0.1 * h
  h = 1/h * rrand(0.99, 1/0.99)
end


j = rrand(0.995, 1/0.995)
plax 63 + rrand(-0.25, 0.25), 2.5 * j
j = 1/j * rrand(0.995, 1/0.995)
plax 63 + rrand(-0.25, 0.25), 1.5 * j
j = 1/j * rrand(0.995, 1/0.995)
plax 65 + rrand(-0.25, 0.25), 4 * j
j = 1/j * rrand(0.995, 1/0.995)
plax 63 + rrand(-0.25, 0.25), 4 * j
j = 1/j * rrand(0.995, 1/0.995)
plax 70 + rrand(-0.25, 0.25), 4 * j
j = 1/j * rrand(0.995, 1/0.995)
plax 68 + rrand(-0.25, 0.25), 7.9 * j
j = 1/j * rrand(0.995, 1/0.995)
sleep 0.1 * j
j = 1/j * rrand(0.995, 1/0.995)


in_thread do
  g = rrand(0.99, 1/0.99)
  plax 63 + rrand(-0.1, 0.1), 2.5 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 63 + rrand(-0.1, 0.1), 1.5 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 75 + rrand(-0.1, 0.1), 4 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 72 + rrand(-0.1, 0.1), 4.05 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 68 + rrand(-0.1, 0.1), 4.1 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 67 + rrand(-0.1, 0.1), 4.2 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 65 + rrand(-0.1, 0.1), 6.4 * g
  g = 1/g * rrand(0.99, 1/0.99)
  sleep 0.15 * g
  g = 1/g * rrand(0.99, 1/0.99)
end


in_thread do
  i = rrand(0.995, 1/0.995)
  plax 63 + rrand(-0.025, 0.025), 2.5 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 63 + rrand(-0.025, 0.025), 1.5 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 75 + rrand(-0.025, 0.025), 4 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 72 + rrand(-0.025, 0.025), 4.05 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 68 + rrand(-0.025, 0.025), 4.1 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 67 + rrand(-0.025, 0.025), 4.2 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 65 + rrand(-0.025, 0.025), 6.4 * i
  i = 1/i * rrand(0.995, 1/0.995)
  sleep 0.15 * i
  i = 1/i * rrand(0.995, 1/0.995)
end


in_thread do
  h = rrand(0.99, 1/0.99)
  plax 63-7 + rrand(-0.2, 0.2), 2.5 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 63-7 + rrand(-0.2, 0.2), 1.5 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 75-7 + rrand(-0.5, 0.5), 4 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 72-7 + rrand(-0.5, 0.5), 4.05 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 68-7 + rrand(-0.2, 0.2), 4.1 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 67-7 + rrand(-0.2, 0.2), 4.2 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 65-7 + rrand(-0.2, 0.2), 4 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 65-7 + rrand(-0.2, 0.2), 4 * h
  h = 1/h * rrand(0.99, 1/0.99)
  sleep 0.15 * h * 0
  h = 1/h * rrand(0.99, 1/0.99)
end


j = rrand(0.99, 1/0.99)
plax 63-7 + rrand(-0.25, 0.25), 2.5 * j
j = 1/j * rrand(0.99, 1/0.99)
plax 63-7 + rrand(-0.25, 0.25), 1.5 * j
j = 1/j * rrand(0.99, 1/0.99)
plax 75-7 + rrand(-0.5, 0.5), 4 * j
j = 1/j * rrand(0.99, 1/0.99)
plax 72-7 + rrand(-0.5, 0.5), 4.05 * j
j = 1/j * rrand(0.99, 1/0.99)
plax 68-7 + rrand(-0.25, 0.25), 4.1 * j
j = 1/j * rrand(0.99, 1/0.99)
plax 67-7 + rrand(-0.25, 0.25), 4.2 * j
j = 1/j * rrand(0.99, 1/0.99)
plax 65-7 + rrand(-0.25, 0.25), 6.4 * j
j = 1/j * rrand(0.99, 1/0.99)
sleep 0.15 * j
j = 1/j * rrand(0.99, 1/0.99)

in_thread do
  
  g = rrand(0.99, 1/0.99)
  plax 73 + rrand(-0.1, 0.1), 2.64 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 73 + rrand(-0.1, 0.1), 1.584 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 72 + rrand(-0.1, 0.1), 4.22 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 68 + rrand(-0.1, 0.1), 4.23 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 70 + rrand(-0.1, 0.1), 4.25 * g
  g = 1/g * rrand(0.99, 1/0.99)
  plax 68 + rrand(-0.1, 0.1), 7.4 * g
  g = 1/g * rrand(0.99, 1/0.99)
end

in_thread do
  
  i = rrand(0.995, 1/0.995)
  plax 73 + rrand(-0.025, 0.025), 2.64 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 73 + rrand(-0.025, 0.025), 1.584 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 72 + rrand(-0.025, 0.025), 4.22 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 68 + rrand(-0.025, 0.025), 4.23 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 70 + rrand(-0.025, 0.025), 4.25 * i
  i = 1/i * rrand(0.995, 1/0.995)
  plax 68 + rrand(-0.025, 0.025), 7.4 * i
  i = 1/i * rrand(0.995, 1/0.995)
end

in_thread do
  h = rrand(0.99, 1/0.99)
  plax 73-7 + rrand(-0.2, 0.2), 2.64 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 73-7 + rrand(-0.2, 0.2), 1.584 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 72-7 + rrand(-0.2, 0.2), 4.22 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 68-7 + rrand(-0.2, 0.2), 4.23 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 70-7 + rrand(-0.2, 0.2), 4.25 * h
  h = 1/h * rrand(0.99, 1/0.99)
  plax 68-7 + rrand(-0.2, 0.2), 7.4 * h
  h = 1/h * rrand(0.99, 1/0.99)
end

j = rrand(0.99, 1/0.99)
plax 73-7 + rrand(-0.25, 0.25), 2.64 * j
j = 1/j * rrand(0.99, 1/0.99)
plax 73-7 + rrand(-0.25, 0.25), 1.584 * j
j = 1/j * rrand(0.99, 1/0.99)
plax 72-7 + rrand(-0.25, 0.25), 4.22 * j
j = 1/j * rrand(0.99, 1/0.99)
plax 68-7 + rrand(-0.25, 0.25), 4.23 * j
j = 1/j * rrand(0.99, 1/0.99)
plax 70-7 + rrand(-0.25, 0.25), 4.25 * j
j = 1/j * rrand(0.99, 1/0.99)
plax 68-7 + rrand(-0.25, 0.25), 7.4 * j
j = 1/j * rrand(0.99, 1/0.99)