On 25.06.2018 13:25, Richard Shann wrote:
In 18th c. mss and prints it is quite common to create line breaks
during bars - I've found this much improves the legibility of some
florid slow movements.

However, it seems that the available accidental styles only take
account of barlines and ignore line breaks,

It’s not what you ask for, but of course in the 18th century accidentals generally pertained only to one note and its immediate repetitions – with exceptions according to common sense. Except for the exceptions this can be modelled very well using a LilyPond accidental style – see attachment.

Best, Simon
\version "2.19.35"
%% 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 measurepos)
   "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))
          (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 "local-entry for ~a was found to be ~a.\n" pitch local-entry)

     ;; 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)
                                      ()))))
\version "2.19.35"
#(use-modules (ice-9 pretty-print))
\include "accidental-style-baroque-verbose.ily"

printKeysig =
\applyContext #(lambda (context)
                 (pretty-print (ly:context-property context
                                 'localAlterations)))
%printKeysig = {}
\transpose c c \relative {
  \accidentalStyle baroque
  %% all of the following notes should get an accidental, except for the last...
  %% ...three (baroque)
  %% ...two (baroque-within-bar)
  dis'4 cis dis fis
  f es e' fis,
  fis fis e
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to