<?xml version="1.0"?>
<Denemo>
  <merge>
    <title>A Denemo Keymap</title>
    <author>AT, JRR, RTS</author>
    <map>
      <row>
        <action>Upbeat</action>
        <scheme>(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)
   (d-WarningDialog "Upbeat can only be used in 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)
 )
 


; 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)) ; ?
	)

(GoToMeasureEnd)
(if  (not (d-MoveToMeasureRight))
	(d-SplitMeasure)
)
)</scheme>
        <label>Upbeat (convert current measure)</label>
        <tooltip>Convert the current measure to a partial measure. Also known as upbeat or anacrusis.</tooltip>
      </row>
    </map>
  </merge>
</Denemo>
