;; it helps to have a little wrapper for each plugin
;; so this wrapper gives us a nice 'functional' style
;; by returning a closure wrapper for us.
(bind-func init_lv2_amp
(lambda (samplerate)
(let ((in_buf:float* (halloc))
(out_buf:float* (halloc))
(gain_buf:float* (halloc))
(instance (lilv_load_plugin "http://plugin.org.uk/swh-plugins/amp" samplerate))
(descriptor (tref instance 0))
(handle (tref instance 1))
(run (tref descriptor 4)))
(printf "decriptor name: %s\n" (tref descriptor 0))
;; setup ports
(lilv_connect_to_port instance 0 (cast gain_buf))
(lilv_connect_to_port instance 1 (cast in_buf))
(lilv_connect_to_port instance 2 (cast out_buf))
;; create closure wrapper
(lambda (in amp)
(pset! gain_buf 0 (dtof amp))
(pset! in_buf 0 (dtof in))
(fptrcall run handle 1)
(ftod (pref out_buf 0))))))