home *** CD-ROM | disk | FTP | other *** search
/ PC Musician 2000 / PC_Musician_2000.iso / PCMUSIC / SEQUENCE / CAL_CONT / C-MPLMIT.CAL < prev    next >
Encoding:
Text File  |  1991-08-26  |  4.6 KB  |  176 lines

  1. ;;; Robert C. Prince, III  Cakewalk Pro SN: 406176-CP-4.0A
  2. ;;; P. O. Box 8043
  3. ;;; Athens, GA 30603-8043
  4. ;;; (404) 725-1014
  5. ;;;
  6. ;;; C-MPLIMT.CAL
  7. ;;;
  8. ;;; This is a CAL program that acts similar to an electronic compressor/
  9. ;;;  limiter by scaling velocity and adding some set amount to velocity
  10. ;;;  to make up for losses caused by the scaling.
  11. ;;;
  12. ;;;  It allows you to set an upper limit for the compressed velocities.
  13. ;;;
  14. ;;;  It works on any MIDI instrument that correlates velocity with volume.
  15. ;;;  If velocity affects anything but volume, you will get some wierd results!
  16. ;;;
  17. ;;;  NOTE: Enter the first number of the compression ratio
  18. ;;;             desired TIMES 10!
  19. ;;;
  20. ;;;        If you want a compression ratio of
  21. ;;;                                            2:1, enter 20.
  22. ;;;                                          1.5:1, enter 15.
  23. ;;;
  24. ;;;  Remember, the higher the compression ratio, the closer
  25. ;;;         you bring the note velocities together.
  26. ;;;
  27. ;;;  You can have the pgm figure how to center the compressed
  28. ;;;         velocities, but you have to provide the highest velocity
  29. ;;;         to be compressed. The fastest way to do that is to run
  30. ;;;         the companion pgm HIVEL.CAL, which will do all the searching
  31. ;;;         for you.
  32. ;;;
  33. ;;;        OR
  34. ;;;
  35. ;;;        You can provide the offset you want.
  36. ;;;
  37. ;;;        AND/OR
  38. ;;;
  39. ;;;        You can run VELOCITY.CAL after this pgm, adding or subtracting
  40. ;;;         a fixed amount to all velocities.
  41. ;;;
  42. ;;; The file is named so it will be the first among the C's when
  43. ;;;  selecting a CAL pgm.
  44. ;;;
  45. ;;; *******************************************************************
  46. ;;; Prolog
  47.  
  48. (do
  49.  
  50.   ; set variables
  51.   (int CompRatio 20)  ; the Compression ratio denominator times ten
  52.   (int Limit 127)     ; limiting value for velocity
  53.   (int auto 0)        ; should pgm automatically center resulting velocities?
  54.   (int HiVel 127)     ; highest velocity to be compressed
  55.   (int Constant 0)    ; constant amount to add to velocity after compression
  56.   (int TempVel 0)     ; temporary variable for Velocity
  57.   (int Yes 1)         ; Yes = 1
  58.   (int No 0)          ; No = 0
  59.   (int c 0)           ; counter to let user know something's going on
  60.  
  61.   ; get user input
  62.   (getInt CompRatio
  63.         "Enter the 1st number of the compression ratio times 10: " 10 200
  64.   )
  65.  
  66.   (getInt Limit "Enter the highest velocity desired: " 0 127)
  67.  
  68.   (getInt auto "Automatic Centering of Velocities (0=No 1=Yes)? " 0 1)
  69.  
  70.   ; was auto chosen?
  71.   (switch auto
  72.  
  73.     ; yes, so do the following
  74.     Yes
  75.       (do
  76.         ; have user enter the highest velocity
  77.         (getInt HiVel "Enter the highest velocity to be compressed: " 0 127)
  78.  
  79.         ; figure what the compressed highest velocity will be
  80.         (= TempVel (/ (* HiVel 10) CompRatio))
  81.  
  82.         ; get the dif between uncompressed high vel and compressed hi vel
  83.         (= Constant (- HiVel TempVel))
  84.  
  85.         ; divide the dif by 2 for correct constant to add
  86.         (/= Constant 2)
  87.       
  88.       ; close the yes auto chosen do paren
  89.       )
  90.  
  91.     ; no, auto was not chosen
  92.     No
  93.  
  94.       (getInt Constant "Enter velocity to add after compression: " -127 127)
  95.  
  96.   ; close switch paren
  97.   )
  98.  
  99. ; close the do/prolog paren
  100. )
  101.  
  102. ;;; *****************************************************************
  103. ;;; Body
  104. ;;;
  105.  
  106. (do
  107.  
  108.   ; let user know something's up
  109.   (message "Ratio: " CompRatio
  110.            "to 10  Velocity Limit: " Limit
  111.            "  Notes: " c
  112.            "  Events: " (index)
  113.   )
  114.  
  115.   ; if the kind of event is a note do something
  116.   (if (== Event.Kind NOTE)
  117.  
  118.     ; yes it is a note event, so let's do some compression/limiting
  119.     (do
  120.  
  121.       ; compress
  122.  
  123.         ; multiply velocity times 10
  124.         (= TempVel (* Note.Vel 10))
  125.  
  126.         ; now divide result by the ratio
  127.         (/= TempVel CompRatio)
  128.  
  129.         ; add the constant to make up for volume loss
  130.         (+= TempVel Constant)
  131.  
  132.       ; limit, if necessary
  133.         (if (> TempVel Limit)
  134.  
  135.           ; yes, the new velocity exceeds the limit, so make it equal the limit
  136.           (= TempVel Limit)
  137.  
  138.           ; no, the new velocity does not exceed the limit
  139.           NIL
  140.         )
  141.  
  142.       ; change the velocity
  143.         (= Note.Vel TempVel)
  144.  
  145.       ; bump up counter
  146.         (++ c)
  147.  
  148.     ; close off the yes it is a note do paren
  149.     )
  150.  
  151.     ; it is not a note, so do nothing
  152.     NIL
  153.  
  154.   ;close off if it is a note paren
  155.   )
  156.  
  157. ; close off body/do paren
  158. )
  159.  
  160. ;;; *****************************************************************
  161. ;;; Epilog
  162. ;;;
  163.  
  164. NIL
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.