[CM] BoundingBox mystery in CMN output

Anders Vinjar andersvi@extern.uio.no
Sun, 27 Feb 2005 18:59:59 +0100


>>> "A" == Anders Vinjar <andersvi@extern.uio.no> writes:
A> 
A> Heres a fix to #'display-crescendo in cmn3 which hopefully fixes
A> the problem.

Sorry, too fast there, it screws up when placing dynamics.

Heres another attempt.  It seems to do a better job, but still
doesnt function properly when giving (rotate xxx) messages
etc. to this mark with attached dynamics.  


(defun display-crescendo (mark note score &optional justifying)
  (when (not justifying)
    (let* ((dsize *dynamics-size*)
           (cresc (eq (tag-type mark) :crescendo))
           (begin-dynamics-size (* (if (crescendo-begin-dynamic mark)
                                       (let ((w (width (crescendo-begin-dynamic mark))))
                                         (if (zerop w)
                                             (* 0.35 (length (dynamics-mark (crescendo-begin-dynamic mark)))) w))
                                     0.0)
                                   dsize))
           (end-dynamics-size (* (if (crescendo-end-dynamic mark)
                                     (let ((w (width (crescendo-end-dynamic mark))))
                                       (if (zerop w)
                                           (* 0.35 (length (dynamics-mark (crescendo-end-dynamic mark)))) w))
                                   0.0)
                                 dsize))
           (x0-mark (+ (vis-dx mark) 
                       (if (or (> (box-x0 mark) (box-x0 note))
                               (/= (onset-offset mark) 0.0))
                           (box-x0 mark)
                         (+ (box-x0 note) .125))
                       (* .5 begin-dynamics-size)
                       (if (crescendo-user-data mark) (first (crescendo-user-data mark)) 0)))
           (x1-mark (+ (max (- (box-x1 mark) .125) (+ x0-mark .5))
                       (- (* .5 end-dynamics-size))
                       (if (crescendo-user-data mark) (third (crescendo-user-data mark)) 0)))
           (x0 x0-mark)
	   (ct (* (or (thickness mark) .25) (- x1-mark x0-mark))) 
           (x0-off (+ x0 ct))
           (x1 x1-mark)
           (width (or (width mark) .25))
           (half-width (* .5 width))
           (y0 (+ (staff-y0 note)
                  (vis-dy mark)
                  (box-y0 mark)
                  (if (member (visible-justification mark) '(:up :above))
                      (+ (max (* (max 10 (+ (maximum-line note)
                                            (if (member (stem-direction note) '(:up)) 8 4)))
                                 *staff-line-separation*)
                              (+ (y1 note) 0.2))
                         (* 0.5 width))
                    (+ (min 0 
                            (* (- (minimum-line note)
                                  (if (member (stem-direction note) '(:down)) 6 2))
                               *staff-line-separation*)
                            (if (tag-note mark) (* (- (minimum-line (tag-note mark)) 2) *staff-line-separation*) 0))
                       -.25))))
           (y1 (+ y0 half-width))
           (y2 (- y0 half-width)))
      
      (when (crescendo-user-data mark)
        (incf y0 (if cresc (second (crescendo-user-data mark)) (fourth (crescendo-user-data mark))))
        (incf y1 (if (not cresc) (second (crescendo-user-data mark)) (fourth (crescendo-user-data mark))))
        (incf y2 (if (not cresc) (second (crescendo-user-data mark)) (fourth (crescendo-user-data mark)))))

      (when (crescendo-begin-dynamic mark)
	;; the "x0" above is the wedge point -- can be either left or rightmost x
	(show score (crescendo-begin-dynamic mark)
	      :matrix (scale-matrix (translate-matrix score mark 
						      (+ (dx (crescendo-begin-dynamic mark)) (- x0 begin-dynamics-size .2))
						      (+ (dy (crescendo-begin-dynamic mark)) (- y0 .125)))
				    dsize dsize)
	      :data (dynamics-mark (crescendo-begin-dynamic mark))))
      
      (when (crescendo-end-dynamic mark)
	(show score (crescendo-end-dynamic mark)
	      :matrix (scale-matrix (translate-matrix score mark
                                                      (+ x1 (dx (crescendo-end-dynamic mark)) .2)
                                                      (+ (dy (crescendo-end-dynamic mark)) (- y0 .125)))
				    dsize dsize)
	      :data (dynamics-mark (crescendo-end-dynamic mark))))

      (matrix-front score (if cresc
                              (translate-matrix score mark x0 y0)
                            (mirror-matrix
                             (translate-matrix score mark x1 y0))))      
      
      (with-color score mark
                  (moveto score 0 0)
                  (lineto score (- x1 x0) (- y1 y0))
                  (lineto score (- x0-off x0) 0)
                  (lineto score (- x1 x0) (- y2 y0))
                  (lineto score 0 0)
                  (fill-in score))
      (matrix-back score))))