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