User:Lilipond/Klaviernoten/scheme

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
#(define (MM->Script-text evt)
   (if (eq? 'MultiMeasureTextEvent (ly:music-property evt 'name))
       (let ((res (make-music 'TextScriptEvent)))
         ;; (display (ly:music-mutable-properties evt)) ; if you are curious ...
         (for-each (lambda(props)
                     (ly:music-set-property! res (car props) (cdr props)))
           (ly:music-mutable-properties evt))
         res)
       evt))

ghostMusic = #(define-music-function (parser location music) (ly:music? )
                (map-some-music
                 (lambda(x)
                   (let ((dur (ly:music-property x 'duration #f)))
                     (and (or dur (eq? 'EventChord (ly:music-property x 'name)))
                          (let ((skip (make-music 'SkipEvent 'duration
                                        (or dur (make-duration-of-length (ly:music-length x)))))
                                (artis (let ((elts (ly:music-property x 'elements #f)))
                                         (if elts (filter (lambda(y)   ;; EventChord
                                                            (not (eq? 'NoteEvent (ly:music-property y 'name))))
                                                          elts)
                                             (map MM->Script-text (ly:music-property x 'articulations '()))))))
                            (ly:music-set-property! skip 'articulations artis)
                            skip))))
                 music))

%%make DynamicText from \markup for use in Dynamics-context
dynamictext =
#(define-event-function (text) (markup?)
   (if (string? text)
       (let* ((underscores-replaced
               (string-map
                (lambda (x) (if (eq? x #\_) #\space x))
                text))
              (split-text (string-split underscores-replaced #\space))
              (formatted (map
                          (lambda (word)
                            (if (string-match "^[mrzfps]*$" word)
                                (markup #:dynamic word)
                                (markup #:normal-text #:italic word)))
                          split-text)))
         #{
           #(make-dynamic-script (make-line-markup formatted))
         #})
       ;; user provided a full-blown markup, so we don't mess with it:
       #{
         #(make-dynamic-script (markup #:normal-text text))
       #}))

%%make DynamicText from string for use in Dynamics-context
dynstr =
#(define-event-function (text) (string?)
   (let* ((underscores-replaced
           (string-map
            (lambda (x) (if (eq? x #\_) #\space x))
            text))
          (split-text (string-split underscores-replaced #\space))
          (formatted (map
                      (lambda (word)
                        (markup #:normal-text #:italic #:whiteout word))
                      split-text)))
     #{
       #(make-dynamic-script (make-line-markup formatted))
     #}))

myottava =
#(define-music-function (o) (integer?)
   (let ((text (case o
                 ((0) #f)
                 ((1 -1) "8")
                 ((2 -2) "15"))))
     #{
       \ottava #o
       \set Staff.ottavation = #text
     #}))

#(define (my-tuplet-number::calc-denominator-text grob)
   (let (;; let 'direction evaluate to use the generic tie-markup-command
          (dir (ly:grob-property grob 'direction)))
     (make-tie-markup
      (string-append  "  " (tuplet-number::calc-denominator-text grob) "  "))))

tupletFormats = {
  \override TupletNumber.font-size = #0
  \override TupletNumber.font-shape = #'italic
  \override TupletBracket.padding = #1.5
  \override TupletNumber.text = #my-tuplet-number::calc-denominator-text
}