- (if (or (not (ambitus-pitch ambitus DOWN))
- (ly:pitch<? pitch (ambitus-pitch ambitus DOWN)))
- (begin ;; update down pitch
- (set! (ambitus-pitch ambitus DOWN) pitch)
- (set! (ambitus-cause ambitus DOWN) note-event)))
- (if (or (not (ambitus-pitch ambitus UP))
- (ly:pitch<? (ambitus-pitch ambitus UP) pitch))
- (begin ;; update up pitch
- (set! (ambitus-pitch ambitus UP) pitch)
- (set! (ambitus-cause ambitus UP) note-event)))))))
-
-#(define-method (finalize-ambitus (ambitus <ambitus>) translator)
- (if (and (ambitus-pitch ambitus UP) (ambitus-pitch ambitus DOWN))
- (let ((accidental-placement (ly:engraver-make-grob translator
- 'AccidentalPlacement
- (ambitus-accidental ambitus DOWN))))
+ ;; if this pitch is lower than the current ambitus lower
+ ;; note pitch (or it has not been initialized yet),
+ ;; then this pitch is the new ambitus lower pitch,
+ ;; and conversely for upper pitch.
+ (for-each (lambda (direction pitch-compare)
+ (if (or (not (ambitus-note-pitch (ambitus-note ambitus direction)))
+ (pitch-compare pitch
+ (ambitus-note-pitch (ambitus-note ambitus direction))))
+ (begin
+ (set! (ambitus-note-pitch (ambitus-note ambitus direction))
+ pitch)
+ (set! (ambitus-note-cause (ambitus-note ambitus direction))
+ note-event))))
+ (list DOWN UP)
+ (list ly:pitch<? (lambda (p1 p2)
+ (ly:pitch<? p2 p1))))))))
+
+#(define-method (typeset-ambitus (ambitus <ambitus>) translator)
+ "Typeset the ambitus:
+- place the lower and upper ambitus notes according to their pitch and
+ the position of the middle C;
+- typeset or delete the note accidentals, according to the key signature.
+ An accidental, if it is to be printed, is added to an AccidentalPlacement
+ grob (a grob dedicated to the placement of accidentals near a chord);
+- both note heads are added to the ambitus line grob, so that a line should
+ be printed between them."
+ ;; check if there are lower and upper pitches
+ (if (and (ambitus-note-pitch (ambitus-note ambitus UP))
+ (ambitus-note-pitch (ambitus-note ambitus DOWN)))
+ ;; make an AccidentalPlacement grob, for placement of note accidentals
+ (let ((accidental-placement (ly:engraver-make-grob
+ translator
+ 'AccidentalPlacement
+ (ambitus-note-accidental (ambitus-note ambitus DOWN)))))
+ ;; For lower and upper ambitus notes: