(bind-func cerberus_amp_pitch_env_cc
(lambda ()
(let ((val 0.0:f)
(envlgth 1.0:f)
(ampenv (vector_ref 0.0:f 0.0:f 1.0:f 0.0:f))
(penv (vector_ref 0.0:f 0.0:f)))
(lambda (inst offset:i32 cc:i32 value:i32)
;; (println 'cerberus_amp_pitch_env_cc cc value)
(set! val (/ (i32tof value) 127.0))
(cond ((= cc (+ offset 0)) ;; amp env attack
(vset! ampenv 0 (* val 127.0))
(set_amp_env inst (* envlgth (vref ampenv 0)) (* envlgth (vref ampenv 1)) (vref ampenv 2) (* envlgth (vref ampenv 3))))
((= cc (+ offset 1)) ;; amp env decay
(vset! ampenv 1 (* val 127.0 10.0))
(set_amp_env inst (* envlgth (vref ampenv 0)) (* envlgth (vref ampenv 1)) (vref ampenv 2) (* envlgth (vref ampenv 3))))
((= cc (+ offset 2)) ;; amp env sustain
(vset! ampenv 2 val)
(set_amp_env inst (* envlgth (vref ampenv 0)) (* envlgth (vref ampenv 1)) (vref ampenv 2) (* envlgth (vref ampenv 3))))
((= cc (+ offset 3)) ;; amp env release
(vset! ampenv 3 (* val 127.0 50.0))
(set_amp_env inst (* envlgth (vref ampenv 0)) (* envlgth (vref ampenv 1)) (vref ampenv 2) (* envlgth (vref ampenv 3))))
((= cc (+ offset 4))
(set! envlgth (* 127.0 val))
(set_amp_env inst (* envlgth (vref ampenv 0)) (* envlgth (vref ampenv 1)) (vref ampenv 2) (* envlgth (vref ampenv 3))))
((= cc (+ offset 5)) ;; pitch env attack
(vset! penv 0 (* val 1000.0))
(set_pitch_env inst (vref penv 0) (vref penv 1)))
((= cc (+ offset 6)) ;; pitch env decay
(vset! penv 1 (* val 1000.0))
(set_pitch_env inst (vref penv 0) (vref penv 1)))
((= cc (+ offset 7)) ;; pitch env amt
(set_pitch_env_amt inst (- (* 2.0 val) 1.0))))))))