]> git.donarmstrong.com Git - lilypond.git/blobdiff - Documentation/user/tweaks.itely
Merge branch 'lilypond/translation' of ssh://jomand@git.sv.gnu.org/srv/git/lilypond...
[lilypond.git] / Documentation / user / tweaks.itely
index 8064696afeb6298d7b078192cff55bee731491fd..a68fd71359e45d46581d889cef45fc804ceb549c 100644 (file)
@@ -160,11 +160,17 @@ properties.
 @node Tweaking methods
 @subsection Tweaking methods
 
+@strong{\override command}
+
+@cindex override command
+@funindex \override
+
 We have already met the commands @code{\set} and @code{\with},
 used to change the properties of @strong{contexts} and to remove
 and add @strong{engravers}, in
 @ref{Modifying context properties} and @ref{Adding
-and removing engravers}.  We now must meet one more command.
+and removing engravers}.  We now must meet one more important
+command.
 
 The command to change the properties of @strong{layout objects} is
 @code{\override}.  Because this command has to modify
@@ -182,7 +188,7 @@ The general syntax of this command is:
 
 @noindent
 This will set the property with the name @emph{layout_property}
-of the layout object with the name 
+of the layout object with the name
 @emph{layout_object}, which is a member of the @emph{context}
 context, to the value @emph{value}.
 
@@ -214,29 +220,101 @@ Again, just like @emph{context} in the @code{\override} command,
 @emph{context} is often not needed.  It will be omitted
 in many of the following examples.
 
-There is another form of the override command, 
+@strong{\overrideProperty command}
+
+@cindex overrideProperty command
+@funindex \overrideProperty
+
+There is another form of the override command,
 @code{\overrideProperty}, which is occasionally required.
-We mention it here for completeness, but for details see 
+We mention it here for completeness, but for details see
 @ruser{Difficult tweaks}.
 @c Maybe explain in a later iteration  -td
 
+@strong{\tweak command}
+
+@cindex tweak command
+@funindex \tweak
+
 The final tweaking command which is available is @code{\tweak}.
 This should be used to change the properties of objects which
 occur at the same musical moment, such as the notes within a
 chord.  Using @code{\override} would affect all the notes
 within a chord, whereas @code{\tweak} affects just the following
-item in the input stream.  You may find the details in
+item in the input stream.
+
+Here's an example.  Suppose we wish to change the size of the
+middle note (the E) in a C major chord.  Let's first see what
+@code{\once \override} would do:
+
+@lilypond[quote,fragment,ragged-right,verbatim,relative=1]
+  <c e g>4
+  \once \override NoteHead #'font-size = #-3
+  <c e g>4
+@end lilypond
+
+We see the override affects @emph{all} the notes in the chord.
+This is because all the notes of a chord occur at the same
+@emph{musical moment}, and the action of @code{\once} is to
+apply the override to all layout objects of the type specified
+which occur at the same musical moment as the @code{\override}
+command itself.
+
+The @code{\tweak} command operates in a different way.  It acts
+on the immediately following item in the input stream.  However,
+it is effective only on objects which are created directly from
+the input stream, essentially note heads and articulations.
+(Objects such as stems and accidentals are created later and
+cannot be tweaked in this way).  Furthermore, when it is applied
+to note heads these must be within a chord, i.e., within single
+angle brackets, so to tweak a single note the @code{\tweak}
+command must be placed inside single angle brackets with the
+note.
+
+So to return to our example, the size of the middle note of
+a chord would be changed in this way:
+
+@lilypond[quote,fragment,ragged-right,verbatim,relative=1]
+  <c e g>4
+  <c \tweak #'font-size #-3 e g>4
+@end lilypond
+
+Note that the syntax of @code{\tweak} is different from that
+of the @code{\override} command.  Neither the context nor the
+layout object should be specified; in fact, it would generate
+an error to do so.  These are both implied by the following
+item in the input stream.  So the general syntax of the
+@code{\tweak} command is simply:
+
+@example
+\tweak #'@emph{layout_property} = #@emph{value}
+@end example
+
+A @code{\tweak} command can also be used to modify just one in
+a series of articulations, as shown here:
+
+@lilypond[quote,fragment,ragged-right,verbatim,relative=2]
+a ^Black
+  -\tweak #'color #red ^Red
+  -\tweak #'color #green _Green
+@end lilypond
+
+Note that the @code{\tweak} command must be preceded by an
+articulation mark as if it were an articulation itself.
+
+You can find more details of the @code{\tweak} command in
 @ruser{Objects connected to the input}.
 
