\version "2.18.2" #(begin (define (key-entry-bar-number entry) "Return the bar number of an entry in @code{localAlterations} or @code {#f} if the entry does not have a bar number. See @code{key-entry-notename} for details." (and (pair? (cdr entry)) (caddr entry))) (define (key-entry-measure-position entry) "Return the measure position of an entry in @code{localAlterations} or @code {#f} if the entry does not have a measure position. See @code{key-entry-notename} for details." (and (pair? (cdr entry)) (cdddr entry))) (define (key-entry-alteration entry) "Return the alteration of an entry in localAlterations For convenience, returns @code{0} if entry is @code{#f}." (if entry (if (number? (cdr entry)) (cdr entry) (cadr entry)) 0)) (define-public (my-teaching-accidental-rule context pitch barnum measurepos) "An accidental rule that typesets a cautionary accidental if it is included in the key signature @emph{and} does not directly follow a note on the same staff line." (let* ((keysig (ly:context-property context 'localKeySignature)) (entry (find-pitch-entry keysig pitch #t #t))) (if (not entry) (cons #f #f) (let* ((global-entry (find-pitch-entry keysig pitch #f #f)) (key-acc (key-entry-alteration global-entry)) (acc (ly:pitch-alteration pitch)) (entrymp (key-entry-measure-position entry)) (entrybn (key-entry-bar-number entry))) (cons #f (not (or (equal? acc key-acc) (and (equal? entrybn barnum) (equal? entrymp measurepos))))))))) ) \layout { \context { \Score autoAccidentals = #`(Staff ,my-teaching-accidental-rule) } } { \key d\major d'4 e' fis' g' a' b' cis'' d'' d'4 fis' d' fis' d'4 fis' d' fis' }