;; This works for single-note and multi-note tremolos!
(let* ((children (if (music-is-of-type? main 'sequential-music)
;; \repeat tremolo n { ... }
- (length (ly:music-property main 'elements))
+ (length (extract-named-music main 'EventChord))
;; \repeat tremolo n c4
1))
;; # of dots is equal to the 1 in bitwise representation (minus 1)!
(define (calc-repeat-slash-count music)
"Given the child-list @var{music} in @code{PercentRepeatMusic},
calculate the number of slashes based on the durations. Returns @code{0}
-if durations in in @var{music} vary, allowing slash beats and double-percent
+if durations in @var{music} vary, allowing slash beats and double-percent
beats to be distinguished."
(let* ((durs (map (lambda (elt)
(duration-of-note elt))
'grob-property gprop))
(define direction-polyphonic-grobs
- '(DotColumn
+ '(AccidentalSuggestion
+ DotColumn
Dots
Fingering
LaissezVibrerTie
+ LigatureBracket
PhrasingSlur
RepeatTie
Rest
Slur
Stem
TextScript
- Tie))
+ Tie
+ TupletBracket
+ TrillSpanner))
(define-safe-public (make-voice-props-set n)
(make-sequential-music
(make-property-set 'graceSettings
;; TODO: take this from voicedGraceSettings or similar.
'((Voice Stem font-size -3)
+ (Voice Flag font-size -3)
(Voice NoteHead font-size -3)
(Voice TabNoteHead font-size -4)
(Voice Dots font-size -3)
(set! (ly:grob-property grob symbol) val))))
-;;
-(define-public (smart-bar-check n)
- "Make a bar check that checks for a specific bar number."
- (let ((m (make-music 'ApplyContext)))
- (define (checker tr)
- (let* ((bn (ly:context-property tr 'currentBarNumber)))
- (or (= bn n)
- (ly:error
- ;; FIXME: uncomprehensable message
- (_ "Bar check failed. Expect to be at ~a, instead at ~a")
- n bn))))
- (set! (ly:music-property m 'procedure) checker)
- m))
-
-
(define-public (skip->rest mus)
"Replace @var{mus} by @code{RestEvent} of the same duration if it is a
@code{SkipEvent}. Useful for extracting parts from crowded scores."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; warn for bare chords at start.
-
(define-public (ly:music-message music msg)
(let ((ip (ly:music-property music 'origin)))
(if (ly:input-location? ip)
- (ly:input-message ip msg)
- (ly:warning msg))))
+ (ly:input-message ip msg)
+ (ly:message msg))))
+
+(define-public (ly:music-warning music msg)
+ (let ((ip (ly:music-property music 'origin)))
+ (if (ly:input-location? ip)
+ (ly:input-warning ip msg)
+ (ly:warning msg))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
music
(ly:music-deep-copy ,stop))))))
-(defmacro-public define-music-function (args signature . body)
+(defmacro-public define-syntax-function (type args signature . body)
"Helper macro for `ly:make-music-function'.
Syntax:
- (define-music-function (parser location arg1 arg2 ...) (arg1-type? arg2-type? ...)
+ (define-syntax-function (result-type? parser location arg1 arg2 ...) (result-type? arg1-type? arg2-type? ...)
...function body...)
"
-(if (and (pair? body) (pair? (car body)) (eqv? '_i (caar body)))
+ (if (and (pair? body) (pair? (car body)) (eqv? '_i (caar body)))
;; When the music function definition contains a i10n doc string,
;; (_i "doc string"), keep the literal string only
(let ((docstring (cadar body))
(body (cdr body)))
- `(ly:make-music-function (list ,@signature)
- (lambda (,@args)
+ `(ly:make-music-function (list ,type ,@signature)
+ (lambda ,args
,docstring
,@body)))
- `(ly:make-music-function (list ,@signature)
- (lambda (,@args)
+ `(ly:make-music-function (list ,type ,@signature)
+ (lambda ,args
,@body))))
+(defmacro-public define-music-function rest
+ "Helper macro for `ly:make-music-function'.
+Syntax:
+ (define-music-function (parser location arg1 arg2 ...) (arg1-type? arg2-type? ...)
+ ...function body...)
+"
+ `(define-syntax-function ly:music? ,@rest))
+
+
+(defmacro-public define-scheme-function rest
+ "Helper macro for `ly:make-music-function'.
+Syntax:
+ (define-scheme-function (parser location arg1 arg2 ...) (arg1-type? arg2-type? ...)
+ ...function body...)
+"
+ `(define-syntax-function scheme? ,@rest))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(set! (ly:music-property music 'quoted-events) quoted-vector)
(set! (ly:music-property music 'iterator-ctor)
ly:quote-iterator::constructor))
- (ly:warning (_ "cannot find quoted music: `~S'") quoted-name)))
+ (ly:music-warning music (ly:format (_ "cannot find quoted music: `~S'") quoted-name))))
music))
(equal? laziness #t)
(<= bar-number (+ (cadr alteration-def) laziness))))
-(define (is-tied? alteration-def)
- (let* ((def (if (pair? alteration-def)
- (car alteration-def)
- alteration-def)))
+(define (accidental-invalid? alteration-def)
+ "Checks an alteration entry for being invalid.
+
+Non-key alterations are invalidated when tying into the next bar or
+when there is a clef change, since neither repetition nor cancellation
+can be omitted when the same note occurs again.
- (if (equal? def 'tied) #t #f)))
+Returns @code{#f} or the reason for the invalidation, a symbol."
+ (let* ((def (if (pair? alteration-def)
+ (car alteration-def)
+ alteration-def)))
+ (and (symbol? def) def)))
(define (extract-alteration alteration-def)
(cond ((number? alteration-def)
(from-key-sig
(set! previous-alteration from-key-sig)))
- (if (is-tied? previous-alteration)
+ (if (accidental-invalid? previous-alteration)
(set! need-accidental #t)
(let* ((prev-alt (extract-alteration previous-alteration))
(begin
(set! need-accidental #t)
(if (and (not (= this-alt 0))
- (or (< (abs this-alt) (abs prev-alt))
- (< (* prev-alt this-alt) 0)))
+ (and (< (abs this-alt) (abs prev-alt))
+ (> (* prev-alt this-alt) 0)))
(set! need-restore #t))))))
(cons need-restore need-accidental)))
@var{laziness} states over how many bars an accidental should be remembered.
@code{0}@tie{}is the default -- accidental lasts over 0@tie{}bar lines, that
is, to the end of current measure. A positive integer means that the
-accidental lasts over that many bar lines. @code{-1} is `forget
+accidental lasts over that many bar lines. @w{@code{-1}} is `forget
immediately', that is, only look at key signature. @code{#t} is `forever'."
(check-pitch-against-signature context pitch barnum laziness octaveness))
(and (pair? (car entry)) (cdddr entry)))
(define (key-entry-alteration entry)
- "Return the alteration of an entry in localKeySignature."
- (if (number? (car entry))
- (cdr entry)
- (cadr entry)))
+ "Return the alteration of an entry in localKeySignature.
+
+For convenience, returns @code{0} if entry is @code{#f}."
+ (if entry
+ (if (number? (car entry))
+ (cdr entry)
+ (cadr entry))
+ 0))
(define-public (find-pitch-entry keysig pitch accept-global accept-local)
"Return the first entry in @var{keysig} that matches @var{pitch}.
(if (not entry)
(cons #f #f)
(let* ((global-entry (find-pitch-entry keysig pitch #t #f))
- (key-acc (if (equal? global-entry #f)
- 0
- (key-entry-alteration global-entry)))
+ (key-acc (key-entry-alteration global-entry))
(acc (ly:pitch-alteration pitch))
(entrymp (key-entry-measure-position entry))
(entrybn (key-entry-bar-number entry)))
(if (not entry)
(cons #f #f)
(let* ((global-entry (find-pitch-entry keysig pitch #f #f))
- (key-acc (if (equal? global-entry #f)
- 0
- (key-entry-alteration global-entry)))
+ (key-acc (key-entry-alteration global-entry))
(acc (ly:pitch-alteration pitch))
(entrymp (key-entry-measure-position entry))
(entrybn (key-entry-bar-number entry)))
(ly:warning (_ "unknown accidental style: ~S") style)
(make-sequential-music '()))))))
+(define-public (invalidate-alterations context)
+ "Invalidate alterations in @var{context}.
+
+Elements of @code{'localKeySignature} corresponding to local
+alterations of the key signature have the form
+@code{'((octave . notename) . (alter barnum . measurepos))}.
+Replace them with a version where @code{alter} is set to @code{'clef}
+to force a repetition of accidentals.
+
+Entries that conform with the current key signature are not invalidated."
+ (let* ((keysig (ly:context-property context 'keySignature)))
+ (set! (ly:context-property context 'localKeySignature)
+ (map-in-order
+ (lambda (entry)
+ (let* ((localalt (key-entry-alteration entry))
+ (localoct (key-entry-octave entry)))
+ (if (or (accidental-invalid? localalt)
+ (not localoct)
+ (= localalt
+ (key-entry-alteration
+ (find-pitch-entry
+ keysig
+ (ly:make-pitch localoct
+ (key-entry-notename entry)
+ 0)
+ #t #t))))
+ entry
+ (cons (car entry) (cons 'clef (cddr entry))))))
+ (ly:context-property context 'localKeySignature)))))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-public (skip-of-length mus)