<?xml version="1.0"?>
<Denemo>
  <merge>
    <title>A Denemo Keymap</title>
    <author>AT, JRR, RTS</author>
    <map>
      <row>
        <after>CreateCuesForStaff</after>
        <action>StaffMultiMeasureRests</action>
        <scheme>;;;StaffMultiMeasureRests
(let ()
  (define (whole-measure-rest)
    (d-Directive-chord? "WholeMeasureRest"))

    ;;; find-block looks at the measures from the cursor onwards returning with the cursor on the first of a block of wmrs (#t) or at the end if none (#f)
  (define (find-block)
    (define position #f)
    (define count 0)
    (disp "find-block called")
    (let loop ()
      (if (whole-measure-rest)
	(begin
	  (if (not position)
	    (set! position (GetPosition)))
	  (set! count (+ count 1))
	  (if (d-MoveToMeasureRight)
	    (loop)))
	  (begin ;; not on a whole measure rest
	    (if (zero? count)
	      (if (d-MoveToMeasureRight)
		(loop)))
	    (if (&lt; count 3) ;;; do not MM less than 3
	      (begin
		(set! count 0)
		(set! position #f)
		(if (d-MoveToMeasureRight)
		  (loop))))))
      (if position
	  (apply d-GoToPosition position)
	  #f)))

;;; actual code
  (d-PushPosition)
  (d-GoToBeginning)
  (while (and (not (whole-measure-rest)) (d-MoveToMeasureRight)))
  (let loop ()
    (if (find-block)
      (begin
	(d-MultiMeasureRests)
	(while (d-MoveToMeasureRight)
	  (if (whole-measure-rest)
	    (loop))))))
  (d-PopPosition))
</scheme>
        <label>Multi-Measure Rests</label>
        <tooltip>Groups of whole measure rests of three or more are changed to multi-measure rests for the whole staff.</tooltip>
      </row>
    </map>
  </merge>
</Denemo>
