Hello everybody,

I hope it is appropriate for me to post this here, I haven’t closely followed development for a long time.

I have a custom accidental style following 18th century usage (example attached) which fails in 2.23.6 because the internals have changed. Namely, for the sixth note in the attached example, the alteration value query returns the symbol tied instead of a number.

I’ve tried to find the merge request or issue corresponding to this change, and haven’t found anything. Even looking directly at <https://gitlab.com/lilypond/lilypond/-/blob/master/scm/music-functions.scm#L1696> shows no change. Can someone point me in the right direction to understand how I should adapt my code?

I do think this accidental style might be a worthwhile addition to openLilyLib or even to LilyPond itself, but I’m not sure the coding is good enough.

Best, Simon
\version "2.23.6"

%%%%%%%%%%%%%%%% \include "accidental-style-baroque.ily" %%%%%%

%% LOCAL FUNCTIONS FROM scm/music-functions.scm
%%{
#(define (key-entry-notename entry)
   "Return the pitch of an @var{entry} in @code{localKeySignature}.
      The @samp{car} of the entry is either of the form @code{notename} or
of the form @code{(octave . notename)}.  The latter form is used for special
key signatures or to indicate an explicit accidental.

The @samp{cdr} of the entry is either a rational @code{alter} indicating
a key signature alteration, or of the form
@code{(alter . (barnum . measurepos))} indicating an alteration caused by
an accidental in music."
   (if (pair? (car entry))
       (cdar entry)
       (car entry)))

#(define (key-entry-octave entry)
   "Return the octave of an entry in @code{localKeySignature}
      or @code{#f} if the entry does not have an octave.
See @code{key-entry-notename} for details."
   (and (pair? (car entry)) (caar 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 (key-entry-bar-number entry)
   "Return the bar number of an entry in @code{localKeySignature}
      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{localKeySignature}
      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-public (find-pitch-entry keysig pitch accept-global accept-local . oi)
   "Return the first entry in @var{keysig} that matches @var{pitch}
by notename and octave (or only notename if @var{oi} is set to @code{#t}).
Alteration is not considered.
@var{accept-global} states whether key signature entries should be included.
@var{accept-local} states whether local accidentals should be included.
If no matching entry is found, @var{#f} is returned."
   (and (pair? keysig)
        (let* ((entry (car keysig))
               (entryoct (key-entry-octave entry))
               (entrynn (key-entry-notename entry))
               (nn (ly:pitch-notename pitch))
               ;; When in doubt, use octave-sensitive form
               (octave-insensitive (if (eq? oi '()) #f oi)))
          (if (and (equal? nn entrynn)
                   (or (not entryoct)
                       (= entryoct (ly:pitch-octave pitch))
                       octave-insensitive)
                   (if (key-entry-bar-number entry)
                       accept-local
                       accept-global))
              entry
              (find-pitch-entry (cdr keysig) pitch accept-global accept-local oi)))))

%%%%%%%%%%%%%%% END COPIED STUFF %%%%%%%%%%%%%%%%

#(define-public (baroque-rule context pitch barnum)
   "An accidental rule to simulate the practice in 18th century manuscripts and
prints. Don’t remember local accidentals, except with immediate repetitions
(disregarding barlines) and chromatic steps.
Will cease to work properly after time signature changes (if they change @var{measureLength})."
   ;; 18th century practice is somewhat inconsistent, so it’s impossible to
   ;; handle all cases in an automated manner.  This is especially true
   ;; for pitches repeated with only one note inbetween.
   ;; But there is no mechanism for that anyway.
   (let* ((keysig (ly:context-property context 'localAlterations))
          (global-entry (find-pitch-entry keysig pitch #t #f))
          (local-entry (find-pitch-entry keysig pitch #f #t #t))

          (ml (ly:context-property context 'measureLength))
          (ml-main (ly:moment-main ml))
          (measurepos (ly:context-current-moment context))
          (total-pos (let* ((measurepos-main (ly:moment-main measurepos))
                            (total-main (+ (* barnum ml-main) measurepos-main))
                            (measurepos-grace (ly:moment-grace measurepos)))
                       (ly:make-moment total-main measurepos-grace)))

          (entrymp (if local-entry (key-entry-measure-position local-entry)))
          (entrybn (if local-entry (key-entry-bar-number local-entry)))
          (entry-total-pos (if local-entry
                               (let* ((entrymp-main (ly:moment-main entrymp))
                                      (entry-total-main (+ (* entrybn ml-main) entrymp-main))
                                      (entrymp-grace (ly:moment-grace entrymp)))
                                 (ly:make-moment entry-total-main entrymp-grace))))
          (entryalt (if local-entry (key-entry-alteration local-entry)))
          (entryoct (if local-entry (key-entry-octave local-entry)))

          (globalalt (key-entry-alteration global-entry))

          (alt (ly:pitch-alteration pitch))
          (oct (ly:pitch-octave pitch))

          (local-entry-belongs-to-previous-note (if local-entry (moment<=? total-pos entry-total-pos))))

     (format #t "alteration in the localAlterations entry relevant for ~a was found to be ~a.\n" pitch entryalt)

     ;; no extra natural in any case
     (cons #f
       ;; should we print an accidental?
       ;; we start consideration from the most ‘dramatic’ necessity
       (cond
        ;; chromatic step and previous note was altered: yes
        ((and local-entry
              local-entry-belongs-to-previous-note
              (not (= alt entryalt)))
         #t)
        ;; this note belongs into the current (global) key signature: no
        ((= alt globalalt) #f)
        ;; immediate repetition: no
        ((and local-entry
              local-entry-belongs-to-previous-note
              (= alt entryalt)
              (= oct entryoct))
         #f)
        ;; all other situations: yes
        (else #t)
        ))))

#(set! accidental-styles (append accidental-styles
                           `((baroque #f
                                      (Voice ,baroque-rule)
                                      ()))))

%%%%%%%%%%%%%%% end \include file %%%%%%%%%%%%%%%%%%%%

\layout {
  \context {
    \Staff
    \accidentalStyle baroque
  }
}

{
  b'2 b'~
  b' ais'~
  ais' a'~
  a'
}

Reply via email to