;; Program name   -   BenAWE32.CAL (c) 1995 Ben Halliday
;;
;; Author         -   Ben Halliday  <ben@carlton.demon.co.uk>
;;
;; Version        -   0.1
;;
;; Version Date   -   13th May 1995
;;
;;
;; Comments :-
;;
;;      **   This program controls the AWE32's NRPN's   **
;;
;; You  can  change  an instrument's SoundFont parameters  (for
;; example, LFO depth and speed, envelope contour) through MIDI
;; in  real  time via NRPN, or Non Registered Parameter  Number
;; control.
;;
;; By default it adds that Classic Acid filter sweep --  At last
;; I can do this on the AWE32!!! ;-}
;;
;; N.B. Please mail me if you find problems with this program,
;;        in fact mail me anyway as I would like your comments.
;;        and to know what you can do with your AWE32 and
;;        CalkWalk.

(do
   (include "need20.cal") ; Require version 2.0 or higher of CAL

   ;;  Set Variables
   ;;
   (dword current From)   ; Current Time point
   (dword end Thru)       ; End Time point
   (dword gap TIMEBASE)   ; Gap Time

   (int param 21)         ; NRPN Parameter to effect. Default value 21 (Initial 
Filter Cut-off)
   (int param_min 0)      ; Minimum value for NRPN
   (int param_max 127)    ; Maximum value for NRPN
   (int param_value 127)  ; Initial value for NRPN
   (int param_delta 10)   ; NRPN Change value

   ;; Get the various values
   ;;
   (getInt param "Value of parameter to sweep (leave as 21 for Acid sweep): " 
param_min param_max)
   (getInt param_max "Highest value for parameter: " param_min param_max)
   (getInt param_min "Lowest value for parameter: " param_min param_max)
   (getInt param_delta "Value for sweep amount: " 1 param_max)
     (getTime gap "TIMEBASE For sweep")

   ;; Do the work
   ;;
   (while (<= current end)
      (do
         ;; The following 4 lines insert the events that set the NRPN to the 
required value
         ;;
         (insert current Event.Chan CONTROL 38 (% (+ param_value  8192) 128))
         (insert current Event.Chan CONTROL 6 (/ (+ param_value  8192) 128))
         (insert current Event.Chan CONTROL 98 param)
         (insert current Event.Chan CONTROL 99 127)

         ;; Display the progress
         ;;
         (message "Count = " (- current From) "  [ " (- Thru From) "]")

         ;; Do we need to reverse the sweep
         ;;
         (if (>= (+ param_value param_delta) param_max) (= param_delta (* 
param_delta -1)))
         (if (<= (+ param_value param_delta) param_min) (= param_delta (* 
param_delta -1)))

         ;; Set the next event's values
         ;;
         (= param_value (+ param_value param_delta))
         (= current (+ current gap))
      )
   )
   (pause "NRPN Sweep Complerted")
)
 
