Advanced tweaks with Scheme - GNU LilyPond
Description: GNU LilyPond

Previous: Default files, Up: Tweaking output

### 5.4 Advanced tweaks with Scheme

We have seen how LilyPond output can be heavily modified using commands like `\override TextScript #'extra-offset = ( 1 . -1)`. But we have even more power if we use Scheme. For a full explantion of this, see the Scheme tutorial and Interfaces for programmers.

We can use Scheme to simply `\override` commands,

>          padText = #(define-music-function (parser location padding) (number?)
>          #{
>            \once \override TextScript #'padding = #$padding
>          #})

>          \relative c''' {
>            c4^"piu mosso" b a b
>            \padText #1.8
>            c4^"piu mosso" d e f
>            \padText #2.6
>            c4^"piu mosso" fis a g
>          }

We can use it to create new commands,

>          tempoMark = #(define-music-function
>            (parser location marktext padding) (string? number?)
>          #{
>            \once \override Score . RehearsalMark #'padding = $padding
>            \once \override Score . RehearsalMark #'no-spacing-rods = ##t
>            \mark \markup { \bold $marktext }
>          #})

>          \relative c'' {
>          c2 e
>          \tempoMark #"Allegro" #3.0
>          g c
>          }

Even music expressions can be passed in.

>          pattern = #(define-music-function (parser location x y) (ly:music? ly:music?)
>          #{
>            $x e8 a b $y b a e
>          #})

>          \relative c''{
>            \pattern c8 c8\f
>            \pattern {d16 dis} { ais16-> b\p }
>          }

This page is for LilyPond-2.8.8 (stable-branch).

Other languages: English.
Using automatic language selection.