> You could try the attached, which is the 2.20.0 source code for the
> teaching accidental style (+some helper functions) with one change to
> accommodate 2.18 syntax, i.e. the key signature is obtained from the
> localKeySignature context property instead of localAlterations.

That's very close to what I need but look at the attached sample, the
first dis has no sharp sign!

F
\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 e \minor
  dis'8 c' dis' e' dis' e' fis'4
  dis'8 c' dis' dis' dis' e' fis'4
}

Reply via email to