+
 @node The Internals Reference manual
 @section The Internals Reference manual
 
 @cindex Internals Reference
 
 @menu
-* Properties of layout objects::  
-* Properties found in interfaces::  
-* Types of properties::         
+* Properties of layout objects::
+* Properties found in interfaces::
+* Types of properties::
 @end menu
 
 @node Properties of layout objects
@@ -346,7 +424,7 @@ the context.  Let's use a very large value for the thickness
 at first, so we can be sure the command is working.  We get:
 
 @example
-  \override Slur #'thickness = #5.0
+\override Slur #'thickness = #5.0
 @end example 
 
 Don't forget the @code{#'} preceding the
@@ -584,7 +662,7 @@ Ok, so the @code{\override} command we need to print the lyrics
 in italics should be
 
 @example
-  \override LyricText #'font-shape = #'italic
+\override LyricText #'font-shape = #'italic
 @end example
 
 @noindent
@@ -625,7 +703,7 @@ object name, as otherwise the two names are run together and
 the interpreter cannot recognise them.  So the command should be:
 
 @example
-  \override Lyrics . LyricText #'font-shape = #'italic
+\override Lyrics . LyricText #'font-shape = #'italic
 @end example
 
 @warning{In lyrics always leave whitespace between the final
@@ -2123,7 +2201,47 @@ objects outside it are moved.
 @cindex left-padding property
 @cindex right-padding property
 
-TODO Example showing the utility of these properties  -td
+The @code{right-padding} property affects the spacing between the
+accidental and the note to which it applies.  It is not often
+required, but the following example shows one situation where it
+is needed.  Suppose we wish to show a chord containing both
+a B-natural and a B-flat.  To avoid ambiguity we would like to
+precede the notes with both a natural and a flat sign.  Here
+are a few attempts to do this:
+
+@lilypond[quote,fragment,ragged-right,verbatim,relative=2]
+<b bes>
+<b! bes>
+<b? bes>
+@end lilypond
+
+None work, with the second two showing bad collisions between
+the two signs.
+
+One way of achieving this is to override the accidental stencil
+with a markup containing the natural and flat symbols in the
+order we would like, like this:
+
+@lilypond[quote,ragged-right,verbatim]
+naturalplusflat = \markup { \natural \flat }
+\relative c'' {
+  \once \override Accidental
+    #'stencil = #ly:text-interface::print
+  \once \override Accidental #'text = #naturalplusflat
+  \once \override Score.AccidentalPlacement #'right-padding = #1.5
+  <b bes>
+}
+@end lilypond
+
+@noindent
+This necessarily uses an override for the accidental stencil which
+will not be covered until later.  The stencil type must be a
+procedure, here changed to print the contents of the @code{text}
+property of @code{Accidental}, which itself is set to be a natural 
+sign followed by a flat sign.  These are then moved further away 
+from the note head by overriding @code{right-padding}.
+
+@noindent
 
 @subheading staff-padding property
 @cindex staff-padding property
@@ -2776,11 +2894,11 @@ lhMusic = \relative c' {
 @section Further tweaking
 
 @menu
-* Other uses for tweaks::       
-* Using variables for tweaks::  
-* Other sources of information::  
-* Advanced tweaks with Scheme::  
-* Avoiding tweaks with slower processing::  
+* Other uses for tweaks::
+* Using variables for tweaks::
+* Other sources of information::
+* Avoiding tweaks with slower processing::
+* Advanced tweaks with Scheme::
 @end menu
 
 @node Other uses for tweaks
@@ -2800,44 +2918,44 @@ lhMusic = \relative c' {
 @subheading Tying notes across voices
 
 The following example demonstrates how to connect notes in
-different voices using ties.  Normally, only two notes in the 
+different voices using ties.  Normally, only two notes in the
 same voice can be connected with ties.  By using two voices,
 with the tied notes in one of them
 
 @lilypond[quote,fragment,relative=2]
-<< { b8~ b8\noBeam } 
-\\ { b[ g8] } 
+<< { b8~ b8\noBeam }
+\\ { b[ g8] }
 >>
 @end lilypond
 
 @noindent
-and blanking the first up-stem in that voice, the tie appears to 
+and blanking the first up-stem in that voice, the tie appears to
 cross voices:
 
 @lilypond[quote,fragment,relative=2,verbatim]
-<< 
+<<
   {
     \once \override Stem #'transparent = ##t
     b8~ b8\noBeam
-  } 
-\\ 
+  }
+\\
   { b[ g8] }
 >>
 @end lilypond
 
