anchor.diff:     dur
      (tolerance :default 0)
      (current-dur :state t)
  -   (current-elapsed :state t :initform 0))
  +   (elapsed-dur :state t :initform 0))
     :documentation "pfindur yields events from PATTERN until their total duration is within TOLERANCE of DUR, or greater than DUR. Any events that would end beyond DUR are cut short. If PATTERN outputs numbers, their total sum is limited instead.
   
   Example:
  
positive.code:   (pattern
     sync-quant
     (maxdur :default nil)
     (tolerance :default 0.001))
    :documentation "psync yields events from PATTERN until their total duration is within TOLERANCE of MAXDUR, cutting off any events that would extend past MAXDUR. If PATTERN ends before MAXDUR, a rest is added to the pstream to round its duration up to the nearest multiple of SYNC-QUANT.
  
  Example:
  
negative.code:            (if (event-p ev)
                 (event-value ev :delta)
                 ev)))
      (with-slots (pattern dur tolerance current-dur elapsed-dur) pfindur
        (when-let ((n-event (next pattern)))
          (unless (slot-boundp pfindur 'current-dur)
            (setf current-dur (next dur)))
          (when current-dur
            (if (eql :inf current-dur)
                n-event
                (let ((new-elapsed (+ (get-delta n-event) elapsed-dur)))
                  (prog1
                      (if (> (if (= 0 tolerance)
                                 new-elapsed
                                 (round-by-direction new-elapsed tolerance))
                             current-dur)
                          (let ((tdur (- current-dur elapsed-dur)))
                            (when (plusp tdur)
                              (if (event-p n-event)
                                  (combine-events n-event (event :dur tdur))
                                  tdur)))
                          n-event)
                    (incf elapsed-dur (get-delta n-event))))))))))
  
  ;;; psync
  
  