Last active
September 11, 2017 15:02
-
-
Save suitougreentea/a7c72085bf63fb3a302eb5ac54ac7a50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\version "2.19.64" | |
#(set-object-property! 'stem-fork-position 'backend-type? pair?) | |
#(set-object-property! 'skip-stem-fork-printing 'backend-type? boolean?) | |
forkedChord = #(define-music-function | |
(lst chord) (list? ly:music?) | |
(let* ((note-event-list (ly:music-property chord 'elements))) | |
(begin | |
(for-each | |
(lambda (note lst) | |
(set! (ly:music-property note 'tweaks) | |
(append | |
(list `((NoteHead . X-offset) . ,(car lst))) | |
(list `((Accidental . X-offset) . ,(cadr lst))) | |
(ly:music-property note 'tweaks)))) | |
note-event-list lst) | |
#{ | |
\once \override NoteColumn.before-line-breaking = | |
#(lambda (grob) | |
(let* ((note-heads (ly:grob-array->list (ly:grob-object grob 'note-heads)))) | |
(for-each (lambda (note-head-grob lst) | |
(let* ((stencil (ly:grob-property note-head-grob 'stencil)) | |
(X-ext (ly:stencil-extent stencil X)) | |
(width (interval-length X-ext)) | |
(head-position (caddr lst)) | |
(offset (ly:grob-property note-head-grob 'X-offset)) | |
(stem-grob (ly:grob-object grob 'stem)) | |
(stem-width (/ (ly:grob-property stem-grob 'thickness) 10)) | |
(direction (ly:grob-property stem-grob 'direction))) | |
(begin | |
(if (and (= direction UP) (= head-position RIGHT)) | |
(ly:grob-set-property! note-head-grob 'X-offset (+ offset width (- stem-width)))) | |
(if (and (= direction DOWN) (= head-position LEFT)) | |
(ly:grob-set-property! note-head-grob 'X-offset (- offset width (- stem-width))))))) | |
note-heads lst))) | |
\once \override Stem.stencil = | |
#(lambda (grob) | |
(let* ((stencil (ly:stem::print grob)) | |
(X-ext (ly:stencil-extent stencil X)) | |
(Y-ext (ly:stencil-extent stencil Y)) | |
(grob-start-y (interval-start Y-ext)) | |
(grob-end-y (interval-end Y-ext)) | |
(width (interval-length X-ext)) | |
(note-column (ly:grob-parent grob X)) | |
(note-head-grobs (ly:grob-array->list (ly:grob-object note-column 'note-heads))) | |
(direction (ly:grob-property grob 'direction))) | |
(apply ly:stencil-add | |
(map (lambda (note-head-grob lst) | |
(let* ((note-head-stencil (ly:grob-property note-head-grob 'stencil)) | |
(skip (ly:grob-property note-head-grob 'skip-stem-fork-printing #f)) | |
(fork (ly:grob-property note-head-grob 'stem-fork-position '(2.75 . 3.5))) | |
(fork-start (car fork)) | |
(fork-end (cdr fork)) | |
(head-position (caddr lst)) | |
(note-head-height (interval-length (ly:stencil-extent note-head-stencil Y))) | |
(staff-position (ly:grob-property note-head-grob 'staff-position)) | |
(stem-attachment (ly:grob-property note-head-grob 'stem-attachment)) | |
(start-y-raw ((if (= head-position RIGHT) - +) staff-position (* note-head-height (cdr stem-attachment)))) | |
(start-y (/ start-y-raw 2)) | |
(start-x (car lst))) | |
(if skip | |
empty-stencil | |
(grob-interpret-markup grob | |
(markup (#:overlay | |
((#:path width | |
(cond | |
((= direction UP) | |
(list (list 'moveto start-x start-y) | |
(list 'lineto start-x (max (- grob-end-y fork-end) start-y)) | |
(list 'lineto 0 (- grob-end-y fork-start)) | |
(list 'lineto 0 grob-end-y))) | |
((= direction DOWN) | |
(list (list 'moveto start-x start-y) | |
(list 'lineto start-x (min (+ grob-start-y fork-end) start-y)) | |
(list 'lineto 0 (+ grob-start-y fork-start)) | |
(list 'lineto 0 grob-start-y))) | |
(else empty-stencil)))))))))) | |
note-head-grobs lst)))) | |
$chord | |
#}))) | |
\relative { | |
\autoBeamOff | |
\once \override Stem.length = 10 | |
\forkedChord #`((-1.5 -2.5 ,LEFT) (1.5 0.2 ,LEFT) (1.5 0 ,LEFT)) | |
<c'! cis e>8 | |
\once \override Stem.length = 10 | |
\forkedChord #`((-3.0 -4.0 ,LEFT) (0 -1.3 ,LEFT) (0 0 ,RIGHT)) | |
<ces cis d>8 | |
\once \override Stem.length = 12 | |
\forkedChord #`((-1.5 -2.5 ,LEFT) (1.5 0.2 ,LEFT) (1.5 0 ,LEFT)) | |
<\tweak NoteHead.stem-fork-position #'(2.75 . +inf.0) c! cis a>8 | |
\once \override Stem.length = 10 | |
\forkedChord #`((-1.5 -2.5 ,LEFT) (1.5 0.2 ,LEFT) (1.5 0 ,LEFT)) | |
<\tweak NoteHead.skip-stem-fork-printing ##t c! cis e>8 | |
\stemDown | |
\once \override Stem.length = 10 | |
\forkedChord #`((-1.5 -2.5 ,RIGHT) (1.5 0.2 ,RIGHT) (1.5 0 ,RIGHT)) | |
<c'! cis e>8 | |
\once \override Stem.length = 10 | |
\forkedChord #`((-4.0 -5.0 ,RIGHT) (0 -2.5 ,LEFT) (0 0 ,RIGHT)) | |
<ces cis d>8 | |
\once \override Stem.length = 12 | |
\forkedChord #`((-1.5 -2.5 ,RIGHT) (1.5 0.2 ,RIGHT) (1.5 0 ,RIGHT)) | |
<\tweak NoteHead.stem-fork-position #'(2.75 . +inf.0) c! cis a>8 | |
\once \override Stem.length = 10 | |
\forkedChord #`((-1.5 -2.5 ,RIGHT) (1.5 0.2 ,RIGHT) (1.5 0 ,RIGHT)) | |
<\tweak NoteHead.skip-stem-fork-printing ##t c! cis e>8 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment