<?xml version="1.0"?>
<Denemo>
  <merge>
    <title>A Denemo Keymap</title>
    <author>AT, JRR, RTS</author>
    <map>
      <row>
        <action>Upbeat</action>
        <scheme>;;;Upbeat
(let script ()
  ; How many ticks are in a 100% filled measure?
  (define MaxTicks (* 1536 (GetPrevailingTimeSig #t) )) 
  (define EndTick #f)
  ;Upbeat is only for underful measures
  (define (warning)
   (Help::TimedNotice "Upbeat can only be used in an underful, non-empty measures")   
   #f)
 
 ; Create Upbeat-Directive Subprogram
 (define (createUpbeat)
   (define remainingTicks (- MaxTicks EndTick))
   (define partialDuartion (number-&gt;string (/ EndTick 6 )))
   (GoToMeasureBeginning)
   (StandAloneDirectiveProto (cons "Upbeat" (string-append "\\partial 256*" partialDuartion 	" "))  #f)
   (d-SetDurationInTicks remainingTicks)
   (GoToMeasureEnd)
   (if  (not (d-MoveToMeasureRight))
	(d-AddMeasure)))
 
; First action: delete any old Upbeat directive in this measure
   (GoToMeasureBeginning)
   (if (d-DirectiveGet-standalone-display "Upbeat")
 	(d-DeleteObject))

; Save how many ticks are in this measure
	(GoToMeasureEnd)
	(set! EndTick (d-GetEndTick))

; Cond what to do, only create Upbeat if the measure is not full, else give warning. 	
	(cond 
 		((not EndTick) (warning)) ; empty
 		((&lt; EndTick MaxTicks) (createUpbeat)) ; underful
 		((= MaxTicks EndTick) (warning))  ; 100% filled
 		((&lt; MaxTicks EndTick) (warning)) ; &gt;100% filled
		(else  (warning)) ; ?
		))

</scheme>
        <label>Anacrusis (Upbeat, Pickup)</label>
        <tooltip>Convert the current measure to a partial measure so that it is complete with just the beats already inserted.</tooltip>
      </row>
    </map>
  </merge>
</Denemo>
