[CM] BoundingBox mystery in CMN output

Anders Vinjar andersvi@extern.uio.no
Sun, 27 Feb 2005 11:29:14 +0100


This is a bug in cmn/cmn3.lisp.  To save code the
crescendo/diminuendo marks are "optimized" so that the diminuendo
mark is infact a sort of mirrored crescendo giving negative
values for the objects house or something.  Im sure Bill can
explain whats actually happening here :)

Heres a fix to #'display-crescendo in cmn3 which hopefully fixes
the problem.

(defun display-crescendo (mark note score &optional justifying)
  (when (not justifying)
    (let* ((dsize *dynamics-size*)
           (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))
                                        ;(width (crescendo-begin-dynamic mark)) AV 28-Jun-00
                               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 dynamics-size)
                       (if (crescendo-user-data mark) (first (crescendo-user-data mark)) 0)))
           (x1-mark (+ (max (- (box-x1 mark) .125) (+ x0-mark .5))
                       (if (crescendo-user-data mark) (third (crescendo-user-data mark)) 0)))
           (cresc (eq (tag-type mark) :crescendo))
           ;;(x0 (if cresc x0-mark x1-mark))
           (x0 x0-mark)

	   ;; (ct (if (> (- x1-mark x0-mark) 1.0) (or (thickness mark) .25) .05))
	   (ct (* (or (thickness mark) .25) (- x1-mark x0-mark))) ;AV 28-Jun-00

           (x0-off (+ x0 (if cresc ct (- ct))))
           ;;(x1 (if cresc x1-mark x0-mark))
           (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 ;AV 28-Jun-00
						      (+ (dx (crescendo-begin-dynamic mark)) (- x0-mark 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 ;AV 28-Jun-00
						      (+ (dx (crescendo-end-dynamic mark)) (- x1-mark .125))
						      (+ (dy (crescendo-end-dynamic mark)) (- y0 .125)))
				    dsize dsize)
	      :data (dynamics-mark (crescendo-end-dynamic mark)))
	(if cresc (decf x1 .3) (decf x0 .3))
	(if (not cresc) (decf x0-off .3)))
      
      (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))))

>>>>> "K" == Kyle Markley <kmarkley@seffera.net> writes:

    K> In the score I've been working on, I've noticed there's always a bunch
    K> of  extra whitespace at the left margin despite my margin settings.
    K> I've been  able to minimize the issue to the following example.  If
    K> you view this in  gv and use the BBox "paper size", you'll see a left
    K> margin much bigger  than it ought to be.

    K> If you remove the diminuendo, the output file's bounding box changes
    K> from  "%%BoundingBox: -78 -26 133 102" to "%%BoundingBox: 0 -26 133
    K> 102" and the  box much better fits the left margin specified.

    K> (cmn
    K>    (header-margin 0.1)
    K>    (left-margin 0.1)
    K>    (right-margin 0.1)
    K>    (footer-margin 0.1)
    K>    (system (staff

    K> c5 q
    K> begin-diminuendo
    K> d5 q
    K> e5 q
    K> g5 q
    K> a5 q
    K> end-diminuendo

    K> )))

    K> I believe this issue or something related to it is causing an extra
    K> inch  or so of whitespace on the left side of my full score.  I could
    K> probably  fit another measure on each line if there wasn't so much
    K> unwanted  whitespace.

    K> -- 
    K> Kyle Markley

    K> _______________________________________________
    K> Cmdist mailing list
    K> Cmdist@ccrma.stanford.edu
    K> http://ccrma-mail.stanford.edu/mailman/listinfo/cmdist