1@c -*- coding: utf-8; mode: texinfo; -*- 2 3@ignore 4 Translation of GIT committish: FILL-IN-HEAD-COMMITTISH 5 6 When revising a translation, copy the HEAD committish of the 7 version that you are working on. For details, see the Contributors' 8 Guide, node Updating translation committishes.. 9@end ignore 10 11@c \version "2.21.0" 12 13@node Changing defaults 14@chapter Changing defaults 15 16The purpose of LilyPond's design is to provide the finest quality 17output by default. Nevertheless, it may happen that you need to 18change this default layout. The layout is controlled through a large 19number of @q{knobs and switches} collectively called @q{properties}. 20A tutorial introduction to accessing and modifying these properties 21can be found in the Learning Manual, see @rlearning{Tweaking output}. 22This should be read first. This chapter covers similar ground, but 23in a style more appropriate to a reference manual. 24 25@cindex Internals Reference 26 27The definitive description of the controls available for tuning can 28be found in a separate document: @rinternalsnamed{Top,the Internals 29Reference}. That manual lists all the variables, functions and 30options available in LilyPond. It is written as a HTML document, 31which is available 32@c leave the @uref as one long line. 33@uref{http://@/lilypond@/.org/@/doc/@/stable/@/Documentation/@/internals/,on@/-line}, 34and is also included with the LilyPond documentation package. 35 36Internally, LilyPond uses Scheme (a LISP dialect) to provide 37infrastructure. Overriding layout decisions in effect accesses the 38program internals, which requires Scheme input. Scheme elements are 39introduced in a @file{.ly} file with the hash 40mark@tie{}@code{#}.@footnote{@rextend{Scheme tutorial}, contains a 41short tutorial on entering numbers, lists, strings, and symbols in 42Scheme.} 43 44 45@menu 46* Interpretation contexts:: 47* Explaining the Internals Reference:: 48* Modifying properties:: 49* Useful concepts and properties:: 50* Advanced tweaks:: 51* Using music functions:: 52@end menu 53 54 55@node Interpretation contexts 56@section Interpretation contexts 57 58This section describes what contexts are, and how to modify them. 59 60@menu 61* Contexts explained:: 62* Creating and referencing contexts:: 63* Keeping contexts alive:: 64* Modifying context plug-ins:: 65* Changing context default settings:: 66* Defining new contexts:: 67* Context layout order:: 68@end menu 69 70@morerefs 71Learning Manual: 72@rlearning{Contexts and engravers}. 73 74Installed Files: 75@file{ly/engraver-init.ly}, 76@file{ly/performer-init.ly}. 77 78Snippets: 79@rlsr{Contexts and engravers}. 80 81Internals Reference: 82@rinternals{Contexts}, 83@rinternals{Engravers and Performers}. 84 85 86@node Contexts explained 87@subsection Contexts explained 88 89@ignore 90@c TODO Rethink and rewrite 91 92>> > > - list of contexts: my *danger unmaintainable* 93>> > > alarm just went off. I'm 94I knew it would... And leaving out some of them is perfectly fine 95with me. I do think that a list like this, with the main contexts and a 96brief description of what they do (perhaps also with a note about what 97default behavior is associated with each of them, but this may be 98unmanageable), should be there, and then we could simply list the 99remaining ones without further explanation and with links to the IR. 100@end ignore 101 102@c TODO Improve layout, order and consistency of wording -td 103 104@c TODO Add introduction which explains contexts in generality -td 105 106@c TODO Describe propagation of property values -td 107 108Contexts are arranged hierarchically: 109 110@menu 111* Output definitions - blueprints for contexts:: 112* Score - the master of all contexts:: 113* Top-level contexts - staff containers:: 114* Intermediate-level contexts - staves:: 115* Bottom-level contexts - voices:: 116@end menu 117 118@node Output definitions - blueprints for contexts 119@unnumberedsubsubsec Output definitions - blueprints for contexts 120 121This section explains the relevance of output definitions when 122working with contexts. Examples for actual output definitions are 123given later (see @ref{Changing all contexts of the same type}). 124 125@cindex output definition 126@funindex \layout 127While music written in a file may refer to context types and 128names, contexts are created only when the music is actually being 129interpreted. LilyPond interprets music under control of an 130@q{output definition} and may do so for several different output 131definitions, resulting in different output. The output definition 132relevant for printing music is specified using @code{\layout}. 133 134@funindex \midi 135A much simpler output definition used for producing Midi output is 136specified using @code{\midi}. Several other output definitions 137are used by LilyPond internally, like when using the part combiner 138(@ref{Automatic part combining}) or creating music quotes 139(@ref{Quoting other voices}). 140 141Output definitions define the relation between contexts as well as 142their respective default settings. While most changes will 143usually be made inside of a @code{\layout} block, Midi-related 144settings will only have an effect when made within a @code{\midi} 145block. 146 147@funindex autoBeaming 148Some settings affect several outputs: for example, if 149@code{autoBeaming} is turned off in some context, beams count as 150melismata for the purpose of matching music to lyrics as described 151in @ref{Automatic syllable durations}. This matching is done both 152for printed output as well as for Midi. If changes made to 153@code{autoBeaming} within a context definition of a @code{\layout} 154block are not repeated in the corresponding @code{\midi} block, 155lyrics and music will get out of sync in Midi. 156 157@morerefs 158Installed Files: 159@file{ly/engraver-init.ly}. 160@file{ly/performer-init.ly}. 161 162@node Score - the master of all contexts 163@unnumberedsubsubsec Score - the master of all contexts 164 165This is the top level notation context. No other context can 166contain a Score context. By default the Score context handles 167the administration of time signatures and makes sure that items 168such as clefs, time signatures, and key-signatures are aligned 169across staves. 170 171A Score context is instantiated implicitly when a 172@code{\score @{@dots{}@}} block is processed. 173 174@node Top-level contexts - staff containers 175@unnumberedsubsubsec Top-level contexts - staff containers 176 177@strong{@emph{StaffGroup}} 178 179Groups staves while adding a bracket on the left side, grouping 180the staves together. The bar lines of the contained staves are 181connected vertically. @code{StaffGroup} only consists of a collection 182of staves, with a bracket in front and spanning bar lines. 183 184@strong{@emph{ChoirStaff}} 185 186Identical to @code{StaffGroup} except that the bar lines of the 187contained staves are not connected vertically. 188 189@strong{@emph{GrandStaff}} 190 191A group of staves, with a brace on the left side, grouping the 192staves together. The bar lines of the contained staves are 193connected vertically. 194 195@strong{@emph{PianoStaff}} 196 197Just like @code{GrandStaff}, but with support for instrument names 198to the left of each system. 199 200@node Intermediate-level contexts - staves 201@unnumberedsubsubsec Intermediate-level contexts - staves 202 203@strong{@emph{Staff}} 204 205Handles clefs, bar lines, keys, accidentals. It can contain 206@code{Voice} contexts. 207 208@strong{@emph{RhythmicStaff}} 209 210Like @code{Staff} but for printing rhythms. Pitches are ignored 211when engraving; the notes are printed on one line. The MIDI 212rendition retains pitches unchanged. 213 214@strong{@emph{TabStaff}} 215 216Context for generating tablature. By default lays the music 217expression out as a guitar tablature, printed on six lines. 218 219@strong{@emph{DrumStaff}} 220 221Handles typesetting for percussion. Can contain @code{DrumVoice}. 222 223@strong{@emph{VaticanaStaff}} 224 225Same as @code{Staff}, except that it is designed for typesetting 226a piece in gregorian style. 227 228@strong{@emph{MensuralStaff}} 229 230Same as @code{Staff}, except that it is designed for typesetting 231a piece in mensural style. 232 233@node Bottom-level contexts - voices 234@unnumberedsubsubsec Bottom-level contexts - voices 235 236Voice-level contexts initialise certain properties and start 237appropriate engravers. A bottom-level context is one without 238@code{defaultchild}. While it is possible to let it 239accept/@/contain subcontexts, they can only be created and entered 240explicitly. 241 242@strong{@emph{Voice}} 243 244Corresponds to a voice on a staff. This context handles the 245conversion of dynamic signs, stems, beams, super- and sub-scripts, 246slurs, ties, and rests. You have to instantiate this explicitly 247if you require multiple voices on the same staff. 248 249@strong{@emph{VaticanaVoice}} 250 251Same as @code{Voice}, except that it is designed for typesetting 252a piece in gregorian style. 253 254@strong{@emph{MensuralVoice}} 255 256Same as @code{Voice}, with modifications for typesetting a piece in 257mensural style. 258 259@strong{@emph{Lyrics}} 260 261Corresponds to a voice with lyrics. Handles the printing of a 262single line of lyrics. 263 264@strong{@emph{DrumVoice}} 265 266The voice context used in a percussion staff. 267 268@strong{@emph{FiguredBass}} 269 270The context in which @code{BassFigure} objects are created from 271input entered in @code{\figuremode} mode. 272 273@strong{@emph{TabVoice}} 274 275The voice context used within a @code{TabStaff} context. Usually 276left to be created implicitly. 277 278@strong{@emph{CueVoice}} 279 280A voice context used to render notes of a reduced size, intended 281primarily for adding cue notes to a staff, see @ref{Formatting 282cue notes}. Usually left to be created implicitly. 283 284@strong{@emph{ChordNames}} 285 286Typesets chord names. 287 288@ignore 289TODO 290 291Then the following, which I don't know what to do with: 292 293 * GregorianTranscriptionVoice 294 * GregorianTranscriptionStaff 295 296 * FretBoards 297 Engraves fretboards from chords. Not easy... Not 298documented. 299 There is now some documentation on FretBoards in the NR, under 300 instrument-specific notation -- cds. 301 302 * NoteNames 303 304 * Global 305 Hard coded entry point for LilyPond. Cannot be tuned. 306 * Devnull 307 Silently discards all musical information given to this 308context. 309 310@end ignore 311 312@node Creating and referencing contexts 313@subsection Creating and referencing contexts 314 315@funindex \new 316@funindex \context 317@cindex new context 318@cindex referencing context 319@cindex context, creating and referencing 320 321LilyPond will create lower-level contexts automatically if a music 322expression is encountered before a suitable context exists, but this 323is usually successful only for simple scores or music fragments like 324the ones in the documentation. For more complex scores it is 325advisable to specify all contexts explicitly with either the 326@code{\new} or @code{\context} command. The syntax of 327these two commands is very similar: 328 329@example 330[\new | \context] @var{Context} [ = @var{name}] [@var{music-expression}] 331@end example 332 333@noindent 334where either @code{\new} or @code{\context} may be specified. 335@var{Context} is the type of context which is to be created, 336@var{name} is an optional name to be given to the particular context 337being created and @var{music-expression} is a single music expression 338that is to be interpreted by the engravers and performers in this 339context. 340 341The @code{\new} prefix without a name is commonly used to create 342scores with many staves: 343 344@lilypond[quote,verbatim] 345<< 346 \new Staff \relative { 347 % leave the Voice context to be created implicitly 348 c''4 c 349 } 350 \new Staff \relative { 351 d''4 d 352 } 353>> 354@end lilypond 355 356@noindent 357and to place several voices into one staff: 358 359@lilypond[quote,verbatim] 360\new Staff << 361 \new Voice \relative { 362 \voiceOne 363 c''8 c c4 c c 364 } 365 \new Voice \relative { 366 \voiceTwo 367 g'4 g g g 368 } 369>> 370@end lilypond 371 372@noindent 373@code{\new} should always be used to specify unnamed contexts. 374 375The difference between @code{\new} and @code{\context} is in the 376action taken: 377 378@itemize 379@item 380@code{\new} with or without a name will always create a fresh, 381distinct, context, even if one with the same name already exists: 382 383@lilypond[quote,verbatim] 384\new Staff << 385 \new Voice = "A" \relative { 386 \voiceOne 387 c''8 c c4 c c 388 } 389 \new Voice = "A" \relative { 390 \voiceTwo 391 g'4 g g g 392 } 393>> 394@end lilypond 395 396@item 397@code{\context} with a name specified will create a distinct context 398only if a context of the same type with the same name in the same 399context hierarchy does not already exist. Otherwise it will be taken 400as a reference to that previously created context, and its music 401expression will be passed to that context for interpretation. 402 403Named contexts may be useful in special cases such as 404lyrics or figured bass, as demonstrated in 405@ref{Working with lyrics and variables} and 406@rlearning{Vocal ensembles templates} for the former and 407@ref{Displaying figured bass} for the latter. 408More generally, one application of named contexts is in separating the 409score layout from the musical content. Either of these two forms is valid: 410 411@lilypond[quote,verbatim] 412\score { 413 << 414 % score layout 415 \new Staff << 416 \new Voice = "one" { 417 \voiceOne 418 } 419 \new Voice = "two" { 420 \voiceTwo 421 } 422 >> 423 424 % musical content 425 \context Voice = "one" { 426 \relative { 427 c''4 c c c 428 } 429 } 430 \context Voice = "two" { 431 \relative { 432 g'8 g g4 g g 433 } 434 } 435 >> 436} 437@end lilypond 438 439@lilypond[quote,verbatim] 440\score { 441 << 442 % score layout 443 \new Staff << 444 \context Voice = "one" { 445 \voiceOne 446 } 447 \context Voice = "two" { 448 \voiceTwo 449 } 450 >> 451 452 % musical content 453 \context Voice = "one" { 454 \relative { 455 c''4 c c c 456 } 457 } 458 \context Voice = "two" { 459 \relative { 460 g'8 g g4 g g 461 } 462 } 463 >> 464} 465@end lilypond 466 467@noindent 468Alternatively, variables may be employed to similar effect. See 469@rlearning{Organizing pieces with variables}. 470 471@item 472@funindex \applyContext 473@code{\context} with no name will match the first of any previously 474created contexts of the same type in the same context heirarchy, 475even one that has been given a name, and its music expression will be 476passed to that context for interpretation. This form is rarely 477useful. However, @code{\context} with no name and no music expression 478is used to set the context in which a Scheme procedure specified with 479@code{\applyContext} is executed: 480 481@example 482\new Staff \relative @{ 483 c'1 484 \context Timing 485 \applyContext #(lambda (ctx) 486 (newline) 487 (display (ly:context-current-moment ctx))) 488 c1 489@} 490@end example 491 492@end itemize 493 494A context must be named if it is to be referenced later, for example 495when lyrics are associated with music: 496 497@example 498\new Voice = "tenor" @var{music} 499@dots{} 500\new Lyrics \lyricsto "tenor" @var{lyrics} 501@end example 502 503@noindent 504For details of associating lyrics with music see 505@ref{Automatic syllable durations}. 506 507The properties of all contexts of a particular type can be modified 508in a @code{\layout} block (with a different syntax), see 509@ref{Changing all contexts of the same type}. This construct also 510provides a means of keeping layout instructions separate from the 511musical content. If a single context is to be modified, a @code{\with} 512block must be used, see @ref{Changing just one specific context}. 513 514@morerefs 515Learning Manual: 516@rlearning{Organizing pieces with variables}. 517 518Notation Reference: 519@ref{Changing just one specific context}, 520@ref{Automatic syllable durations}. 521 522 523@node Keeping contexts alive 524@subsection Keeping contexts alive 525 526@cindex context, keeping alive 527@cindex context, lifetime 528 529Contexts are usually terminated at the first musical moment in 530which they have nothing to do. So @code{Voice} contexts die as 531soon as they contain no events, @code{Staff} contexts die as soon 532as all the @code{Voice} contexts within them contain no events, etc. 533This can cause difficulties if earlier contexts which have died 534have to be referenced, for example, when changing staves with 535@code{\change} commands, associating lyrics with a voice with 536@code{\lyricsto} commands, or when adding further musical events to 537an earlier context. 538 539There is an exception to this general rule: inside of an 540@code{@{@dots{}@}} construct (sequential music), the construct's 541notion of the ``current context'' will descend whenever an element 542of the sequence ends in a subcontext of the previous current 543context. This avoids spurious creation of implicit contexts in a 544number of situations but means that the first context descended 545into will be kept alive until the end of the expression. 546 547In contrast, the contexts of a @code{<<@dots{}>>} construct's 548(simultaneous music) expression are not carried forth, so 549enclosing a context creating command in an extra pair of 550@code{<<@dots{}>>} will keep the context from persisting through 551all of the enclosing @code{@{@dots{}@}} sequence. 552 553Any context can be kept alive by ensuring it has something to do at 554every musical moment. @code{Staff} contexts are kept alive by 555ensuring one of their voices is kept alive. One way of doing this 556is to add spacer rests to a voice in parallel with the real music. 557These need to be added to every @code{Voice} context which needs to 558be kept alive. If several voices are to be used sporadically it is 559safest to keep them all alive rather than attempting to rely on the 560exceptions mentioned above. 561 562In the following example, both voice A and voice B are kept alive 563in this way for the duration of the piece: 564 565@lilypond[quote,verbatim] 566musicA = \relative { d''4 d d d } 567musicB = \relative { g'4 g g g } 568keepVoicesAlive = { 569 << 570 \new Voice = "A" { s1*5 } % Keep Voice "A" alive for 5 bars 571 \new Voice = "B" { s1*5 } % Keep Voice "B" alive for 5 bars 572 >> 573} 574 575music = { 576 \context Voice = "A" { 577 \voiceOneStyle 578 \musicA 579 } 580 \context Voice = "B" { 581 \voiceTwoStyle 582 \musicB 583 } 584 \context Voice = "A" { \musicA } 585 \context Voice = "B" { \musicB } 586 \context Voice = "A" { \musicA } 587} 588 589\score { 590 \new Staff << 591 \keepVoicesAlive 592 \music 593 >> 594} 595@end lilypond 596 597@cindex lyrics, aligning with sporadic melody 598 599The following example shows how a sporadic melody line with lyrics 600might be written using this approach. In a real situation the 601melody and accompaniment would consist of several different 602sections, of course. 603 604@lilypond[quote,verbatim] 605melody = \relative { a'4 a a a } 606accompaniment = \relative { d'4 d d d } 607words = \lyricmode { These words fol -- low the mel -- o -- dy } 608\score { 609 << 610 \new Staff = "music" { 611 << 612 \new Voice = "melody" { 613 \voiceOne 614 s1*4 % Keep Voice "melody" alive for 4 bars 615 } 616 { 617 \new Voice = "accompaniment" { 618 \voiceTwo 619 \accompaniment 620 } 621 << 622 \context Voice = "melody" { \melody } 623 \context Voice = "accompaniment" { \accompaniment } 624 >> 625 \context Voice = "accompaniment" { \accompaniment } 626 << 627 \context Voice = "melody" { \melody } 628 \context Voice = "accompaniment" { \accompaniment } 629 >> 630 } 631 >> 632 } 633 \new Lyrics \with { alignAboveContext = "music" } 634 \lyricsto "melody" { \words } 635 >> 636} 637@end lilypond 638 639An alternative way, which may be better in many circumstances, is 640to keep the melody line alive by simply including spacer notes to 641line it up correctly with the accompaniment: 642 643@lilypond[quote,verbatim] 644melody = \relative { 645 s1 % skip a bar 646 a'4 a a a 647 s1 % skip a bar 648 a4 a a a 649} 650accompaniment = \relative { 651 d'4 d d d 652 d4 d d d 653 d4 d d d 654 d4 d d d 655} 656words = \lyricmode { These words fol -- low the mel -- o -- dy } 657 658\score { 659 << 660 \new Staff = "music" { 661 << 662 \new Voice = "melody" { 663 \voiceOne 664 \melody 665 } 666 \new Voice = "accompaniment" { 667 \voiceTwo 668 \accompaniment 669 } 670 >> 671 } 672 \new Lyrics \with { alignAboveContext = "music" } 673 \lyricsto "melody" { \words } 674 >> 675} 676@end lilypond 677 678 679@node Modifying context plug-ins 680@subsection Modifying context plug-ins 681 682@c TODO Should this be Modifying engravers or Modifying contexts? 683 684Notation contexts (like @code{Score} and @code{Staff}) not only store 685properties, they also contain plug-ins called @q{engravers} that create 686notation elements. For example, the @code{Voice} context contains a 687@code{Note_heads_engraver} and the @code{Staff} context contains a 688@code{Key_engraver}. 689 690For a full a description of each plug-in, see 691@ifhtml 692@rinternals{Engravers and Performers}. 693@end ifhtml 694@ifnothtml 695Internals Reference @expansion{} Translation @expansion{} Engravers. 696@end ifnothtml 697Every context described in 698@ifhtml 699@rinternals{Contexts} 700@end ifhtml 701@ifnothtml 702Internals Reference @expansion{} Translation @expansion{} Context. 703@end ifnothtml 704lists the engravers used for that context. 705 706 707It can be useful to shuffle around these plug-ins. This is done by 708starting a new context with @code{\new} or @code{\context}, and 709modifying it, 710 711@funindex \with 712@funindex \consists 713@funindex \remove 714 715@example 716\new @var{context} \with @{ 717 \consists @dots{} 718 \consists @dots{} 719 \remove @dots{} 720 \remove @dots{} 721 @emph{etc.} 722@} 723@{ 724 @emph{@dots{}music@dots{}} 725@} 726@end example 727 728@noindent 729where each @dots{} should be the name of an engraver. Here is a simple 730example which removes @code{Time_signature_engraver} and 731@code{Clef_engraver} from a @code{Staff} context, 732 733@lilypond[quote,verbatim] 734<< 735 \new Staff \relative { 736 f'2 g 737 } 738 \new Staff \with { 739 \remove "Time_signature_engraver" 740 \remove "Clef_engraver" 741 } \relative { 742 f'2 g2 743 } 744>> 745@end lilypond 746 747In the second staff there are no time signature or clef symbols. This 748is a rather crude method of making objects disappear since it will affect 749the entire staff. This method also influences the spacing, which may or 750may not be desirable. More sophisticated methods of blanking objects 751are shown in @rlearning{Visibility and color of objects}. 752 753The next example shows a practical application. Bar lines and time 754signatures are normally synchronized across the score. This is done 755by the @code{Timing_translator} and @code{Default_bar_line_engraver}. 756This plug-in keeps an administration of time signature, location 757within the measure, etc. By moving these engraver from @code{Score} to 758@code{Staff} context, we can have a score where each staff has its own 759time signature. 760 761@cindex polymetric score 762@cindex time signature, multiple 763 764@lilypond[quote,verbatim] 765\score { 766 << 767 \new Staff \with { 768 \consists "Timing_translator" 769 \consists "Default_bar_line_engraver" 770 } 771 \relative { 772 \time 3/4 773 c''4 c c c c c 774 } 775 \new Staff \with { 776 \consists "Timing_translator" 777 \consists "Default_bar_line_engraver" 778 } 779 \relative { 780 \time 2/4 781 c''4 c c c c c 782 } 783>> 784\layout { 785 \context { 786 \Score 787 \remove "Timing_translator" 788 \remove "Default_bar_line_engraver" 789 } 790 } 791} 792@end lilypond 793 794@knownissues 795 796The order in which the engravers are specified is the order in 797which they are called to carry out their processing. Usually the 798order in which the engravers are specified does not matter, but in 799a few special cases the order is important, for example where one 800engraver writes a property and another reads it, or where one 801engraver creates a grob and another must process it. 802 803The following orderings are important: 804 805@itemize 806@item 807the @code{Bar_engraver} must normally be first, 808 809@item 810the @code{New_fingering_engraver} must come before the 811@code{Script_column_engraver}, 812 813@item 814the @code{Timing_translator} must come before the 815@code{Bar_number_engraver}. 816 817@end itemize 818 819@morerefs 820Installed Files: 821@file{ly/engraver-init.ly}. 822 823 824@node Changing context default settings 825@subsection Changing context default settings 826 827@cindex default context property, changing 828@cindex context property, changing default 829 830Context and grob properties can be changed with @code{\set} 831and @code{\override} commands, as described in 832@ref{Modifying properties}. These commands create music events, 833making the changes take effect at the point in time the music 834is being processed. 835 836In contrast, this section explains how to change the @emph{default} 837values of context and grob properties at the time the context is 838created. There are two ways of doing this. One modifies the default 839values in all contexts of a particular type, the other modifies the 840default values in just one particular instance of a context. 841 842@menu 843* Changing all contexts of the same type:: 844* Changing just one specific context:: 845* Order of precedence:: 846@end menu 847 848@node Changing all contexts of the same type 849@unnumberedsubsubsec Changing all contexts of the same type 850 851@cindex @code{\context} in @code{\layout} block 852@funindex \context 853@funindex \layout 854 855The default context settings which are to be used for typesetting in 856@code{Score}, @code{Staff}, @code{Voice} and other contexts may be 857specified in a @code{\context} block within any @code{\layout} 858block. 859 860Settings for Midi output as opposed to typesetting will have to be 861separately specified in @code{\midi} blocks (see @ref{Output 862definitions - blueprints for contexts}). 863 864The @code{\layout} block should be placed within the @code{\score} 865block to which it is to apply, after the music. 866 867@example 868\layout @{ 869 \context @{ 870 \Voice 871 [context settings for all Voice contexts] 872 @} 873 \context @{ 874 \Staff 875 [context settings for all Staff contexts] 876 @} 877@} 878@end example 879 880The following types of settings may be specified: 881 882@itemize 883@item 884An @code{\override} command, but with the context name omitted 885 886@lilypond[quote,verbatim] 887\score { 888 \relative { 889 a'4^"Thicker stems" a a a 890 a4 a a\ff a 891 } 892 \layout { 893 \context { 894 \Staff 895 \override Stem.thickness = #4.0 896 } 897 } 898} 899@end lilypond 900 901@item 902Directly setting a context property 903 904@lilypond[quote,verbatim] 905\score { 906 \relative { 907 a'4^"Smaller font" a a a 908 a4 a a\ff a 909 } 910 \layout { 911 \context { 912 \Staff 913 fontSize = #-4 914 } 915 } 916} 917@end lilypond 918 919@item 920A predefined command such as @code{\dynamicUp} or a music 921expression like @code{\accidentalStyle dodecaphonic} 922 923@lilypond[quote,verbatim] 924\score { 925 \relative { 926 a'4^"Dynamics above" a a a 927 a4 a a\ff a 928 } 929 \layout { 930 \context { 931 \Voice 932 \dynamicUp 933 } 934 \context { 935 \Staff 936 \accidentalStyle dodecaphonic 937 } 938 } 939} 940@end lilypond 941 942@item 943A user-defined variable containing a @code{\with} block; for details 944of the @code{\with} block see 945@ref{Changing just one specific context}. 946 947@lilypond[quote,verbatim] 948StaffDefaults = \with { 949 fontSize = #-4 950} 951 952\score { 953 \new Staff { 954 \relative { 955 a'4^"Smaller font" a a a 956 a4 a a a 957 } 958 } 959 \layout { 960 \context { 961 \Staff 962 \StaffDefaults 963 } 964 } 965} 966@end lilypond 967 968@end itemize 969 970Property-setting commands can be placed in a @code{\layout} block 971without being enclosed in a @code{\context} block. Such settings 972are equivalent to including the same property-setting commands at 973the start of every context of the type specified. If no context 974is specified @emph{every} bottom-level context is affected, see 975@ref{Bottom-level contexts - voices}. The syntax of a 976property-setting command in a @code{\layout} block is the same as 977the same command written in the music stream. 978 979@lilypond[quote,verbatim] 980\score { 981 \new Staff { 982 \relative { 983 a'4^"Smaller font" a a a 984 a4 a a a 985 } 986 } 987 \layout { 988 \accidentalStyle dodecaphonic 989 \set fontSize = #-4 990 \override Voice.Stem.thickness = #4.0 991 } 992} 993@end lilypond 994 995 996@node Changing just one specific context 997@unnumberedsubsubsec Changing just one specific context 998 999@funindex \with 1000 1001The context properties of just one specific context instance can be 1002changed in a @code{\with} block. All other context instances of the 1003same type retain the default settings built into LilyPond and modified 1004by any @code{\layout} block within scope. The @code{\with} block 1005must be placed immediately after the @code{\new} @var{context-type} 1006command: 1007 1008@example 1009\new Staff \with @{ 1010 [context settings for this context instance only] 1011@} @{ 1012 @dots{} 1013@} 1014@end example 1015 1016Alternatively, if the music is being entered using the short form of the 1017input mode-specifying commands, e.g. @code{\chords} rather than 1018@code{\chordmode}, the @code{\with} command must be placed immediately 1019after the mode-specifying command: 1020 1021@example 1022\chords \with @{ 1023 [context settings for this (implicit) context instance only] 1024@} @{ 1025 @dots{} 1026@} 1027@end example 1028 1029@noindent 1030as it is the implicit context created by these short forms which should 1031be modified. The same consideration applies to the other input 1032mode-specifying short forms (@code{\drums}, @code{\figures}), see 1033@ref{Input modes}. 1034 1035Since context modifications specified in @code{\with} blocks are inside 1036music, they will affect @emph{all} outputs (typesetting @emph{and} 1037Midi) as opposed to changes within an output definition. 1038 1039The following types of settings may be specified: 1040 1041@itemize 1042@item 1043An @code{\override} command, but with the context name omitted 1044 1045@lilypond[quote,verbatim] 1046\score { 1047 \new Staff { 1048 \new Voice \with { \override Stem.thickness = #4.0 } 1049 { 1050 \relative { 1051 a'4^"Thick stems" a a a 1052 a4 a a a 1053 } 1054 } 1055 } 1056} 1057@end lilypond 1058 1059@item 1060Directly setting a context property 1061 1062@lilypond[quote,verbatim] 1063\score { 1064 << 1065 \new Staff { 1066 \relative { 1067 a'4^"Default font" a a a 1068 a4 a a a 1069 } 1070 } 1071 \new Staff \with { fontSize = #-4 } 1072 { 1073 \relative { 1074 a'4^"Smaller font" a a a 1075 a4 a a a 1076 } 1077 } 1078 >> 1079} 1080@end lilypond 1081 1082@item 1083A predefined command such as @code{\dynamicUp} 1084 1085@lilypond[quote,verbatim] 1086\score { 1087 << 1088 \new Staff { 1089 \new Voice { 1090 \relative { 1091 a'4^"Dynamics below" a a a 1092 a4 a a\ff a 1093 } 1094 } 1095 } 1096 \new Staff \with { \accidentalStyle dodecaphonic } 1097 { 1098 \new Voice \with { \dynamicUp } 1099 { 1100 \relative { 1101 a'4^"Dynamics above" a a a 1102 a4 a a\ff a 1103 } 1104 } 1105 } 1106 >> 1107} 1108@end lilypond 1109 1110@end itemize 1111 1112@morerefs 1113Notation Reference: 1114@ref{Input modes} 1115 1116@node Order of precedence 1117@unnumberedsubsubsec Order of precedence 1118 1119The value of a property which applies at a particular time is 1120determined as follows: 1121 1122@itemize 1123@item 1124if an @code{\override} or @code{\set} command in the input stream is 1125in effect that value is used, 1126 1127@item 1128otherwise the default value taken from a @code{\with} statement 1129on the context initiation statement is used, 1130 1131@item 1132otherwise the default value taken from the most recent appropriate 1133@code{\context} block in the @code{\layout} or @code{\midi} blocks 1134is used, 1135 1136@item 1137otherwise the LilyPond built-in default is used. 1138@end itemize 1139 1140@morerefs 1141Learning Manual: 1142@rlearning{Modifying context properties}. 1143 1144Notation Reference: 1145@ref{Contexts explained}, 1146@ref{Bottom-level contexts - voices}, 1147@ref{The set command}, 1148@ref{The override command}, 1149@ref{The layout block,,The @code{@bs{}layout} block}. 1150 1151 1152@node Defining new contexts 1153@subsection Defining new contexts 1154 1155@cindex context, defining new 1156@cindex engraver, including in context 1157 1158@funindex \alias 1159@funindex \name 1160@funindex \type 1161@funindex \consists 1162@funindex \accepts 1163@funindex \denies 1164 1165Specific contexts, like @code{Staff} and @code{Voice}, are made from 1166simple building blocks. It is possible to create new types of 1167contexts with different combinations of engraver plug-ins. 1168 1169The next example shows how to build a different type of 1170@code{Voice} context from scratch. It will be similar to 1171@code{Voice}, but only prints centered slash note heads. It can be used 1172to indicate improvisation in jazz pieces, 1173 1174@lilypond[quote,ragged-right] 1175\layout { \context { 1176 \name ImproVoice 1177 \type "Engraver_group" 1178 \consists "Note_heads_engraver" 1179 \consists "Rhythmic_column_engraver" 1180 \consists "Text_engraver" 1181 \consists "Pitch_squash_engraver" 1182 squashedPosition = #0 1183 \override NoteHead.style = #'slash 1184 \hide Stem 1185 \alias Voice 1186} 1187\context { \Staff 1188 \accepts "ImproVoice" 1189}} 1190 1191\relative { 1192 a'4 d8 bes8 \new ImproVoice { c4^"ad lib" c 1193 c4 c^"undress" c_"while playing :)" c } 1194 a1 1195} 1196@end lilypond 1197 1198 1199These settings are defined within a @code{\context} block inside a 1200@code{\layout} block, 1201 1202@example 1203\layout @{ 1204 \context @{ 1205 @dots{} 1206 @} 1207@} 1208@end example 1209 1210In the following discussion, the example input shown should go in place 1211of the @dots{} in the previous fragment. 1212 1213First it is necessary to define a name for the new context: 1214 1215@example 1216\name ImproVoice 1217@end example 1218 1219Since it is similar to the @code{Voice} context, we want commands that 1220work in (existing) @code{Voice} contexts to continue working. This is 1221achieved by giving the new context an alias of @code{Voice}, 1222 1223@example 1224\alias Voice 1225@end example 1226 1227The context will print notes and instructive texts, so we need to add 1228the engravers which provide this functionality, plus the engraver which 1229groups notes, stems and rests which occur at the same musical moment 1230into columns, 1231 1232@example 1233\consists "Note_heads_engraver" 1234\consists "Text_engraver" 1235\consists "Rhythmic_column_engraver" 1236@end example 1237 1238The note heads should all be placed on the center line, 1239 1240@example 1241\consists "Pitch_squash_engraver" 1242squashedPosition = #0 1243@end example 1244 1245The @code{Pitch_squash_engraver} modifies note heads (created 1246by the @code{Note_heads_engraver}) and sets their vertical 1247position to the value of @code{squashedPosition}, in this 1248case@tie{}@code{0}, the center line. 1249 1250The notes look like a slash, and have no stem, 1251 1252@example 1253\override NoteHead.style = #'slash 1254\hide Stem 1255@end example 1256 1257All these plug-ins have to communicate under the control of the 1258context. The mechanisms with which contexts communicate are 1259established by declaring the context @code{\type}. Within a 1260@code{\layout} block, most contexts will be of type 1261@code{Engraver_group}. Some special contexts and contexts in 1262@code{\midi} blocks use other context types. Copying and 1263modifying an existing context definition will also fill in the 1264type. Since this example creates a definition from scratch, it 1265needs to be specified explicitly. 1266 1267@example 1268\type "Engraver_group" 1269@end example 1270 1271Put together, we get 1272 1273@example 1274\context @{ 1275 \name ImproVoice 1276 \type "Engraver_group" 1277 \consists "Note_heads_engraver" 1278 \consists "Text_engraver" 1279 \consists "Rhythmic_column_engraver" 1280 \consists "Pitch_squash_engraver" 1281 squashedPosition = #0 1282 \override NoteHead.style = #'slash 1283 \hide Stem 1284 \alias Voice 1285@} 1286@end example 1287 1288@funindex \accepts 1289Contexts form hierarchies. We want to place the @code{ImproVoice} 1290context within the @code{Staff} context, just like normal @code{Voice} 1291contexts. Therefore, we modify the @code{Staff} definition with the 1292@code{\accepts} command, 1293 1294@example 1295\context @{ 1296 \Staff 1297 \accepts ImproVoice 1298@} 1299@end example 1300 1301@funindex \inherit-acceptability 1302Often when reusing an existing context definition, the resulting 1303context can be used anywhere where the original context would have 1304been useful. 1305 1306@example 1307\layout @{ 1308 @dots{} 1309 \inherit-acceptability @var{to} @var{from} 1310@} 1311@end example 1312 1313@noindent 1314will arrange to have contexts of type @var{to} accepted by all 1315contexts also accepting @var{from}. For example, using 1316 1317@example 1318\layout @{ 1319 @dots{} 1320 \inherit-acceptability "ImproVoice" "Voice" 1321@} 1322@end example 1323 1324@noindent 1325will add an @code{\accepts} for @code{ImproVoice} to both 1326@code{Staff} and @code{RhythmicStaff} definitions. 1327 1328@funindex \denies 1329The opposite of @code{\accepts} is @code{\denies}, 1330which is sometimes needed when reusing existing context definitions. 1331 1332Arranging the required pieces into a @code{\layout} block leaves 1333us with 1334 1335@example 1336\layout @{ 1337 \context @{ 1338 \name ImproVoice 1339 @dots{} 1340 @} 1341 \inherit-acceptability "ImproVoice" "Voice" 1342@} 1343@end example 1344 1345Then the output at the start of this subsection can be entered as 1346 1347@example 1348\relative @{ 1349 a'4 d8 bes8 1350 \new ImproVoice @{ 1351 c4^"ad lib" c 1352 c4 c^"undress" 1353 c c_"while playing :)" 1354 @} 1355 a1 1356@} 1357@end example 1358 1359To complete this example, changes affecting the context hierarchy 1360should be repeated in a @code{\midi} block so that Midi output 1361depends on the same context relations. 1362 1363@morerefs 1364 1365Internals Reference: 1366@rinternals{Note_heads_engraver}, 1367@rinternals{Text_engraver}, 1368@rinternals{Rhythmic_column_engraver}, 1369@rinternals{Pitch_squash_engraver}. 1370 1371 1372@node Context layout order 1373@subsection Context layout order 1374 1375@cindex context, layout order 1376@funindex \accepts 1377@funindex \denies 1378 1379Contexts are normally positioned in a system from top to bottom 1380in the order in which they are encountered in the input file. When 1381contexts are nested, the outer context will include inner nested 1382contexts as specified in the input file, provided the inner contexts 1383are included in the outer context's @qq{accepts} list. Nested 1384contexts which are not included in the outer context's @qq{accepts} 1385list will be repositioned below the outer context rather than nested 1386within it. 1387 1388The @qq{accepts} list of a context can be changed with the 1389@code{\accepts} or @code{\denies} commands. @code{\accepts} adds a 1390context to the @qq{accepts} list and @code{\denies} removes a context 1391from the list. 1392 1393For example, a square-braced staff group is not usually found within a 1394curved-braced staff with connecting staff bars, and a @code{GrandStaff} 1395does not accept a @code{StaffGroup} inside it by default. 1396 1397@lilypond[verbatim,quote] 1398\score { 1399 \new GrandStaff << 1400 \new StaffGroup << 1401 \new Staff { c'1 } 1402 \new Staff { d'1 } 1403 >> 1404 \new Staff { \set Staff.instrumentName = bottom f'1 } 1405 >> 1406} 1407@end lilypond 1408 1409However, by using the @code{\accepts} command, @code{StaffGroup} can be 1410added to the @code{GrandStaff} context: 1411 1412@lilypond[verbatim,quote] 1413\score { 1414 \new GrandStaff << 1415 \new StaffGroup << 1416 \new Staff { c'1 } 1417 \new Staff { d'1 } 1418 >> 1419 \new Staff { \set Staff.instrumentName = bottom f'1 } 1420 >> 1421 \layout { 1422 \context { 1423 \GrandStaff 1424 \accepts "StaffGroup" 1425 } 1426 } 1427} 1428@end lilypond 1429 1430@code{\denies} is mainly used when a new context is being based on 1431another, but the required nesting differs. For example, the 1432@code{VaticanaStaff} context is based on the @code{Staff} context, but 1433with the @code{VaticanaVoice} context substituted for the @code{Voice} 1434context in the @qq{accepts} list. 1435 1436@cindex context, implicit 1437@cindex implicit context 1438@funindex \defaultchild 1439 1440Note that a context will be silently created implicitly if a 1441command is encountered when there is no suitable context available 1442to contain it. 1443 1444Within a context definition, the type of subcontext to be 1445implicitly created is specified using @code{\defaultchild}. A 1446number of music events require a @samp{Bottom} context: when such 1447an event is encountered, subcontexts are created recursively until 1448reaching a context with no @samp{defaultchild} setting. 1449 1450Implicit context creation can at times give rise to unexpected new 1451staves or scores. Using @code{\new} to create contexts explicitly 1452avoids those problems. 1453 1454@funindex alignAboveContext 1455@funindex alignBelowContext 1456 1457Sometimes a context is required to exist for just a brief period, a 1458good example being the staff context for an ossia. This is usually 1459achieved by introducing the context definition at the appropriate 1460place in parallel with corresponding section of the main music. 1461By default, the temporary context will be placed below all the 1462existing contexts. To reposition it above the context called 1463@qq{main}, it should be defined like this: 1464 1465@example 1466\new Staff \with @{ alignAboveContext = "main" @} 1467@end example 1468 1469A similar situation arises when positioning a temporary lyrics 1470context within a multi-staff layout such as a @code{ChoirStaff}, 1471for example, when adding a second verse to a repeated section. 1472By default the temporary lyrics context will be placed beneath the 1473lower staves. By defining the temporary lyrics context with 1474@code{alignBelowContext} it can be positioned correctly beneath 1475the (named) lyrics context containing the first verse. 1476 1477Examples showing this repositioning of temporary contexts can be 1478found elsewhere --- see @rlearning{Nesting music expressions}, 1479@ref{Modifying single staves} and @ref{Techniques specific to lyrics}. 1480 1481@morerefs 1482Learning Manual: 1483@rlearning{Nesting music expressions}. 1484 1485Notation Reference: 1486@ref{Modifying single staves}, 1487@ref{Techniques specific to lyrics}. 1488 1489Application Usage: 1490@rprogram{An extra staff appears}. 1491 1492Installed Files: 1493@file{ly/engraver-init.ly}. 1494 1495 1496@node Explaining the Internals Reference 1497@section Explaining the Internals Reference 1498 1499@menu 1500* Navigating the program reference:: 1501* Layout interfaces:: 1502* Determining the grob property:: 1503* Naming conventions:: 1504@end menu 1505 1506@node Navigating the program reference 1507@subsection Navigating the program reference 1508 1509@c TODO remove this (it's in the LM) 1510@c Replace with more factual directions 1511 1512Suppose we want to move the fingering indication in the fragment 1513below: 1514 1515@lilypond[quote,fragment,verbatim] 1516c''-2 1517@end lilypond 1518 1519If you visit the documentation on fingering instructions (in 1520@ref{Fingering instructions}), you will notice: 1521 1522@quotation 1523@strong{See also} 1524 1525Internals Reference: @rinternals{Fingering}. 1526 1527@end quotation 1528 1529 1530@c outdated info; probably will delete. 1531@ignore 1532This fragment points to two parts of the program reference: a page 1533on @code{FingeringEvent} and one on @code{Fingering}. 1534 1535The page on @code{FingeringEvent} describes the properties of the music 1536expression for the input @w{@code{-2}}. The page contains many links 1537forward. For example, it says 1538 1539@quotation 1540Accepted by: @rinternals{Fingering_engraver}, 1541@end quotation 1542 1543@noindent 1544That link brings us to the documentation for the Engraver, the 1545plug-in, which says 1546 1547@quotation 1548This engraver creates the following layout objects: @rinternals{Fingering}. 1549@end quotation 1550 1551In other words, once the @code{FingeringEvent}s are interpreted, the 1552@code{Fingering_engraver} plug-in will process them. 1553@end ignore 1554 1555@ignore 1556@c I can't figure out what this is supposed to mean. -gp 1557 1558The @code{Fingering_engraver} is also listed to create 1559@rinternals{Fingering} objects, 1560 1561@c old info? it doesn't make any sense to me with our current docs. 1562This is also the 1563second bit of information listed under @b{See also} in the Notation 1564manual. 1565@end ignore 1566 1567@ifnothtml 1568The programmer's reference is available as an HTML document. It is 1569highly recommended that you read it in HTML form, either online or 1570by downloading the HTML documentation. This section will be much more 1571difficult to understand if you are using the 1572PDF manual. 1573@end ifnothtml 1574 1575Follow the link to @rinternals{Fingering}. At the top of the 1576page, you will see 1577 1578@quotation 1579Fingering objects are created by: @rinternals{Fingering_engraver} and 1580@rinternals{New_fingering_engraver}. 1581@end quotation 1582 1583By following related links inside the program reference, we can follow the 1584flow of information within the program: 1585 1586@itemize 1587 1588@item @rinternals{Fingering}: 1589@rinternals{Fingering} objects are created by: 1590@rinternals{Fingering_engraver} 1591 1592@item @rinternals{Fingering_engraver}: 1593Music types accepted: @rinternals{fingering-event} 1594 1595@item @rinternals{fingering-event}: 1596Music event type @code{fingering-event} is in Music expressions named 1597@rinternals{FingeringEvent} 1598@end itemize 1599 1600This path goes against the flow of information in the program: it 1601starts from the output, and ends at the input event. You could 1602also start at an input event, and read with the flow of 1603information, eventually ending up at the output object(s). 1604 1605The program reference can also be browsed like a normal document. It 1606contains chapters on 1607@ifhtml 1608@rinternals{Music definitions}, 1609@end ifhtml 1610@ifnothtml 1611@code{Music definitions} 1612@end ifnothtml 1613on @rinternals{Translation}, and the @rinternals{Backend}. Every 1614chapter lists all the definitions used and all properties that may be 1615tuned. 1616 1617 1618@node Layout interfaces 1619@subsection Layout interfaces 1620 1621@cindex interface, layout 1622@cindex layout interface 1623@cindex grob 1624 1625The HTML page that we found in the previous section describes the 1626layout object called @rinternals{Fingering}. Such an object is a 1627symbol within the score. It has properties that store numbers (like 1628thicknesses and directions), but also pointers to related objects. A 1629layout object is also called a @emph{Grob}, which is short for Graphical 1630Object. For more details about Grobs, see @rinternals{grob-interface}. 1631 1632The page for @code{Fingering} lists the definitions for the 1633@code{Fingering} object. For example, the page says 1634 1635@quotation 1636@code{padding} (dimension, in staff space): 1637 1638@code{0.5} 1639@end quotation 1640 1641@noindent 1642which means that the number will be kept at a distance of at least 0.5 1643of the note head. 1644 1645 1646Each layout object may have several functions as a notational or 1647typographical element. For example, the Fingering object 1648has the following aspects 1649 1650@itemize 1651@item 1652Its size is independent of the horizontal spacing, unlike slurs or beams. 1653 1654@item 1655It is a piece of text. Granted, it is usually a very short text. 1656 1657@item 1658That piece of text is typeset with a font, unlike slurs or beams. 1659 1660@item 1661Horizontally, the center of the symbol should be aligned to the 1662center of the note head. 1663 1664@item 1665Vertically, the symbol is placed next to the note and the staff. 1666 1667@item 1668The vertical position is also coordinated with other superscript 1669and subscript symbols. 1670@end itemize 1671 1672Each of these aspects is captured in so-called @emph{interface}s, 1673which are listed on the @rinternals{Fingering} page at the bottom 1674 1675@quotation 1676This object supports the following interfaces: 1677@rinternals{item-interface}, 1678@rinternals{self-alignment-interface}, 1679@rinternals{side-position-interface}, @rinternals{text-interface}, 1680@rinternals{text-script-interface}, @rinternals{font-interface}, 1681@rinternals{finger-interface}, and @rinternals{grob-interface}. 1682@end quotation 1683 1684Clicking any of the links will take you to the page of the respective 1685object interface. Each interface has a number of properties. Some of 1686them are not user-serviceable (@q{Internal properties}), but others 1687can be modified. 1688 1689We have been talking of @emph{the} @code{Fingering} object, but actually it 1690does not amount to much. The initialization file (see 1691@rlearning{Other sources of information}) 1692@file{scm/define-grobs.scm} shows the soul of the @q{object}, 1693 1694@example 1695(Fingering 1696 . ((padding . 0.5) 1697 (avoid-slur . around) 1698 (slur-padding . 0.2) 1699 (staff-padding . 0.5) 1700 (self-alignment-X . 0) 1701 (self-alignment-Y . 0) 1702 (script-priority . 100) 1703 (stencil . ,ly:text-interface::print) 1704 (direction . ,ly:script-interface::calc-direction) 1705 (font-encoding . fetaText) 1706 (font-size . -5) ; don't overlap when next to heads. 1707 (meta . ((class . Item) 1708 (interfaces . (finger-interface 1709 font-interface 1710 text-script-interface 1711 text-interface 1712 side-position-interface 1713 self-alignment-interface 1714 item-interface)))))) 1715@end example 1716 1717@noindent 1718As you can see, the @code{Fingering} object is nothing more than a 1719bunch of variable settings, and the webpage in the Internals Reference 1720is directly generated from this definition. 1721 1722 1723@node Determining the grob property 1724@subsection Determining the grob property 1725 1726@c TODO remove this (it's in the LM) 1727@c Replace with more factual directions 1728 1729Recall that we wanted to change the position of the @b{2} in 1730 1731@lilypond[quote,fragment,verbatim] 1732c''-2 1733@end lilypond 1734 1735Since the @b{2} is vertically positioned next to its note, we have to 1736meddle with the interface associated with this positioning. This is 1737done using @code{side-position-interface}. The page for this interface 1738says 1739 1740@quotation 1741@code{side-position-interface} 1742 1743Position a victim object (this one) next to other objects (the 1744support). The property @code{direction} signifies where to put the 1745victim object relative to the support (left or right, up or down?) 1746@end quotation 1747 1748@cindex padding 1749@noindent 1750Below this description, the variable @code{padding} is described as 1751 1752@quotation 1753@table @code 1754@item padding 1755(dimension, in staff space) 1756 1757Add this much extra space between objects that are next to each other. 1758@end table 1759@end quotation 1760 1761By increasing the value of @code{padding}, we can move the fingering 1762away from the note head. The following command will insert @qq{three 1763staff spaces} worth of distance between the note and a fingering mark: 1764 1765@example 1766\once \override Voice.Fingering.padding = #3 1767@end example 1768 1769Inserting the padding before the fingering object is created results in 1770the following: 1771 1772@lilypond[quote,fragment,verbatim] 1773\once \override Voice.Fingering.padding = #3 1774c''-2 1775@end lilypond 1776 1777In this case, the context for this tweak is @code{Voice}. See 1778@rinternals{Fingering_engraver} plug-in, which says: 1779 1780@quotation 1781Fingering_engraver is part of contexts: @dots{} @rinternals{Voice} 1782@end quotation 1783 1784 1785@node Naming conventions 1786@subsection Naming conventions 1787 1788Another thing that is needed, is an overview of the various naming 1789conventions: 1790 1791@itemize 1792@item scheme functions: lowercase-with-hyphens (also includes one-word 1793names) 1794 1795@item LilyPond-specific scheme functions: ly:plus-scheme-style 1796 1797@item music events, music classes and music properties: 1798as-scheme-functions 1799 1800@item Grob interfaces: scheme-style 1801 1802@item backend properties: scheme-style (but X and Y!) 1803 1804@item contexts (and MusicExpressions and grobs): Capitalized or 1805CamelCase 1806 1807@item context properties: lowercaseFollowedByCamelCase 1808 1809@item engravers: Capitalized_followed_by_lowercase_and_with_underscores 1810@end itemize 1811 1812Questions to be answered: 1813@itemize 1814 1815@item Which of these are conventions and which are rules? 1816 1817@item Which are rules of the underlying language, and which are 1818LilyPond-specific? 1819@end itemize 1820 1821@node Modifying properties 1822@section Modifying properties 1823 1824@c TODO change the menu and subsection node names to use 1825@c backslash once the new macro to handle the refs 1826@c is available. Need to find and change all refs at 1827@c the same time. -td 1828 1829@menu 1830* Overview of modifying properties:: 1831* The set command:: 1832* The override command:: 1833* The tweak command:: 1834* set versus override:: 1835* The offset command:: 1836* Modifying alists:: 1837@end menu 1838 1839 1840@node Overview of modifying properties 1841@subsection Overview of modifying properties 1842 1843Each context is responsible for creating certain types of graphical 1844objects. The settings used for printing these objects are also stored by 1845context. By changing these settings, the appearance of objects can be 1846altered. 1847 1848There are two different kinds of properties stored in contexts: 1849context properties and grob properties. Context properties are 1850properties that apply to the context as a whole and control 1851how the context itself is displayed. In contrast, grob properties 1852apply to specific grob types that will be displayed in the context. 1853 1854The @code{\set} and @code{\unset} commands are used to change values 1855for context properties. The @code{\override} and @code{\revert} 1856commands are used to change values for grob properties. 1857 1858@ignore 1859The syntax for this is 1860 1861@example 1862\override @var{context}.@var{name} #'@var{property} = #@var{value} 1863@end example 1864 1865Here @var{name} is the name of a graphical object, like 1866@code{Stem} or @code{NoteHead}, and @var{property} is an internal 1867variable of the formatting system (@q{grob property} or @q{layout 1868property}). The latter is a symbol, so it must be quoted. The 1869subsection @ref{Modifying properties}, explains what to fill in 1870for @var{name}, @var{property}, and @var{value}. Here we only 1871discuss the functionality of this command. 1872 1873The command 1874 1875@verbatim 1876\override Staff.Stem.thickness = #4.0 1877@end verbatim 1878 1879@noindent 1880makes stems thicker (the default is 1.3, with staff line thickness as a 1881unit). Since the command specifies @code{Staff} as context, it only 1882applies to the current staff. Other staves will keep their normal 1883appearance. Here we see the command in action: 1884 1885@lilypond[quote,fragment,verbatim] 1886c''4 1887\override Staff.Stem.thickness = #4.0 1888c''4 1889c''4 1890c''4 1891@end lilypond 1892 1893The @code{\override} command changes the definition of the @code{Stem} 1894within the current @code{Staff}. After the command is interpreted 1895all stems are thickened. 1896 1897Analogous to @code{\set}, the @var{context} argument may be left out, 1898causing the default context @code{Voice} to be used. Adding 1899@code{\once} applies the change during one timestep only. 1900 1901@lilypond[quote,fragment,verbatim] 1902c''4 1903\once \override Stem.thickness = #4.0 1904c''4 1905c''4 1906@end lilypond 1907 1908The @code{\override} must be done before the object is 1909started. Therefore, when altering @emph{Spanner} objects such as slurs 1910or beams, the @code{\override} command must be executed at the moment 1911when the object is created. In this example, 1912 1913@lilypond[quote,fragment,verbatim] 1914\override Slur.thickness = #3.0 1915c''8[( c'' 1916\override Beam.beam-thickness = #0.6 1917c''8 c'']) 1918@end lilypond 1919 1920@noindent 1921the slur is fatter but the beam is not. This is because the command for 1922@code{Beam} comes after the Beam is started, so it has no effect. 1923 1924Analogous to @code{\unset}, the @code{\revert} command for a context 1925undoes an @code{\override} command; like with @code{\unset}, it only 1926affects settings that were made in the same context. In other words, the 1927@code{\revert} in the next example does not do anything. 1928 1929@example 1930\override Voice.Stem.thickness = #4.0 1931\revert Staff.Stem.thickness 1932@end example 1933 1934Some tweakable options are called @q{subproperties} and reside inside 1935properties. To tweak those, use commands of the form 1936 1937@c leave this as a long long 1938@example 1939\override @var{context}.@var{name} #'@var{property} #'@var{subproperty} = #@var{value} 1940@end example 1941 1942@noindent 1943such as 1944 1945@example 1946\override Stem.details.beamed-lengths = #'(4 4 3) 1947@end example 1948 1949@end ignore 1950 1951@morerefs 1952Internals Reference: 1953@rinternals{Backend}, 1954@rinternals{All layout objects}, 1955@rinternals{OverrideProperty}, 1956@rinternals{RevertProperty}, 1957@rinternals{PropertySet}. 1958 1959@knownissues 1960The back-end is not very strict in type-checking object properties. 1961Cyclic references in Scheme values for properties can cause hangs 1962or crashes, or both. 1963 1964 1965@node The set command 1966@subsection The @code{@bs{}set} command 1967 1968@cindex property 1969@funindex \set 1970@cindex changing property 1971 1972Each context has a set of @emph{properties}, variables contained 1973in that context. Context properties are changed with the @code{\set} 1974command, which has the following syntax: 1975 1976@example 1977\set @var{context}.@var{property} = #@var{value} 1978@end example 1979 1980@var{value} is a Scheme object, which is why it must be preceded by 1981the @code{#}@tie{}character. 1982 1983Contexts properties are usually named in 1984@code{studlyCaps}. They mostly control the translation from 1985music to notation, e.g., @code{localAlterations} (for determining 1986whether to print accidentals), or @code{measurePosition} (for 1987determining when to print a bar line). Context properties can 1988change value over time while interpreting a piece of music; 1989@code{measurePosition} is an obvious example of 1990this. Context properties are modified with @code{\set}. 1991 1992For example, multimeasure rests will be combined into a single bar 1993(as explained in @ref{Compressing empty measures}) 1994if the context property @code{skipBars} is set to @code{#t}: 1995 1996@lilypond[quote,fragment,verbatim] 1997R1*2 1998\set Score.skipBars = ##t 1999R1*2 2000@end lilypond 2001 2002If the @var{context} argument is left out, then the property will be 2003set in the current bottom context (typically @code{ChordNames}, 2004@code{Voice}, @code{TabVoice}, or @code{Lyrics}). 2005 2006@lilypond[quote,fragment,verbatim] 2007\set Score.autoBeaming = ##f 2008\relative { 2009 e''8 e e e 2010 \set autoBeaming = ##t 2011 e8 e e e 2012} \\ 2013\relative { 2014 c''8 c c c c8 c c c 2015} 2016@end lilypond 2017 2018The change is applied @q{on-the-fly}, during the music, so that the 2019setting only affects the second group of eighth notes. 2020 2021Note that the bottom-most context does not always contain the property 2022that you wish to change -- for example, attempting to set the 2023@code{skipBars} property of the default bottom context, in this case 2024@code{Voice}, will have no effect, because skipBars is a property of 2025the @code{Score} context. 2026 2027@lilypond[quote,fragment,verbatim] 2028R1*2 2029\set skipBars = ##t 2030R1*2 2031@end lilypond 2032 2033Contexts are hierarchical, so if an enclosing context was specified, for 2034example @code{Staff}, then the change would also apply to all 2035@code{Voice}s in the current staff. 2036 2037@funindex \unset 2038 2039The @code{\unset} command: 2040 2041@example 2042\unset @var{context}.@var{property} 2043@end example 2044 2045@noindent 2046is used to remove the definition of @var{property} from 2047@var{context}. This command removes 2048the definition only if it is set in @var{context}. 2049Properties that have been set in enclosing contexts will 2050not be altered by an unset in an enclosed context: 2051 2052@lilypond[quote,fragment,verbatim] 2053\set Score.autoBeaming = ##t 2054\relative { 2055 \unset autoBeaming 2056 e''8 e e e 2057 \unset Score.autoBeaming 2058 e8 e e e 2059} \\ 2060\relative { 2061 c''8 c c c c8 c c c 2062} 2063@end lilypond 2064 2065Like @code{\set}, the @var{context} argument does not have to be 2066specified for a bottom context, so the two statements 2067 2068@example 2069\set Voice.autoBeaming = ##t 2070\set autoBeaming = ##t 2071@end example 2072 2073@noindent 2074are equivalent if the current bottom context is @code{Voice}. 2075 2076 2077@funindex \once 2078Preceding a @code{\set} or @code{\unset} command by @code{\once} 2079makes the setting apply to only a single time-step: 2080 2081@lilypond[quote,fragment,verbatim] 2082c''4 2083\once \set fontSize = #4.7 2084c''4 2085c''4 2086@end lilypond 2087 2088A full description of all available context properties is in the 2089internals reference, see 2090@ifhtml 2091@rinternals{Tunable context properties}. 2092@end ifhtml 2093@ifnothtml 2094Translation @expansion{} Tunable context properties. 2095@end ifnothtml 2096 2097@morerefs 2098Internals Reference: 2099@rinternals{Tunable context properties}. 2100 2101 2102@node The override command 2103@subsection The @code{\override} command 2104 2105@cindex grob, property 2106@cindex property, grob 2107@funindex \override 2108 2109There is a special type of context property: the grob 2110description. Grob descriptions are named in @code{StudlyCaps} 2111(starting with capital letters). They contain the 2112@q{default settings} for a particular kind of grob as an 2113association list. See @file{scm/define-grobs.scm} 2114to see the settings for each grob description. Grob descriptions 2115are modified with @code{\override}. 2116 2117The syntax for the @code{\override} command is 2118 2119@example 2120\override [@var{context}.]@var{GrobName}.@var{property} = #@var{value} 2121@end example 2122 2123For example, we can increase the thickness of a note stem by 2124overriding the @code{thickness} property of the @code{Stem} 2125object: 2126 2127@lilypond[quote,fragment,verbatim] 2128c''4 c'' 2129\override Voice.Stem.thickness = #3.0 2130c''4 c'' 2131@end lilypond 2132 2133If no context is specified in an @code{\override}, the bottom 2134context is used: 2135 2136@lilypond[quote,fragment,verbatim] 2137\override Staff.Stem.thickness = #3.0 2138<< 2139 \relative { 2140 e''4 e 2141 \override Stem.thickness = #0.5 2142 e4 e 2143 } \\ 2144 \relative { 2145 c''4 c c c 2146 } 2147>> 2148@end lilypond 2149 2150Some tweakable options are called @q{subproperties} and reside inside 2151properties. To tweak those, use commands in the form 2152 2153@example 2154\override Stem.details.beamed-lengths = #'(4 4 3) 2155@end example 2156 2157or to modify the ends of spanners, use a form like these 2158 2159@example 2160\override TextSpanner.bound-details.left.text = "left text" 2161\override TextSpanner.bound-details.right.text = "right text" 2162@end example 2163 2164@funindex \revert 2165@cindex reverting override 2166@cindex override, reverting 2167 2168The effects of @code{\override} can be undone by @code{\revert}. 2169 2170The syntax for the @code{\revert} command is 2171 2172@example 2173\revert [@var{context}.]@var{GrobName}.@var{property} 2174@end example 2175 2176For example, 2177 2178@lilypond[quote,verbatim] 2179\relative { 2180 c''4 2181 \override Voice.Stem.thickness = #3.0 2182 c4 c 2183 \revert Voice.Stem.thickness 2184 c4 2185} 2186@end lilypond 2187 2188The effects of @code{\override} and @code{\revert} apply to all 2189grobs in the affected context from the current time forward: 2190 2191@lilypond[quote,verbatim] 2192<< 2193 \relative { 2194 e''4 2195 \override Staff.Stem.thickness = #3.0 2196 e4 e e 2197 } \\ 2198 \relative { 2199 c''4 c c 2200 \revert Staff.Stem.thickness 2201 c4 2202 } 2203>> 2204@end lilypond 2205 2206@funindex \once 2207@cindex overriding for only one moment 2208 2209@code{\once} can be used with @code{\override} or @code{\revert} 2210to affect only the current time step: 2211 2212@lilypond[quote,verbatim] 2213<< 2214 \relative c { 2215 \override Stem.thickness = #3.0 2216 e''4 e e e 2217 } \\ 2218 \relative { 2219 c''4 2220 \once \override Stem.thickness = #3.0 2221 c4 c c 2222 } 2223>> 2224@end lilypond 2225 2226 2227@ignore 2228Commands which change output generally look like 2229 2230@example 2231\override Voice.Stem.thickness = #3.0 2232@end example 2233 2234@noindent 2235To construct this tweak we must determine these bits of information: 2236 2237@itemize 2238@item the context: here @code{Voice}. 2239@item the layout object: here @code{Stem}. 2240@item the layout property: here @code{thickness}. 2241@item a sensible value: here @code{3.0}. 2242@end itemize 2243 2244@cindex internal documentation 2245@cindex finding graphical object 2246@cindex graphical object description 2247@cindex tweaking 2248@funindex \override 2249@cindex internal documentation 2250 2251For many properties, regardless of the data type of the property, setting the 2252property to false (@code{#f}) will result in turning it off, causing 2253LilyPond to ignore that property entirely. This is particularly useful for 2254turning off grob properties which may otherwise be causing problems. 2255 2256We demonstrate how to glean this information from the notation manual 2257and the program reference. 2258@end ignore 2259 2260@morerefs 2261Internals Reference: 2262@rinternals{Backend} 2263 2264 2265@node The tweak command 2266@subsection The @code{\tweak} command 2267 2268@funindex \tweak 2269@cindex tweaking 2270 2271Changing grob properties 2272with @code{\override} causes the changes to apply to all of the 2273given grobs in the context at the moment the change applies. 2274Sometimes, however, it is desirable to have changes apply to just 2275one grob, rather than to all grobs in the affected context. This is 2276accomplished with the @code{\tweak} command, which has the following 2277syntax: 2278 2279@example 2280\tweak [@var{layout-object}.]@var{grob-property} @var{value} 2281@end example 2282 2283Specifying @var{layout-object} is optional. 2284The @code{\tweak} command applies to the music object that immediately 2285follows @var{value} in the music stream. 2286 2287@ignore 2288In some cases, it is possible to take a short-cut for tuning 2289graphical objects. For objects that are created directly from 2290an item in the input file, you can use the @code{\tweak} command. 2291For example: 2292 2293@lilypond[verbatim,quote] 2294\relative { 2295 < c'' 2296 \tweak color #red 2297 d 2298 g 2299 \tweak duration-log #1 2300 a 2301 > 4 2302 -\tweak padding #8 2303 -^ 2304} 2305@end lilypond 2306 2307 2308 2309The main use of the @code{\tweak} command is to modify just 2310one of a number of notation elements which start at the same musical 2311moment, like the notes of a chord, or tuplet brackets which start 2312at the same time. 2313 2314The @code{\tweak} command sets a property in the following object 2315directly, without requiring the grob name or context to be 2316specified. For this to work, it is necessary for the @code{\tweak} 2317command to remain immediately adjacent to the object to which it is 2318to apply after the input file has been converted to a music stream. 2319This is often not the case, as many additional elements are inserted 2320into the music stream implicitly. For example, when a note which is 2321not part of a chord is processed, LilyPond implicitly inserts a 2322@code{ChordEvent} event before the note, so separating the tweak 2323from the note. However, if chord symbols are placed round the 2324tweak and the note, the @code{\tweak} command comes after the 2325@code{ChordEvent} in the music stream, so remaining adjacent to the 2326note, and able to modify it. 2327 2328So, this works: 2329 2330@lilypond[verbatim,fragment,quote] 2331<\tweak color #red c''>4 2332@end lilypond 2333 2334@noindent 2335but this does not: 2336 2337@lilypond[verbatim,fragment,quote] 2338\tweak color #red c''4 2339@end lilypond 2340 2341@end ignore 2342 2343For an introduction to the syntax and uses of the tweak command 2344see @rlearning{Tweaking methods}. 2345 2346When several similar items are placed at the same musical moment, 2347the @code{\override} command cannot be used to modify just one of 2348them -- this is where the @code{\tweak} command must be used. 2349Items which may appear more than once at the same musical moment 2350include the following: 2351 2352@c TODO expand to include any further uses of \tweak 2353@itemize 2354@item note heads of notes inside a chord 2355@item articulation signs on a single note 2356@item ties between notes in a chord 2357@item tuplet brackets starting at the same time 2358@end itemize 2359 2360@c TODO add examples of these 2361 2362@cindex chord, modifying one note in 2363 2364In this example, the color of one note head and the type of another 2365note head are modified within a single chord: 2366 2367@lilypond[verbatim,fragment,quote] 2368< c'' 2369 \tweak color #red 2370 d'' 2371 g'' 2372 \tweak duration-log #1 2373 a'' 2374> 4 2375@end lilypond 2376 2377@code{\tweak} can be used to modify slurs: 2378 2379@lilypond[verbatim,quote] 2380\relative { c'-\tweak thickness #5 ( d e f) } 2381@end lilypond 2382 2383 2384For the @code{\tweak} command to work, it must 2385remain immediately adjacent to the object to which it is 2386to apply after the input file has been converted to a music stream. 2387Tweaking a whole chord does not do anything since its music event 2388only acts as a container, and all layout objects are created from events 2389inside of the @code{EventChord}: 2390 2391@lilypond[verbatim,fragment,quote] 2392\tweak color #red c''4 2393\tweak color #red <c'' e''>4 2394<\tweak color #red c'' e''>4 2395@end lilypond 2396 2397The simple @code{\tweak} command cannot be used to modify any object 2398that is not directly created from the input. In particular 2399it will not affect stems, automatic 2400beams or accidentals, since these are generated later by 2401@code{NoteHead} layout objects rather than by music elements in the 2402input stream. 2403 2404Such indirectly created layout objects can be tweaked using the form 2405of the @code{\tweak} command in which the grob name is specified 2406explicitly: 2407 2408@lilypond[fragment,verbatim,quote] 2409\tweak Stem.color #red 2410\tweak Beam.color #green c''8 e'' 2411<c'' e'' \tweak Accidental.font-size #-3 ges''>4 2412@end lilypond 2413 2414@code{\tweak} cannot be used to modify clefs or time 2415signatures, since these become separated from any preceding 2416@code{\tweak} command in the input stream by the automatic 2417insertion of extra elements required to specify the context. 2418 2419Several @code{\tweak} commands may be placed before a 2420notational element -- all affect it: 2421 2422@lilypond[verbatim,fragment,quote] 2423c' 2424 -\tweak style #'dashed-line 2425 -\tweak dash-fraction #0.2 2426 -\tweak thickness #3 2427 -\tweak color #red 2428 \glissando 2429f'' 2430@end lilypond 2431 2432The music stream which is generated from a section of an input file, 2433including any automatically inserted elements, may be examined, 2434see @rextend{Displaying music expressions}. This may be helpful in 2435determining what may be modified by a @code{\tweak} command, or 2436in determining how to adjust the input to make a @code{\tweak} 2437apply. 2438 2439@morerefs 2440Learning Manual: 2441@rlearning{Tweaking methods}. 2442 2443Extending LilyPond: 2444@rextend{Displaying music expressions}. 2445 2446@knownissues 2447 2448@cindex tweaking control point 2449@cindex control point, tweaking 2450 2451The @code{\tweak} command cannot be used to modify the control 2452points of just one of several ties in a chord, other than the first 2453one encountered in the input file. 2454 2455@node set versus override 2456@subsection @code{\set} vs. @code{\override} 2457 2458@c TODO Should't a bunch of that be explained earlier? 2459 2460@funindex \set 2461@funindex \override 2462 2463The @code{\set} and @code{\override} commands manipulate properties 2464associated with contexts. In both cases, the properties follow a 2465@emph{hierarchy of contexts}; properties that are not set themselves in 2466a context will still show the values of their respective parent's 2467context. 2468 2469The lifetime and value of a context property is dynamic and only 2470available when music is being interpreted (i.e., @q{iterated}). At the 2471time of the context's creation, properties are initialized from its 2472corresponding definitions (along with any other modifications) of that 2473context. Any subsequent changes are achieved with any 2474@q{property-setting} commands that are within the music itself. 2475 2476Graphical Object (or @qq{grob}) definitions are a @emph{special} 2477category of context properties as their structure and use is different 2478from that of normal context properties. Unlike normal context 2479properties, grob definitions are subdivided into @emph{grob properties}. 2480 2481Also, in contrast to normal context properties, grob definitions have 2482their own internal @q{bookkeeping} used to keep track of their own 2483individual grob properties and any sub-properties. This means that it 2484is possible to define those parts within different contexts and yet 2485still have the overall grob definition at the time of grob creation from 2486all the pieces provided amongst the current context and its parent(s). 2487 2488A grob is usually created by an engraver at the time of interpreting a 2489music expression and receives its initial properties from the current 2490grob definition of the engraver's context. The engraver (or other 2491@q{backend} parts of LilyPond) can then change (or add to) the grob's 2492initial properties. However, this does not affect the context's own 2493grob definition. 2494 2495What LilyPond calls @emph{grob properties} in the context of 2496@q{user-level} tweaks are really the properties of a @emph{context's} 2497own grob definition. 2498 2499Grob definitions are accessed with a different set of commands and are 2500manipulated using @code{\override} and @code{\revert} and have a name 2501starting with a capital letter (e.g., @samp{NoteHead}); whereas normal 2502context properties are manipulated using @code{\set} and @code{\unset} 2503and are named starting with a lowercase letter. 2504 2505@cindex @code{tweak}, relation to @code{\override} 2506@funindex \tweak 2507@funindex \overrideProperty 2508 2509The commands @code{\tweak} and @code{\overrideProperty} change grob 2510properties by bypassing all context properties completely and, instead, 2511catch grobs as they are being created, setting properties on them for 2512a music event (@code{\tweak}) or, in the case of 2513@code{\overrideProperty} for a specific override. 2514 2515 2516@node The offset command 2517@subsection The @code{\offset} command 2518 2519@funindex \offset 2520@cindex offsetting 2521@cindex default, offsetting 2522 2523While it is possible to set grob properties to new values with the 2524@code{\override}, @code{\tweak}, and @code{\overrideProperty} commands, 2525it is often more convenient to modify such properties relative to a 2526default value. The @code{\offset} command is available for this 2527purpose. 2528 2529The syntax for @code{\offset} is 2530 2531@example 2532[-]\offset @var{property} @var{offsets} @var{item} 2533@end example 2534 2535The command works by adding the contents of @var{offsets} to the 2536default setting of the property @var{property} of the grob indicated by 2537@var{item}. 2538 2539Depending on the formulation of the command, @code{\offset} may act 2540as either a @code{\tweak} or @code{\override}. The variations in 2541usage are discussed after consideration is given to grob properties 2542that may be used with @code{\offset}. 2543 2544@subsubsubheading{Properties which may be offset} 2545 2546Many, but not all, grob properties may be offset. If @var{property} 2547cannot be offset, the object will remain unchanged and a warning will 2548be issued. In such cases, @code{\override} or @code{\tweak} should be 2549used to modify the object instead. 2550 2551One can work by trial and error and let the warnings be the guide to 2552what may or may not be offset. A more systematic approach is possible, 2553however. 2554 2555The following criteria determine whether a property can be modified with 2556@code{\offset}: 2557 2558@itemize 2559 2560@item 2561The property has a @q{default setting} in the grob's description. Such 2562properties are listed for each grob in @rinternals{All layout objects}. 2563(They are also found in @file{scm/define-grobs.scm}.) 2564 2565@item 2566The property takes a numerical value. Numerical values include 2567@code{number}, list of @code{number}s, @code{number-pair}, and 2568@code{number-pair-list}. The pages at @rinternals{All layout objects} 2569list the type of data characteristic to each property. It is immaterial 2570whether the default setting is a function. 2571 2572@item 2573The property cannot be a @q{subproperty}---a property residing within 2574another property. 2575 2576@item 2577Properties set to infinite values cannot be offset. There is no 2578sensible way to offset positive and negative infinity. 2579@end itemize 2580 2581The following examples consider several grob properties against the 2582criteria outlined above. 2583 2584@itemize 2585 2586@item Properties that may be offset 2587 2588@table @asis 2589 2590@item @code{Hairpin.height} 2591 2592This property is not a subproperty, and it is listed at 2593@rinternals{Hairpin}. For a value, it takes @q{dimension, in staff 2594space} set to @code{0.6666}---clearly a non-infinite @code{number}. 2595 2596@item @code{Arpeggio.positions} 2597 2598The page @rinternals{Arpeggio} lists a @code{positions} property which 2599accepts a @q{pair of numbers}. It defaults to 2600@code{ly:arpeggio::positions}---a callback which will be evaluated 2601during the typesetting phase to yield a pair of numbers for any given 2602@code{Arpeggio} object. 2603 2604@end table 2605 2606@item Properties that may not be offset 2607 2608@table @asis 2609 2610@item @code{Hairpin.color} 2611 2612There is no listing for @code{color} at @rinternals{Hairpin}. 2613 2614@item @code{Hairpin.circled-tip} 2615 2616The listing for @code{Hairpin.circled-tip} at @rinternals{Hairpin} shows 2617that it takes a @code{boolean} value. Booleans are non-numerical. 2618 2619@item @code{Stem.details.lengths} 2620 2621Though listed at @rinternals{Stem} and defaulting to a list of 2622@code{number}s, this is a @q{subproperty}. There is currently no 2623support for @q{nested properties}. 2624 2625@end table 2626 2627@end itemize 2628 2629@subsubsubheading{@bs{}offset as an override} 2630 2631If @var{item} is a grob name like @code{Arpeggio} or 2632@code{Staff.OttavaBracket}, the result is an @code{\override} of the 2633specified grob-type. 2634 2635@example 2636\offset @var{property} @var{offsets} [@var{context}.]@var{GrobName} 2637@end example 2638 2639Note that the leading hyphen is @emph{never} used with the @q{override} 2640form, just as it is never used with the @code{\override} command itself. 2641 2642The following example uses the @q{override} form to lengthen the 2643default arpeggios shown in the first measure to cover the extent of 2644the chords more fully. The arpeggios are stretched by a half 2645staff-space to top and bottom. Also shown is the same operation done on 2646the first chord with an ordinary override of the @code{positions} 2647property. This method is not at all expressive of the task of 2648@q{stretching by a half staff-space}, as the endpoints must be specified 2649with absolute rather than relative coordinates. Furthermore, individual 2650overrides would be needed for the other chords, as they vary in size and 2651position. 2652 2653@lilypond[quote,verbatim] 2654arpeggioMusic = { 2655 <c' e' g'>\arpeggio <a' c'' e''>\arpeggio 2656 <d' f' a' c''>\arpeggio <c' e' g' b' d'' f'' a''>\arpeggio 2657} 2658 2659{ 2660 \arpeggioMusic 2661 \bar "||" 2662 \offset positions #'(-0.5 . 0.5) Arpeggio 2663 \arpeggioMusic 2664 \bar "||" 2665 \once \override Arpeggio.positions = #'(-3.5 . -0.5) 2666 <c' e' g'>1\arpeggio 2667 \bar "||" 2668} 2669@end lilypond 2670 2671@funindex \once 2672@funindex \temporary 2673 2674In its @q{override} usage, @code{\offset} may be prefaced with 2675@code{\once} or @code{\temporary} and reverted using @code{\revert} 2676with @var{property} (see @rextend{Intermediate substitution 2677functions}). This follows from the fact that @code{\offset} 2678actually creates an @code{\override} of @var{property}. 2679 2680@lilypond[quote,verbatim] 2681music = { c'8\< d' e' f'\! } 2682 2683{ 2684 \music 2685 \offset height 1 Hairpin 2686 \music 2687 \music 2688 \revert Hairpin.height 2689 \music 2690 \bar "||" 2691 \once \offset height 1 Hairpin 2692 \music \music 2693 \bar "||" 2694 \override Hairpin.height = 0.2 2695 \music 2696 \temporary \offset height 2 Hairpin 2697 \music 2698 \music 2699 \revert Hairpin.height 2700 \music 2701 \bar "||" 2702} 2703@end lilypond 2704 2705@funindex \single 2706@funindex \undo 2707 2708Also like @code{\override}, the @q{override} form of @code{\offset} may 2709be used with @code{\undo} and @code{\single}. 2710 2711@lilypond[quote,verbatim] 2712longStem = \offset length 6 Stem 2713 2714{ 2715 \longStem c'4 c''' c' c'' 2716 \bar "||" 2717 \undo \longStem c'4 c''' c' c'' 2718 \bar "||" 2719 \single \longStem c'4 c''' c' c'' 2720 \bar "||" 2721} 2722@end lilypond 2723 2724@subsubsubheading{@bs{}offset as a tweak} 2725 2726If @var{item} is a music expression such as @code{(} or 2727@code{\arpeggio}, the result is the same music expression with a tweak 2728applied. 2729 2730@example 2731[-]\offset [@var{GrobName}.]@var{property} @var{offsets} @var{music-expression} 2732@end example 2733 2734The syntax of @code{\offset} in its @q{tweak} form is analogous to the 2735@code{\tweak} command itself, both in ordering and in the presence or 2736absence of the leading hyphen. 2737 2738The following example uses the @q{tweak} form to adjust the vertical 2739position of the @code{BreathingSign} object. Compare this with the 2740ordinary @code{\tweak} command also demonstrated. The syntax is 2741equivalent; however, the output of @code{\tweak} is less intuitive, 2742since @code{BreathingSign.Y-offset} is calculated from the middle 2743staff-line. It is not necessary to know how @code{Y-offset} is 2744calculated when using @code{\offset}. 2745 2746@lilypond[quote,verbatim] 2747{ 2748 c''4 2749 \breathe 2750 c''4 2751 \offset Y-offset 2 \breathe 2752 c''2 2753 \tweak Y-offset 3 \breathe 2754} 2755@end lilypond 2756 2757In the previous example, the tweaked objects were created directly from 2758the user input: the @code{\breathe} command was an explicit instruction 2759to return a @code{BreathingSign} object. Since the focus of the command 2760was unambiguous, there was no need to specify the object's name. When 2761an object is @emph{indirectly} created, however, it is necessary to 2762include the grob's name. This is the same as for the @code{\tweak} 2763command. 2764 2765In the following example, the @code{Beam} object is lowered two 2766staff-spaces by applying @code{\offset} to the @code{positions} 2767property. 2768 2769The first application of @code{\offset} requires that the grob's name 2770be included, because nothing in the input explicitly creates the 2771beam. In the second application, the beam is created manually with the 2772music expression @code{[}; therefore, the grob's name is not needed. 2773(Also illustrated is a shorthand: a single @code{number} will be applied 2774to both members of a @code{number-pair}.) 2775 2776@lilypond[quote,verbatim] 2777{ 2778 c''8 g'' e'' d'' 2779 \offset Beam.positions #'(-2 . -2) 2780 c''8 g'' e'' d'' 2781 c''8 g'' e'' d'' 2782 c''8-\offset positions #-2 [ g'' e'' d''] 2783} 2784@end lilypond 2785 2786@subsubsubheading{@bs{}offset with broken spanners} 2787 2788Independently modifying segments of a spanner extending over a line 2789break or breaks is also possible. In this case, @var{offsets} 2790takes a list of values of the property's required data type. 2791 2792The @code{\offset} command used in this manner is similar to the 2793@code{\alterBroken} command. (See @ref{Modifying broken spanners}.) 2794In contrast with @code{\alterBroken}, however, the values given to 2795@code{\offset} are relative, not absolute. 2796 2797The following example displaces the @q{broken} @code{OttavaBracket} 2798object through its @code{staff-padding} property. Since the property 2799takes a @code{number}, @var{offsets} is provided with a list of 2800@code{number}s to account for the two segments created by the line 2801break. The bracket piece on the first line is effectively untouched 2802since @code{0} is added to its default value of @code{staff-padding}. 2803The segment on the second line is raised three staff-spaces from its 2804default height. The default height happens to be @code{2}, though it is 2805not necessary to know this to achieve the desired positioning. 2806 2807@lilypond[quote,verbatim] 2808{ 2809 \offset staff-padding #'(0 3) Staff.OttavaBracket 2810 \ottava #1 2811 c'''2 c''' 2812 \break 2813 c'''2 c''' 2814} 2815@end lilypond 2816 2817The following example mimics the effect of the @code{\shape} command by 2818offsetting the @code{control-points} property of the @code{Slur} object. 2819Here, @var{offsets} is a list of @code{number-pair-list}s, one for each 2820slur segment. This example achieves a result identical to the 2821corresponding illustration at @ref{Modifying shapes}. 2822 2823@lilypond[quote,verbatim] 2824{ 2825 c'4-\offset control-points #'( 2826 ((0 . 0) (0 . 0) (0 . 0) (0 . 1)) 2827 ((0.5 . 1.5) (1 . 0) (0 . 0) (0 . -1.5)) 2828 ) ( f'4 g' c'' 2829 \break 2830 d'4 c'' f' c') 2831} 2832@end lilypond 2833 2834 2835@node Modifying alists 2836@subsection Modifying alists 2837 2838Some user-configurable properties are internally represented as 2839@emph{alists} (association lists), which store pairs of 2840@emph{keys} and @emph{values}. The structure of an alist is: 2841 2842@example 2843'((@var{key1} . @var{value1}) 2844 (@var{key2} . @var{value2}) 2845 (@var{key3} . @var{value3}) 2846 @dots{}) 2847@end example 2848 2849If an alist is a grob property or @code{\paper} variable, its keys 2850can be modified individually without affecting other keys. 2851 2852For example, to reduce the space between adjacent staves in a 2853staff-group, use the @code{staff-staff-spacing} property of the 2854@code{StaffGrouper} grob. The property is an alist with four 2855keys: @code{basic-distance}, @code{minimum-distance}, 2856@code{padding}, and @code{stretchability}. The standard settings 2857for this property are listed in the @qq{Backend} section of the 2858Internals Reference (see @rinternals{StaffGrouper}): 2859 2860@example 2861'((basic-distance . 9) 2862 (minimum-distance . 7) 2863 (padding . 1) 2864 (stretchability . 5)) 2865@end example 2866 2867One way to bring the staves closer together is by reducing the 2868value of the @code{basic-distance} key (@code{9}) to match the 2869value of @code{minimum-distance} (@code{7}). To modify a single 2870key individually, use a @emph{nested declaration}: 2871 2872@lilypond[quote,verbatim] 2873% default space between staves 2874\new PianoStaff << 2875 \new Staff { \clef treble c''1 } 2876 \new Staff { \clef bass c1 } 2877>> 2878 2879% reduced space between staves 2880\new PianoStaff \with { 2881 % this is the nested declaration 2882 \override StaffGrouper.staff-staff-spacing.basic-distance = #7 2883} << 2884 \new Staff { \clef treble c''1 } 2885 \new Staff { \clef bass c1 } 2886>> 2887@end lilypond 2888 2889Using a nested declaration will update the specified key (such as 2890@code{basic-distance} in the above example) without altering any 2891other keys already set for the same property. 2892 2893Now suppose we want the staves to be as close as possible without 2894overlapping. The simplest way to do this is to set all four alist 2895keys to zero. However, it is not necessary to enter four nested 2896declarations, one for each key. Instead, the property can be 2897completely re-defined with one declaration, as an alist: 2898 2899@lilypond[quote,verbatim] 2900\new PianoStaff \with { 2901 \override StaffGrouper.staff-staff-spacing = 2902 #'((basic-distance . 0) 2903 (minimum-distance . 0) 2904 (padding . 0) 2905 (stretchability . 0)) 2906} << 2907 \new Staff { \clef treble c''1 } 2908 \new Staff { \clef bass c1 } 2909>> 2910@end lilypond 2911 2912Note that any keys not explicitly listed in the alist definition 2913will be reset to their @emph{default-when-unset} values. In the 2914case of @code{staff-staff-spacing}, any unset key-values would be 2915reset to zero (except @code{stretchability}, which takes the value 2916of @code{basic-distance} when unset). Thus the following two 2917declarations are equivalent: 2918 2919@example 2920\override StaffGrouper.staff-staff-spacing = 2921 #'((basic-distance . 7)) 2922 2923\override StaffGrouper.staff-staff-spacing = 2924 #'((basic-distance . 7) 2925 (minimum-distance . 0) 2926 (padding . 0) 2927 (stretchability . 7)) 2928@end example 2929 2930One (possibly unintended) consequence of this is the removal of 2931any standard settings that are set in an initialization file and 2932loaded each time an input file is compiled. In the above example, 2933the standard settings for @code{padding} and 2934@code{minimum-distance} (defined in @file{scm/define-grobs.scm}) 2935are reset to their default-when-unset values (zero for both keys). 2936Defining a property or variable as an alist (of any size) will 2937always reset all unset key-values to their default-when-unset 2938values. Unless this is the intended result, it is safer to update 2939key-values individually with a nested declaration. 2940 2941@warning{Nested declarations will not work for context property 2942alists (such as @code{beamExceptions}, @code{keyAlterations}, 2943@code{timeSignatureSettings}, etc.). These properties can only be 2944modified by completely re-defining them as alists.} 2945 2946 2947@node Useful concepts and properties 2948@section Useful concepts and properties 2949 2950 2951@menu 2952* Input modes:: 2953* Direction and placement:: 2954* Distances and measurements:: 2955* Dimensions:: 2956* Staff symbol properties:: 2957* Spanners:: 2958* Visibility of objects:: 2959* Line styles:: 2960* Rotating objects:: 2961@end menu 2962 2963@node Input modes 2964@subsection Input modes 2965 2966The way in which the notation contained within an input file is 2967interpreted is determined by the current input mode. In general, 2968there are two ways of specifying the mode: a long form, e.g. 2969@code{\chordmode}, and a short form, e.g. @code{\chords}. The long 2970form is typically used when supplying input to a variable or when 2971entering input directly into an explicitly created context. The short 2972form implicitly creates a context of the correct type for the input and 2973passes the input directly to it. It is useful in simple situations 2974when there is no requirement to explicitly create the receiving context. 2975 2976@subsubsubheading Chord mode 2977 2978@funindex \chordmode 2979@funindex \chords 2980 2981This is activated with the @code{\chordmode} command, and causes 2982input to be interpreted with the syntax of chord notation, see 2983@ref{Chord notation}. Music in chord mode is rendered as chords on a staff 2984when entered into a @code{Staff} context, as chord names when entered 2985into a @code{ChordNames} context or as fretboards when entered into 2986a @code{FretBoards} context. 2987 2988Chord mode is also activated with the @code{\chords} command. This 2989also causes the following input to be interpreted with the syntax of 2990chord notation but in addition it implicitly creates a new 2991@code{ChordNames} context and renders the input into it as chord names, 2992see @ref{Printing chord names}. 2993 2994@subsubsubheading Drum mode 2995 2996@funindex \drummode 2997@funindex \drums 2998 2999This is activated with the @code{\drummode} command, and causes 3000input to be interpreted with the syntax of drum notation, see 3001@ref{Basic percussion notation}. Music in drum mode is rendered as 3002percussion notes when entered into a @code{DrumStaff} context. 3003 3004Drum mode is also activated with the @code{\drums} command. This 3005also causes the following input to be interpreted with the syntax of 3006drum notation but in addition it implicitly creates a new 3007@code{DrumStaff} context and renders the input into it as percussion 3008notes, see @ref{Basic percussion notation}. 3009 3010@subsubsubheading Figure mode 3011 3012@funindex \figuremode 3013@funindex \figures 3014 3015This is activated with the @code{\figuremode} command, and causes 3016input to be interpreted with the syntax of figured bass, see 3017@ref{Entering figured bass}. Music in figure mode is rendered as 3018figured bass when entered into a @code{FiguredBass} context or a 3019@code{Staff} context. 3020 3021Figure mode is also activated with the @code{\figures} command. 3022This also causes the following input to be interpreted with the 3023figured bass syntax but in addition it implicitly creates a new 3024@code{FiguredBass} context and renders the input into it as figured 3025bass, see @ref{Introduction to figured bass}. 3026 3027@subsubsubheading Fret and tab modes 3028 3029There are no special input modes for entering fret and tab symbols. 3030 3031To create tab diagrams, enter notes or chords in note mode and 3032render them in a @code{TabStaff} context, see 3033@ref{Default tablatures}. 3034 3035To create fret diagrams above a staff, enter notes or chords in either 3036note mode or chord mode and render them in a @code{FretBoards} context, 3037see @ref{Automatic fret diagrams}. Alternatively, fret diagrams can be 3038entered as markup above the notes using the @code{\fret-diagram} 3039command, see @ref{Fret diagram markups}. 3040 3041@subsubsubheading Lyrics mode 3042 3043@funindex \lyricmode 3044@funindex \lyrics 3045 3046This is activated with the @code{\lyricmode} command, and causes 3047input to be interpreted as lyric syllables with optional durations 3048and associated lyric modifiers, see @ref{Vocal music}. Input in 3049lyric mode is rendered as lyric syllables when entered into a 3050@code{Lyrics} context. 3051 3052Lyric mode is also activated with the @code{\lyrics} command. This 3053also causes the following input to be interpreted as lyric syllables 3054but in addition it implicitly creates a new @code{Lyrics} context and 3055renders the input into it as lyric syllables. 3056 3057Lyric mode is also activated with the @code{\addlyrics} command. This 3058also implicitly creates a new @code{Lyrics} context and in addition it 3059adds an implicit @code{\lyricsto} command which associates the following 3060lyrics with the preceding music, see @ref{Automatic syllable durations}. 3061 3062@subsubsubheading Markup mode 3063 3064@funindex \markup 3065 3066This is activated with the @code{\markup} command, and causes 3067input to be interpreted with the syntax of markup, see 3068@ref{Text markup commands}. 3069 3070@subsubsubheading Note mode 3071 3072@funindex \notemode 3073 3074This is the default mode or it may be activated with the 3075@code{\notemode} command. Input is interpreted as pitches, 3076durations, markup, etc and typeset as musical notation on a staff. 3077 3078It is not normally necessary to specify note mode explicitly, but 3079it may be useful to do so in certain situations, for example if you 3080are in lyric mode, chord mode or any other mode and want to insert 3081something that only can be done with note mode syntax. 3082 3083 3084@node Direction and placement 3085@subsection Direction and placement 3086 3087In typesetting music the direction and placement of many items is 3088a matter of choice. For example, the stems of notes can 3089be directed up or down; lyrics, dynamics, and other expressive 3090marks may be placed above or below the staff; text may be aligned 3091left, right or center; etc. Most of these choices may be left to 3092be determined automatically by LilyPond, but in some cases it may 3093be desirable to force a particular direction or placement. 3094 3095@menu 3096* Articulation direction indicators:: 3097* The direction property:: 3098@end menu 3099 3100 3101@node Articulation direction indicators 3102@unnumberedsubsubsec Articulation direction indicators 3103 3104By default some directions are always up or always down (e.g., 3105dynamics or fermata), while other things can alternate between 3106up or down based on the stem direction (like slurs or accents). 3107 3108@c TODO Add table showing these 3109 3110The default action may be overridden by prefixing the articulation 3111by a @emph{direction indicator}. Three direction indicators are 3112available: @code{^} (meaning @qq{up}), @code{_} (meaning @qq{down}) 3113and @code{-} (meaning @qq{use default direction}). The direction 3114indicator can usually be omitted, in which case @code{-} is assumed, 3115but a direction indicator is @strong{always} required before 3116 3117@itemize 3118@item @code{\tweak} commands 3119@item @code{\markup} commands 3120@item @code{\tag} commands 3121@item string markups, e.g., -"string" 3122@item fingering instructions, e.g., @w{@code{-1}} 3123@item articulation shortcuts, e.g., @w{@code{-.}}, @w{@code{->}}, @w{@code{--}} 3124@end itemize 3125 3126Direction indicators affect only the next note: 3127 3128@lilypond[verbatim,quote] 3129\relative { 3130 c''2( c) 3131 c2_( c) 3132 c2( c) 3133 c2^( c) 3134} 3135@end lilypond 3136 3137 3138@node The direction property 3139@unnumberedsubsubsec The direction property 3140 3141The position or direction of many layout objects is controlled by the 3142@code{direction} property. 3143 3144The value of the @code{direction} property may be set to @code{1}, 3145meaning @qq{up} or @qq{above}, or to @w{@code{-1}}, meaning @qq{down} or 3146@qq{below}. The symbols @code{UP} and @code{DOWN} may be used instead 3147of @code{1} and @w{@code{-1}} respectively. The default direction may 3148be specified by setting @code{direction} to @code{0} or @code{CENTER}. 3149Alternatively, in many cases predefined commands exist to specify the 3150direction. These are of the form 3151 3152@example 3153\@var{xxx}Up, \@var{xxx}Down or \@var{xxx}Neutral 3154@end example 3155 3156@noindent 3157where @code{\@var{xxx}Neutral} means @qq{use the default} direction. 3158See @rlearning{Within-staff objects}. 3159 3160In a few cases, arpeggio for example, the value of the @code{direction} 3161property can specify whether the object is to be placed to the right or 3162left of the parent. In this case @w{@code{-1}} or @code{LEFT} means 3163@qq{to the left} and @code{1} or @code{RIGHT} means @qq{to the right}. 3164@code{0} or @code{CENTER} means @qq{use the default} direction. 3165 3166@ignore 3167These all have side-axis set to #X 3168AmbitusAccidental - direction has no effect 3169Arpeggio - works 3170StanzaNumber - not tried 3171TrillPitchAccidental - not tried 3172TrillPitchGroup - not tried 3173@end ignore 3174 3175These indications affect all notes until they are canceled. 3176 3177@lilypond[verbatim,quote] 3178\relative { 3179 c''2( c) 3180 \slurDown 3181 c2( c) 3182 c2( c) 3183 \slurNeutral 3184 c2( c) 3185} 3186@end lilypond 3187 3188In polyphonic music, it is generally better to specify an explicit 3189@code{voice} than change an object's direction. For more information, 3190see @ref{Multiple voices}. 3191 3192@morerefs 3193Learning Manual: 3194@rlearning{Within-staff objects}. 3195 3196Notation Reference: 3197@ref{Multiple voices}. 3198 3199 3200@node Distances and measurements 3201@subsection Distances and measurements 3202 3203@cindex distance, absolute 3204@cindex distance, scaled 3205 3206@funindex \mm 3207@funindex \cm 3208@funindex \in 3209@funindex \pt 3210 3211Distances in LilyPond are of two types: absolute and scaled. 3212 3213@funindex \staff-space 3214 3215Absolute distances are used for specifying margins, indents, and 3216other page layout details, and are by default specified in 3217millimeters. Distances may be specified in other units by 3218following the quantity by @code{\mm}, @code{\cm}, 3219@code{\in}@tie{}(inches), or @code{\pt}@tie{}(points, 1/72.27 of 3220an inch). Page layout distances can also be specified in scalable 3221units (see the following paragraph) by appending 3222@code{\staff-space} to the quantity. Page layout is described in 3223detail in @ref{Page layout}. 3224 3225Scaled distances are always specified in units of the staff-space 3226or, rarely, the half staff-space. The staff-space is the distance 3227between two adjacent staff lines. The default value can be changed 3228globally by setting the global staff size, or it can be overridden 3229locally by changing the @code{staff-space} property of 3230@code{StaffSymbol}. Scaled distances automatically scale with any 3231change to the either the global staff size or the 3232@code{staff-space} property of @code{StaffSymbol}, but fonts scale 3233automatically only with changes to the global staff size. 3234The global staff size thus enables the overall size of a rendered 3235score to be easily varied. For the methods of setting the global 3236staff size see @ref{Setting the staff size}. 3237 3238@funindex magstep 3239 3240If just a section of a score needs to be rendered to a different 3241scale, for example an ossia section or a footnote, the global staff 3242size cannot simply be changed as this would affect the entire score. 3243In such cases the change in size is made by overriding both the 3244@code{staff-space} property of @code{StaffSymbol} and the size of 3245the fonts. A Scheme function, @code{magstep}, is available to 3246convert from a font size change to the equivalent change in 3247@code{staff-space}. For an explanation and an example of its use, 3248see @rlearning{Length and thickness of objects}. 3249 3250@morerefs 3251Learning Manual: 3252@rlearning{Length and thickness of objects}. 3253 3254Notation Reference: 3255@ref{Page layout}, 3256@ref{Setting the staff size}. 3257 3258 3259@node Dimensions 3260@subsection Dimensions 3261 3262@cindex dimension 3263@cindex bounding box 3264 3265The dimensions of a graphical object specify the positions of the left 3266and right edges and the bottom and top edges of the objects' bounding 3267box as distances from the objects' reference point in units of 3268staff-spaces. These positions are usually coded as two Scheme pairs. 3269For example, the text markup command @code{\with-dimensions} takes 3270three arguments, the first two of which are a Scheme pair giving the 3271left and right edge positions and a Scheme pair giving the bottom and 3272top edge positions: 3273 3274@example 3275\with-dimensions #'(-5 . 10) #'(-3 . 15) @var{arg} 3276@end example 3277 3278This specifies a bounding box for @var{arg} with its left edge at -5, 3279its right edge at 10, its bottom edge at -3 and its top edge at 15, 3280all measured from the objects' reference point in units of 3281staff-spaces. 3282 3283@morerefs 3284Notation Reference: 3285@ref{Distances and measurements}. 3286 3287 3288@node Staff symbol properties 3289@subsection Staff symbol properties 3290 3291@cindex adjusting staff symbol 3292@cindex drawing staff symbol 3293@cindex staff symbol, setting of 3294 3295@c TODO Extend or remove this section. See also NR 1.6.2 Staff symbol 3296@c Need to think of uses for these properties. Eg 'line-positions 3297@c is used in a snippet to thicken centre line. 3298@c If retained, add @ref to here in 1.6.2 -td 3299 3300The vertical position of staff lines and the number of staff lines 3301can be defined at the same time. As the following example shows, 3302note positions are not influenced by the staff line positions. 3303 3304@warning{The @code{'line-positions} property overrides the 3305@code{'line-count} property. The number of staff lines is 3306implicitly defined by the number of elements in the list of values 3307for @code{'line-positions}.} 3308 3309@lilypond[verbatim,quote] 3310\new Staff \with { 3311 \override StaffSymbol.line-positions = #'(7 3 0 -4 -6 -7) 3312} 3313\relative { a4 e' f b | d1 } 3314@end lilypond 3315 3316The width of a staff can be modified. The units are staff 3317spaces. The spacing of objects inside the staff is not affected by 3318this setting. 3319 3320@lilypond[verbatim,quote] 3321\new Staff \with { 3322 \override StaffSymbol.width = #23 3323} 3324\relative { a4 e' f b | d1 } 3325@end lilypond 3326 3327 3328@node Spanners 3329@subsection Spanners 3330 3331Many objects of musical notation extend over several notes or even 3332several bars. Examples are slurs, beams, tuplet brackets, volta 3333repeat brackets, crescendi, trills, and glissandi. Such objects 3334are collectively called @qq{spanners}, and have special properties to control 3335their appearance and behaviour. Some of these properties are common 3336to all spanners; others are restricted to a sub-set of the spanners. 3337 3338All spanners support the @code{spanner-interface}. A few, essentially 3339those that draw a straight line between the two objects, support in 3340addition the @code{line-spanner-interface}. 3341 3342@menu 3343* Using the spanner-interface:: 3344* Using the line-spanner-interface:: 3345@end menu 3346 3347@node Using the spanner-interface 3348@unnumberedsubsubsec Using the @code{spanner-interface} 3349 3350This interface provides two properties that apply to several spanners. 3351 3352@subsubsubheading The @code{minimum-length} property 3353 3354The minimum length of the spanner is specified by the 3355@code{minimum-length} property. Increasing this usually has the 3356necessary effect of increasing the spacing of the notes between the 3357two end points. However, this override has no effect on 3358many spanners, as their length is determined by other considerations. 3359A few examples where it is effective are shown below. 3360 3361@ignore 3362Works for: 3363 Tie 3364 MultiMeasureRest 3365 Hairpin 3366 Slur 3367 PhrasingSlur 3368 3369Works as long as callback is made: 3370 Glissando 3371 Beam 3372 3373Works not at all for: 3374 LyricSpace 3375 LyricHyphen 3376 LyricExtender 3377 TextSpanner 3378 System 3379 3380@end ignore 3381 3382@lilypond[verbatim,quote,fragment] 3383a'~ a' 3384a' 3385% increase the length of the tie 3386-\tweak minimum-length #5 3387~ a' 3388@end lilypond 3389 3390@lilypond[verbatim,quote] 3391\relative \compressMMRests { 3392 a'1 3393 R1*23 3394 % increase the length of the rest bar 3395 \once \override MultiMeasureRest.minimum-length = #20 3396 R1*23 3397 a1 3398} 3399@end lilypond 3400 3401@lilypond[verbatim,quote] 3402\relative { 3403 a' \< a a a \! 3404 % increase the length of the hairpin 3405 \override Hairpin.minimum-length = #20 3406 a \< a a a \! 3407} 3408@end lilypond 3409 3410This override can also be used to increase the length of slurs and 3411phrasing slurs: 3412 3413@lilypond[verbatim,quote] 3414\relative { 3415 a'( g) 3416 a 3417 -\tweak minimum-length #5 3418 ( g) 3419 3420 a\( g\) 3421 a 3422 -\tweak minimum-length #5 3423 \( g\) 3424} 3425@end lilypond 3426 3427For some layout objects, the @code{minimum-length} property becomes 3428effective only if the @code{set-spacing-rods} procedure is called 3429explicitly. To do this, the @code{springs-and-rods} property should 3430be set to @code{ly:spanner::set-spacing-rods}. For example, 3431the minimum length of a glissando has no effect unless the 3432@code{springs-and-rods} property is set: 3433 3434@lilypond[verbatim,fragment,quote] 3435% default 3436e' \glissando c'' 3437 3438% not effective alone 3439\once \override Glissando.minimum-length = #20 3440e' \glissando c'' 3441 3442% effective only when both overrides are present 3443\once \override Glissando.minimum-length = #20 3444\once \override Glissando.springs-and-rods = 3445 #ly:spanner::set-spacing-rods 3446e' \glissando c'' 3447@end lilypond 3448 3449The same is true of the @code{Beam} object: 3450 3451@lilypond[verbatim,fragment,quote] 3452% not effective alone 3453\once \override Beam.minimum-length = #20 3454e'8 e' e' e' 3455 3456% effective only when both overrides are present 3457\once \override Beam.minimum-length = #20 3458\once \override Beam.springs-and-rods = 3459 #ly:spanner::set-spacing-rods 3460e'8 e' e' e' 3461@end lilypond 3462 3463@subsubsubheading The @code{to-barline} property 3464 3465The second useful property of the @code{spanner-interface} is 3466@code{to-barline}. By default this is true, causing hairpins and 3467other spanners which are terminated on the first note of a measure to 3468end instead on the immediately preceding bar line. If set to false, 3469the spanner will extend beyond the bar line and end on the note 3470itself: 3471 3472@lilypond[verbatim,quote] 3473\relative { 3474 a' \< a a a a \! a a a \break 3475 \override Hairpin.to-barline = ##f 3476 a \< a a a a \! a a a 3477} 3478@end lilypond 3479 3480This property is not effective for all spanners. For example, 3481setting it to @code{#t} has no effect on slurs or phrasing slurs 3482or on other spanners for which terminating on the bar line would 3483not be meaningful. 3484 3485@node Using the line-spanner-interface 3486@unnumberedsubsubsec Using the @code{line-spanner-interface} 3487 3488Objects which support the @code{line-spanner-interface} include 3489 3490@itemize 3491@item @code{DynamicTextSpanner} 3492@item @code{Glissando} 3493@item @code{TextSpanner} 3494@item @code{TrillSpanner} 3495@item @code{VoiceFollower} 3496@end itemize 3497 3498The routine responsible for drawing the stencils for these spanners is 3499@code{ly:line-spanner::print}. This routine determines the 3500exact location of the two end points and draws a line 3501between them, in the style requested. The locations of the two 3502end points of the spanner are computed on-the-fly, but it is 3503possible to override their Y-coordinates. The 3504properties which need to be specified are nested 3505two levels down within the property hierarchy, but the syntax of 3506the @code{\override} command is quite simple: 3507 3508@lilypond[quote,fragment,verbatim] 3509e''2 \glissando b' 3510\once \override Glissando.bound-details.left.Y = #3 3511\once \override Glissando.bound-details.right.Y = #-2 3512e''2 \glissando b' 3513@end lilypond 3514 3515The units for the @code{Y} property are @code{staff-space}s, 3516with the center line of the staff being the zero point. 3517For the glissando, this is the value for @code{Y} at the 3518X-coordinate corresponding to the center point of each note head, 3519if the line is imagined to be extended to there. 3520 3521If @code{Y} is not set, the value is computed from the vertical 3522position of the corresponding attachment point of the spanner. 3523 3524In case of a line break, the values for the end points are 3525specified by the @code{left-broken} and @code{right-broken} 3526sub-lists of @code{bound-details}. For example: 3527 3528@lilypond[ragged-right,fragment,verbatim,quote] 3529\override Glissando.breakable = ##t 3530\override Glissando.bound-details.right-broken.Y = #-3 3531c''1 \glissando \break 3532f''1 3533@end lilypond 3534 3535 3536A number of further properties of the @code{left} and 3537@code{right} sub-lists of the @code{bound-details} property 3538may be modified in the same way as @code{Y}: 3539 3540@table @code 3541@item Y 3542This sets the Y-coordinate of the end point, in @code{staff-space}s 3543offset from the staff center line. By default, it is the center of 3544the bound object, so a glissando points to the vertical center of 3545the note head. 3546 3547For horizontal spanners, such as text spanners and trill spanners, 3548it is hardcoded to 0. 3549 3550@item attach-dir 3551This determines where the line starts and ends in the X-direction, 3552relative to the bound object. So, a value of @w{@code{-1}} (or 3553@code{LEFT}) makes the line start/end at the left side of the note 3554head it is attached to. 3555 3556@item X 3557This is the absolute X-coordinate of the end point. It is usually 3558computed on the fly, and overriding it has little useful effect. 3559 3560@item stencil 3561Line spanners may have symbols at the beginning or end, which is 3562contained in this sub-property. This is for internal use; it is 3563recommended that @code{text} be used instead. 3564 3565@item text 3566This is a markup that is evaluated to yield the stencil. It is used 3567to put @i{cresc.}, @i{tr} and other text on horizontal spanners. 3568 3569@lilypond[quote,ragged-right,fragment,verbatim] 3570\override TextSpanner.bound-details.left.text 3571 = \markup { \small \bold Slower } 3572\relative { c''2\startTextSpan b c a\stopTextSpan } 3573@end lilypond 3574 3575@item stencil-align-dir-y 3576@item stencil-offset 3577Without setting one of these, the stencil is simply put at the 3578end-point, centered on the line, as defined by the @code{X} and 3579@code{Y} sub-properties. Setting either @code{stencil-align-dir-y} 3580or @code{stencil-offset} will move the symbol at the edge vertically 3581relative to the end point of the line: 3582 3583@lilypond[quote,fragment,verbatim] 3584\override TextSpanner.bound-details 3585 .left.stencil-align-dir-y = #-2 3586\override TextSpanner.bound-details 3587 .right.stencil-align-dir-y = #UP 3588 3589\override TextSpanner.bound-details.left.text = "ggg" 3590\override TextSpanner.bound-details.right.text = "hhh" 3591 3592\relative { c'4^\startTextSpan c c c \stopTextSpan } 3593@end lilypond 3594 3595Note that negative values move the text @emph{up}, contrary to the 3596effect that might be expected, as a value of @w{@code{-1}} or 3597@code{DOWN} means align the @emph{bottom} edge of the text with 3598the spanner line. A value of @code{1} or @code{UP} aligns 3599the top edge of the text with the spanner line. 3600 3601@item arrow 3602Setting this sub-property to @code{#t} produces an arrowhead at the 3603end-points of the line. 3604 3605@item padding 3606This sub-property controls the space between the specified 3607end point of the line and the actual end. Without padding, a 3608glissando would start and end in the center of each note head. 3609 3610@end table 3611 3612@funindex \endSpanners 3613 3614The music function @code{\endSpanners} terminates the spanner 3615which starts on the immediately following note prematurely. It 3616is terminated after exactly one note, or at the following bar line 3617if @code{to-barline} is true and a bar line occurs before the next 3618note. 3619 3620@lilypond[verbatim,quote,ragged-right] 3621\relative c'' { 3622 \endSpanners 3623 c2 \startTextSpan c2 c2 3624 \endSpanners 3625 c2 \< c2 c2 3626} 3627@end lilypond 3628 3629When using @code{\endSpanners} it is not necessary to close 3630\startTextSpan with \stopTextSpan, nor is it necessary to close 3631hairpins with @code{\!}. 3632 3633@morerefs 3634Internals Reference: 3635@rinternals{TextSpanner}, 3636@rinternals{Glissando}, 3637@rinternals{VoiceFollower}, 3638@rinternals{TrillSpanner}, 3639@rinternals{line-spanner-interface}. 3640 3641 3642@node Visibility of objects 3643@subsection Visibility of objects 3644 3645@cindex object, visibility of 3646@cindex grob, visibility of 3647@cindex visibility of object 3648 3649There are four main ways in which the visibility of layout objects 3650can be controlled: their stencil can be removed, they can be made 3651transparent, they can be colored white, or their 3652@code{break-visibility} property can be overridden. The first 3653three apply to all layout objects; the last to just a few -- the 3654@emph{breakable} objects. The Learning Manual introduces these 3655four techniques, see @rlearning{Visibility and color of objects}. 3656 3657There are also a few other techniques which are specific to 3658certain layout objects. These are covered under Special 3659considerations. 3660 3661@menu 3662* Removing the stencil:: 3663* Making objects transparent:: 3664* Painting objects white:: 3665* Using break-visibility:: 3666* Special considerations:: 3667@end menu 3668 3669 3670@node Removing the stencil 3671@unnumberedsubsubsec Removing the stencil 3672 3673@cindex stencil, removing 3674@funindex \omit 3675 3676Every layout object has a stencil property. By default this is set 3677to the specific function which draws that object. If this property 3678is overridden to @code{#f} no function will be called and the object 3679will not be drawn. The default action can be recovered with 3680@code{\revert}. 3681 3682@lilypond[quote,fragment,verbatim] 3683a1 a 3684\override Score.BarLine.stencil = ##f 3685a a 3686\revert Score.BarLine.stencil 3687a a a 3688@end lilypond 3689 3690This rather common operation has a shortcut @code{\omit}: 3691 3692@lilypond[quote,fragment,verbatim] 3693a1 a 3694\omit Score.BarLine 3695a a 3696\undo \omit Score.BarLine 3697a a a 3698@end lilypond 3699 3700@node Making objects transparent 3701@unnumberedsubsubsec Making objects transparent 3702 3703@cindex transparent, making objects 3704@funindex \hide 3705 3706Every layout object has a transparent property which by default is 3707set to @code{#f}. If set to @code{#t} the object still occupies 3708space but is made invisible. 3709 3710@lilypond[quote,fragment,verbatim] 3711a'4 a' 3712\once \override NoteHead.transparent = ##t 3713a' a' 3714@end lilypond 3715 3716This rather common operation has a shortcut @code{\hide}: 3717 3718@lilypond[quote,fragment,verbatim] 3719a'4 a' 3720\once \hide NoteHead 3721a' a' 3722@end lilypond 3723 3724@node Painting objects white 3725@unnumberedsubsubsec Painting objects white 3726 3727@cindex object, coloring 3728@cindex coloring object 3729@cindex layer 3730@cindex printing order 3731@cindex overwriting object 3732@cindex object, overwriting 3733@cindex grob, overwriting 3734 3735Every layout object has a color property which by default is set 3736to @code{black}. If this is overridden to @code{white} the object 3737will be indistinguishable from the white background. However, 3738if the object crosses other objects the color of the crossing 3739points will be determined by the order in which they are drawn, 3740and this may leave a ghostly image of the white object, as shown 3741here: 3742 3743@lilypond[quote,fragment,verbatim] 3744\override Staff.Clef.color = #white 3745a'1 3746@end lilypond 3747 3748This may be avoided by changing the order of printing the objects. 3749All layout objects have a @code{layer} property which should be set 3750to an integer. Objects with the lowest value of @code{layer} are 3751drawn first, then objects with progressively higher values are drawn, 3752so objects with higher values overwrite objects with lower values. 3753By default most objects are assigned a @code{layer} value of 3754@code{1}, although a few objects, including @code{StaffSymbol} and 3755@code{BarLine}, are assigned a value of @code{0}. The order of 3756printing objects with the same value of @code{layer} is indeterminate. 3757 3758In the example above the white clef, with a default @code{layer} 3759value of @code{1}, is drawn after the staff lines (default 3760@code{layer} value @code{0}), so overwriting them. To change this, 3761the @code{Clef} object must be given in a lower value of 3762@code{layer}, say @w{@code{-1}}, so that it is drawn earlier: 3763 3764@lilypond[quote,fragment,verbatim] 3765\override Staff.Clef.color = #white 3766\override Staff.Clef.layer = #-1 3767a'1 3768@end lilypond 3769 3770@node Using break-visibility 3771@unnumberedsubsubsec Using break-visibility 3772 3773@c TODO Add making other objects breakable 3774 3775@funindex break-visibility 3776 3777Most layout objects are printed only once, but some like 3778bar lines, clefs, time signatures and key signatures, may need 3779to be printed twice when a line break occurs -- once at the end 3780of the line and again at the start of the next line. Such 3781objects are called @emph{breakable}, and have a property, the 3782@code{break-visibility} property to control their visibility 3783at the three positions in which they may appear -- at the 3784start of a line, within a line if they are changed, and at the 3785end of a line if a change takes place there. 3786 3787For example, the time signature 3788by default will be printed at the start of the first line, but 3789nowhere else unless it changes, when it will be printed at the 3790point at which the change occurs. If this change occurs at the 3791end of a line the new time signature will be printed at the start 3792of the next line and a cautionary time signature will be printed 3793at the end of the previous line as well. 3794 3795This behaviour is controlled by the @code{break-visibility} 3796property, which is explained in 3797@c Leave this ref on a newline - formats incorrectly otherwise -td 3798@rlearning{Visibility and color of objects}. This property takes 3799a vector of three booleans which, in order, determine whether the 3800object is printed at the end of, within the body of, or at the 3801beginning of a line. Or to be more precise, before a line break, 3802where there is no line break, or after a line break. 3803 3804Alternatively, these eight combinations may be specified 3805by pre-defined functions, defined in @file{scm/output-lib.scm}, 3806where the last three columns indicate whether the layout objects 3807will be visible in the positions shown at the head of the columns: 3808 3809@multitable {@code{begin-of-line-invisible}} {@code{#(#t #t #t)}} {Before} {At no} {After} 3810@headitem Function @tab Vector @tab Before @tab At no @tab After 3811@headitem form @tab form @tab break @tab break @tab break 3812 3813@item @code{all-visible} @tab @code{#(#t #t #t)} @tab yes @tab yes @tab yes 3814@item @code{begin-of-line-visible} @tab @code{#(#f #f #t)} @tab no @tab no @tab yes 3815@item @code{center-visible} @tab @code{#(#f #t #f)} @tab no @tab yes @tab no 3816@item @code{end-of-line-visible} @tab @code{#(#t #f #f)} @tab yes @tab no @tab no 3817@item @code{begin-of-line-invisible} @tab @code{#(#t #t #f)} @tab yes @tab yes @tab no 3818@item @code{center-invisible} @tab @code{#(#t #f #t)} @tab yes @tab no @tab yes 3819@item @code{end-of-line-invisible} @tab @code{#(#f #t #t)} @tab no @tab yes @tab yes 3820@item @code{all-invisible} @tab @code{#(#f #f #f)} @tab no @tab no @tab no 3821@end multitable 3822 3823The default settings of @code{break-visibility} depend on the 3824layout object. The following table shows all the layout objects 3825of interest which are affected by @code{break-visibility} and the 3826default setting of this property: 3827 3828@multitable @columnfractions .3 .3 .4 3829 3830@headitem Layout object @tab Usual context @tab Default setting 3831 3832@c omit Ambitus as it appears not to be affected by break-visibility -td 3833@c @item @code{Ambitus} @tab as specified @tab @code{begin-of-line-visible} 3834@item @code{BarLine} @tab @code{Score} @tab calculated 3835@item @code{BarNumber} @tab @code{Score} @tab @code{begin-of-line-visible} 3836@c omit the following item until it can be explained -td 3837@c @item @code{BreakAlignGroup} @tab @code{Score} @tab calculated 3838@item @code{BreathingSign} @tab @code{Voice} @tab @code{begin-of-line-invisible} 3839@item @code{Clef} @tab @code{Staff} @tab @code{begin-of-line-visible} 3840@item @code{Custos} @tab @code{Staff} @tab @code{end-of-line-visible} 3841@item @code{DoublePercentRepeat} @tab @code{Voice} @tab @code{begin-of-line-invisible} 3842@item @code{KeyCancellation} @tab @code{Staff} @tab @code{begin-of-line-invisible} 3843@item @code{KeySignature} @tab @code{Staff} @tab @code{begin-of-line-visible} 3844@c omit LeftEdge until it can be explained -td 3845@c @item @code{LeftEdge} @tab @code{Score} @tab @code{center-invisible} 3846@item @code{ClefModifier} @tab @code{Staff} @tab @code{begin-of-line-visible} 3847@item @code{RehearsalMark} @tab @code{Score} @tab @code{end-of-line-invisible} 3848@item @code{TimeSignature} @tab @code{Staff} @tab @code{all-visible} 3849 3850@end multitable 3851 3852The example below shows the use of the vector form to control the 3853visibility of bar lines: 3854 3855@lilypond[quote,verbatim,ragged-right] 3856\relative { 3857 f'4 g a b 3858 f4 g a b 3859 % Remove bar line at the end of the current line 3860 \once \override Score.BarLine.break-visibility = ##(#f #t #t) 3861 \break 3862 f4 g a b 3863 f4 g a b 3864} 3865@end lilypond 3866 3867Although all three components of the vector used to override 3868@code{break-visibility} must be present, not all of them are 3869effective with every layout object, and some combinations may 3870even give errors. The following limitations apply: 3871 3872@itemize @bullet 3873@item Bar lines cannot be printed at the start of line. 3874 3875@item A bar number cannot be printed at the start of the @emph{first} 3876line unless it is set to be different from @code{1}. 3877 3878@item Clef -- see the next section. 3879 3880@item Double percent repeats are either @emph{all printed} or 3881@emph{all suppressed}. Use @code{begin-of-line-invisible} 3882to print them and @code{all-invisible} to suppress them. 3883 3884@item Key signature -- see the next section. 3885 3886@item ClefModifier -- see the next section. 3887@end itemize 3888 3889 3890@node Special considerations 3891@unnumberedsubsubsec Special considerations 3892 3893@subsubsubheading Visibility following explicit changes 3894 3895@cindex key signature, visibility following explicit change 3896@funindex explicitKeySignatureVisibility 3897@cindex clef, visibility following explicit change 3898@funindex explicitClefVisibility 3899 3900The @code{break-visibility} property controls the visibility of 3901key signatures and changes of clef only at the start of lines, 3902i.e., after a break. It has no effect on the visibility of the 3903key signature or clef following an explicit key change or an 3904explicit clef change within or at the end of a line. In the 3905following example the key signature following the explicit change 3906to B-flat major is still visible, even though @code{all-invisible} 3907is set. 3908 3909@lilypond[quote,verbatim,ragged-right] 3910\relative { 3911 \key g \major 3912 f'4 g a b 3913 % Try to remove all key signatures 3914 \override Staff.KeySignature.break-visibility = #all-invisible 3915 \key bes \major 3916 f4 g a b 3917 \break 3918 f4 g a b 3919 f4 g a b 3920} 3921@end lilypond 3922 3923The visibility of such explicit key signature and clef changes is 3924controlled by the @code{explicitKeySignatureVisibility} and 3925@code{explicitClefVisibility} properties. These are the equivalent 3926of the @code{break-visibility} property and both take a vector of 3927three booleans or the predefined functions listed above, exactly like 3928@code{break-visibility}. Both are properties of the Staff context, 3929not the layout objects themselves, and so they are set using the 3930@code{\set} command. Both are set by default to @code{all-visible}. 3931These properties control only the visibility of key signatures and 3932clefs resulting from explicit changes and do not affect key 3933signatures and clefs at the beginning of lines; 3934@code{break-visibility} must still be overridden in the appropriate 3935object to remove these. 3936 3937@lilypond[quote,verbatim,ragged-right] 3938\relative { 3939 \key g \major 3940 f'4 g a b 3941 \set Staff.explicitKeySignatureVisibility = #all-invisible 3942 \override Staff.KeySignature.break-visibility = #all-invisible 3943 \key bes \major 3944 f4 g a b \break 3945 f4 g a b 3946 f4 g a b 3947} 3948@end lilypond 3949 3950@subsubsubheading Visibility of cancelling accidentals 3951 3952To remove the cancelling accidentals printed at an explicit key 3953change, set the Staff context property @code{printKeyCancellation} 3954to @code{#f}: 3955 3956@lilypond[quote,verbatim,ragged-right] 3957\relative { 3958 \key g \major 3959 f'4 g a b 3960 \set Staff.explicitKeySignatureVisibility = #all-invisible 3961 \set Staff.printKeyCancellation = ##f 3962 \override Staff.KeySignature.break-visibility = #all-invisible 3963 \key bes \major 3964 f4 g a b \break 3965 f4 g a b 3966 f4 g a b 3967} 3968@end lilypond 3969 3970With these overrides only the accidentals before the notes remain 3971to indicate the change of key. 3972 3973Note that when changing the key to C@tie{}major or A@tie{}minor 3974the cancelling accidentals would be the @emph{only} indication of 3975the key change. In this case setting @code{printKeyCancellation} to 3976@code{#f} has no effect: 3977 3978@lilypond[quote,verbatim,ragged-right] 3979\relative { 3980 \key g \major 3981 f'4 g a b 3982 \set Staff.explicitKeySignatureVisibility = #all-invisible 3983 \set Staff.printKeyCancellation = ##f 3984 \key c \major 3985 f4 g a b \break 3986 f4 g a b 3987 f4 g a b 3988} 3989@end lilypond 3990 3991To suppress the cancelling accidentals even when the key is 3992changed to C@tie{}major or A@tie{}minor, override 3993the visibility of the @code{KeyCancellation} grob instead: 3994 3995@lilypond[quote,verbatim,ragged-right] 3996\relative { 3997 \key g \major 3998 f'4 g a b 3999 \set Staff.explicitKeySignatureVisibility = #all-invisible 4000 \override Staff.KeyCancellation.break-visibility = #all-invisible 4001 \key c \major 4002 f4 g a b \break 4003 f4 g a b 4004 f4 g a b 4005} 4006@end lilypond 4007 4008@c TODO Add visibility of cautionary accidentals before notes 4009 4010@subsubsubheading Automatic bars 4011 4012@funindex automaticBars 4013@cindex bar line, suppressing 4014 4015As a special case, the printing of bar lines can also be turned off 4016by setting the @code{automaticBars} property in the Score context. 4017If set to @code{#f}, bar lines will not be printed automatically; 4018they must be explicitly created with a @code{\bar} command. Unlike 4019the @code{\cadenzaOn} predefined command, measures are still counted. 4020Bar generation will resume according to that count if this property 4021is later set to @code{#t}. When set to @code{#f}, line breaks can 4022occur only at explicit @code{\bar} commands. 4023 4024@c TODO Add example 4025 4026@subsubsubheading Transposed clefs 4027 4028@cindex transposed clef, visibility of 4029@cindex visibility of transposed clef 4030@cindex clef, visibility of transposition 4031 4032The small transposition symbol on transposed clefs is produced by the 4033@code{ClefModifier} layout object. Its visibility is automatically 4034inherited from the @code{Clef} object, so it is not necessary to apply 4035any required @code{break-visibility} overrides to the @code{ClefModifier} 4036layout objects to suppress transposition symbols for invisible clefs. 4037 4038For explicit clef changes, the @code{explicitClefVisibility} 4039property controls both the clef symbol and any transposition symbol 4040associated with it. 4041 4042@morerefs 4043Learning Manual: 4044@rlearning{Visibility and color of objects}. 4045 4046 4047@node Line styles 4048@subsection Line styles 4049 4050Some performance indications, e.g., @i{rallentando} and 4051@i{accelerando} and @i{trills} are written as text and are 4052extended over many measures with lines, sometimes dotted or wavy. 4053 4054These all use the same routines as the glissando for drawing the 4055texts and the lines, and tuning their behavior is therefore also 4056done in the same way. It is done with a spanner, and the routine 4057responsible for drawing the spanners is 4058@code{ly:line-spanner::print}. This routine determines the 4059exact location of the two @i{span points} and draws a line 4060between them, in the style requested. 4061 4062Here is an example showing the different line styles available, 4063and how to tune them. 4064 4065@lilypond[ragged-right,verbatim,quote] 4066\relative { 4067 d''2 \glissando d'2 4068 \once \override Glissando.style = #'dashed-line 4069 d,2 \glissando d'2 4070 \override Glissando.style = #'dotted-line 4071 d,2 \glissando d'2 4072 \override Glissando.style = #'zigzag 4073 d,2 \glissando d'2 4074 \override Glissando.style = #'trill 4075 d,2 \glissando d'2 4076} 4077@end lilypond 4078 4079The locations of the end-points of the spanner are computed 4080on-the-fly for every graphic object, but it is possible to 4081override these: 4082 4083@c TODO Complete 4084@lilypond[ragged-right,verbatim,quote] 4085\relative { 4086 e''2 \glissando f 4087 \once \override Glissando.bound-details.right.Y = #-2 4088 e2 \glissando f 4089} 4090@end lilypond 4091 4092The value for @code{Y} is set to @w{@code{-2}} for the right end 4093point. The left side may be similarly adjusted by specifying 4094@code{left} instead of @code{right}. 4095 4096If @code{Y} is not set, the value is computed from the vertical 4097position of the left and right attachment points of the spanner. 4098 4099Other adjustments of spanners are possible, for details, see 4100@ref{Spanners}. 4101 4102@node Rotating objects 4103@subsection Rotating objects 4104 4105Both layout objects and elements of markup text can be rotated by 4106any angle about any point, but the method of doing so differs. 4107 4108@menu 4109* Rotating layout objects:: 4110* Rotating markup:: 4111@end menu 4112 4113@node Rotating layout objects 4114@unnumberedsubsubsec Rotating layout objects 4115 4116@cindex rotating object 4117@cindex object, rotating 4118 4119All layout objects which support the @code{grob-interface} can be 4120rotated by setting their @code{rotation} property. This takes a 4121list of three items: the angle of rotation counter-clockwise, 4122and the x and y coordinates of the point relative to the object's 4123reference point about which the rotation is to be performed. The 4124angle of rotation is specified in degrees and the coordinates in 4125staff-spaces. 4126 4127The angle of rotation and the coordinates of the rotation point must 4128be determined by trial and error. 4129 4130@cindex hairpin, angled 4131@cindex angled hairpin 4132 4133There are only a few situations where the rotation of layout 4134objects is useful; the following example shows one situation where 4135they may be: 4136 4137@lilypond[quote,fragment,verbatim] 4138g4\< e' d'' f''\! 4139\override Hairpin.rotation = #'(15 -1 0) 4140g4\< e' d'' f''\! 4141@end lilypond 4142 4143@node Rotating markup 4144@unnumberedsubsubsec Rotating markup 4145 4146All markup text can be rotated to lie at any angle by prefixing it 4147with the @code{\rotate} command. The command takes two arguments: 4148the angle of rotation in degrees counter-clockwise and the text to 4149be rotated. The extents of the text are not rotated: they take 4150their values from the extremes of the x and y coordinates of the 4151rotated text. In the following example the 4152@code{outside-staff-priority} property for text is set to @code{#f} 4153to disable the automatic collision avoidance, which would push some 4154of the text too high. 4155 4156@lilypond[quote,fragment,verbatim] 4157\override TextScript.outside-staff-priority = ##f 4158g4^\markup { \rotate #30 "a G" } 4159b^\markup { \rotate #30 "a B" } 4160des'^\markup { \rotate #30 "a D-Flat" } 4161fis'^\markup { \rotate #30 "an F-Sharp" } 4162@end lilypond 4163 4164@node Advanced tweaks 4165@section Advanced tweaks 4166 4167This section discusses various approaches to fine tuning the 4168appearance of the printed score. 4169 4170@menu 4171* Aligning objects:: 4172* Vertical grouping of grobs:: 4173* Modifying stencils:: 4174* Modifying shapes:: 4175* Modifying broken spanners:: 4176* Unpure-pure containers:: 4177@end menu 4178 4179@morerefs 4180Learning Manual: 4181@rlearning{Tweaking output}, 4182@rlearning{Other sources of information}. 4183 4184Notation Reference: 4185@ref{Explaining the Internals Reference}, 4186@ref{Modifying properties}. 4187 4188Extending LilyPond: 4189@rextend{Interfaces for programmers}. 4190 4191Installed Files: 4192@file{scm/define-grobs.scm}. 4193 4194Snippets: 4195@rlsr{Tweaks and overrides}. 4196 4197Internals Reference: 4198@rinternals{All layout objects}. 4199 4200 4201@node Aligning objects 4202@subsection Aligning objects 4203 4204Graphical objects which support the @code{self-alignment-interface} 4205and/or the @code{side-position-interface} can be aligned to a previously 4206placed object in a variety of ways. For a list of these objects, see 4207@rinternals{self-alignment-interface} and @rinternals{side-position-interface}. 4208 4209All graphical objects have a reference point, a horizontal extent and a 4210vertical extent. The horizontal extent is a pair of numbers 4211giving the displacements from the reference point of the left and 4212right edges, displacements to the left being negative. The vertical 4213extent is a pair of numbers giving the displacement from the reference 4214point to the bottom and top edges, displacements down being negative. 4215 4216An object's position on a staff is given by the values of the 4217@code{X-offset} and @code{Y-offset} properties. The value of 4218@code{X-offset} gives the displacement from the X coordinate of 4219the reference point of the parent object, and the value of 4220@code{Y-offset} gives the displacement from the center line of the 4221staff. The values of @code{X-offset} and @code{Y-offset} may 4222be set directly or may be set to be calculated by procedures in order 4223to achieve alignment with the parent object. 4224 4225@warning{Many objects have special positioning considerations which 4226cause any setting of @code{X-offset} or @code{Y-offset} to be 4227ignored or modified, even though the object supports the 4228@code{self-alignment-interface}. Overriding the @code{X-offset} 4229or @code{Y-offset} properties to a fixed value causes the respective 4230@code{self-alignment} property to be disregarded.} 4231 4232For example, an accidental can be repositioned vertically by setting 4233@code{Y-offset} but any changes to @code{X-offset} have no effect. 4234 4235Rehearsal marks may be aligned with breakable objects such as bar 4236lines, clef symbols, time signature symbols and key signatures. There 4237are special properties to be found in the @code{break-aligned-interface} 4238for positioning rehearsal marks on such objects. 4239 4240@morerefs 4241Notation Reference: 4242@ref{Using the break-alignable-interface}. 4243 4244Extending LilyPond: 4245@rextend{Callback functions}. 4246 4247@menu 4248* Setting X-offset and Y-offset directly:: 4249* Using the side-position-interface:: 4250* Using the self-alignment-interface:: 4251* Using the break-alignable-interface:: 4252@end menu 4253 4254@node Setting X-offset and Y-offset directly 4255@unnumberedsubsubsec Setting @code{X-offset} and @code{Y-offset} directly 4256 4257Numerical values may be given to the @code{X-offset} and @code{Y-offset} 4258properties of many objects. The following example shows three 4259notes with the default fingering position and the positions with @code{X-offset} 4260and @code{Y-offset} modified. 4261 4262@lilypond[verbatim,fragment,quote] 4263a'-3 4264a' 4265-\tweak X-offset #0 4266-\tweak Y-offset #0 4267-3 4268a' 4269-\tweak X-offset #-1 4270-\tweak Y-offset #1 4271-3 4272@end lilypond 4273 4274@c TODO write more 4275 4276@node Using the side-position-interface 4277@unnumberedsubsubsec Using the @code{side-position-interface} 4278 4279An object which supports the @code{side-position-interface} can be 4280placed next to its parent object so that 4281the specified edges of the two objects touch. The object may be 4282placed above, below, to the right or to the left of the parent. 4283The parent cannot be specified; it is determined by the order of 4284elements in the input stream. Most objects have the associated 4285note head as their parent. 4286 4287The values of the @code{side-axis} and @code{direction} properties 4288determine where the object is to be placed, as follows: 4289 4290@c TODO add an example of each to the table 4291 4292@multitable @columnfractions .3 .3 .3 4293@headitem @code{side-axis} @tab @code{direction} @tab 4294@headitem property @tab property @tab Placement 4295 4296@item @code{0} @tab @code{-1} @tab left 4297@item @code{0} @tab @code{1} @tab right 4298@item @code{1} @tab @code{-1} @tab below 4299@item @code{1} @tab @code{1} @tab above 4300 4301@end multitable 4302 4303When @code{side-axis} is @code{0}, @code{X-offset} should be set to 4304the procedure @code{ly:side-position-interface::x-aligned-side}. 4305This procedure will return the correct value of @code{X-offset} to 4306place the object to the left or right side of the parent according 4307to value of @code{direction}. 4308 4309When @code{side-axis} is @code{1}, @code{Y-offset} should be set to 4310the procedure @code{ly:side-position-interface::y-aligned-side}. 4311This procedure will return the correct value of @code{Y-offset} to 4312place the object to the top or bottom of the parent according 4313to value of @code{direction}. 4314 4315@c TODO Add examples 4316 4317@node Using the self-alignment-interface 4318@unnumberedsubsubsec Using the @code{self-alignment-interface} 4319 4320@subsubsubheading Self-aligning objects horizontally 4321 4322The horizontal alignment of an object which supports the 4323@code{self-alignment-interface} is controlled by the value of 4324the @code{self-alignment-X} property, provided the object's 4325@code{X-offset} property is set to 4326@code{ly:self-alignment-interface::x-aligned-on-self}. 4327@code{self-alignment-X} may be given any 4328real value, in units of half the total X extent of the 4329object. Negative values move the object to the right, positive 4330to the left. A value of @code{0} centers the object on the 4331reference point of its parent, a value of @w{@code{-1}} aligns the 4332left edge of the object on the reference point of its parent, 4333and a value of @code{1} aligns the right edge of the object on the 4334reference point of its parent. The symbols @code{LEFT}, 4335@code{CENTER}, and @code{RIGHT} may be used instead of the values 4336@w{@code{-1}}, @code{0}, and @code{1}, respectively. 4337 4338Normally the @code{\override} command would be used to modify the 4339value of @code{self-alignment-X}, but the @code{\tweak} command 4340can be used to separately align several annotations on a single 4341note: 4342 4343@lilypond[quote,verbatim,fragment] 4344a' 4345-\tweak self-alignment-X #-1 4346^"left-aligned" 4347-\tweak self-alignment-X #0 4348^"center-aligned" 4349-\tweak self-alignment-X #RIGHT 4350^"right-aligned" 4351-\tweak self-alignment-X #-2.5 4352^"aligned further to the right" 4353@end lilypond 4354 4355@subsubsubheading Self-aligning objects vertically 4356 4357Objects may be aligned vertically in an analogous way to aligning 4358them horizontally if the @code{Y-offset} property is set to 4359@code{ly:self-alignment-interface::y-aligned-on-self}. However, 4360other mechanisms are often involved in vertical alignment: the 4361value of @code{Y-offset} is just one variable taken into account. 4362This may make adjusting the value of some objects tricky. 4363The units are just half the vertical extent of the object, which 4364is usually quite small, so quite large numbers may be required. 4365A value of @w{@code{-1}} aligns the lower edge of the object with 4366the reference point of the parent object, a value of @code{0} 4367aligns the center of the object with the reference point of the 4368parent, and a value of @code{1} aligns the top edge of the object 4369with the reference point of the parent. The symbols @code{DOWN}, 4370@code{CENTER}, and @code{UP} may be substituted for @w{@code{-1}}, 4371@code{0}, and @code{1}, respectively. 4372 4373@subsubsubheading Self-aligning objects in both directions 4374 4375By setting both @code{X-offset} and @code{Y-offset}, an object may 4376be aligned in both directions simultaneously. 4377 4378The following example shows how to adjust a fingering mark so 4379that it nestles close to the note head. 4380 4381@lilypond[quote,verbatim,fragment] 4382a' 4383-\tweak self-alignment-X #0.5 % move horizontally left 4384-\tweak Y-offset #ly:self-alignment-interface::y-aligned-on-self 4385-\tweak self-alignment-Y #-1 % move vertically up 4386-3 % third finger 4387@end lilypond 4388 4389@ignore 4390@unnumberedsubsubsec Using the @code{aligned-on-parent} procedures 4391 4392@c Cannot document as they do not seem to operate consistently on all objects -td 4393@c TODO investigate further 4394 4395The @code{aligned-on-parent} procedures are used in the same way 4396as the @code{aligned-on-self} procedures, they difference being 4397that they permit an object to be aligned with the @emph{edges} of 4398the parent rather than the parent's reference point. The following 4399example shows the difference: 4400 4401@c TODO Add example 4402 4403@lilypond[verbatim,quote] 4404@end lilypond 4405 4406@end ignore 4407 4408@ignore 4409@unnumberedsubsubsec Using the @code{centered-on-parent} procedures 4410 4411@c Cannot document as they do not seem to operate consistently on all objects -td 4412@c TODO investigate further 4413 4414@end ignore 4415 4416@c TODO The align-interface, BassFigureAlignment and VerticalAlignment 4417 4418@node Using the break-alignable-interface 4419@unnumberedsubsubsec Using the @code{break-alignable-interface} 4420 4421@cindex align to object 4422@funindex break-align-symbols 4423 4424Rehearsal marks and bar numbers may be aligned with notation 4425objects other than bar lines. These objects include @code{ambitus}, 4426@code{breathing-sign}, @code{clef}, @code{custos}, @code{staff-bar}, 4427@code{left-edge}, @code{key-cancellation}, @code{key-signature}, and 4428@code{time-signature}. 4429 4430Each type of object has its own default reference point, to which 4431rehearsal marks are aligned: 4432 4433@lilypond[verbatim,quote,fragment] 4434% The rehearsal mark will be aligned 4435% to the right edge of the Clef 4436\override Score.RehearsalMark.break-align-symbols = 4437 #'(clef) 4438\key a \major 4439\clef treble 4440\mark "↓" 4441e'1 4442% The rehearsal mark will be aligned 4443% to the left edge of the Time Signature 4444\override Score.RehearsalMark.break-align-symbols = 4445 #'(time-signature) 4446\key a \major 4447\clef treble 4448\time 3/4 4449\mark "↓" 4450e'2. 4451% The rehearsal mark will be centered 4452% above the Breath Mark 4453\override Score.RehearsalMark.break-align-symbols = 4454 #'(breathing-sign) 4455\key a \major 4456\clef treble 4457\time 4/4 4458e'1 4459\breathe 4460\mark "↓" 4461@end lilypond 4462 4463A list of possible target alignment objects may be specified. If 4464some of the objects are invisible at that point due to the setting 4465of @code{break-visibility} or the explicit visibility settings for 4466keys and clefs, the rehearsal mark or bar number is aligned to the 4467first object in the list which is visible. If no objects in the 4468list are visible the object is aligned to the bar line. If the bar 4469line is invisible the object is aligned to the place where the bar 4470line would be. 4471 4472@lilypond[verbatim,quote,fragment] 4473% The rehearsal mark will be aligned 4474% to the right edge of the Key Signature 4475\override Score.RehearsalMark.break-align-symbols = 4476 #'(key-signature clef) 4477\key a \major 4478\clef treble 4479\mark "↓" 4480e'1 4481% The rehearsal mark will be aligned 4482% to the right edge of the Clef 4483\set Staff.explicitKeySignatureVisibility = #all-invisible 4484\override Score.RehearsalMark.break-align-symbols = 4485 #'(key-signature clef) 4486\key a \major 4487\clef bass 4488\mark "↓" 4489gis,1 4490% The rehearsal mark will be centered 4491% above the Bar Line 4492\set Staff.explicitKeySignatureVisibility = #all-invisible 4493\set Staff.explicitClefVisibility = #all-invisible 4494\override Score.RehearsalMark.break-align-symbols = 4495 #'(key-signature clef) 4496\key a \major 4497\clef treble 4498\mark "↓" 4499e'1 4500@end lilypond 4501 4502The alignment of the rehearsal mark relative to the notation object 4503can be changed, as shown in the following example. In a score with 4504multiple staves, this setting should be done for all the staves. 4505 4506@lilypond[verbatim,quote,fragment] 4507% The RehearsalMark will be aligned 4508% with the right edge of the Key Signature 4509\override Score.RehearsalMark.break-align-symbols = 4510 #'(key-signature) 4511\key a \major 4512\clef treble 4513\time 4/4 4514\mark "↓" 4515e'1 4516% The RehearsalMark will be centered 4517% above the Key Signature 4518\once \override Score.KeySignature.break-align-anchor-alignment = 4519 #CENTER 4520\mark "↓" 4521\key a \major 4522e'1 4523% The RehearsalMark will be aligned 4524% with the left edge of the Key Signature 4525\once \override Score.KeySignature.break-align-anchor-alignment = 4526 #LEFT 4527\key a \major 4528\mark "↓" 4529e'1 4530@end lilypond 4531 4532The rehearsal mark can also be offset to the right or left of the left 4533edge by an arbitrary amount. The units are staff-spaces: 4534 4535@lilypond[verbatim,quote,fragment] 4536% The RehearsalMark will be aligned 4537% with the left edge of the Key Signature 4538% and then shifted right by 3.5 staff-spaces 4539\override Score.RehearsalMark.break-align-symbols = 4540 #'(key-signature) 4541\once \override Score.KeySignature.break-align-anchor = #3.5 4542\key a \major 4543\mark "↓" 4544e'1 4545% The RehearsalMark will be aligned 4546% with the left edge of the Key Signature 4547% and then shifted left by 2 staff-spaces 4548\once \override Score.KeySignature.break-align-anchor = #-2 4549\key a \major 4550\mark "↓" 4551e'1 4552@end lilypond 4553 4554 4555@node Vertical grouping of grobs 4556@subsection Vertical grouping of grobs 4557 4558@c TODO Expand this section 4559 4560The VerticalAlignment and VerticalAxisGroup grobs work together. 4561VerticalAxisGroup groups together different grobs like Staff, Lyrics, 4562etc. VerticalAlignment then vertically aligns the different grobs 4563grouped together by VerticalAxisGroup. There is usually only one 4564VerticalAlignment per score but every Staff, Lyrics, etc., has its own 4565VerticalAxisGroup. 4566 4567 4568@node Modifying stencils 4569@subsection Modifying stencils 4570 4571All layout objects have a @code{stencil} property which is part of 4572the @code{grob-interface}. By default, this property is usually 4573set to a function specific to the object that is tailor-made to 4574render the symbol which represents it in the output. For example, 4575the standard setting for the @code{stencil} property of the 4576@code{MultiMeasureRest} object is @code{ly:multi-measure-rest::print}. 4577 4578The standard symbol for any object can be replaced by modifying the 4579@code{stencil} property to reference a different, specially-written, 4580procedure. This requires a high level of knowledge of the internal 4581workings of LilyPond, but there is an easier way which can often 4582produce adequate results. 4583 4584This is to set the @code{stencil} property to the procedure which 4585prints text -- @code{ly:text-interface::print} -- and to add a 4586@code{text} property to the object which is set to contain the 4587markup text which produces the required symbol. Due to the 4588flexibility of markup, much can be achieved -- see in particular 4589@ref{Graphic notation inside markup}. 4590 4591The following example demonstrates this by changing the note head 4592symbol to a cross within a circle. 4593 4594@lilypond[verbatim,quote] 4595XinO = { 4596 \once \override NoteHead.stencil = #ly:text-interface::print 4597 \once \override NoteHead.text = \markup { 4598 \combine 4599 \halign #-0.7 \draw-circle #0.85 #0.2 ##f 4600 \musicglyph "noteheads.s2cross" 4601 } 4602} 4603\relative { 4604 a' a \XinO a a 4605} 4606@end lilypond 4607 4608Any of the @emph{Feta} glyphs used in the Emmentaler font can be 4609supplied to the @code{\musicglyph} markup command -- see 4610@ref{The Emmentaler font}. 4611 4612@file{EPS} files and Postscript commands can both be inserted inline 4613using the @code{\epsfile} and @code{\postscript} markup commands 4614respectively -- see @ref{Graphic}. 4615 4616 4617@morerefs 4618Notation Reference: 4619@ref{Graphic notation inside markup}, 4620@ref{Formatting text}, 4621@ref{Text markup commands}, 4622@ref{The Emmentaler font}, 4623@ref{Graphic}. 4624 4625 4626@node Modifying shapes 4627@subsection Modifying shapes 4628 4629@menu 4630* Modifying ties and slurs:: 4631@end menu 4632 4633@node Modifying ties and slurs 4634@unnumberedsubsubsec Modifying ties and slurs 4635 4636@cindex slur, modifying 4637@cindex tie, modifying 4638@cindex Bézier curve, control points 4639@cindex control point, Bézier curve 4640 4641@code{Tie}s, @code{Slur}s, @code{PhrasingSlur}s, 4642@code{LaissezVibrerTie}s and @code{RepeatTie}s are all drawn as 4643third-order Bézier curves. If the shape of the tie or slur which 4644is calculated automatically is not optimum, the shape may be 4645modified manually in two ways: 4646 4647@enumerate a 4648@item 4649by specifying the displacements to be made to the control points 4650of the automatically calculated Bézier curve, or 4651 4652@item 4653by explicitly specifying the positions of the four control points 4654required to define the wanted curve. 4655@end enumerate 4656 4657Both methods are explained below. The first method is more suitable 4658if only slight adjustments to the curve are required; the second may 4659be better for creating curves which are related to just a single 4660note. 4661 4662@subsubsubheading Cubic Bézier curves 4663 4664Third-order or cubic Bézier curves are defined by four control 4665points. The first and fourth control points are precisely the 4666starting and ending points of the curve. The intermediate two 4667control points define the shape. Animations showing how the curve 4668is drawn can be found on the web, but the following description 4669may be helpful. The curve starts from the first control point 4670heading directly towards the second, gradually bending over to 4671head towards the third and continuing to bend over to head towards 4672the fourth, arriving there travelling directly from the third 4673control point. The curve is entirely contained in the 4674quadrilateral defined by the four control points. Translations, 4675rotations and scaling of the control points all result in exactly 4676the same operations on the curve. 4677 4678@subsubsubheading Specifying displacements from current control points 4679 4680@cindex shaping slurs and ties 4681@funindex \shape 4682 4683In this example the automatic placement of the tie is not optimum, 4684and @code{\tieDown} would not help. 4685 4686@lilypond[verbatim,quote] 4687<< 4688 { e'1~ 1 } 4689\\ 4690 \relative { r4 <g' c,> <g c,> <g c,> } 4691>> 4692@end lilypond 4693 4694Adjusting the control points of the tie with @code{\shape} allows 4695the collisions to be avoided. 4696 4697The syntax of @code{\shape} is 4698 4699@example 4700[-]\shape @var{displacements} @var{item} 4701@end example 4702 4703This will reposition the control-points of @var{item} by the amounts 4704given by @var{displacements}. The @var{displacements} argument is a 4705list of number pairs or a list of such lists. Each element of a pair 4706represents the displacement of one of the coordinates of a 4707control-point. If @var{item} is a string, the result is 4708@code{\once\override} for the specified grob type. If @var{item} is 4709a music expression, the result is the same music expression with an 4710appropriate tweak applied. 4711 4712In other words, the @code{\shape} function can act as either a 4713@code{\once\override} command or a @code{\tweak} command depending 4714on whether the @var{item} argument is a grob name, like @qq{Slur}, 4715or a music expression, like @qq{(}. The @var{displacements} argument 4716specifies the displacements of the four control points as a list of 4717four pairs of (dx . dy) values in units of staff-spaces (or a list 4718of such lists if the curve has more than one segment). 4719 4720The leading hyphen is required if and only if the @code{\tweak} form 4721is being used. 4722 4723So, using the same example as above and the @code{\once\override} 4724form of @code{\shape}, this will raise the tie by half a staff-space: 4725 4726@lilypond[verbatim,quote] 4727<< 4728 { 4729 \shape #'((0 . 0.5) (0 . 0.5) (0 . 0.5) (0 . 0.5)) Tie 4730 e'1~ 1 4731 } 4732\\ 4733 \relative { r4 <g' c,> <g c,> <g c,> } 4734>> 4735@end lilypond 4736 4737This positioning of the tie is better, but maybe it should be raised 4738more in the center. The following example does this, this time using 4739the alternative @code{\tweak} form: 4740 4741@lilypond[verbatim,quote] 4742<< 4743 { 4744 e'1-\shape #'((0 . 0.5) (0 . 1) (0 . 1) (0 . 0.5)) ~ e' 4745 } 4746\\ 4747 \relative { r4 <g' c,> <g c,> <g c,> } 4748>> 4749@end lilypond 4750 4751Changes to the horizontal positions of the control points may be made 4752in the same way, and two different curves starting at the same 4753musical moment may also be shaped: 4754 4755@lilypond[verbatim,quote,ragged-right] 4756\relative { 4757 c''8(\( a) a'4 e c\) 4758 \shape #'((0.7 . -0.4) (0.5 . -0.4) (0.3 . -0.3) (0 . -0.2)) Slur 4759 \shape #'((0 . 0) (0 . 0.5) (0 . 0.5) (0 . 0)) PhrasingSlur 4760 c8(\( a) a'4 e c\) 4761} 4762@end lilypond 4763 4764The @code{\shape} function can also displace the control points of 4765curves which stretch across line breaks. Each piece of the broken 4766curve can be given its own list of offsets. If changes to a 4767particular segment are not needed, the empty list can serve as a 4768placeholder. In this example the line break makes the single slur 4769look like two: 4770 4771@lilypond[verbatim,quote,ragged-right] 4772\relative { 4773 c'4( f g c 4774 \break 4775 d,4 c' f, c) 4776} 4777@end lilypond 4778 4779Changing the shapes of the two halves of the slur makes it clearer 4780that the slur continues over the line break: 4781 4782@lilypond[verbatim,quote,ragged-right] 4783% () may be used as a shorthand for ((0 . 0) (0 . 0) (0 . 0) (0 . 0)) 4784% if any of the segments does not need to be changed 4785\relative c' { 4786 \shape #'( 4787 (( 0 . 0) (0 . 0) (0 . 0) (0 . 1)) 4788 ((0.5 . 1.5) (1 . 0) (0 . 0) (0 . -1.5)) 4789 ) Slur 4790 c4( f g c 4791 \break 4792 d,4 c' f, c) 4793} 4794@end lilypond 4795 4796If an S-shaped curve is required the control points must always be 4797adjusted manually --- LilyPond will never select such shapes 4798automatically. 4799 4800@lilypond[verbatim,quote] 4801\relative c'' { 4802 c8( e b-> f d' a e-> g) 4803 \shape #'((0 . -1) (5.5 . -0.5) (-5.5 . -10.5) (0 . -5.5)) 4804 PhrasingSlur 4805 c8\( e b-> f d' a e-> g\) 4806} 4807@end lilypond 4808 4809@subsubsubheading Specifying control points explicitly 4810 4811The coordinates of the Bézier control points are specified in units 4812of staff-spaces. The X@tie{}coordinate is relative to the reference 4813point of the note to which the tie or slur is attached, and the 4814Y@tie{}coordinate is relative to the staff center line. The 4815coordinates are specified as a list of four pairs of decimal numbers 4816(reals). One approach is to estimate the coordinates of the two 4817end points, and then guess the two intermediate points. The optimum 4818values are then found by trial and error. Be aware that these values 4819may need to be manually adjusted if any further changes are made to 4820the music or the layout. 4821 4822One situation where specifying the control points explicitly is 4823preferable to specifying displacements is when they need to be 4824specified relative to a single note. Here is an example of this. 4825It shows one way of indicating a slur extending into alternative 4826sections of a volta repeat. 4827 4828@lilypond[verbatim,quote] 4829\relative { 4830 c''1 4831 \repeat volta 3 { c4 d( e f } 4832 \alternative { 4833 { g2) d } 4834 { 4835 g2 4836 % create a slur and move it to a new position 4837 % the <> is just an empty chord to carry the slur termination 4838 -\tweak control-points 4839 #'((-2 . 3.8) (-1 . 3.9) (0 . 4) (1 . 3.4)) ( <> ) 4840 f, 4841 } 4842 { 4843 e'2 4844 % create a slur and move it to a new position 4845 -\tweak control-points 4846 #'((-2 . 3) (-1 . 3.1) (0 . 3.2) (1 . 2.4)) ( <> ) 4847 f, 4848 } 4849 } 4850} 4851@end lilypond 4852 4853@knownissues 4854It is not possible to modify shapes of ties or slurs by changing 4855the @code{control-points} property if there are multiple ties or slurs 4856at the same musical moment -- the @code{\tweak} command will also not 4857work in this case. However, the @code{tie-configuration} property of 4858@code{TieColumn} can be overridden to set start line and direction as 4859required. 4860 4861@morerefs 4862Internals Reference: 4863@rinternals{TieColumn}. 4864 4865 4866@node Modifying broken spanners 4867@subsection Modifying broken spanners 4868 4869@menu 4870* Using alterBroken:: 4871@end menu 4872 4873@node Using alterBroken 4874@unnumberedsubsubsec Using @code{\alterBroken} 4875 4876@cindex spanner, modifying 4877@cindex broken spanner, modifying 4878@funindex \alterBroken 4879 4880When a spanner crosses a line break or breaks, each piece 4881inherits the attributes of the original spanner. Thus, ordinary 4882tweaking of a broken spanner applies the same modifications to 4883each of its segments. In the example below, overriding 4884@code{thickness} affects the slur on either side of the line 4885break. 4886 4887@lilypond[verbatim,quote,ragged-right] 4888\relative c'' { 4889 r2 4890 \once\override Slur.thickness = 10 4891 c8( d e f 4892 \break 4893 g8 f e d) r2 4894} 4895@end lilypond 4896 4897Independently modifying the appearance of individual pieces 4898of a broken spanner is possible with the @code{\alterBroken} 4899command. This command can produce either an @code{\override} 4900or a @code{\tweak} of a spanner property. 4901 4902The syntax for @code{\alterBroken} is 4903 4904@example 4905[-]\alterBroken @var{property} @var{values} @var{item} 4906@end example 4907 4908The argument @var{values} is a list of values, one for each 4909broken piece. If @var{item} is a grob name like @code{Slur} or 4910@code{Staff.PianoPedalBracket}, the result is an @code{\override} 4911of the specified grob type. If @var{item} is a music expression 4912such as @qq{(} or @qq{[} the result is the same music expression 4913with an appropriate tweak applied. 4914 4915The leading hyphen must be used with the @code{\tweak} form. Do 4916not add it when @code{\alterBroken} is used as an 4917@code{\override}. 4918 4919@funindex \once 4920@funindex \temporary 4921 4922In its @code{\override} usage, @code{\alterBroken} may be prefaced 4923by @code{\once} or @code{\temporary} and reverted by using 4924@code{\revert} with @var{property} (see @rextend{Intermediate 4925substitution functions}). 4926 4927The following code applies an independent @code{\override} to 4928each of the slur segments in the previous example: 4929 4930@lilypond[verbatim,quote,ragged-right] 4931\relative c'' { 4932 r2 4933 \alterBroken thickness #'(10 1) Slur 4934 c8( d e f 4935 \break 4936 g8 f e d) r2 4937} 4938@end lilypond 4939 4940The @code{\alterBroken} command may be used with any spanner 4941object, including @code{Tie}, @code{PhrasingSlur}, @code{Beam} 4942and @code{TextSpanner}. For example, an editor preparing a 4943scholarly edition may wish to indicate the absence of part of a 4944phrasing slur in a source by dashing only the segment which has 4945been added. The following example illustrates how this can be 4946done, in this case using the @code{\tweak} form of the command: 4947 4948@lilypond[verbatim,quote,ragged-right] 4949% The empty list is conveniently used below, because it is the 4950% default setting of dash-definition, resulting in a solid curve. 4951\relative { 4952 c''2-\alterBroken dash-definition #'(() ((0 1.0 0.4 0.75))) \(e 4953 \break 4954 g2 e\) 4955} 4956@end lilypond 4957 4958It is important to understand that @code{\alterBroken} will set 4959each piece of a broken spanner to the corresponding value in 4960@var{values}. When there are fewer values than pieces, any 4961additional piece will be assigned the empty list. This may lead 4962to undesired results if the layout property is not set to the 4963empty list by default. In such cases, each segment should be 4964assigned an appropriate value. 4965 4966@knownissues 4967Line breaks may occur in different places following changes in 4968layout. Settings chosen for @code{\alterBroken} may be unsuitable 4969for a spanner that is no longer broken or is split into more 4970segments than before. Explicit use of @code{\break} can guard 4971against this situation. 4972 4973The @code{\alterBroken} command is ineffective for spanner 4974properties accessed before line-breaking such as 4975@code{direction}. 4976 4977@morerefs 4978Extending LilyPond: 4979@rextend{Difficult tweaks}. 4980 4981 4982@node Unpure-pure containers 4983@subsection Unpure-pure containers 4984 4985@cindex Scheme, pure container 4986@cindex Scheme, unpure container 4987@cindex pure container, Scheme 4988@cindex unpure container, Scheme 4989@cindex horizontal spacing, overriding 4990 4991Unpure-pure containers are useful for overriding @emph{Y-axis} spacing 4992calculations - specifically @code{Y-offset} and @code{Y-extent} - with a 4993Scheme function instead of a literal (i.e., a number or pair). 4994 4995For certain grobs, the @code{Y-extent} is based on the @code{stencil} 4996property, overriding the stencil property of one of these will 4997require an additional @code{Y-extent} override with an unpure-pure 4998container. When a function overrides a @code{Y-offset} and/or 4999@code{Y-extent} it is assumed that this will trigger line breaking 5000calculations too early during compilation. So the function is not 5001evaluated at all (usually returning a value of @samp{0} or 5002@samp{'(0 . 0)}) which can result in collisions. A @q{pure} function 5003will not affect properties, objects or grob suicides and therefore will 5004always have its Y-axis-related evaluated correctly. 5005 5006Currently, there are about thirty functions that are already considered 5007@q{pure} and Unpure-pure containers are a way to set functions not on 5008this list as @q{pure}. The @q{pure} function is evaluated @emph{before} 5009any line-breaking and so the horizontal spacing can be adjusted 5010@q{in time}. The @q{unpure} function is then evaluated @emph{after} 5011line breaking. 5012 5013@warning{As it is difficult to always know which functions are on this 5014list we recommend that any @q{pure} functions you create do not use 5015@code{Beam} or @code{VerticalAlignment} grobs.} 5016 5017An unpure-pure container is constructed as follows; 5018 5019@code{(ly:make-unpure-pure-container f0 f1)} 5020 5021where @code{f0} is a function taking @var{n} arguments (@var{n >= 1}) 5022and the first argument must always be the grob. This is the function 5023that gives the actual result. @var{f1} is the function being labeled 5024as @q{pure} that takes @var{n + 2} arguments. Again, the first argument 5025must always still be the grob but the second and third are @q{start} 5026and @q{end} arguments. 5027 5028@var{start} and @var{end} are, for all intents and purposes, dummy 5029values that only matter for @code{Spanners} (i.e @code{Hairpin} or 5030@code{Beam}), that can return different height estimations based on a 5031starting and ending column. 5032 5033The rest are the other arguments to the first function (which 5034may be none if @var{n = 1}). 5035 5036The results of the second function are used as an approximation of the 5037value needed which is then used by the first function to get the real 5038value which is then used for fine-tuning much later during the spacing 5039process. 5040 5041@c TODO: The following example supposedly showing a collision no longer 5042@c 'works' since 2.18.x. Another example of a collision is needed. 5043@c Issue #3512 5044 5045@lilypond[verbatim,quote,ragged-right] 5046#(define (square-line-circle-space grob) 5047(let* ((pitch (ly:event-property (ly:grob-property grob 'cause) 5048 'pitch)) 5049 (notename (ly:pitch-notename pitch))) 5050 (if (= 0 (modulo notename 2)) 5051 (make-circle-stencil 0.5 0.0 #t) 5052 (make-filled-box-stencil '(0 . 1.0) 5053 '(-0.5 . 0.5))))) 5054 5055squareLineCircleSpace = { 5056 \override NoteHead.stencil = #square-line-circle-space 5057} 5058 5059smartSquareLineCircleSpace = { 5060 \squareLineCircleSpace 5061 \override NoteHead.Y-extent = 5062 #(ly:make-unpure-pure-container 5063 ly:grob::stencil-height 5064 (lambda (grob start end) (ly:grob::stencil-height grob))) 5065} 5066 5067\new Voice \with { \remove "Stem_engraver" } 5068\relative c'' { 5069 \squareLineCircleSpace 5070 cis4 ces disis d 5071 \smartSquareLineCircleSpace 5072 cis4 ces disis d 5073} 5074@end lilypond 5075 5076In the first measure, without the unpure-pure container, the spacing 5077engine does not know the width of the note head and lets it collide with 5078the accidentals. In the second measure, with unpure-pure containers, 5079the spacing engine knows the width of the note heads and avoids the 5080collision by lengthening the line accordingly. 5081 5082Usually for simple calculations nearly-identical functions for 5083both the @q{unpure} and @q{pure} parts can be used, by only 5084changing the number of arguments passed to, and the scope of, the 5085function. This use case is frequent enough that 5086@code{ly:make-unpure-pure-container} constructs such a second 5087function by default when called with only one function argument. 5088 5089@warning{If a function is labeled as @q{pure} and it turns out not to 5090be, the results can be unexpected.} 5091 5092 5093@node Using music functions 5094@section Using music functions 5095 5096@c TODO -- add @morerefs, etc. to these subsections 5097 5098Where tweaks need to be reused with different music expressions, 5099it is often convenient to make the tweak part of a @emph{music 5100function}. In this section, we discuss only @emph{substitution} 5101functions, where the object is to substitute a variable into a 5102piece of LilyPond input code. Other more complex functions are 5103described in @rextend{Music functions}. 5104 5105@menu 5106* Substitution function syntax:: 5107* Substitution function examples:: 5108@end menu 5109 5110@node Substitution function syntax 5111@subsection Substitution function syntax 5112 5113Making a function that substitutes a variable into LilyPond 5114code is easy. The general form of these functions is 5115 5116@example 5117function = 5118#(define-music-function 5119 (@var{arg1} @var{arg2} @dots{}) 5120 (@var{type1?} @var{type2?} @dots{}) 5121 #@{ 5122 @var{@dots{}music@dots{}} 5123 #@}) 5124@end example 5125 5126@noindent 5127where 5128 5129@multitable @columnfractions .33 .66 5130@item @code{@var{argN}} 5131@tab @var{n}th argument 5132 5133@item @code{@var{typeN?}} 5134@tab a scheme @emph{type predicate} for which @code{@var{argN}} 5135must return @code{#t}. 5136 5137@item @code{@var{@dots{}music@dots{}}} 5138@tab normal LilyPond input, using @code{$} (in places where only 5139LilyPond constructs are allowed) or @code{#} (to use it as a Scheme 5140value or music function argument or music inside of music lists) to 5141reference arguments 5142(eg. @samp{#arg1}). 5143@end multitable 5144 5145The list of type predicates is required. Some of the most common 5146type predicates used in music functions are: 5147 5148@example 5149boolean? 5150cheap-list? @emph{(use instead of }@q{list?}@emph{ for faster processing)} 5151ly:duration? 5152ly:music? 5153ly:pitch? 5154markup? 5155number? 5156pair? 5157string? 5158symbol? 5159@end example 5160 5161@noindent 5162For a list of available type predicates, see 5163@ref{Predefined type predicates}. User-defined type predicates 5164are also allowed. 5165 5166@morerefs 5167Notation Reference: 5168@ref{Predefined type predicates}. 5169 5170Extending LilyPond: 5171@rextend{Music functions}. 5172 5173Installed Files: 5174@file{lily/music-scheme.cc}, 5175@file{scm/c++.scm}, 5176@file{scm/lily.scm}. 5177 5178 5179@node Substitution function examples 5180@subsection Substitution function examples 5181 5182This section introduces some substitution function examples. 5183These are not intended to be exhaustive, but rather to demonstrate 5184some of the possibilities of simple substitution functions. 5185 5186In the first example, a function is defined that simplifies 5187setting the padding of a TextScript: 5188 5189@lilypond[quote,verbatim,ragged-right] 5190padText = 5191#(define-music-function 5192 (padding) 5193 (number?) 5194 #{ 5195 \once \override TextScript.padding = #padding 5196 #}) 5197 5198\relative { 5199 c''4^"piu mosso" b a b 5200 \padText #1.8 5201 c4^"piu mosso" b a b 5202 \padText #2.6 5203 c4^"piu mosso" b a b 5204} 5205@end lilypond 5206 5207In addition to numbers, we can use music expressions such 5208as notes for arguments to music functions: 5209 5210@lilypond[quote,verbatim,ragged-right] 5211custosNote = 5212#(define-music-function 5213 (note) 5214 (ly:music?) 5215 #{ 5216 \tweak NoteHead.stencil #ly:text-interface::print 5217 \tweak NoteHead.text 5218 \markup \musicglyph "custodes.mensural.u0" 5219 \tweak Stem.stencil ##f 5220 #note 5221 #}) 5222 5223\relative { c'4 d e f \custosNote g } 5224@end lilypond 5225 5226@funindex \etc 5227Both of those functions are simple single expressions where only 5228the last element of a function call or override is missing. For 5229those particular function definitions, there is a simpler 5230alternative syntax, namely just writing out the constant part of 5231the expression and replacing its final missing element with 5232@code{\etc}: 5233 5234@lilypond[quote,verbatim,ragged-right] 5235padText = 5236 \once \override TextScript.padding = \etc 5237 5238\relative { 5239 c''4^"piu mosso" b a b 5240 \padText #1.8 5241 c4^"piu mosso" b a b 5242 \padText #2.6 5243 c4^"piu mosso" b a b 5244} 5245@end lilypond 5246 5247@lilypond[quote,verbatim,ragged-right] 5248custosNote = 5249 \tweak NoteHead.stencil #ly:text-interface::print 5250 \tweak NoteHead.text 5251 \markup \musicglyph "custodes.mensural.u0" 5252 \tweak Stem.stencil ##f 5253 \etc 5254 5255\relative { c'4 d e f \custosNote g } 5256@end lilypond 5257 5258 5259Substitution functions with multiple arguments can be defined: 5260 5261@lilypond[quote,verbatim,ragged-right] 5262tempoPadded = 5263#(define-music-function 5264 (padding tempotext) 5265 (number? markup?) 5266 #{ 5267 \once \override Score.MetronomeMark.padding = #padding 5268 \tempo \markup { \bold #tempotext } 5269 #}) 5270 5271\relative { 5272 \tempo \markup { "Low tempo" } 5273 c''4 d e f g1 5274 \tempoPadded #4.0 "High tempo" 5275 g4 f e d c1 5276} 5277@end lilypond 5278 5279@c TODO: add appropriate @@ref's here. 5280