load "tap-detect.sal"
load "instr.sal"

define variable tap-list
set tap-list = extract-taps("tapping.wav")

define variable *tapscore*
set *tapscore* = {}
define variable i
set i = 0

loop
  for elem in tap-list
  set *tapscore* = append(*tapscore*,
                          list(list(nth(0, elem), 0.5, list(quote(simple-note), pitch: (60 + i), vel: linear-to-vel(nth(1, elem))))))
  set i = i + 1
end

function f4() play timed-seq(*tapscore*)

define variable *beat*
loop
  for elem in tap-list
  set *beat* = append(*beat*,
                      list(list(nth(0, elem), 0.5, list(quote(simple-note), pitch: (60), vel: linear-to-vel(nth(1, elem))))))
  set i = i + 1
end

function f5() play timed-seq(score-transpose(*beat*, keyword(pitch), -24))

define variable mel-list
set mel-list = list(c5, bf4, g4, g4, bf4, g4, g4, g4, f4, g4, f4, ef4, f4, ef4, f4, ef4, c4, c4)
set i = 0

define variable *melody*

loop
  for elem in tap-list
  set *melody* = append(*melody*,
                      list(list(nth(0, elem), 0.5, list(quote(simple-note), pitch: (nth(i, mel-list)), vel: linear-to-vel(nth(1, elem))))))
  set i = i + 1
end

function f6() play timed-seq(*melody*)
function f7() play timed-seq(score-transpose(*melody*, keyword(pitch), -12))

define variable *harmony*
define variable har-list
set har-list = list(ef4, d4, c4, c4, ef4, c4, c4, c4, d4, ef4, d4, c4, d4, c4, d4, c4, ef4, ef4)
set i = 0

loop
  for elem in tap-list
  set *harmony* = append(*harmony*,
                      list(list(nth(0, elem), 0.5, list(quote(simple-note), pitch: (nth(i, har-list)), vel: linear-to-vel(nth(1, elem))))))
  set i = i + 1
end

function f8() play timed-seq(*harmony*)
function f9() play timed-seq(score-transpose(*harmony*, keyword(pitch), 12))