-To make sure that the just-blanked stem doesn't squeeze the tie 
+To make sure that the just-blanked stem doesn't squeeze the tie
 too much, we can lengthen the stem by setting the
 @code{length} to @code{8},
 
 @lilypond[quote,fragment,relative=2,verbatim]
-<< 
+<<
   {
     \once \override Stem #'transparent = ##t
     \once \override Stem #'length = #8
     b8~ b8\noBeam
-  } 
-\\ 
-  { b[ g8] } 
+  }
+\\
+  { b[ g8] }
 >>
 @end lilypond
 
@@ -2849,7 +2967,7 @@ too much, we can lengthen the stem by setting the
 
 For outside-staff objects it is usually better to override the
 object's @code{stencil} property rather than its @code{transparent}
-property when you wish to remove it from the printed output.  
+property when you wish to remove it from the printed output.
 Setting the @code{stencil} property of an object to @code{#f} will
 remove that object entirely from the printed output.  This means it
 has no effect on the placement of other objects placed relative to
@@ -2859,7 +2977,7 @@ For example, if we wished to change the metronome setting in order
 to simulate a fermata in the MIDI output we would not want the
 metronome markings to appear in the printed output, and we would
 not want it to influence the spacing between the two systems or
-the spacing of the notes on the staff.  So setting its 
+the spacing of the notes on the staff.  So setting its
 @code{stencil} property to @code{#f} would be the best way.
 We show here the effect of the two methods:
 
@@ -2898,8 +3016,8 @@ Override commands are often long and tedious to type, and they
 have to be absolutely correct.  If the same overrides are to be
 used many times it may be worth defining variables to hold them.
 Suppose we wish to emphasize certain words in lyrics by printing
-them in bold italics.  The @code{\italic} and @code{\bold} 
-commands do not work within lyrics so we must instead use the 
+them in bold italics.  The @code{\italic} and @code{\bold}
+commands do not work within lyrics so we must instead use the
 following @code{\override} and @code{\revert} commands:
 
 @example
@@ -2964,14 +3082,12 @@ about LilyPond, but even more information can be gathered by
 looking at the internal LilyPond files.  To explore these, first
 find the directory appropriate to your system, as follows:
 
-@itemize
-
-@item Linux
+@strong{Linux}
 
-Navigate to 
+Navigate to
 @file{@var{installdir}/lilypond/usr/share/lilypond/current/}
 
-@item OSX
+@strong{OSX}
 
 Navigate to
 @file{@var{installdir}/LilyPond.app/Contents/Resources/share/lilypond/current/}
@@ -2979,21 +3095,16 @@ by either @code{cd}-ing into this directory from the
 Terminal, or control-clicking on the LilyPond application and
 selecting @q{Show Package Contents}.
 
-@item Windows
+@strong{Windows}
 
 Using Windows Explorer, navigate to
 @file{@var{installdir}/LilyPond/usr/share/lilypond/current/}
 
-@end itemize
-
 Within this directory the two interesting subdirectories are
 
 @itemize
-
 @item @file{../ly/ } - contains files in LilyPond format
-
 @item @file{../scm/} - contains files in Scheme format
-
 @end itemize
 
 Let's begin by looking at some files in @file{../ly/}.
@@ -3016,7 +3127,7 @@ If you do not like the default values these built-in commands can
 be redefined easily, just like any other variable, at the
 head of your input file.
 
-The following are the most useful files to be found in 
+The following are the most useful files to be found in
 @file{../ly/}:
 
 @multitable @columnfractions .4 .6
@@ -3066,70 +3177,6 @@ interest are:
 
 
 
-@node Advanced tweaks with Scheme
-@subsection Advanced tweaks with Scheme
-
-We have seen how LilyPond output can be heavily modified using
-commands like
-@code{\override TextScript #'extra-offset = ( 1 . -1)}.  But
-we have even more power if we use Scheme.  For a full explantion
-of this, see the @ref{Scheme tutorial}, and
-@ruser{Interfaces for programmers}.
-
-We can use Scheme to simply @code{\override} commands,
-
-TODO Check this is a valid example with skylining
-
-@lilypond[quote,verbatim,ragged-right]
-padText = #(define-music-function (parser location padding) (number?)
-#{
-  \once \override TextScript #'padding = #$padding
-#})
-
-\relative c''' {
-  c4^"piu mosso" b a b
-  \padText #1.8
-  c4^"piu mosso" d e f
-  \padText #2.6
-  c4^"piu mosso" fis a g
-}
-@end lilypond
-
-We can use it to create new commands,
-
-TODO Check this is a valid example with skylining
-
-@lilypond[quote,verbatim,ragged-right]
-tempoMark = #(define-music-function (parser location padding marktext)
-                                    (number? string?)
-#{
-  \once \override Score . RehearsalMark #'padding = $padding
-  \once \override Score . RehearsalMark #'extra-spacing-width = #'(+inf.0 . -inf.0)
-  \mark \markup { \bold $marktext }
-#})
-
-\relative c'' {
-  c2 e
-  \tempoMark #3.0 #"Allegro"
-  g c
-}
-@end lilypond
-
-Even music expressions can be passed in.
-
-@lilypond[quote,verbatim,ragged-right]
-pattern = #(define-music-function (parser location x y) (ly:music? ly:music?)
-#{
-  $x e8 a b $y b a e
-#})
-
-\relative c''{
-  \pattern c8 c8\f
-  \pattern {d16 dis} { ais16-> b\p }
-}
-@end lilypond
-
-
 @node Avoiding tweaks with slower processing
 @subsection Avoiding tweaks with slower processing
 
@@ -3141,20 +3188,71 @@ compress that line of the score just enough to fit within the
 margins.
 
 To be effective under all circumstances these checks must be enabled
-by placing the overrides in a Score @code{\with} block, rather than 
+by placing the overrides in a Score @code{\with} block, rather than
 in-line in music, as follows:
 
-@verbatim
-\new Score \with {
+@example
+\new Score \with @{
   % Makes sure text scripts and lyrics are within the paper margins
   \override PaperColumn #'keep-inside-line = ##t
   \override NonMusicalPaperColumn #'keep-inside-line = ##t
-{
+@} @{
    ..
-}
-@end verbatim
+@}
+@end example
+
+@node Advanced tweaks with Scheme
+@subsection Advanced tweaks with Scheme
 
+Although many things are possible with the @code{\override} and
+@code{\tweak} commands, an even more powerful way of modifying
+the action of LilyPond is available through a programmable
+interface to the LilyPond internal operation.  Code written in
+the Scheme programming language can be incorporated directly in
+the internal operation of LilyPond.  Of course, at least a basic
+knowledge of programming in Scheme is required to do this, and an
+introduction is provided in the @ref{Scheme tutorial}.
+
+As an illustration of one of the many possibilities, instead of
+setting a property to a constant it can be set to a Scheme
+procedure which is then called whenever that property is accessed
+by LilyPond.  The property can then be set dynamically to a value
+determined by the procedure at the time it is called.  In this
+example we color the note head in accordance with its position on
+the staff.
+
+@lilypond[quote,verbatim,ragged-right]
+#(define (color-notehead grob)
+  "Color the notehead according to its position on the staff."
+  (let ((mod-position (modulo (ly:grob-property grob 'staff-position) 7)))
+    (case mod-position
+      ;;   Return rainbow colors
+      ((1) (x11-color 'red    ))  ; for C
+      ((2) (x11-color 'orange ))  ; for D
+      ((3) (x11-color 'yellow ))  ; for E
+      ((4) (x11-color 'green  ))  ; for F
+      ((5) (x11-color 'blue   ))  ; for G
+      ((6) (x11-color 'purple ))  ; for A
+      ((0) (x11-color 'violet ))  ; for B
+    )
+  )
+)
+
+\relative c' {
+  % Arrange to obtain color from color-notehead procedure
+  \override NoteHead #'color = #color-notehead
+  c2 c' | 
+  b4 g8 a b4 c | 
+  c,2 a' | 
+  g1 |
+}
+\addlyrics {
+  Some -- where o -- ver the Rain -- bow way up high,
+}
+@end lilypond
 
+Further examples showing the use of these programmable interfaces
+can be found in @ref{Tweaking with Scheme}.