home *** CD-ROM | disk | FTP | other *** search
- ;;; Robert C. Prince, III Cakewalk Pro SN: 406176-CP-4.0A
- ;;; P. O. Box 8043
- ;;; Athens, GA 30603-8043
- ;;; (404) 725-1014
- ;;;
- ;;; C-MPLIMT.CAL
- ;;;
- ;;; This is a CAL program that acts similar to an electronic compressor/
- ;;; limiter by scaling velocity and adding some set amount to velocity
- ;;; to make up for losses caused by the scaling.
- ;;;
- ;;; It allows you to set an upper limit for the compressed velocities.
- ;;;
- ;;; It works on any MIDI instrument that correlates velocity with volume.
- ;;; If velocity affects anything but volume, you will get some wierd results!
- ;;;
- ;;; NOTE: Enter the first number of the compression ratio
- ;;; desired TIMES 10!
- ;;;
- ;;; If you want a compression ratio of
- ;;; 2:1, enter 20.
- ;;; 1.5:1, enter 15.
- ;;;
- ;;; Remember, the higher the compression ratio, the closer
- ;;; you bring the note velocities together.
- ;;;
- ;;; You can have the pgm figure how to center the compressed
- ;;; velocities, but you have to provide the highest velocity
- ;;; to be compressed. The fastest way to do that is to run
- ;;; the companion pgm HIVEL.CAL, which will do all the searching
- ;;; for you.
- ;;;
- ;;; OR
- ;;;
- ;;; You can provide the offset you want.
- ;;;
- ;;; AND/OR
- ;;;
- ;;; You can run VELOCITY.CAL after this pgm, adding or subtracting
- ;;; a fixed amount to all velocities.
- ;;;
- ;;; The file is named so it will be the first among the C's when
- ;;; selecting a CAL pgm.
- ;;;
- ;;; *******************************************************************
- ;;; Prolog
-
- (do
-
- ; set variables
- (int CompRatio 20) ; the Compression ratio denominator times ten
- (int Limit 127) ; limiting value for velocity
- (int auto 0) ; should pgm automatically center resulting velocities?
- (int HiVel 127) ; highest velocity to be compressed
- (int Constant 0) ; constant amount to add to velocity after compression
- (int TempVel 0) ; temporary variable for Velocity
- (int Yes 1) ; Yes = 1
- (int No 0) ; No = 0
- (int c 0) ; counter to let user know something's going on
-
- ; get user input
- (getInt CompRatio
- "Enter the 1st number of the compression ratio times 10: " 10 200
- )
-
- (getInt Limit "Enter the highest velocity desired: " 0 127)
-
- (getInt auto "Automatic Centering of Velocities (0=No 1=Yes)? " 0 1)
-
- ; was auto chosen?
- (switch auto
-
- ; yes, so do the following
- Yes
- (do
- ; have user enter the highest velocity
- (getInt HiVel "Enter the highest velocity to be compressed: " 0 127)
-
- ; figure what the compressed highest velocity will be
- (= TempVel (/ (* HiVel 10) CompRatio))
-
- ; get the dif between uncompressed high vel and compressed hi vel
- (= Constant (- HiVel TempVel))
-
- ; divide the dif by 2 for correct constant to add
- (/= Constant 2)
-
- ; close the yes auto chosen do paren
- )
-
- ; no, auto was not chosen
- No
-
- (getInt Constant "Enter velocity to add after compression: " -127 127)
-
- ; close switch paren
- )
-
- ; close the do/prolog paren
- )
-
- ;;; *****************************************************************
- ;;; Body
- ;;;
-
- (do
-
- ; let user know something's up
- (message "Ratio: " CompRatio
- "to 10 Velocity Limit: " Limit
- " Notes: " c
- " Events: " (index)
- )
-
- ; if the kind of event is a note do something
- (if (== Event.Kind NOTE)
-
- ; yes it is a note event, so let's do some compression/limiting
- (do
-
- ; compress
-
- ; multiply velocity times 10
- (= TempVel (* Note.Vel 10))
-
- ; now divide result by the ratio
- (/= TempVel CompRatio)
-
- ; add the constant to make up for volume loss
- (+= TempVel Constant)
-
- ; limit, if necessary
- (if (> TempVel Limit)
-
- ; yes, the new velocity exceeds the limit, so make it equal the limit
- (= TempVel Limit)
-
- ; no, the new velocity does not exceed the limit
- NIL
- )
-
- ; change the velocity
- (= Note.Vel TempVel)
-
- ; bump up counter
- (++ c)
-
- ; close off the yes it is a note do paren
- )
-
- ; it is not a note, so do nothing
- NIL
-
- ;close off if it is a note paren
- )
-
- ; close off body/do paren
- )
-
- ;;; *****************************************************************
- ;;; Epilog
- ;;;
-
- NIL
-
-
-
-
-
-
-
-
-
-
-
-