]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/programming-interface.itely
b5058b609b70ac633aeeaffe7f9a5b1112b32cd4
[lilypond.git] / Documentation / user / programming-interface.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @node Interfaces for programmers
3 @chapter Interfaces for programmers
4
5
6
7 @menu
8 * Programmer interfaces for input ::  
9 * Markup programmer interface::  
10 * Contexts for programmers::    
11 @end menu
12
13 @node Programmer interfaces for input 
14 @section Programmer interfaces for input 
15
16 @menu
17 * Input variables and Scheme::  
18 * Internal music representation::  
19 * Extending music syntax::      
20 * Manipulating music expressions::  
21 * Displaying music expressions::  
22 * Using LilyPond syntax inside Scheme::  
23 @end menu
24
25 @node Input variables and Scheme
26 @subsection Input variables and Scheme
27
28
29 The input format supports the notion of variables: in the following
30 example, a music expression is assigned to a variable with the name
31 @code{traLaLa}.
32 @example
33 traLaLa = @{ c'4 d'4 @}
34 @end example
35
36 @noindent
37
38 There is also a form of scoping: in the following example, the
39 @code{\layout} block also contains a @code{traLaLa} variable, which is
40 independent of the outer @code{\traLaLa}.
41 @example
42 traLaLa = @{ c'4 d'4 @}
43 \layout @{ traLaLa = 1.0 @}
44 @end example
45 @c
46 In effect, each input file is a scope, and all @code{\header},
47 @code{\midi}, and @code{\layout} blocks are scopes nested inside that
48 toplevel scope.
49
50 Both variables and scoping are implemented in the GUILE module system.
51 An anonymous Scheme module is attached to each scope.  An assignment of
52 the form
53 @example
54 traLaLa = @{ c'4 d'4 @}
55 @end example
56
57 @noindent
58 is internally converted to a Scheme definition
59 @example
60 (define traLaLa @var{Scheme value of ``@code{... }''})
61 @end example
62
63 This means that input variables and Scheme variables may be freely
64 mixed.  In the following example, a music fragment is stored in the
65 variable @code{traLaLa}, and duplicated using Scheme.  The result is
66 imported in a @code{\score} block by means of a second variable
67 @code{twice}:
68 @example
69 traLaLa = @{ c'4 d'4 @}
70
71 #(define newLa (map ly:music-deep-copy
72   (list traLaLa traLaLa)))
73 #(define twice
74   (make-sequential-music newLa))
75
76 @{ \twice @}
77 @end example
78
79 In the above example, music expressions can be `exported' from the
80 input to the Scheme interpreter.  The opposite is also possible.  By
81 wrapping a Scheme value in the function @code{ly:export}, a Scheme
82 value is interpreted as if it were entered in LilyPond syntax.  Instead
83 of defining @code{\twice}, the example above could also have been
84 written as
85 @example
86 @dots{}
87 @{ #(ly:export (make-sequential-music (list newLa))) @}
88 @end example
89
90 @refbugs
91
92 Mixing Scheme and LilyPond identifiers is not possible with the
93 @code{--safe} option.
94
95 @node Internal music representation
96 @subsection Internal music representation
97
98 When a music expression is parsed, it is converted into a set of
99 Scheme music objects.  The defining property of a music object is that
100 it takes up time.  Time is a rational number that measures the length
101 of a piece of music, in whole notes.
102
103 A music object has three kinds of types:
104 @itemize @bullet
105 @item
106 music name: Each music expression has a name, for example, a note
107 leads to a @internalsref{NoteEvent}, and @code{\simultaneous} leads to
108 a @internalsref{SimultaneousMusic}.  A list of all expressions
109 available is in the internals manual, under
110 @internalsref{Music expressions}.
111
112 @item
113 `type' or interface: Each music name has several `types' or
114 interfaces, for example, a note is an @code{event}, but it is also a
115 @code{note-event}, a @code{rhythmic-event}, and a @code{melodic-event}.
116
117 All classes of music are listed in the internals manual, under
118 @internalsref{Music classes}.
119
120 @item
121 C++ object: Each music object is represented by a C++ object.  For
122 technical reasons, different music objects may be represented by
123 different C++ object types.  For example, a note is @code{Event}
124 object, while @code{\grace} creates a @code{Grace_music} object.
125
126 We expect that distinctions between different C++ types will disappear
127 in the future.
128 @end itemize
129
130 The actual information of a music expression is stored in properties.
131 For example, a @internalsref{NoteEvent} has @code{pitch} and
132 @code{duration} properties that store the pitch and duration of that
133 note.  A list of all properties available is in the internals manual,
134 under @internalsref{Music properties}.
135
136 A compound music expression is a music object that contains other
137 music objects in its properties.  A list of objects can be stored in
138 the @code{elements} property of a music object, or a single `child'
139 music object in the @code{element} object.  For example,
140 @internalsref{SequentialMusic} has its children in @code{elements},
141 and @internalsref{GraceMusic} has its single argument in
142 @code{element}.  The body of a repeat is stored in the @code{element}
143 property of @internalsref{RepeatedMusic}, and the alternatives in
144 @code{elements}.
145
146
147
148
149 @node Extending music syntax
150 @subsection Extending music syntax
151
152 @c TODO: rewrite example.
153 @c The use of FUNC as example  argument is rather confusing.
154
155 The syntax of composite music expressions, like @code{\repeat},
156 @code{\transpose}, and @code{\context} follows the general form of
157
158 @example
159 \@code{keyword} @var{non-music-arguments} @var{music-arguments}
160 @end example
161
162 Such syntax can also be defined as user code.  To do this, it is
163 necessary to create a @emph{music function}.  This is a specially marked
164 Scheme function.  For example, the music function @code{\applyMusic} applies
165 a user-defined function to a music expression.  Its syntax is
166
167 @example
168 \applyMusic #@var{func} @var{music}
169 @end example
170
171 A music function is created with @code{ly:make-music-function},
172
173 @example
174 (ly:make-music-function
175 @end example
176
177 @code{\applyMusic} takes a Scheme function and a Music expression as
178 arguments.  This is encoded in its parameter list,
179
180 @example
181 (list procedure? ly:music?)
182 @end example
183
184 The function itself takes another argument, an Input location
185 object.  That object is used to provide error messages with file names
186 and line numbers.  The definition is the second argument of
187 @code{ly:make-music-function}.  The body simply calls the function
188
189 @example
190 (lambda (where func music)
191  (func music))
192 @end example
193
194 The above Scheme code only defines the functionality.  The tag
195 @code{\applyMusic} is selected by defining
196
197 @example
198 applyMusic = #(ly:make-music-function
199                 (list procedure? ly:music?)
200                 (lambda (parser location func music)
201                   (func music)))
202 @end example
203
204 A @code{def-music-function} macro is introduced on top of
205 @code{ly:make-music-function} to ease the definition of music
206 functions:
207
208 @example
209 applyMusic = #(def-music-function (parser location func music)
210                 (procedure? ly:music?)
211                 (func music))
212 @end example
213
214 Examples of the use of @code{\applyMusic} are in the next section.
215
216 @seealso
217 @file{ly/@/music@/-functions@/-init@/.ly}.
218
219 @node Manipulating music expressions
220 @subsection Manipulating music expressions
221
222 Music objects and their properties can be accessed and manipulated
223 directly, through the @code{\applyMusic} mechanism.
224 The syntax for @code{\applyMusic} is
225 @example
226 \applyMusic #@var{func} @var{music}
227 @end example
228
229 @noindent
230 This means that the Scheme function @var{func} is called with
231 @var{music} as its argument.  The return value of @var{func} is the
232 result of the entire expression.  @var{func} may read and write music
233 properties using the functions @code{ly:music-property} and
234 @code{ly:music-set-property!}.
235
236 An example is a function that reverses the order of elements in
237 its argument,
238 @lilypond[quote,verbatim,raggedright]
239 #(define (rev-music-1 m)
240   (ly:music-set-property! m 'elements 
241     (reverse (ly:music-property m 'elements)))
242   m)
243
244 \applyMusic #rev-music-1 { c'4 d'4 } 
245 @end lilypond
246
247 The use of such a function is very limited.  The effect of this
248 function is void when applied to an argument that does not have
249 multiple children.  The following function application has no effect
250
251 @example
252 \applyMusic #rev-music-1 \grace @{ c4 d4 @}
253 @end example
254
255 @noindent
256 In this case, @code{\grace} is stored as @internalsref{GraceMusic}, which
257 has no @code{elements}, only a single @code{element}.  Every generally
258 applicable function for @code{\applyMusic} must -- like music expressions
259 themselves -- be recursive.
260
261 The following example is such a recursive function: It first extracts
262 the @code{elements} of an expression, reverses them and puts them
263 back.  Then it recurses, both on @code{elements} and @code{element}
264 children.
265 @example
266 #(define (reverse-music music)
267   (let* ((elements (ly:music-property music 'elements))
268          (child (ly:music-property music 'element))
269          (reversed (reverse elements)))
270
271     ; set children
272     (ly:music-set-property! music 'elements reversed)
273
274     ; recurse
275     (if (ly:music? child) (reverse-music child))
276     (map reverse-music reversed)
277
278     music))
279 @end example
280
281 A slightly more elaborate example is in
282 @inputfileref{input/@/test,reverse@/-music@/.ly}.
283
284 Some of the input syntax is also implemented as recursive music
285 functions.  For example, the syntax for polyphony
286 @example
287 <<a \\ b>>
288 @end example
289
290 @noindent
291 is actually implemented as a recursive function that replaces the
292 above by the internal equivalent of
293 @example
294 << \context Voice = "1" @{ \voiceOne a @}
295    \context Voice = "2" @{ \voiceTwo b @} >>
296 @end example
297
298 Other applications of @code{\applyMusic} are writing out repeats
299 automatically (@inputfileref{input/@/test,unfold@/-all@/-repeats@/.ly}),
300 saving keystrokes (@inputfileref{input/@/test,music@/-box@/.ly}) and
301 exporting LilyPond input to other formats
302 @c no @inputfileref{} here 
303 (eg. @file{input/@/no@/-notation/@/to@/-xml@/.ly}).
304
305 @seealso
306
307 @file{scm/@/music@/-functions@/.scm}, @file{scm/@/music@/-types@/.scm},
308 @inputfileref{input/@/test,add@/-staccato@/.ly},
309 @inputfileref{input/@/test,unfold@/-all@/-repeats@/.ly}, and
310 @inputfileref{input/@/test,music@/-box@/.ly}.
311
312
313 @node Displaying music expressions
314 @subsection Displaying music expressions
315
316 @cindex internal storage
317 @cindex @code{\displayMusic}
318 @cindex @code{\displayLilyMusic}
319
320 When writing a music function, it is often instructive to inspect how
321 a music expression is stored internally.  This can be done with the
322 music function @code{\displayMusic}.
323
324 @example
325 @{
326   \displayMusic @{ c'4\f @}
327 @}
328 @end example
329
330 Conversely, displaying a music expression in LilyPond notation can be
331 done using the music function @code{\displayLilyMusic}. For instance:
332
333 @example
334 @{
335   \displayLilyMusic \transpose c a, @{ c e g a bes @}
336 @}
337 @end example
338
339 will display:
340
341 @example
342 @{ a, cis e fis g @}
343 @end example
344
345 @node Using LilyPond syntax inside Scheme
346 @subsection Using LilyPond syntax inside Scheme
347
348 Creating music expressions in Scheme can be tedious, as they are
349 heavily nested and the resulting Scheme code is large.  For some
350 simple tasks, this can be avoided, using common LilyPond syntax inside
351 Scheme, with the dedicated @code{#@{ ... #@}} syntax.
352
353 The following two expressions give equivalent music expressions:
354 @example
355 mynotes = @{ \override Stem #'thickness = #4
356             @{ c'8 d' @} @}
357   
358 #(define mynotes #@{ \override Stem #'thickness = #4
359                     @{ c'8 d' @} #@})
360 @end example
361
362 The content of @code{#@{ ... #@}} is enclosed in an implicit @code{@{
363 ... @}} block, which is parsed.  The resulting music expression, a
364 @code{SequentialMusic} music object, is then returned and usable in Scheme.
365
366 Arbitrary Scheme forms, including variables, can be used in @code{#@{ ... #@}}
367 expressions with the @code{$} character (@code{$$} can be used to
368 produce a single @code{$} character).  This makes the creation of simple
369 functions straightforward.  In the following example, a function
370 setting the TextScript's padding is defined:
371
372 @lilypond[quote,verbatim,raggedright]
373 #(use-modules (ice-9 optargs))
374 #(define* (textpad padding #:optional once?)
375   (ly:export   ; this is necessary for using the expression
376                ; directly inside a block
377     (if once?
378         #{ \once \override TextScript #'padding = #$padding #}
379         #{ \override TextScript #'padding = #$padding #})))
380
381  {
382    c'^"1"
383    #(textpad 3.0 #t) % only once
384    c'^"2"
385    c'^"3"
386    #(textpad 5.0)
387    c'^"4"
388    c'^"5"
389  }
390 @end lilypond
391
392 Here, the variable @code{padding} is a number; music expression
393 variables may also be used in a similar fashion, as in the following
394 example:
395
396 @lilypond[quote,verbatim,raggedright]
397 #(define (with-padding padding)
398   (lambda (music)
399    #{ \override TextScript #'padding = #$padding
400       $music
401       \revert TextScript #'padding #}))
402
403 {
404   c'^"1"
405   \applyMusic #(with-padding 3) { c'^"2" c'^"3" }
406   c'^"4"
407 }
408 @end lilypond
409
410 The function created by @code{(with-padding 3)} adds @code{\override} and
411 @code{\revert} statements around the music given as an argument, and returns
412 this new expression.  Thus, this example is equivalent to:
413
414 @example
415 @{
416   c'^"1"
417   @{ \override TextScript #'padding = #3
418     @{ c'^"2" c'^"3"@}
419     \revert TextScript #'padding
420   @}
421   c'^"4"
422 @}
423 @end example
424
425 This function may also be defined as a music function:
426
427 @lilypond[quote,verbatim,raggedright]
428 withPadding =
429   #(def-music-function (parser location padding music) (number? ly:music?)
430     #{ \override TextScript #'padding = #$padding
431        $music 
432        \revert TextScript #'padding #})
433
434 {
435   c'^"1"
436   \withPadding #3 { c'^"2" c'^"3"}
437   c'^"4"
438 }
439 @end lilypond
440
441
442 @node Markup programmer interface
443 @section Markup programmer interface
444
445 @c Please rewrite the second sentence; I don't understand its meaning. AS
446
447 Markups are implemented as special Scheme functions.  When applied
448 with as arguments an output definition (@code{\layout} or
449 @code{\paper}), and a list of properties and other arguments, produce
450 a Stencil object.
451
452 @menu
453 * Markup construction in Scheme::  
454 * How markups work internally ::  
455 * Markup command definition::   
456 @end menu
457
458 @node Markup construction in Scheme
459 @subsection Markup construction in Scheme
460
461 @cindex defining markup commands 
462
463 The @code{markup} macro builds markup expressions in Scheme while
464 providing a LilyPond-like syntax.  For example,
465 @example
466 (markup #:column (#:line (#:bold #:italic "hello" #:raise 0.4 "world")
467                   #:bigger #:line ("foo" "bar" "baz")))
468 @end example
469
470 @noindent
471 is equivalent to:
472 @example
473 \markup \column @{ \line @{ \bold \italic "hello" \raise #0.4 "world" @}
474                   \bigger \line @{ foo bar baz @} @}
475 @end example
476
477 @noindent
478 This example exposes the main translation rules between regular
479 LilyPond markup syntax and Scheme markup syntax, which are summed up
480 is this table:
481
482 @quotation
483 @multitable @columnfractions .3 .3
484 @item @b{LilyPond} @tab @b{Scheme}
485 @item @code{\markup markup1 @}} @tab @code{(markup markup1)}
486 @item @code{\markup @{ markup1 markup2 ... @}} @tab 
487         @code{(markup markup1 markup2 ... )}
488 @item @code{\command} @tab @code{#:command}
489 @item @code{\variable} @tab @code{variable}
490 @item @code{\center-align @{ ... @}} @tab @code{#:center-align ( ... )}
491 @item @code{string} @tab @code{"string"}
492 @item @code{#scheme-arg} @tab @code{scheme-arg}
493 @end multitable
494 @end quotation
495
496 Besides, the whole scheme language is accessible inside the
497 @code{markup} macro: thus, one may use function calls inside
498 @code{markup} in order to manipulate character strings for
499 instance.  This proves useful when defining new markup commands (see
500 @ref{Markup command definition}).
501
502 @refbugs
503
504 One can not feed the @code{#:line} (resp @code{#:center},
505 @code{#:column}) command with a variable or the result of a function
506 call.  Example:
507
508 @lisp
509 (markup #:line (fun-that-returns-markups))
510 @end lisp
511
512 @noindent
513 is invalid.  One should use the @code{make-line-markup} (resp.,
514 @code{make-center-markup} or @code{make-column-markup}) function
515 instead,
516 @lisp
517 (markup (make-line-markup (fun-that-returns-markups)))
518 @end lisp
519
520 @node How markups work internally 
521 @subsection How markups work internally 
522
523 In a markup like
524
525 @example
526 \raise #0.5 "foo"
527 @end example
528
529 @noindent
530 @code{\raise} is actually represented by the @code{raise-markup}
531 function.  The markup expression is stored as
532
533 @example
534 (list raise-markup 0.5 (list simple-markup "foo"))
535 @end example
536
537 When the markup is converted to printable objects (Stencils), the
538 @code{raise-markup} function is called as
539
540 @example
541 (apply raise-markup
542        @var{\layout object}
543        @var{list of property alists}
544        0.5
545        @var{the "foo" markup})
546 @end example
547
548 The @code{raise-markup} function first creates the stencil for the
549 @code{foo} string, and then it raises that Stencil by 0.5 staff space.
550 This is a rather simple example; more complex examples are in the rest
551 of this section, and in @file{scm/@/define@/-markup@/-commands@/.scm}.
552
553 @node Markup command definition
554 @subsection Markup command definition
555
556 New markup commands can be defined
557 with the @code{def-markup-command} scheme macro.
558 @lisp
559 (def-markup-command (@var{command-name} @var{layout} @var{props} @var{arg1} @var{arg2} ...)
560             (@var{arg1-type?} @var{arg2-type?} ...)
561   ..command body..)
562 @end lisp
563
564 The arguments signify
565
566 @table @var
567 @item argi
568 @var{i}th command argument
569 @item argi-type?
570 a type predicate for the i@var{th} argument
571 @item layout
572 the `layout' definition
573 @item props
574 a list of alists, containing all active properties. 
575 @end table
576
577 As a simple example, we show how to add a @code{\smallcaps} command,
578 which selects @TeX{}'s small caps font.  Normally, we could select the
579 small caps font as follows:
580
581 @example
582 \markup @{ \override #'(font-shape . caps) Text-in-caps @}
583 @end example
584
585 This selects the caps font by setting the @code{font-shape} property to
586 @code{#'caps} for interpreting @code{Text-in-caps}.
587
588 To make the above available as @code{\smallcaps} command, we have to
589 define a function using @code{def-markup-command}.  The command should
590 take a single argument, of type markup.  Therefore, the start of the
591 definition should read
592 @example
593 (def-markup-command (smallcaps layout props argument) (markup?)
594 @end example
595
596 @noindent
597
598 What follows is the content of the command: we should interpret
599 the @code{argument} as a markup, i.e.,
600
601 @example
602 (interpret-markup layout @dots{} argument)
603 @end example
604
605 @noindent
606 This interpretation should add @code{'(font-shape . caps)} to the active
607 properties, so we substitute the following for the @dots{} in the
608 above example:
609
610 @example
611 (cons (list '(font-shape . caps) ) props)
612 @end example
613
614 @noindent
615 The variable @code{props} is a list of alists, and we prepend to it by
616 cons'ing a list with the extra setting.
617
618
619 Suppose that we are typesetting a recitative in an opera, and
620 we would like to define a command that will show character names in a
621 custom manner.  Names should be printed with small caps and translated a
622 bit to the left and top.  We will define a @code{\character} command
623 that takes into account the necessary translation, and uses the newly
624 defined @code{\smallcaps} command:
625
626 @example
627 #(def-markup-command (character layout props name) (string?)
628   "Print the character name in small caps, translated to the left and
629   top.  Syntax: \\character #\"name\""
630   (interpret-markup layout props 
631    (markup #:hspace 0 #:translate (cons -3 1) #:smallcaps name)))
632 @end example
633
634 There is one complication that needs explanation: texts above and below
635 the staff are moved vertically to be at a certain distance (the
636 @code{padding} property) from the staff and the notes.  To make sure
637 that this mechanism does not annihilate the vertical effect of our
638 @code{#:translate}, we add an empty string (@code{#:hspace 0}) before the
639 translated text.  Now the @code{#:hspace 0} will be put above the notes, and the
640 @code{name} is moved in relation to that empty string.  The net effect is
641 that the text is moved to the upper left.
642
643 The final result is as follows:
644 @example
645 @{
646   c''^\markup \character #"Cleopatra"
647   e'^\markup \character #"Giulio Cesare"
648 @}
649 @end example
650
651 @lilypond[quote,raggedright]
652 #(def-markup-command (smallcaps layout props str) (string?)
653   "Print the string argument in small caps.  Syntax: \\smallcaps #\"string\""
654   (interpret-markup layout props
655    (make-line-markup
656     (map (lambda (s)
657           (if (= (string-length s) 0)
658               s
659               (markup #:large (string-upcase (substring s 0 1))
660                       #:translate (cons -0.6 0)
661                       #:tiny (string-upcase (substring s 1)))))
662          (string-split str #\Space)))))
663
664 #(def-markup-command (character layout props name) (string?)
665   "Print the character name in small caps, translated to the left and
666   top.  Syntax: \\character #\"name\""
667   (interpret-markup layout props 
668    (markup #:hspace 0 #:translate (cons -3 1) #:smallcaps name)))
669
670 {
671   c''^\markup \character #"Cleopatra" c'' c'' c''
672   e'^\markup \character #"Giulio Cesare" e' e' e'
673 }
674 @end lilypond
675
676 We have used the @code{caps} font shape, but suppose that our font
677 does not have a small-caps variant.  In that case we have to fake
678 the small caps font by setting a string in upcase with the first
679 letter a little larger:
680
681 @example
682 #(def-markup-command (smallcaps layout props str) (string?)
683   "Print the string argument in small caps."
684   (interpret-markup layout props
685    (make-line-markup
686     (map (lambda (s)
687           (if (= (string-length s) 0)
688               s
689               (markup #:large (string-upcase (substring s 0 1))
690                       #:translate (cons -0.6 0)
691                       #:tiny (string-upcase (substring s 1)))))
692          (string-split str #\Space)))))
693 @end example
694
695 The @code{smallcaps} command first splits its string argument into
696 tokens separated by spaces (@code{(string-split str #\Space)}); for
697 each token, a markup is built with the first letter made large and
698 upcased (@code{#:large (string-upcase (substring s 0 1))}), and a
699 second markup built with the following letters made tiny and upcased
700 (@code{#:tiny (string-upcase (substring s 1))}).  As LilyPond
701 introduces a space between markups on a line, the second markup is
702 translated to the left (@code{#:translate (cons -0.6 0) ...}).  Then,
703 the markups built for each token are put in a line by
704 @code{(make-line-markup ...)}.  Finally, the resulting markup is passed
705 to the @code{interpret-markup} function, with the @code{layout} and
706 @code{props} arguments.
707
708
709
710 @node Contexts for programmers
711 @section Contexts for programmers
712
713
714 @menu
715 * Context evaluation::          
716 * Running a function on all layout objects::  
717 @end menu
718
719 @node Context evaluation
720 @subsection Context evaluation
721
722 @cindex calling code during interpreting
723 @cindex @code{\applyContext}
724
725 Contexts can be modified during interpretation with Scheme code.  The
726 syntax for this is
727 @example
728 \applyContext @var{function}
729 @end example
730
731 @var{function} should be a Scheme function taking a single argument,
732 being the context to apply it to.  The following code will print the
733 current bar number on the standard output during the compile:
734
735 @example
736 \applyContext
737   #(lambda (x)
738     (format #t "\nWe were called in barnumber ~a.\n"
739      (ly:context-property x 'currentBarNumber)))
740 @end example
741
742
743
744 @node Running a function on all layout objects
745 @subsection Running a function on all layout objects
746
747
748 @cindex calling code on layout objects
749 @cindex @code{\applyoutput}
750
751
752 The most versatile way of tuning an object is @code{\applyoutput}.  Its
753 syntax is
754 @example
755 \applyoutput @var{proc}
756 @end example
757
758 @noindent
759 where @var{proc} is a Scheme function, taking three arguments.
760
761 When interpreted, the function @var{proc} is called for every layout
762 object found in the context, with the following arguments:
763 @itemize @bullet
764 @item the layout object itself,
765 @item the context where the layout object was created, and
766 @item the context where @code{\applyoutput} is processed.
767 @end itemize
768
769
770 In addition, the cause of the layout object, i.e., the music
771 expression or object that was responsible for creating it, is in the
772 object property @code{cause}.  For example, for a note head, this is a
773 @internalsref{NoteHead} event, and for a @internalsref{Stem} object,
774 this is a @internalsref{NoteHead} object.
775
776 Here is a function to use for @code{\applyoutput}; it blanks
777 note-heads on the center-line:
778
779 @example
780 (define (blanker grob grob-origin context)
781  (if (and (memq (ly:grob-property grob 'interfaces)
782                 note-head-interface)
783           (eq? (ly:grob-property grob 'staff-position) 0))
784      (set! (ly:grob-property grob 'transparent) #t)))
785 @end example
786