-For example, you can tell @code{\\layout-from} to apply a contained
-@example
-\\override #'font-size = #2
-@end example
-to @samp{TabVoice} or @samp{Lyrics} context instead of the default
-@samp{Voice} context, if the context where you would normally use
-@var{music} is not one that would have @samp{Voice} as its
-@samp{Bottom}.")
- (let loop ((m music) (mods #f))
- ;; The parser turns all sets, overrides etc into something
- ;; wrapped in ContextSpeccedMusic. If we ever get a set,
- ;; override etc that is not wrapped in ContextSpeccedMusic, the
- ;; user has created it in Scheme himself without providing the
- ;; required wrapping. In that case, using #f in the place of a
- ;; context modification results in a reasonably recognizable
- ;; error.
- (if (music-is-of-type? m 'layout-instruction-event)
- (ly:add-context-mod
- mods
- (case (ly:music-property m 'name)
- ((PropertySet)
- (list 'assign
- (ly:music-property m 'symbol)
- (ly:music-property m 'value)))
- ((PropertyUnset)
- (list 'unset
- (ly:music-property m 'symbol)))
- ((OverrideProperty)
- (list 'push
- (ly:music-property m 'symbol)
- (ly:music-property m 'grob-property-path)
- (ly:music-property m 'grob-value)))
- ((RevertProperty)
- (list 'pop
- (ly:music-property m 'symbol)
- (ly:music-property m 'grob-property-path)))))
- (case (ly:music-property m 'name)
- ((SequentialMusic SimultaneousMusic)
- (fold loop mods (ly:music-property m 'elements)))
- ((ContextSpeccedMusic)
- ;; It is actually rather embarrassing that we have no
- ;; reliable way to check for the type of a context-def.
- ;; Nor have a Scheme way to add to a context-def.
- (let ((sym (ly:music-property m 'context-type)))
- (if (eq? sym 'Bottom)
- (set! sym bottom))
- (if (module-bound? (current-module) sym)
- (module-set!
- (current-module)
- sym
- #{ \context {
- $(module-ref (current-module) sym)
- $(loop (ly:music-property m 'element)
- (ly:make-context-mod))
- }
- #})
- (ly:warning music (_f "Cannot find context-def \\~a"
- sym)))))))
- mods))
+inherit-acceptability =
+#(define-void-function (to from)
+ (symbol? symbol?)
+ (_i "When used in an output definition, will modify all context
+definitions such that context @var{to} is accepted as a child by all
+contexts that also accept @var{from}.")
+ (let* ((module (current-module))
+ (cmod (ly:make-context-mod)))
+ (ly:add-context-mod cmod (list 'accepts to))
+ (if (output-module? module)
+ (module-map
+ (lambda (_sym var)
+ (if (variable-bound? var)
+ (let ((cdef (variable-ref var)))
+ (if (ly:context-def? cdef)
+ (let ((accepts (ly:context-def-lookup cdef 'accepts)))
+ (if (and (memq from accepts)
+ (not (memq to accepts)))
+ (variable-set! var
+ (ly:context-def-modify cdef cmod))))))))
+ module)
+ (ly:parser-error (_ "Not in an output definition")))))