(define play-note
(lambda (time inst pitch vol dur . args)
(let* ((nargs (length args))
(duration dur)
(dargs (sys:make-cptr (* (if (audio_64bit) 8 4) nargs))) ;; doubles
(native (if (closure? inst)
(llvm:get-native-closure (symbol->string (apply inst (list 'xtlang))))
(if (symbol? inst)
(llvm:get-native-closure (eval (string->symbol (string-append (symbol->string inst) "_xtlang_name"))))
(if (cptr? inst)
inst
#f)))))
(if (= (audio_64bit) 1)
(dotimes (i nargs) (cptr:set-double dargs (* i 8) (eval (list-ref args i))))
(dotimes (i nargs) (cptr:set-float dargs (* i 4) (eval (list-ref args i)))))
(if (cptr? native)
(if (list? pitch)
(for-each (lambda (p)
(xtm_play_note (real->integer time)
native
(midi2frq (* 1.0 p))
(/ (exp (/ vol 26.222)) 127.0)
(real->integer duration)
nargs
dargs))
pitch)
(xtm_play_note (real->integer time)
native
(midi2frq (* 1.0 pitch))
(/ (exp (/ vol 26.222)) 127.0)
(real->integer duration)
nargs
dargs))
(log-error 'No 'inst 'named (symbol->string inst))))))