Skip to content

Instantly share code, notes, and snippets.

@kris7t
Created June 20, 2013 10:46
Show Gist options
  • Save kris7t/5821800 to your computer and use it in GitHub Desktop.
Save kris7t/5821800 to your computer and use it in GitHub Desktop.
\version "2.17.20"
\include "articulate.ly"
#(define (contains-articulation? a-type articulations)
(find (lambda (a)
(equal? (ly:music-property a 'articulation-type) a-type))
articulations))
#(define (restify-note note)
(let ((rest (make-music 'RestEvent
'duration (ly:music-property note 'duration)))
(as (ly:music-property note 'articulations)))
(if (pair? as)
(set! (ly:music-property rest 'articulations) as))
rest))
#(define (restify-list music)
(let ((contains-rest #f))
(filter-map (lambda (y)
(case (ly:music-property y 'name)
((NoteEvent)
(if contains-rest
#f
(begin
(set! contains-rest #t)
(restify-note y))))
((RestEvent)
(if contains-rest
#f
(begin
(set! contains-rest #t)
y)))
((TieEvent)
#f)
(else
y)))
music)))
#(define (restify-by-articulations pred? m)
(case (ly:music-property m 'name)
((NoteEvent)
(if (pred? (ly:music-property m 'articulations))
(music-clone m)
(restify-note m)))
((EventChord)
(if (pred? (ly:music-property m 'elements))
(music-clone m)https://gist.github.com/kris7topher/5792972
(music-clone m
'elements
(restify-list (ly:music-property m 'elements)))))
(else
(let ((mm (music-clone m))
(es (ly:music-property m 'elements))
(e (ly:music-property m 'element)))
(if (pair? es)
(set! (ly:music-property mm 'elements)
(map (lambda (y) (restify-by-articulations pred? y)) es)))
(if (ly:music? e)
(set! (ly:music-property mm 'element)
(restify-by-articulations pred? e)))
mm))))
filterByArticulation =
#(define-music-function
(parser location a-type m)
(string? ly:music?)
(restify-by-articulations
(lambda (as) (contains-articulation? a-type as))
m))
filterByArticulationInverse =
#(define-music-function
(parser location a-type m)
(string? ly:music?)
(restify-by-articulations
(lambda (as) (not (contains-articulation? a-type as)))
m))
originalMusic = \relative c' {
\time 4/4
c4\mf <d e>~\startTrillSpan <d e> f\>\stopTrillSpan | c-. <d e>-.~ <d e>-.\! f-.
}
\new Staff \with { instrumentName = "Orig."}
\originalMusic
\new Staff \with { instrumentName = "Stacc." }
\filterByArticulation "staccato" \originalMusic
\new Staff \with { instrumentName = "Not Stacc."}
\filterByArticulationInverse "staccato" \originalMusic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment