X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=ly%2Fmusic-functions-init.ly;h=1f94319bce743ca1e6994eebdff7daa672db0e12;hb=ece789bf5f661cb8f16b50f87a248dedd6e1d8d5;hp=98e6203630dedd13dabc1b4aaa3ee02a06218674;hpb=2c75141e4d2b706a24d70296354a065ee8606bb8;p=lilypond.git diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index 98e6203630..1f94319bce 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -18,7 +18,7 @@ %%%% You should have received a copy of the GNU General Public License %%%% along with LilyPond. If not, see . -\version "2.19.22" +\version "2.19.25" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -29,8 +29,6 @@ #(use-modules (srfi srfi-1) (ice-9 optargs)) -%% TODO: using define-music-function in a .scm causes crash. - absolute = #(define-music-function (music) (ly:music?) @@ -58,12 +56,17 @@ addQuote = (add-quotable name music)) %% keep these two together -afterGraceFraction = #(cons 6 8) +afterGraceFraction = 3/4 afterGrace = -#(define-music-function (main grace) (ly:music? ly:music?) - (_i "Create @var{grace} note(s) after a @var{main} music expression.") +#(define-music-function (fraction main grace) ((fraction?) ly:music? ly:music?) + (_i "Create @var{grace} note(s) after a @var{main} music expression. + +The musical position of the grace expression is after a +given fraction of the main note's duration has passed. If +@var{fraction} is not specified as first argument, it is taken from +@code{afterGraceFraction} which has a default value of @code{3/4}.") (let ((main-length (ly:music-length main)) - (fraction (ly:parser-lookup 'afterGraceFraction))) + (fraction (or fraction (ly:parser-lookup 'afterGraceFraction)))) (make-simultaneous-music (list main @@ -73,10 +76,8 @@ afterGrace = (make-music 'SkipMusic 'duration (ly:make-duration 0 0 - (* (ly:moment-main-numerator main-length) - (car fraction)) - (* (ly:moment-main-denominator main-length) - (cdr fraction)))) + (* (ly:moment-main main-length) + (/ (car fraction) (cdr fraction))))) (make-music 'GraceMusic 'element grace))))))) @@ -95,7 +96,7 @@ markups), or inside a score.") alterBroken = #(define-music-function (property arg item) - (symbol-list-or-symbol? list? symbol-list-or-music?) + (key-list-or-symbol? list? key-list-or-music?) (_i "Override @var{property} for pieces of broken spanner @var{item} with values @var{arg}. @var{item} may either be music in the form of a starting spanner event, or a symbol list in the form @@ -152,11 +153,18 @@ applyMusic = (func music)) applyOutput = -#(define-music-function (ctx proc) (symbol? procedure?) - (_i "Apply function @code{proc} to every layout object in context @code{ctx}") - (make-music 'ApplyOutputEvent - 'procedure proc - 'context-type ctx)) +#(define-music-function (target proc) (symbol-list-or-symbol? procedure?) + (_i "Apply function @code{proc} to every layout object matched by +@var{target} which takes the form @code{Context} or @code{Context.Grob}.") + (let ((p (check-grob-path target (*location*) #:max 2))) + (if p + (make-music 'ApplyOutputEvent + 'procedure proc + 'context-type (car p) + (if (pair? (cdr p)) + (list (cons 'symbol (cadr p))) + '())) + (make-music 'Music)))) appoggiatura = #(def-grace-function startAppoggiaturaMusic stopAppoggiaturaMusic @@ -175,27 +183,24 @@ assertBeamSlope = (make-grob-property-override 'Beam 'positions (check-slope-callbacks comp))) autochange = -#(define-music-function (music) (ly:music?) - (_i "Make voices that switch between staves automatically") - (let ;; keep the contexts alive for the full duration - ((skip (make-skip-music (make-duration-of-length - (ly:music-length music))))) - #{ - << - \context Staff = "up" << - #(make-autochange-music music) - \new Voice { #skip } - >> - \context Staff = "down" \with { - clefGlyph = "clefs.F" - clefPosition = 2 - middleCPosition = 6 - middleCClefPosition = 6 - } { - \new Voice { #skip } - } - >> - #} )) +#(define-music-function (pitch clef-1 clef-2 music) + ((ly:pitch? (ly:make-pitch 0 0)) (ly:context-mod?)(ly:context-mod?) ly:music?) + (_i "Make voices that switch between staves automatically. As an option the +pitch where to switch staves may be specified. The clefs for the staves are +optional as well. Setting clefs works only for implicitly instantiated +staves.") + (let ;; keep the contexts alive for the full duration + ((skip (make-duration-of-length (ly:music-length music))) + (clef-1 (or clef-1 #{ \with { \clef "treble" } #})) + (clef-2 (or clef-2 #{ \with { \clef "bass" } #}))) + (make-simultaneous-music + (list + (descend-to-context (make-autochange-music pitch music) 'Staff + "up" clef-1) + (context-spec-music (make-skip-music skip) 'Staff + "up" clef-1) + (context-spec-music (make-skip-music skip) 'Staff + "down" clef-2))))) balloonGrobText = #(define-music-function (grob-name offset text) @@ -488,7 +493,7 @@ to the preceding note or rest as a post-event with @code{-}.") 'automatically-numbered (not mark) 'text (or mark (make-null-markup)) 'footnote-text footnote))) - (once (tweak 'footnote-music mus item)))) + (once (propertyTweak 'footnote-music mus item)))) grace = #(def-grace-function startGraceMusic stopGraceMusic @@ -547,7 +552,7 @@ If @var{item} is a symbol list of form @code{GrobName} or @code{Context.GrobName}, the result is an override for the grob name specified by it. If @var{item} is a music expression, the result is the same music expression with an appropriate tweak applied to it.") - (tweak 'transparent #t item)) + (propertyTweak 'transparent #t item)) inStaffSegno = #(define-music-function () () @@ -838,6 +843,37 @@ mark = (if label (set! (ly:music-property ev 'label) label)) ev)))) +markupMap = +#(define-music-function (path markupfun music) + (symbol-list-or-symbol? markup-function? ly:music?) + (_i "This applies the given markup function @var{markupfun} to all markup +music properties matching @var{path} in @var{music}. + +For example, +@example +\\new Voice @{ g'2 c'' @} +\\addlyrics @{ + \\markupMap LyricEvent.text + \\markup \\with-color #red \\etc + @{ Oh yes! @} +@} +@end example +") + (let* ((p (check-music-path path (*location*))) + (name (and p (car p))) + (prop (and p (cadr p)))) + (if p + (for-some-music + (lambda (m) + (if (or (not name) (eq? (ly:music-property m 'name) name)) + (let ((text (ly:music-property m prop))) + (if (markup? text) + (set! (ly:music-property m prop) + (list markupfun text))))) + #f) + music))) + music) + musicMap = #(define-music-function (proc mus) (procedure? ly:music?) (_i "Apply @var{proc} to @var{mus} and all of the music it contains.") @@ -875,7 +911,7 @@ octaveCheck = offset = #(define-music-function (property offsets item) - (symbol-list-or-symbol? scheme? symbol-list-or-music?) + (symbol-list-or-symbol? scheme? key-list-or-music?) (_i "Offset the default value of @var{property} of @var{item} by @var{offsets}. If @var{item} is a string, the result is @code{\\override} for the specified grob type. If @var{item} is @@ -918,7 +954,7 @@ If @var{item} is a symbol list of form @code{GrobName} or @code{Context.GrobName}, the result is an override for the grob name specified by it. If @var{item} is a music expression, the result is the same music expression with an appropriate tweak applied to it.") - (tweak 'stencil #f item)) + (propertyTweak 'stencil #f item)) once = #(define-music-function (music) (ly:music?) @@ -926,7 +962,7 @@ once = in @var{music}. This will complain about music with an actual duration. As a special exception, if @var{music} contains @samp{tweaks} it will be silently ignored in order to allow for -@code{\\once \\tweak} to work as both one-time override and proper +@code{\\once \\propertyTweak} to work as both one-time override and proper tweak.") (if (not (pair? (ly:music-property music 'tweaks))) (for-some-music @@ -963,7 +999,7 @@ of @var{base-moment}, @var{beat-structure}, and @var{beam-exceptions}.") overrideProperty = #(define-music-function (grob-property-path value) - (symbol-list? scheme?) + (key-list? scheme?) (_i "Set the grob property specified by @var{grob-property-path} to @var{value}. @var{grob-property-path} is a symbol list of the form @@ -981,13 +1017,10 @@ creation.") (if p (make-music 'ApplyOutputEvent 'context-type (first p) + 'symbol (second p) 'procedure (lambda (grob orig-context context) - (if (equal? - (cdr (assoc 'name (ly:grob-property grob 'meta))) - (second p)) - (ly:grob-set-nested-property! - grob (cddr p) value)))) + (ly:grob-set-nested-property! grob (cddr p) value))) (make-music 'Music)))) @@ -1042,9 +1075,9 @@ Example: d d | e e | f f | } <==> - A = { c c | d d | } - B = { d d | e e | } - C = { e e | f f | } + A = { c c | d d } + B = { d d | e e } + C = { e e | f f } @end verbatim The last bar checks in a sequence are not copied to the result in @@ -1261,25 +1294,7 @@ that they share a staff with stems directed downward.") #{ \with { \voiceTwo \override DynamicLineSpanner.direction = #DOWN } #} #{ \with { \voiceTwo \override DynamicLineSpanner.direction = #DOWN } #} )) -partcombineForce = -#(define-music-function (type once) (boolean-or-symbol? boolean?) - (_i "Override the part-combiner.") - (make-music 'EventChord - 'elements (list (make-music 'PartCombineForceEvent - 'forced-type type - 'once once)))) -partcombineApart = \partcombineForce #'apart ##f -partcombineApartOnce = \partcombineForce #'apart ##t -partcombineChords = \partcombineForce #'chords ##f -partcombineChordsOnce = \partcombineForce #'chords ##t -partcombineUnisono = \partcombineForce #'unisono ##f -partcombineUnisonoOnce = \partcombineForce #'unisono ##t -partcombineSoloI = \partcombineForce #'solo1 ##f -partcombineSoloIOnce = \partcombineForce #'solo1 ##t -partcombineSoloII = \partcombineForce #'solo2 ##f -partcombineSoloIIOnce = \partcombineForce #'solo2 ##t -partcombineAutomatic = \partcombineForce ##f ##f -partcombineAutomaticOnce = \partcombineForce ##f ##t +%% Part combine forcing to be found in ly/property-init.ly partial = #(define-music-function (dur) (ly:duration?) @@ -1324,7 +1339,7 @@ print @var{secondary-note} as a stemless note head in parentheses.") propertyOverride = #(define-music-function (grob-property-path value) - (symbol-list? scheme?) + (key-list? scheme?) (_i "Set the grob property specified by @var{grob-property-path} to @var{value}. @var{grob-property-path} is a symbol list of the form @code{Context.GrobName.property} or @code{GrobName.property}, possibly @@ -1347,7 +1362,7 @@ command.") propertyRevert = #(define-music-function (grob-property-path) - (symbol-list?) + (key-list?) (_i "Revert the grob property specified by @var{grob-property-path} to its previous value. @var{grob-property-path} is a symbol list of the form @code{Context.GrobName.property} or @code{GrobName.property}, possibly @@ -1382,6 +1397,78 @@ Scheme as a substitute for the built-in @code{\\set} command.") (car p)) (make-music 'Music)))) +propertyTweak = +#(define-music-function (prop value item) + (key-list-or-symbol? scheme? key-list-or-music?) + (_i "Add a tweak to the following @var{item}, usually music. +This generally behaves like @code{\\tweak} but will turn into an +@code{\\override} when @var{item} is a symbol list. + +In that case, @var{item} specifies the grob path to override. This is +mainly useful when using @code{\\propertyTweak} as as a component for +building other functions like @code{\\omit}. It is not the default +behavior for @code{\\tweak} since many input strings in +@code{\\lyricmode} can serve equally as music or as symbols which +causes surprising behavior when tweaking lyrics using the less +specific semantics of @code{\\propertyTweak}. + +@var{prop} can contain additional elements in which case a nested +property (inside of an alist) is tweaked.") + ;; Why not instead make the parser treat strings preferably as + ;; music in lyrics mode rather than as symbol? Because then + ;; + ;; \tweak text "whatever" mylyrics + ;; + ;; will try putting a lyric event with text "whatever" in the text + ;; property of lyrics. So we want expressions allowing both + ;; strings and lyrics to deliver strings: more complex conversions + ;; should only be attempted when the simple uses don't match the + ;; given predicate. + (if (ly:music? item) + (if (music-is-of-type? item 'context-specification) + ;; This is essentially dealing with the case + ;; \propertyTweak color #red \propertyTweak font-size #3 NoteHead + ;; namely when stacked tweaks end in a symbol list + ;; rather than a music expression. + ;; + ;; We have a tweak here to convert into an override, + ;; so we need to know the grob to apply it to. That's + ;; easy if we have a directed tweak, and otherwise we + ;; need to find the symbol in the expression itself. + (let* ((p (check-grob-path prop (*location*) + #:start 1 + #:default #t + #:min 2)) + (elt (ly:music-property item 'element)) + (seq (if (music-is-of-type? elt 'sequential-music) + elt + (make-sequential-music (list elt)))) + (elts (ly:music-property seq 'elements)) + (symbol (if (symbol? (car p)) + (car p) + (and (pair? elts) + (ly:music-property (car elts) + 'symbol))))) + (if (symbol? symbol) + (begin + (set! (ly:music-property seq 'elements) + (cons (make-music 'OverrideProperty + 'symbol symbol + 'grob-property-path (cdr p) + 'pop-first #t + 'grob-value value + 'origin (*location*)) + elts)) + (set! (ly:music-property item 'element) seq)) + (begin + (ly:parser-error (_ "Cannot \\propertyTweak") + (*location*)) + (ly:music-message item (_ "untweakable")))) + item) + (tweak prop value item)) + (propertyOverride (append item (if (symbol? prop) (list prop) prop)) + value))) + propertyUnset = #(define-music-function (property-path) (symbol-list-or-symbol?) @@ -1464,7 +1551,12 @@ retrograde = #(define-music-function (music) (ly:music?) (_i "Return @var{music} in reverse order.") - (retrograde-music music)) + (retrograde-music + (expand-repeat-notes! + (expand-repeat-chords! + (cons 'rhythmic-event + (ly:parser-lookup '$chord-repeat-events)) + music)))) revertTimeSignatureSettings = #(define-music-function @@ -1543,7 +1635,7 @@ a context modification duplicating their effect.") shape = #(define-music-function (offsets item) - (list? symbol-list-or-music?) + (list? key-list-or-music?) (_i "Offset control-points of @var{item} by @var{offsets}. The argument is a list of number pairs or list of such lists. Each element of a pair represents an offset to one of the coordinates of a @@ -1551,21 +1643,15 @@ control-point. If @var{item} is a string, the result is @code{\\once\\override} for the specified grob type. If @var{item} is a music expression, the result is the same music expression with an appropriate tweak applied.") - (define (shape-curve grob) + (define (shape-curve grob coords) (let* ((orig (ly:grob-original grob)) (siblings (if (ly:spanner? grob) (ly:spanner-broken-into orig) '())) - (total-found (length siblings)) - (function (assoc-get 'control-points - (reverse (ly:grob-basic-properties grob)))) - (coords (function grob))) - + (total-found (length siblings))) (define (offset-control-points offsets) (if (null? offsets) coords - (map - (lambda (x y) (coord-translate x y)) - coords offsets))) + (map coord-translate coords offsets))) (define (helper sibs offs) (if (pair? offs) @@ -1582,7 +1668,9 @@ appropriate tweak applied.") (if (>= total-found 2) (helper siblings offsets) (offset-control-points (car offsets))))) - (once (tweak 'control-points shape-curve item))) + (once (propertyTweak 'control-points + (grob-transformer 'control-points shape-curve) + item))) shiftDurations = #(define-music-function (dur dots arg) @@ -1801,10 +1889,10 @@ command without explicit @samp{tuplet-span}, use #{ \unset tupletSpannerDuration #})) tweak = -#(define-music-function (prop value item) - (symbol-list-or-symbol? scheme? symbol-list-or-music?) - (_i "Add a tweak to the following @var{item}, usually music. -Layout objects created by @var{item} get their property @var{prop} +#(define-music-function (prop value music) + (key-list-or-symbol? scheme? ly:music?) + (_i "Add a tweak to the following @var{music}. +Layout objects created by @var{music} get their property @var{prop} set to @var{value}. If @var{prop} has the form @samp{Grob.property}, like with @example \\tweak Accidental.color #red cis' @@ -1813,32 +1901,26 @@ an indirectly created grob (@samp{Accidental} is caused by @samp{NoteHead}) can be tweaked; otherwise only directly created grobs are affected. -As a special case, @var{item} may be a symbol list specifying a grob -path, in which case @code{\\override} is called on it instead of -creating tweaked music. This is mainly useful when using -@code{\\tweak} as as a component for building other functions. - -If this use case would call for @code{\\once \\override} rather than a -plain @code{\\override}, writing @code{\\once \\tweak @dots{}} can be -convenient. - @var{prop} can contain additional elements in which case a nested property (inside of an alist) is tweaked.") - (if (ly:music? item) - (let ((p (check-grob-path prop (*location*) - #:start 1 - #:default #t - #:min 2))) - (if p - (set! (ly:music-property item 'tweaks) - (acons (cond ((pair? (cddr p)) p) - ((symbol? (car p)) - (cons (car p) (cadr p))) - (else (cadr p))) - value - (ly:music-property item 'tweaks)))) - item) - (propertyOverride (append item (if (symbol? prop) (list prop) prop)) value))) + (let ((p (check-grob-path prop (*location*) + #:start 1 + #:default #t + #:min 2))) + (cond ((not p)) + ;; p now contains at least two elements. The first + ;; element is #t when no grob has been explicitly + ;; specified, otherwise it is a grob name. + (else + (set! (ly:music-property music 'tweaks) + (acons (cond ((pair? (cddr p)) p) + ((symbol? (car p)) + (cons (car p) (cadr p))) + (else (cadr p))) + value + (ly:music-property music 'tweaks))))) + music)) + undo = #(define-music-function (music) @@ -1852,10 +1934,10 @@ unsets already in @var{music} cause a warning. Non-property-related music is ig (let ((lst (fold-some-music - (lambda (m) (or (music-is-of-type? m 'layout-instruction-event) - (music-is-of-type? m 'context-specification) - (music-is-of-type? m 'apply-context) - (music-is-of-type? m 'time-signature-music))) + (music-type-predicate '(layout-instruction-event + context-specification + apply-context + time-signature-music)) (lambda (m overrides) (case (ly:music-property m 'name) ((OverrideProperty) @@ -1894,11 +1976,16 @@ unsets already in @var{music} cause a warning. Non-property-related music is ig (else (make-sequential-music lst)))))) unfoldRepeats = -#(define-music-function (music) (ly:music?) - (_i "Force any @code{\\repeat volta}, @code{\\repeat tremolo} or +#(define-music-function (types music) + ((symbol-list-or-symbol? '()) ly:music?) + (_i "Force @code{\\repeat volta}, @code{\\repeat tremolo} or @code{\\repeat percent} commands in @var{music} to be interpreted -as @code{\\repeat unfold}.") - (unfold-repeats music)) +as @code{\\repeat unfold}, if specified in the optional symbol-list @var{types}. +The default for @var{types} is an empty list, which will force any of those +commands in @var{music} to be interpreted as @code{\\repeat unfold}. Possible +entries are @code{volta}, @code{tremolo} or @code{percent}. Multiple entries +are possible.") + (unfold-repeats types music)) void = #(define-void-function (arg) (scheme?)