Files
music/src/includes/functions.ly
T

63 lines
1.8 KiB
LilyPond
Executable File

#(define (naturalize-pitch p)
(let ((o (ly:pitch-octave p))
(a (* 4 (ly:pitch-alteration p)))
;; alteration, a, in quarter tone steps,
;; for historical reasons
(n (ly:pitch-notename p)))
(cond
((and (> a 1) (or (eq? n 6) (eq? n 2)))
(set! a (- a 2))
(set! n (+ n 1)))
((and (< a -1) (or (eq? n 0) (eq? n 3)))
(set! a (+ a 2))
(set! n (- n 1))))
(cond
((> a 2) (set! a (- a 4)) (set! n (+ n 1)))
((< a -2) (set! a (+ a 4)) (set! n (- n 1))))
(if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
(if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7))))
(ly:make-pitch o n (/ a 4))))
#(define (naturalize music)
(let ((es (ly:music-property music 'elements))
(e (ly:music-property music 'element))
(p (ly:music-property music 'pitch)))
(if (pair? es)
(ly:music-set-property!
music 'elements
(map (lambda (x) (naturalize x)) es)))
(if (ly:music? e)
(ly:music-set-property!
music 'element
(naturalize e)))
(if (ly:pitch? p)
(begin
(set! p (naturalize-pitch p))
(ly:music-set-property! music 'pitch p)))
music))
naturalizeMusic = #(define-music-function (parser location m)
(ly:music?)
(naturalize m))
#(define (scoop-stencil grob)
(ly:stencil-add
(ly:note-head::print grob)
(grob-interpret-markup grob
(markup #:with-dimensions '(0 . 0) '(0 . 0)
#:translate '(-1.5 . -0.1)
#:path 0.25 '((moveto 0 0)
(curveto 0 -1 -1 -1.5 -2.0 -2.0)
)
)
)
)
)
scoop = \once \override NoteHead.stencil = #scoop-stencil
toCoda = \markup {
\fontsize #-2 \lower #1 "TO" \musicglyph #"scripts.coda"
}