<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!-- header_tag --> <html lang="en"> <head> <title>Visibility and color of objects - GNU LilyPond Learning Manual</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="description" content="GNU LilyPond Learning Manual"> <meta name="generator" content="makeinfo 4.11"> <link title="Top" rel="start" href="index.de.html#Top"> <link rel="up" href="Appearance-of-objects.de.html#Appearance-of-objects" title="Appearance of objects"> <link rel="next" href="Size-of-objects.de.html#Size-of-objects" title="Size of objects"> <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> <!-- Copyright (C) 1999--2007 by the authors Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections. A copy of the license is included in the section entitled ``GNU Free Documentation License''. --> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"><!-- pre.display { font-family:inherit } pre.format { font-family:inherit } pre.smalldisplay { font-family:inherit; font-size:smaller } pre.smallformat { font-family:inherit; font-size:smaller } pre.smallexample { font-size:smaller } pre.smalllisp { font-size:smaller } span.sc { font-variant:small-caps } span.roman { font-family:serif; font-weight:normal; } span.sansserif { font-family:sans-serif; font-weight:normal; } hr { border:0; height:1; color: #000000; background-color: #000000; } /* hr { border: none; height: 1px; color: #666666; background-color: #666666; } body { border-left: 1px solid #666666; border-right: 1px solid #666666; color: #332d28; margin-right: auto; margin-left: auto; width: 60em; list-style-type: square; font-family: Arial,Helvetica,sans-serif; padding-right: 1em; padding-left: 1em; } a { border-bottom: 1px dashed #344242; text-decoration: none; color: #344242; } a:link { text-decoration: none; } a:visited { border-bottom: 1px dashed #666666; color: #666666; } a:active { border-bottom: 1px solid #00cccc; color: #00cccc; } a:hover { border-bottom: 1px solid #1d7b85; color: #1d7b85; } blockquote { border: 1px solid #cccccc; padding: 3px; width: 40em; } .node { border-left: 1px solid #666666; margin: -0.5em 0px 1em; padding: 2px 1px 0px; font-style: italic; } .node a { border: none; text-decoration: underline; font-style: normal; font-weight: bold; } .verbatim { font-family: "Courier New",Courier,monospace; } .unnumberedsubsubsec { font-size: large; color: #1d7b85; } .subsubheading { font-size: large; color: #3b220d; } .contents { border: 1px dashed #339999; margin: 3px 2em; list-style-type: square; padding-right: 1em; width: 40em; background-color: #fcfff9; } .contents a { border-bottom: 1px dashed #423d34; text-decoration: none; color: #423d34; } .contents a:visited { border-bottom: 1px dashed #666666; color: #666666; } .contents a:active { border-bottom: 1px solid #f0d86d; color: #f0d86d; } .contents a:hover { border-bottom: 1px solid #3b220d; color: #3b220d; } .menu { border-left: 1px dashed #339999; margin: 3px 2em 1em; list-style-type: square; padding-left: 1.4em; width: 40em; } .unnumbered { } h2 { font-size: x-large; color: #1d7b85; } */ --></style> </head> <BODY BGCOLOR=WHITE TEXT=BLACK> <div class="node"> <p> <a name="Visibility-and-color-of-objects"></a> Next: <a rel="next" accesskey="n" href="Size-of-objects.de.html#Size-of-objects">Size of objects</a>, Up: <a rel="up" accesskey="u" href="Appearance-of-objects.de.html#Appearance-of-objects">Appearance of objects</a> <hr> </div> <h4 class="subsection">4.3.1 Visibility and color of objects</h4> <p>In the educational use of music we might wish to print a score with certain elements omitted as an exercise for the student, who is required to supply them. As a simple example, let us suppose the exercise is to supply the missing bar lines in a piece of music. But the bar lines are normally inserted automatically. How do we prevent them printing? <p>Before we tackle this, let us remember that object properties are grouped in what are called <em>interfaces</em> – see <a href="Properties-found-in-interfaces.de.html#Properties-found-in-interfaces">Properties found in interfaces</a>. This is simply to group together those properties that are commonly required together – if one of them is required for an object, so are the others. Some objects then need the properties in some interfaces, others need them from other interfaces. The interfaces which contain the properties required by a particular grob are listed in the IR at the bottom of the page describing that grob, and those properties may be viewed by looking at those interfaces. <p>We explained how to find information about grobs in <a href="Properties-of-layout-objects.de.html#Properties-of-layout-objects">Properties of layout objects</a>. Using the same approach, we go to the IR to find the layout object which prints bar lines. Going via <em>Backend</em> and <em>All layout objects</em> we find there is a layout object called <code>BarLine</code>. Its properties include two that control its visibility: <code>break-visibility</code> and <code>stencil</code>. Barline also supports a number of interfaces, including the <code>grob-interface</code>, where we find the <code>transparent</code> and the <code>color</code> properties. All of these can affect the visibility of bar lines (and, of course, by extension, many other layout objects too.) Let's consider each of these in turn. <h4 class="subheading">stencil</h4> <p><a name="index-stencil-property-372"></a> This property controls the appearance of the bar lines by specifying the symbol (glyph) which should be printed. In common with many other properties, it can be set to print nothing by setting its value to <code>#f</code>. Let's try it, as before, omitting the implied Context, <code>Voice</code>: <blockquote> <pre class="verbatim"> { \time 12/16 \override BarLine #'stencil = ##f c4 b8 c d16 c d8 | g, a16 b8 c d4 e16 | e8 } </pre> <p> <a href="../23/lily-62cf82cd.ly"> <img align="middle" border="0" src="../23/lily-62cf82cd.png" alt="[image of music]"> </a> </p> </blockquote> <p>The bar lines are still printed. What is wrong? Go back to the IR and look again at the page giving the properties of BarLine. At the top of the page it says “Barline objects are created by: Bar_engraver”. Go to the <code>Bar_engraver</code> page. At the bottom it gives a list of Contexts in which the bar engraver operates. All of them are of the type <code>Staff</code>, so the reason the <code>\override</code> command failed to work as expected is because <code>Barline</code> is not in the default <code>Voice</code> context. If the context is specified wrongly, the command simply does not work. No error message is produced, and nothing is logged in the log file. Let's try correcting it by adding the correct context: <blockquote> <pre class="verbatim"> { \time 12/16 \override Staff.BarLine #'stencil = ##f c4 b8 c d16 c d8 | g, a16 b8 c d4 e16 | e8 } </pre> <p> <a href="../4e/lily-f9ac0581.ly"> <img align="middle" border="0" src="../4e/lily-f9ac0581.png" alt="[image of music]"> </a> </p> </blockquote> <p>Now the bar lines have vanished. <h4 class="subheading">break-visibility</h4> <p><a name="index-break_002dvisibility-property-373"></a> We see from the <code>BarLine</code> properties in the IR that the <code>break-visibility</code> property requires a vector of three booleans. These control respectively whether bar lines are printed at the end of a line, in the middle of lines, and at the beginning of lines. For our example we want all bar lines to be suppressed, so the value we need is <code>'#(#f #f #f)</code>. Let's try that, remembering to include the <code>Staff</code> context. Note also that in writing this value we have <code>#'#</code> before the opening bracket. The <code>'#</code> is required as part of the value to introduce a vector, and the first <code>#</code> is required, as always, to precede the value itself in the <code>\override</code> command. <blockquote> <pre class="verbatim"> { \time 12/16 \override Staff.BarLine #'break-visibility = #'#(#f #f #f) c4 b8 c d16 c d8 | g, a16 b8 c d4 e16 | e8 } </pre> <p> <a href="../bd/lily-77d8b3d7.ly"> <img align="middle" border="0" src="../bd/lily-77d8b3d7.png" alt="[image of music]"> </a> </p> </blockquote> <p>And we see this too removes all the bar lines. <h4 class="subheading">transparent</h4> <p><a name="index-transparent-property-374"></a> We see from the properties specified in the <code>grob-interface</code> page in the IR that the <code>transparent</code> property is a boolean. This should be set to <code>#t</code> to make the grob transparent. In this next example let us make the time signature invisible rather than the bar lines. To do this we need to find the grob name for the time signature. Back to the ‘All layout objects’ page in the IR to find the properties of the <code>TimeSignature</code> layout object. This is produced by the <code>Time_signature_engraver</code> which you can check also lives in the <code>Staff</code> context and also supports the <code>grob-interface</code>. So the command to make the time signature transparent is: <blockquote> <pre class="verbatim"> { \time 12/16 \override Staff.TimeSignature #'transparent = ##t c4 b8 c d16 c d8 | g, a16 b8 c d4 e16 | e8 } </pre> <p> <a href="../94/lily-af1cfd91.ly"> <img align="middle" border="0" src="../94/lily-af1cfd91.png" alt="[image of music]"> </a> </p> </blockquote> <p class="noindent">The time signature is gone, but this command leaves a gap where the time signature should be. Maybe this is what is wanted for an exercise for the student to fill it in, but in other circumstances a gap might be undesirable. To remove it, the stencil for the time signature should be set to <code>#f</code> instead: <blockquote> <pre class="verbatim"> { \time 12/16 \override Staff.TimeSignature #'stencil = ##f c4 b8 c d16 c d8 | g, a16 b8 c d4 e16 | e8 } </pre> <p> <a href="../72/lily-9905bb54.ly"> <img align="middle" border="0" src="../72/lily-9905bb54.png" alt="[image of music]"> </a> </p> </blockquote> <p class="noindent">and the difference is obvious: setting the stencil to <code>#f</code> removes the object entirely; making the object <code>transparent</code> leaves it where it is, but makes it invisible. <h4 class="subheading">color</h4> <p><a name="index-color-property-375"></a> Finally let us try making the bar lines invisible by coloring them white. (There is a difficulty with this in that the white bar line may or may not blank out the staff lines where they cross. You may see in some of the examples below that this happens unpredictably. The details of why this is so and how to control it are covered in <a name="index-Painting-objects-white-376"></a><a href="../lilypond/Painting-objects-white.de.html#Painting-objects-white">Painting objects white</a>. But at the moment we are learning about color, so please just accept this limitation for now.) <p>The <code>grob-interface</code> specifies that the color property value is a list, but there is no explanation of what that list should be. The list it requires is actually a list of values in internal units, but, to avoid having to know what these are, several ways are provided to specify colors. The first way is to use one of the ‘normal’ colors listed in the first table in <a name="index-List-of-colors-377"></a><a href="../lilypond/List-of-colors.de.html#List-of-colors">List of colors</a>. To set the bar lines to white we write: <blockquote> <pre class="verbatim"> { \time 12/16 \override Staff.BarLine #'color = #white c4 b8 c d16 c d8 | g, a16 b8 c d4 e16 | e8 } </pre> <p> <a href="../36/lily-5d1ecfa9.ly"> <img align="middle" border="0" src="../36/lily-5d1ecfa9.png" alt="[image of music]"> </a> </p> </blockquote> <p class="noindent">and again, we see the bar lines are not visible. Note that <em>white</em> is not preceded by an apostrophe – it is not a symbol, but a <em>function</em>. When called, it provides the list of internal values required to set the color to white. The other colors in the normal list are functions too. To convince yourself this is working you might like to change the color to one of the other functions in the list. <p><a name="index-color_002c-X11-378"></a><a name="index-X11-colors-379"></a> The second way of changing the color is to use the list of X11 color names in the second list in <a name="index-List-of-colors-380"></a><a href="../lilypond/List-of-colors.de.html#List-of-colors">List of colors</a>. However, these must be preceded by another function, which converts X11 color names into the list of internal values, <code>x11-color</code>, like this: <blockquote> <pre class="verbatim"> { \time 12/16 \override Staff.BarLine #'color = #(x11-color 'white) c4 b8 c d16 c d8 | g, a16 b8 c d4 e16 | e8 } </pre> <p> <a href="../8d/lily-4ec6a6e7.ly"> <img align="middle" border="0" src="../8d/lily-4ec6a6e7.png" alt="[image of music]"> </a> </p> </blockquote> <p class="noindent">Note that in this case the function <code>x11-color</code> takes a symbol as an argument, so the symbol must be preceded by an apostrophe and the two enclosed in brackets. <p><a name="index-rgb-colors-381"></a><a name="index-color_002c-rgb-382"></a> There is yet a third function, one which converts RGB values into internal colors – the <code>rgb-color</code> function. This takes three arguments giving the intensities of the red, green and blue colors. These take values in the range 0 to 1. So to set the color to red the value should be <code>(rgb-color 1 0 0)</code> and to white it should be <code>(rgb-color 1 1 1)</code>: <blockquote> <pre class="verbatim"> { \time 12/16 \override Staff.BarLine #'color = #(rgb-color 1 1 1) c4 b8 c d16 c d8 | g, a16 b8 c d4 e16 | e8 } </pre> <p> <a href="../59/lily-26b4a44d.ly"> <img align="middle" border="0" src="../59/lily-26b4a44d.png" alt="[image of music]"> </a> </p> </blockquote> <p>Finally, there is also a grey scale available as part of the X11 set of colors. These range from black, <code>'grey0'</code>, to white, <code>'grey100</code>, in steps of 1. Let's illustrate this by setting all the layout objects in our example to various shades of grey: <blockquote> <pre class="verbatim"> { \time 12/16 \override Staff.StaffSymbol #'color = #(x11-color 'grey30) \override Staff.TimeSignature #'color = #(x11-color 'grey60) \override Staff.Clef #'color = #(x11-color 'grey60) \override Voice.NoteHead #'color = #(x11-color 'grey85) \override Voice.Stem #'color = #(x11-color 'grey85) \override Staff.BarLine #'color = #(x11-color 'grey10) c4 b8 c d16 c d8 | g, a16 b8 c d4 e16 | e8 } </pre> <p> <a href="../78/lily-1319851f.ly"> <img align="middle" border="0" src="../78/lily-1319851f.png" alt="[image of music]"> </a> </p> </blockquote> <p class="noindent">Note the contexts associated with each of the layout objects. It is important to get these right, or the commands will not work! Remember, the context is the one in which the appropriate engraver is placed. The default context for engravers can be found by starting from the layout object, going from there to the engraver which produces it, and on the engraver page in the IR it tells you in which context the engraver will normally be found. <!-- footer_tag --><br><hr> <div class="node"> <p> Next: <a rel="next" accesskey="n" href="Size-of-objects.de.html#Size-of-objects">Size of objects</a>, Up: <a rel="up" accesskey="u" href="Appearance-of-objects.de.html#Appearance-of-objects">Appearance of objects</a> </div> <div style="background-color: #e8ffe8; padding: 2; border: #c0ffc0 1px solid;"> <p> <font size="-1"> Diese Seite ist für LilyPond-2.11.57 (Entwicklungszweig). <br> <address> Fehler bitte an <a href="http://post.gmane.org/post.php?group=gmane.comp.gnu.lilypond.bugs">http://post.gmane.org/post.php?group=gmane.comp.gnu.lilypond.bugs</a> melden. </address> <br> Ihre <a href="http://lilypond.org/web/devel/participating/documentation-adding">Vorschläge für die Dokumentation</a> sind willkommen. </font> </p> </div> <P> Andere Sprachen: <a href="Visibility-and-color-of-objects.es.html">español</a>. <BR> </P> </BODY></html>