(bind-func filter_env_cc
(lambda ()
(let ((val 0.0:f)
(envlgth 1.0:f)
(fenv (vector_ref 0.0:f 0.0 1.0 0.0)))
(lambda (inst offset:i32 cc:i32 value:i32)
;; (println 'filter_cc cc value)
(set! val (/ (i32tof value) 127.0))
(cond ((= cc (+ offset 0)) ;; filter env attack
(vset! fenv 0 (* val 127.0))
(set_filter_env inst (* envlgth (vref fenv 0)) (* envlgth (vref fenv 1)) (vref fenv 2) (* envlgth (vref fenv 3))))
((= cc (+ offset 1)) ;; filter env decay
(vset! fenv 1 (* val 127.0 10.0))
(set_filter_env inst (* envlgth (vref fenv 0)) (* envlgth (vref fenv 1)) (vref fenv 2) (* envlgth (vref fenv 3))))
((= cc (+ offset 2)) ;; filter env sustain
(vset! fenv 2 val)
(set_filter_env inst (* envlgth (vref fenv 0)) (* envlgth (vref fenv 1)) (vref fenv 2) (* envlgth (vref fenv 3))))
((= cc (+ offset 3)) ;; filter env release
(vset! fenv 3 (* val 127.0 50.0))
(set_filter_env inst (* envlgth (vref fenv 0)) (* envlgth (vref fenv 1)) (vref fenv 2) (* envlgth (vref fenv 3))))
((= cc (+ offset 4))
(set! envlgth (* 127.0 val))
(set_filter_env inst (* envlgth (vref fenv 0)) (* envlgth (vref fenv 1)) (vref fenv 2) (* envlgth (vref fenv 3))))
((= cc (+ offset 5)) ;; filter env amt (frq)
(set_filter_env_amt inst (frq_from_val val)))
((= cc (+ offset 6)) ;; follow note frq (%) i.e. (+ cutoff (* frequency value))
(set_filter_env_follow_frq inst val))
((= cc (+ offset 7)) ;; follow amp i.e. (+ cutoff (* amplitude value))
(set_filter_env_follow_amp inst val)))))))