1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
;;;Upbeat
(let ((upbeat "Upbeat") (ok #t)(params Upbeat::params))
; 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-InfoDialog (_ "Upbeat/Short Measure can only be used in an underfull, non-empty measure"))
(set! ok #f)
#f)
; create upbeat directive and reduce display measure number by one
(define (createUpbeat)
(define remainingTicks (- MaxTicks EndTick))
(define partialDuration (number->string (/ EndTick 6 )))
(GoToMeasureBeginning)
(StandAloneDirectiveProto (cons upbeat (string-append "\\partial 256*" partialDuration " ")) #f #f upbeat)
(d-SetDurationInTicks remainingTicks)
(d-DirectivePut-standalone-override upbeat DENEMO_OVERRIDE_DYNAMIC)
(d-DirectivePut-standalone-graphic upbeat "\n\nemmentaler\n62")
(d-DirectivePut-standalone-gx upbeat 20)
(d-DirectivePut-standalone-gy upbeat 15)
(d-LockDirective)
(d-SetMeasureNumberOffset -1))
(define (ComputeAndCreate)
(begin
; 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))
((zero? EndTick) (warning))
((not EndTick) (warning)) ; empty
((< EndTick MaxTicks) (createUpbeat)) ; underful
((= MaxTicks EndTick) (warning)) ; 100% filled
((< MaxTicks EndTick) (warning)) ; >100% filled
(else (warning)) ; ?
)))
(define (DeleteUpbeat)
(if (d-Directive-standalone? upbeat)
(begin
(d-LockDirective #f) ;; unlock
(d-DirectiveDelete-standalone upbeat)
(d-SetMeasureNumberOffset 0))))
(if (equal? params "delete")
(DeleteUpbeat)
(begin
(GoToMeasureBeginning)
(if Upbeat::params ;;; non-interactive call, this used to take the params as the tag to be used - is that useful?
(DeleteUpbeat))
(if (d-Directive-standalone? upbeat)
(let ( (choice (d-GetOption (string-append (_ "Help") stop (_ "Re-calculate") stop (_ "Delete") stop (_ "Advanced") stop))))
(cond
((boolean? choice)
(d-WarningDialog (_ "Operation cancelled")))
((equal? choice (_ "Help"))
(d-InfoDialog (_ "This object fills up the duration of this measure, so that the notes in the measure form an upbeat. It needs to be renewed if you change the duration of the notes in the measure - use Re-calculate for this, or simply delete it and re-run the Upbeat command.")))
((equal? choice (_ "Re-calculate"))
(DeleteUpbeat)
(ComputeAndCreate))
((equal? choice (_ "Delete"))
(DeleteUpbeat))
((equal? choice (_ "Advanced"))
(if (not (d-DirectiveTextEdit-standalone upbeat))
(DeleteUpbeat)))))
;;;if upbeat not already present
(ComputeAndCreate))
(if (d-Directive-standalone? upbeat)
(begin
(d-SetMark)
(d-Copy)
(d-UnsetMark)
(d-PushPosition)
(while (d-MoveToStaffUp))
(if (d-Directive-clef? DenemoClickTrack)
(d-MoveToStaffDown))
(let loop ()
(DeleteUpbeat)
(d-Paste)
(d-MoveCursorLeft)
(if (d-Directive-standalone? upbeat)
(d-LockDirective))
(d-SetMeasureNumberOffset -1)
(if (d-MoveToStaffDown)
(loop)))
(d-PopPosition)
(d-RefreshDisplay)
(if Upbeat::params
(disp "Upbeat recalculated\n")
(begin
(if ok
(begin
(GoToMeasureEnd)
(if (not (d-MoveToMeasureRight))
(d-AddMeasure)))))))))))
|