home *** CD-ROM | disk | FTP | other *** search
/ PC Musician 2000 / PC_Musician_2000.iso / PCMUSIC / SEQUENCE / CAL_CONT / RANDTIME.CAL < prev    next >
Encoding:
Text File  |  1991-08-21  |  5.4 KB  |  103 lines

  1. ;;  RandTime.CAL, written 1991 by Douglas L. Fetter [UID 5476]
  2. ;;;
  3. ;;  This CAL routine was written to humanize the starting times of notes
  4. ;;  for sequences that have been entered using either Step Record or which
  5. ;;  have been Quantized. The user will be requested to enter a value for the
  6. ;;  maximum number of ticks by which a note's start time can be shifted. The
  7. ;;  start times of all notes found in the From-to-Thru region on the selected
  8. ;;  track(s) will be shifted by a random value which is within a range of +/-
  9. ;;  the user entered value. Before performing a shift that will move a note
  10. ;;  earlier in time, this CAL routine will check to make certain that such a
  11. ;;  negative shift will not cause a note to be moved earlier than time 1:1:0
  12. ;;  (the earliest possible time value). If it would try to go earlier, the
  13. ;;  offset is adjusted so that the note is instead moved just up to 1:1:0,
  14. ;;  and no further.
  15. ;;;
  16. ;;  Then, since shifting one note later in time and a subsequent note earlier
  17. ;;  might cause notes of the same key value to become overlapped (a situation
  18. ;;  which is not handled well by most synths), the duration of shifted notes
  19. ;;  is adjusted proportionately so as to prevent this routine from creating
  20. ;;  this situation. As part of this duration shortening process, this CAL
  21. ;;  routine will check that reduced notes are not made shorter than a user
  22. ;;  specified value. If they would become too short, an error is reported and
  23. ;;  the user asked if the CAL program should abort. If abort is selected, the
  24. ;;  Cakewalk NOW Time will be altered to the point where the error occurred
  25. ;;  so that the user can take a look at the problem area. The user should do
  26. ;;  an Edit UNDO operation to restore the data to the values prior to the
  27. ;;  execution of the aborted RandTime.CAL routine.
  28. ;;;
  29. ;;  Note: the "Processing Note Event" message line was put in to indicate
  30. ;;  program status to the user. However, since it adds another 15-20% to
  31. ;;  the program execution time, it can be removed at the user's discretion.
  32.  
  33. ;Prolog
  34. ;
  35. (do
  36.   (dword SaveTime)         ; Storage for setting NOW time if routine aborted
  37.   (int Range 15)           ; User specified range for +/- to note start times
  38.   (int NegRange)           ; negative version of Range value
  39.   (int Offset)             ; random number between NegRange & Range
  40.   (int Decrease)           ; amount to decrease duration by to avoid overlap
  41.   (int MinDur 5)           ; User specified note duration minimum value
  42.   (int Abort 0)            ; 0 => Program Running; 1 => User Requested Abort
  43.   (int EventCnt 0)         ; Event counter to provide processing status line
  44.  
  45.   (getInt Range "Enter maximum number of ticks to alter note start times +/- by." 0 480)
  46.   (= NegRange (* Range -1))
  47.   (getInt MinDur "Enter minimum duration (in ticks) a note may be reduced to." 1 480)
  48. )
  49.  
  50.  
  51. ;Body
  52. ;
  53. (if (== Abort 1)  ; test if user has aborted note processing
  54.   (message "RandTime.CAL Aborted by User; Please Wait for Routine to Complete")
  55.     ; provide message for user while routine continues thru remaining events
  56.  
  57.   (if (!= Event.Kind NOTE)  ; else test if event kind is a note
  58.     NIL  ; do nothing if event type is not a note
  59.  
  60.     (do  ; else process events that are notes
  61.       (= Offset (random NegRange Range))  ; offset is a random value within +/- Range
  62.       (message "RandTime.CAL Processing Note Event #" (++ EventCnt) "with Offset of " Offset)
  63.  
  64.       (if (< Offset 0)  ; check if minus Offset that will shift note earlier
  65.         (do  ; do these steps for a minus Offset
  66.           (if (> (* Offset -1) Event.Time)
  67.                             ; check if it moves start time before 1:1:0
  68.             (do  ; if moves earlier than the earliest possible time
  69.               (= Offset Event.Time)  ; make it equal to start time
  70.               (*= Offset -1)  ; restore it to negative (this moves it to 1:1:0)
  71.             )  ; close moves earlier than the earliest possible time
  72.             NIL  ; no problem if negative shift not before 1:1:0
  73.           )  ; close check if it moves start time before 1:1:0
  74.         )  ; close do these steps for a minus Offset
  75.         NIL  ; no extra check needed if shift is positive
  76.       )  ; close check if minus Offset that will shift note earlier
  77.  
  78.       (= Decrease (+ Range Offset))
  79.       (if (<= (+ Decrease MinDur) Note.Dur)  ; check decreased duration to Min
  80.          (-= Note.Dur Decrease)  ; reduce duration if passes user's minimum
  81.                                  ; else an error, so check with user for abort
  82.          (getInt Abort "ERROR: A Duration went less than User Minimum; Enter 1 to Abort!" 0 1)
  83.       )  ; close check decreased duration to Min
  84.  
  85.       (if (== Abort 0)           ; check if program to be aborted
  86.         (+= Event.Time Offset)   ; if not, perform shift of note's start time
  87.         (= SaveTime Event.Time)  ; if aborted, then save event time for later
  88.       )  ; close check if program to be aborted
  89.  
  90.     )  ; close of process events that are notes
  91.   )  ; close test if event type is a note
  92. )  ; close test if user has aborted note processing
  93.  
  94. ;Epilog
  95. ;
  96. (if (== Abort 0)  ; check if program was aborted
  97.   NIL  ; if not aborted, nothing to do in epilog
  98.   (do  ; else, set Now time to point when abort occurred & display message
  99.     (= Now SaveTime)  
  100.     (pause "RandTime.CAL Aborted by User; Use UNDO to Restore Original Values  > Hit Enter <")
  101.   )
  102. )  ; close check if program was aborted
  103.