LilyPond snippets: Fretted strings

# Fretted strings

These snippets illustrate the Notation Reference, section Fretted string instruments.

## Adding fingerings to a score

Fingering instructions can be entered using a simple syntax.

    \relative c'' {
      c4-1 d-2 f-4 e-3
    }

## Adding fingerings to tablatures

To add fingerings to tablatures, use a combination of `\markup` and `\finger`.

    one = \markup { \finger 1 }
    two = \markup { \finger 2 }
    threeTwo = \markup {
      \override #'(baseline-skip . 2)
      \column {
        \finger 3
        \finger 2
      }
    }
    threeFour = \markup {
      \override #'(baseline-skip . 2)
      \column {
        \finger 3
        \finger 4
      }
    }

    \score {
      \new TabStaff {
        \stemUp
        e8\4^\one b\2 <e, g\3 e'\1>^>[ b\2 e\4]
        <a\3 fis'\1>^>^\threeTwo[ b\2 e\4]
      }
    }

## Allowing fingerings to be printed inside the staff

By default, vertically oriented fingerings are positioned outside the staff. However, this behavior can be canceled.

    \relative c' {
      <c-1 e-2 g-3 b-5>2
      \once \override Fingering #'staff-padding = #'()
      <c-1 e-2 g-3 b-5>2
    }

## Controlling the placement of chord fingerings

The placement of fingering numbers can be controlled precisely.

    \relative c' {
      \set fingeringOrientations = #'(left)
      <c-1 e-3 a-5>4
      \set fingeringOrientations = #'(down)
      <c-1 e-3 a-5>4
      \set fingeringOrientations = #'(down right up)
      <c-1 e-3 a-5>4
      \set fingeringOrientations = #'(up)
      <c-1 e-3 a-5>4
      \set fingeringOrientations = #'(left)
      <c-1>2
      \set fingeringOrientations = #'(down)
      <e-3>2
    }

## Customizing fretboard fret diagrams

Fret diagram properties can be set through `'fret-diagram-details`. For FretBoard fret diagrams, overrides are applied to the `FretBoards.FretBoard` object. Like `Voice`, `FretBoards` is a bottom level context, therefore can be omitted in property overrides.

    \include "predefined-guitar-fretboards.ly"
    \storePredefinedDiagram \chordmode { c' }
                            #guitar-tuning
                            #"x;1-1-(;3-2;3-3;3-4;1-1-);"
    <<
      \new ChordNames {
        \chordmode { c1 | c | c | d }
      }
      \new FretBoards {
        % Set global properties of fret diagram
        \override FretBoards.FretBoard #'size = #'1.2
        \override FretBoard
          #'(fret-diagram-details finger-code) = #'in-dot
        \override FretBoard
          #'(fret-diagram-details dot-color) = #'white
        \chordmode {
          c
          \once \override FretBoard #'size = #'1.0
          \once \override FretBoard
            #'(fret-diagram-details barre-type) = #'straight
          \once \override FretBoard
            #'(fret-diagram-details dot-color) = #'black
          \once \override FretBoard
            #'(fret-diagram-details finger-code) = #'below-string
          c'
          \once \override FretBoard
            #'(fret-diagram-details barre-type) = #'none
          \once \override FretBoard
            #'(fret-diagram-details number-type) = #'arabic
          \once \override FretBoard
            #'(fret-diagram-details orientation) = #'landscape
          \once \override FretBoard
            #'(fret-diagram-details mute-string) = #"M"
          \once \override FretBoard
            #'(fret-diagram-details label-dir) = #LEFT
          \once \override FretBoard
            #'(fret-diagram-details dot-color) = #'black
          c'
          \once \override FretBoard
            #'(fret-diagram-details finger-code) = #'below-string
          \once \override FretBoard
            #'(fret-diagram-details dot-radius) = #0.35
          \once \override FretBoard
            #'(fret-diagram-details dot-position) = #0.5
          \once \override FretBoard
            #'(fret-diagram-details fret-count) = #3
          d
        }
      }
      \new Voice {
        c'1 | c' | c' | d'
      }
    >>

## Customizing markup fret diagrams

Fret diagram properties can be set through `'fret-diagram-details`. For markup fret diagrams, overrides can be applied to the `Voice.TextScript` object or directly to the markup.

    <<
      \chords { c1 | c | c | d }

      \new Voice = "mel" {
        \textLengthOn
        % Set global properties of fret diagram
        \override TextScript #'size = #'1.2
        \override TextScript
          #'(fret-diagram-details finger-code) = #'in-dot
        \override TextScript
          #'(fret-diagram-details dot-color) = #'white

        %% C major for guitar, no barre, using defaults
           % terse style
        c'1^\markup { \fret-diagram-terse #"x;3-3;2-2;o;1-1;o;" }

        %% C major for guitar, barred on third fret
           % verbose style
           % size 1.0
           % roman fret label, finger labels below string, straight barre
        c'1^\markup {
          % standard size
          \override #'(size . 1.0) {
            \override #'(fret-diagram-details . (
                         (number-type . roman-lower)
                         (finger-code . in-dot)
                         (barre-type . straight))) {
              \fret-diagram-verbose #'((mute 6)
                                       (place-fret 5 3 1)
                                       (place-fret 4 5 2)
                                       (place-fret 3 5 3)
                                       (place-fret 2 5 4)
                                       (place-fret 1 3 1)
                                       (barre 5 1 3))
            }
          }
        }

        %% C major for guitar, barred on third fret
           % verbose style
           % landscape orientation, arabic numbers, M for mute string
           % no barre, fret label down or left, small mute label font
        c'1^\markup {
          \override #'(fret-diagram-details . (
                       (finger-code . below-string)
                       (number-type . arabic)
                       (label-dir . -1)
                       (mute-string . "M")
                       (orientation . landscape)
                       (barre-type . none)
                       (xo-font-magnification . 0.4)
                       (xo-padding . 0.3))) {
            \fret-diagram-verbose #'((mute 6)
                                     (place-fret 5 3 1)
                                     (place-fret 4 5 2)
                                     (place-fret 3 5 3)
                                     (place-fret 2 5 4)
                                     (place-fret 1 3 1)
                                     (barre 5 1 3))
          }
        }

        %% simple D chord
           % terse style
           % larger dots, centered dots, fewer frets
           % label below string
        d'1^\markup {
          \override #'(fret-diagram-details . (
                       (finger-code . below-string)
                       (dot-radius . 0.35)
                       (dot-position . 0.5)
                       (fret-count . 3))) {
            \fret-diagram-terse #"x;x;o;2-1;3-2;2-3;"
          }
        }
      }
    >>

## Defining predefined fretboards for other instruments

Predefined fret diagrams can be added for new instruments in addition to the standards used for guitar. This file shows how this is done by defining a new string-tuning and a few predefined fretboards for the Venezuelan cuatro.

This file also shows how fingerings can be included in the chords used as reference points for the chord lookup, and displayed in the fret diagram and the `TabStaff`, but not the music.

These fretboards are not transposable because they contain string information. This is planned to be corrected in the future.

    % add FretBoards for the Cuatro
    %   Note: This section could be put into a separate file
    %      predefined-cuatro-fretboards.ly
    %      and \included into each of your compositions

    cuatroTuning = #'(11 18 14 9)

    dSix = { <a\4 b\1 d\3 fis\2> }
    dMajor = { <a\4 d\1 d\3 fis \2> }
    aMajSeven = { <a\4 cis\1 e\3 g\2> }
    dMajSeven = { <a\4 c\1 d\3 fis\2> }
    gMajor = { <b\4 b\1 d\3 g\2> }

    \storePredefinedDiagram \dSix
                            #cuatroTuning
                            #"o;o;o;o;"
    \storePredefinedDiagram \dMajor
                            #cuatroTuning
                            #"o;o;o;3-3;"
    \storePredefinedDiagram \aMajSeven
                            #cuatroTuning
                            #"o;2-2;1-1;2-3;"
    \storePredefinedDiagram \dMajSeven
                            #cuatroTuning
                            #"o;o;o;1-1;"
    \storePredefinedDiagram \gMajor
                            #cuatroTuning
                            #"2-2;o;1-1;o;"

    % end of potential include file /predefined-cuatro-fretboards.ly

    #(set-global-staff-size 16)

    primerosNames = \chordmode {
      d:6 d a:maj7 d:maj7
      g
    }
    primeros = {
      \dSix \dMajor \aMajSeven \dMajSeven
      \gMajor
    }

    \score {
      <<
        \new ChordNames {
          \set chordChanges = ##t
          \primerosNames
        }

        \new Staff {
          \new Voice \with {
            \remove "New_fingering_engraver"
          }
          \relative c'' {
            \primeros
          }
        }

        \new FretBoards {
          \set stringTunings = #cuatroTuning
          \override FretBoard
            #'(fret-diagram-details string-count) = #'4
          \override FretBoard
            #'(fret-diagram-details finger-code) = #'in-dot
          \primeros
        }

        \new TabStaff \relative c'' {
          \set TabStaff.stringTunings = #cuatroTuning
          \primeros
        }

      >>

      \layout {
        \context {
          \Score
          \override SpacingSpanner
            #'base-shortest-duration = #(ly:make-moment 1 16)
        }
      }
      \midi { }
    }

## Faking a hammer in tablatures

A hammer in tablature can be faked with slurs.

    \score {
      \new TabStaff {
        \relative c'' {
          c4( d) d( d)
          d2( c)
        }
      }
    }

## Fingerings, string indications, and right-hand fingerings

This example combines left-hand fingering, string indications, and right-hand fingering.

    #(define RH rightHandFinger)

    \relative c {
      \clef "treble_8"
      <c-3\5-\RH #1 >4
      <e-2\4-\RH #2 >4
      <g-0\3-\RH #3 >4
      <c-1\2-\RH #4 >4
    }

## Flamenco notation

For flamenco guitar, special notation is used:

* a golpe symbol to indicate a slap on the guitar body with the nail of the ring finger

* an arrow to indicate (the direction of) strokes

* different letters for fingering ("p": thumb, "i": index finger, "m": middle finger, "a": ring finger and "x": little finger)

* 3- and 4-finger rasgueados; stroke upwards with all fingers, ending with an up- and down using the index finger

* abanicos: strokes (in tuples) with thumb (down), little and index finger (both up). There’s also an abanico 2 where middle and ring finger are used instead of the little finger.

* alza pua: fast playing with the thumb

Most figures use arrows in combination with fingering; with abanicos and rasgueados, noteheads are printed only for the first chord.

This snippet contains some header-like code that can be copied as ‘`flamenco.ly`’ and included in source files.

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%  Cut here ----- Start 'flamenco.ly'

    % Text indicators
    abanico   = \markup { \italic Abanico }
    rasgueaso = \markup { \italic Ras. }
    alzapua   = \markup { \italic Alzapua }

    % Finger stroke symbols
    strokeUp = \markup { \postscript #"
      0.1     setlinewidth
      0.5 0   moveto
      0.5 2   lineto
      0.2 1.4 lineto
      0.5 2   moveto
      0.8 1.4 lineto
      stroke
    "}

    strokeDown = \markup { \postscript #"
      0.1     setlinewidth
      0.5 2   moveto
      0.5 0   lineto
      0.2 0.6 lineto
      0.5 0   moveto
      0.8 0.6 lineto
      stroke
    "}

    % Golpe symbol
    golpe = \markup { \postscript #"
      0.2 setlinewidth
      0 0 moveto
      1 0 lineto
      1 1 lineto
      stroke
      "\postscript #"
      0.1       setlinewidth
      -0.6 -0.1  moveto
      -0.6  1.0 lineto
      0.5  1.0 lineto
      stroke
    "}

    strokeUpGolpe = \markup { \column { \golpe \line { \strokeUp }}}
    iUpGolpe = \markup { \column { \golpe \line { \small i } \line { \strokeUp }}}

    % Strokes for all fingers
    pUp   = \markup { \column { \small p \line { \strokeUp }}}
    pDown = \markup { \column { \small p \line { \strokeDown }}}
    iUp   = \markup { \column { \small i \line { \strokeUp }}}
    iDown = \markup { \column { \small i \line { \strokeDown }}}
    mUp   = \markup { \column { \small m \line { \strokeUp }}}
    mDown = \markup { \column { \small m \line { \strokeDown }}}
    aUp   = \markup { \column { \small a \line { \strokeUp }}}
    aDown = \markup { \column { \small a \line { \strokeDown }}}
    xUp   = \markup { \column { \small x \line { \strokeUp }}}
    xDown = \markup { \column { \small x \line { \strokeDown }}}

    % Just handy :)
    tupletOff = {
      \once \override TupletNumber #'stencil = ##f
      \once \override TupletBracket #'stencil = ##f
    }

    tupletsOff = {
      \override TupletNumber #'stencil = ##f
      \override TupletBracket #'bracket-visibility = #'if-no-beam
    }

    tupletsOn = {
      \override TupletBracket #'bracket-visibility = #'default
      \revert TupletNumber #'stencil
    }

    headsOff = {
      \override TabNoteHead #'transparent = ##t
      \override NoteHead #'transparent = ##t
      \override NoteHead #'no-ledgers = ##t
    }

    headsOn = {
      \override TabNoteHead #'transparent = ##f
      \override NoteHead #'transparent = ##f
      \override NoteHead #'no-ledgers = ##f
    }

    %%%%%%%  Cut here ----- End 'flamenco.ly'
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    part = \relative c' {
      <a, e' a cis e>8^\iUp
      <a e' a cis e>8^\iDown
      r4
      r2^\golpe

      <a e' a cis e>8^\iUp
      <a e' a cis e>8^\iDown
      <a e' a cis e>8^\iUpGolpe
      <a e' a cis e>8^\iDown
      r2

      <a e' a cis e>16^\aUp
      \headsOff
      <a e' a cis e>^\mUp
      <a e' a cis e>^\iUp
      <a e' a cis e>^\iDown~
      \headsOn
      <a e' a cis e>2
      r4

      \tupletOff
      \times 4/5 {
        <a e' a cis e>16^\xUp
        \headsOff
        <a e' a cis e>^\aUp
        <a e' a cis e>^\mUp
        <a e' a cis e>^\iUp
        <a e' a cis e>^\iDown~
        \headsOn
      }
      <a e' a cis e>2
      r4

      \tupletsOff
      \times 2/3 {
        <a e' a cis e>8^\pDown
        \headsOff
        <a e' a cis e>^\xUp
        <a e' a cis e>^\iUp
        \headsOn
      }

      \times 2/3 {
        <a e' a cis e>8^\pDown
        \headsOff
        <a e' a cis e>^\xUp
        <a e' a cis e>^\iUp
        \headsOn
      }

      \times 2/3 {
        <a e' a cis e>8^\pDown
        \headsOff
        <a e' a cis e>^\xUp
        <a e' a cis e>^\iUp
        \headsOn
      }
      \times 2/3 {
        <a e' a cis e>8^\pDown
        \headsOff
        <a e' a cis e>^\xUp
        <a e' a cis e>^\iUp
        \headsOn
      }

      \tupletsOff
      \override Beam #'positions = #'(2 . 2)
      \times 2/3 {
        a8^\markup{ \small p }
        <e' a>^\strokeUpGolpe
        <e a>^\strokeDown
      }
      \times 2/3 {
        a,8^\markup{ \small p }
        <e' a>^\strokeUpGolpe
        <e a>^\strokeDown
      }
      \times 2/3 {
        a,8^\markup{ \small p }
        <e' a>^\strokeUpGolpe
        <e a>^\strokeDown
      }
      \times 2/3 {
        a,8^\markup{ \small p }
        <e' a>^\strokeUpGolpe
        <e a>^\strokeDown
      }
      \tupletsOn

      \once \override TextScript #'extra-offset = #'(0 . -1)
      <g, b f'>1_\golpe^\mUp
      \bar "|."
    }

    \score {
      \new StaffGroup <<
        \context Staff = "part" <<
          \clef G
          \transpose c c'
          {
            \part
          }
        >>
        \context TabStaff {
          \part
        }
      >>
      \layout {
        ragged-right = ##t
      }
    }

## Fret diagrams explained and developed

This snippet shows many possibilities for obtaining and tweaking fret diagrams.

    <<
      \chords {
        a2 a
        \repeat unfold 3 {
          c c c d d
        }
      }

      \new Voice = "mel" {
        \textLengthOn
        % Set global properties of fret diagram
        \override TextScript #'size = #1.2
        \override TextScript
          #'fret-diagram-details #'finger-code = #'below-string
        \override TextScript #'fret-diagram-details #'dot-color = #'black

        %% A chord for ukelele
        a'2^\markup {
          \override #'(fret-diagram-details . (
                       (string-count . 4)
                       (dot-color . white)
                       (finger-code . in-dot))) {
            \fret-diagram #"4-2-2;3-1-1;2-o;1-o;"
          }
        }

        %% A chord for ukelele, with formatting defined in definition string
        %  1.2 * size, 4 strings, 4 frets, fingerings below string
        %  dot radius .35 of fret spacing, dot position 0.55 of fret spacing
        a'2^\markup {
          \override #'(fret-diagram-details . (
                       (dot-color . white)
                       (open-string . "o"))) {
            \fret-diagram #"s:1.2;w:4;h:3;f:2;d:0.35;p:0.55;4-2-2;3-1-1;2-o;1-o;"
          }
        }

          %% These chords will be in normal orientation

        %% C major for guitar, barred on third fret
        %  verbose style
        %  roman fret label, finger labels below string, straight barre
        c'2^\markup {
          % 110% of default size
          \override #'(size . 1.1) {
            \override #'(fret-diagram-details . (
                         (number-type . roman-lower)
                         (finger-code . below-string)
                         (barre-type . straight))) {
              \fret-diagram-verbose #'((mute 6)
                                       (place-fret 5 3 1)
                                       (place-fret 4 5 2)
                                       (place-fret 3 5 3)
                                       (place-fret 2 5 4)
                                       (place-fret 1 3 1)
                                       (barre 5 1 3))
            }
          }
        }

        %% C major for guitar, barred on third fret
        %% Double barre used to test barre function
        %  verbose style
        c'2^\markup {
          % 110% of default size
          \override #'(size . 1.1) {
            \override #'(fret-diagram-details . (
                         (number-type . arabic)
                         (dot-label-font-mag . 0.9)
                         (finger-code . in-dot)
                         (fret-label-font-mag . 0.6)
                         (fret-label-vertical-offset . 0)
                         (label-dir . -1)
                         (mute-string . "M")
                         (xo-font-magnification . 0.4)
                         (xo-padding . 0.3))) {
              \fret-diagram-verbose #'((mute 6)
                                       (place-fret 5 3 1)
                                       (place-fret 4 5 2)
                                       (place-fret 3 5 3)
                                       (place-fret 2 5 4)
                                       (place-fret 1 3 1)
                                       (barre 4 2 5)
                                       (barre 5 1 3))
            }
          }
        }

        %% C major for guitar, with capo on third fret
        %  verbose style
        c'2^\markup {
          % 110% of default size
          \override #'(size . 1.1) {
            \override #'(fret-diagram-details . (
                         (number-type . roman-upper)
                         (dot-label-font-mag . 0.9)
                         (finger-code . none)
                         (fret-label-vertical-offset . 0.5)
                         (xo-font-magnification . 0.4)
                         (xo-padding . 0.3))) {
              \fret-diagram-verbose #'((mute 6)
                                       (capo 3)
                                       (open 5)
                                       (place-fret 4 5 1)
                                       (place-fret 3 5 2)
                                       (place-fret 2 5 3)
                                       (open 1))
            }
          }
        }

        %% simple D chord
        d'2^\markup {
          \override #'(fret-diagram-details . (
                       (finger-code . below-string)
                       (dot-radius . 0.35)
                       (string-thickness-factor . 0.3)
                       (dot-position . 0.5)
                       (fret-count . 3))) {
            \fret-diagram-terse #"x;x;o;2-1;3-2;2-3;"
          }
        }

        %% simple D chord, large top fret thickness
        d'2^\markup  {
          \override #'(fret-diagram-details . (
                       (finger-code . below-string)
                       (dot-radius . 0.35)
                       (dot-position . 0.5)
                       (top-fret-thickness . 7)
                       (fret-count . 3))) {
            \fret-diagram-terse #"x;x;o;2-1;3-2;2-3;"
          }
        }

          % These chords will be in landscape orientation
        \override TextScript
           #'fret-diagram-details #'orientation = #'landscape

        %% C major for guitar, barred on third fret
        %  verbose style
        %  roman fret label, finger labels below string, straight barre
        c'2^\markup {
          % 110% of default size
          \override #'(size . 1.1) {
            \override #'(fret-diagram-details . (
                         (number-type . roman-lower)
                         (finger-code . below-string)
                         (barre-type . straight))) {
              \fret-diagram-verbose #'((mute 6)
                                       (place-fret 5 3 1)
                                       (place-fret 4 5 2)
                                       (place-fret 3 5 3)
                                       (place-fret 2 5 4)
                                       (place-fret 1 3 1)
                                       (barre 5 1 3))
            }
          }
        }

        %% C major for guitar, barred on third fret
        %% Double barre used to test barre function
        %  verbose style
        c'2^\markup {
          % 110% of default size
          \override #'(size . 1.1) {
            \override #'(fret-diagram-details . (
                         (number-type . arabic)
                         (dot-label-font-mag . 0.9)
                         (finger-code . in-dot)
                         (fret-label-font-mag . 0.6)
                         (fret-label-vertical-offset . 0)
                         (label-dir . -1)
                         (mute-string . "M")
                         (xo-font-magnification . 0.4)
                         (xo-padding . 0.3))) {
              \fret-diagram-verbose #'((mute 6)
                                       (place-fret 5 3 1)
                                       (place-fret 4 5 2)
                                       (place-fret 3 5 3)
                                       (place-fret 2 5 4)
                                       (place-fret 1 3 1)
                                       (barre 4 2 5)
                                       (barre 5 1 3))
            }
          }
        }

        %% C major for guitar, with capo on third fret
        %  verbose style
        c'2^\markup {
          % 110% of default size
          \override #'(size . 1.1) {
            \override #'(fret-diagram-details . (
                         (number-type . roman-upper)
                         (dot-label-font-mag . 0.9)
                         (finger-code . none)
                         (fret-label-vertical-offset . 0.5)
                         (xo-font-magnification . 0.4)
                         (xo-padding . 0.3))) {
              \fret-diagram-verbose #'((mute 6)
                                       (capo 3)
                                       (open 5)
                                       (place-fret 4 5 1)
                                       (place-fret 3 5 2)
                                       (place-fret 2 5 3)
                                       (open 1))
            }
          }
        }

        %% simple D chord
        d'2^\markup {
          \override #'(fret-diagram-details . (
                       (finger-code . below-string)
                       (dot-radius . 0.35)
                       (dot-position . 0.5)
                       (fret-count . 3))) {
            \fret-diagram-terse #"x;x;o;2-1;3-2;2-3;"
          }
        }

        %% simple D chord, large top fret thickness
        d'2^\markup {
          \override #'(fret-diagram-details . (
                       (finger-code . below-string)
                       (dot-radius . 0.35)
                       (dot-position . 0.5)
                       (top-fret-thickness . 7)
                       (fret-count . 3))) {
            \fret-diagram-terse #"x;x;o;2-1;3-2;2-3;"
          }
        }

          % These chords will be in opposing-landscape orientation
        \override TextScript #'fret-diagram-details
                               #'orientation = #'opposing-landscape

        %% C major for guitar, barred on third fret
        %  verbose style
        %  roman fret label, finger labels below string, straight barre
        c'2^\markup {
          % 110% of default size
          \override #'(size . 1.1) {
            \override #'(fret-diagram-details . (
                         (number-type . roman-lower)
                         (finger-code . below-string)
                         (barre-type . straight))) {
              \fret-diagram-verbose #'((mute 6)
                                       (place-fret 5 3 1)
                                       (place-fret 4 5 2)
                                       (place-fret 3 5 3)
                                       (place-fret 2 5 4)
                                       (place-fret 1 3 1)
                                       (barre 5 1 3))
            }
          }
        }

        %% C major for guitar, barred on third fret
        %% Double barre used to test barre function
        %  verbose style
        c'2^\markup {
          % 110% of default size
          \override #'(size . 1.1) {
            \override #'(fret-diagram-details . (
                         (number-type . arabic)
                         (dot-label-font-mag . 0.9)
                         (finger-code . in-dot)
                         (fret-label-font-mag . 0.6)
                         (fret-label-vertical-offset . 0)
                         (label-dir . -1)
                         (mute-string . "M")
                         (xo-font-magnification . 0.4)
                         (xo-padding . 0.3))) {
              \fret-diagram-verbose #'((mute 6)
                                       (place-fret 5 3 1)
                                       (place-fret 4 5 2)
                                       (place-fret 3 5 3)
                                       (place-fret 2 5 4)
                                       (place-fret 1 3 1)
                                       (barre 4 2 5)
                                       (barre 5 1 3))
            }
          }
        }

        %% C major for guitar, with capo on third fret
        %  verbose style
        c'2^\markup {
          % 110% of default size
          \override #'(size . 1.1) {
            \override #'(fret-diagram-details . (
                         (number-type . roman-upper)
                         (dot-label-font-mag . 0.9)
                         (finger-code . none)
                         (fret-label-vertical-offset . 0.5)
                         (xo-font-magnification . 0.4)
                         (xo-padding . 0.3))) {
              \fret-diagram-verbose #'((mute 6)
                                       (capo 3)
                                       (open 5)
                                       (place-fret 4 5 1)
                                       (place-fret 3 5 2)
                                       (place-fret 2 5 3)
                                       (open 1))
            }
          }
        }

        %% simple D chord
        d'2^\markup {
          \override #'(fret-diagram-details . (
                       (finger-code . below-string)
                       (dot-radius . 0.35)
                       (dot-position . 0.5)
                       (fret-count . 3))) {
            \fret-diagram-terse #"x;x;o;2-1;3-2;2-3;"
          }
        }

        %% simple D chord, large top fret thickness
        d'2^\markup {
          \override #'(fret-diagram-details . (
                       (finger-code . below-string)
                       (dot-radius . 0.35)
                       (dot-position . 0.5)
                       (top-fret-thickness . 7)
                       (fret-count . 3))) {
            \fret-diagram-terse #"x;x;o;2-1;3-2;2-3;"
          }
        }
      }
    >>

## Guitar strum rhythms

For guitar music, it is possible to show strum rhythms, along with melody notes, chord names and fret diagrams.

    \include "predefined-guitar-fretboards.ly"
    <<
      \new ChordNames {
        \chordmode {
          c1 f g c
        }
      }
      \new FretBoards {
        \chordmode {
          c1 f g c
        }
      }
      \new Voice \with {
        \consists "Pitch_squash_engraver"
      } {
        \relative c'' {
          \improvisationOn
          c4 c8 c c4 c8 c
          f4 f8 f f4 f8 f
          g4 g8 g g4 g8 g
          c4 c8 c c4 c8 c
        }
      }
      \new Voice = "melody" {
        \relative c'' {
          c2 e4 e4
          f2. r4
          g2. a4
          e4 c2.
        }
      }
      \new Lyrics {
        \lyricsto "melody" {
          This is my song.
          I like to sing.
        }
      }
    >>

## How to change fret diagram position

If you want to move the position of a fret diagram, for example, to avoid collision, or to place it between two notes, you have various possibilities:

1) modify #’padding or #’extra-offset values (as shown in the first snippet)

2) you can add an invisible voice and attach the fret diagrams to the invisible notes in that voice (as shown in the second example).

If you need to move the fret according with a rythmic position inside the bar (in the example, the third beat of the measure) the second example is better, because the fret is aligned with the third beat itself.

    harmonies = \chordmode
    {
      a8:13
    % THE FOLLOWING IS THE COMMAND TO MOVE THE CHORD NAME
      \once \override ChordNames.ChordName #'extra-offset = #'(10 . 0)
      b8:13 s2.
    % THIS LINE IS THE SECOND METHOD
        s4 s4  b4:13
    }

    \score
    {
      <<
        \context ChordNames \harmonies
        \context Staff
        {a8^\markup { \fret-diagram  #"6-x;5-0;4-2;3-0;2-0;1-2;"  }
    % THE FOLLOWING IS THE COMMAND TO MOVE THE FRET DIAGRAM
         \once \override TextScript #'extra-offset = #'(10 . 0)
         b4.~^\markup { \fret-diagram  #"6-x;5-2;4-4;3-2;2-2;1-4;"  } b4. a8\break
    % HERE IS THE SECOND METHOD
         <<
           { a8 b4.~ b4. a8}
           { s4 s4 s4^\markup { \fret-diagram  #"6-x;5-2;4-4;3-2;2-2;1-4;"  }
           }
         >>
       }
      >>
    }

## Jazz combo template

This is quite an advanced template, for a jazz ensemble. Note that all instruments are notated in `\key c \major`. This refers to the key in concert pitch; the key will be automatically transposed if the music is within a `\transpose` section.

    \header {
      title = "Song"
      subtitle = "(tune)"
      composer = "Me"
      meter = "moderato"
      piece = "Swing"
      tagline = \markup {
        \column {
          "LilyPond example file by Amelie Zapf,"
          "Berlin 07/07/2003"
        }
      }
    }

    %#(set-global-staff-size 16)
    \include "english.ly"

    %%%%%%%%%%%% Some macros %%%%%%%%%%%%%%%%%%%

    sl = {
      \override NoteHead #'style = #'slash
      \override Stem #'transparent = ##t
    }
    nsl = {
      \revert NoteHead #'style
      \revert Stem #'transparent
    }
    crOn = \override NoteHead #'style = #'cross
    crOff = \revert NoteHead #'style

    %% insert chord name style stuff here.

    jazzChords = { }

    %%%%%%%%%%%% Keys'n'thangs %%%%%%%%%%%%%%%%%

    global = { \time 4/4 }

    Key = { \key c \major }

    % ############ Horns ############

    % ------ Trumpet ------
    trpt = \transpose c d \relative c'' {
      \Key
      c1 | c | c |
    }
    trpHarmony = \transpose c' d {
      \jazzChords
    }
    trumpet = {
      \global
      \set Staff.instrumentName = #"Trumpet"
      \clef treble
      <<
        \trpt
      >>
    }

    % ------ Alto Saxophone ------
    alto = \transpose c a \relative c' {
      \Key
      c1 | c | c |
    }
    altoHarmony = \transpose c' a {
      \jazzChords
    }
    altoSax = {
      \global
      \set Staff.instrumentName = #"Alto Sax"
      \clef treble
      <<
        \alto
      >>
    }

    % ------ Baritone Saxophone ------
    bari = \transpose c a' \relative c {
      \Key
      c1
      c1
      \sl
      d4^"Solo" d d d
      \nsl
    }
    bariHarmony = \transpose c' a \chordmode {
      \jazzChords s1 s d2:maj e:m7
    }
    bariSax = {
      \global
      \set Staff.instrumentName = #"Bari Sax"
      \clef treble
      <<
        \bari
      >>
    }

    % ------ Trombone ------
    tbone = \relative c {
      \Key
      c1 | c | c
    }
    tboneHarmony = \chordmode {
      \jazzChords
    }
    trombone = {
      \global
      \set Staff.instrumentName = #"Trombone"
      \clef bass
      <<
        \tbone
      >>
    }

    % ############ Rhythm Section #############

    % ------ Guitar ------
    gtr = \relative c'' {
      \Key
      c1
      \sl
      b4 b b b
      \nsl
      c1
    }
    gtrHarmony = \chordmode {
      \jazzChords
      s1 c2:min7+ d2:maj9
    }
    guitar = {
      \global
      \set Staff.instrumentName = #"Guitar"
      \clef treble
      <<
        \gtr
      >>
    }

    %% ------ Piano ------
    rhUpper = \relative c'' {
      \voiceOne
      \Key
      c1 | c | c
    }
    rhLower = \relative c' {
      \voiceTwo
      \Key
      e1 | e | e
    }

    lhUpper = \relative c' {
      \voiceOne
      \Key
      g1 | g | g
    }
    lhLower = \relative c {
      \voiceTwo
      \Key
      c1 | c | c
    }

    PianoRH = {
      \clef treble
      \global
      \set Staff.midiInstrument = #"acoustic grand"
      <<
        \new Voice = "one" \rhUpper
        \new Voice = "two" \rhLower
      >>
    }
    PianoLH = {
      \clef bass
      \global
      \set Staff.midiInstrument = "acoustic grand"
      <<
        \new Voice = "one" \lhUpper
        \new Voice = "two" \lhLower
      >>
    }

    piano = {
      <<
        \set PianoStaff.instrumentName = #"Piano"
        \new Staff = "upper" \PianoRH
        \new Staff = "lower" \PianoLH
      >>
    }

    % ------ Bass Guitar ------
    Bass = \relative c {
      \Key
      c1 | c | c
    }
    bass = {
      \global
      \set Staff.instrumentName = #"Bass"
      \clef bass
      <<
        \Bass
      >>
    }

    % ------ Drums ------
    up = \drummode {
      \voiceOne
      hh4 <hh sn> hh <hh sn>
      hh4 <hh sn> hh <hh sn>
      hh4 <hh sn> hh <hh sn>
    }
    down = \drummode {
      \voiceTwo
      bd4 s bd s
      bd4 s bd s
      bd4 s bd s
    }

    drumContents = {
      \global
      <<
        \set DrumStaff.instrumentName = #"Drums"
        \new DrumVoice \up
        \new DrumVoice \down
      >>
    }

    %%%%%%%%% It All Goes Together Here %%%%%%%%%%%%%%%%%%%%%%

    \score {
      <<
        \new StaffGroup = "horns" <<
          \new Staff = "trumpet" \trumpet
          \new Staff = "altosax" \altoSax
          \new ChordNames = "barichords" \bariHarmony
          \new Staff = "barisax" \bariSax
          \new Staff = "trombone" \trombone
        >>

        \new StaffGroup = "rhythm" <<
          \new ChordNames = "chords" \gtrHarmony
          \new Staff = "guitar" \guitar
          \new PianoStaff = "piano" \piano
          \new Staff = "bass" \bass
          \new DrumStaff \drumContents
        >>
      >>

      \layout {
        \context { \RemoveEmptyStaffContext }
        \context {
          \Score
          \override BarNumber #'padding = #3
          \override RehearsalMark #'padding = #2
          skipBars = ##t
        }
      }

      \midi { }
    }

## Laissez vibrer ties

Laissez vibrer ties have a fixed size. Their formatting can be tuned using `'tie-configuration`.

    \relative c' {
      <c e g>4\laissezVibrer r <c f g>\laissezVibrer r
      <c d f g>4\laissezVibrer r <c d f g>4.\laissezVibrer r8

      <c d e f>4\laissezVibrer r
      \override LaissezVibrerTieColumn #'tie-configuration
         = #`((-7 . ,DOWN)
              (-5 . ,DOWN)
              (-3 . ,UP)
              (-1 . ,UP))
      <c d e f>4\laissezVibrer r
    }

## Letter tablature formatting

Tablature can be formatted using letters instead of numbers.

    #(define (letter-tablature-format str context event)
      (let ((tuning (ly:context-property context 'stringTunings))
            (pitch (ly:event-property event 'pitch)))
        (make-whiteout-markup
         (make-vcenter-markup
          (string (integer->char
             (+ (char->integer #\a)
                (- (ly:pitch-semitones pitch)
                (list-ref tuning (- str 1))))))))))

    music = \relative c {
      c4 d e f
      g4 a b c
      d4 e f g
    }

    <<
      \new Staff {
        \clef "G_8"
        \music
      }
      \new TabStaff \with {
        tablatureFormat = #letter-tablature-format
      }
      {
        \music
      }
    >>

## Modern TAB text clef

Use a markup text to replace the (TAB) clef glyph with a modern font.

    TAB = \markup {
      \raise #1.5
      \sans
      \bold
      \huge
      \override #'(baseline-skip . 2.5)
      \left-align
      \center-column {
        T
        A
        B
      }
    }

    \new TabStaff {
      \override Staff.Clef #'stencil = #(lambda (grob)
        (grob-interpret-markup grob TAB))
      a
    }

## Placement of right-hand fingerings

It is possible to exercise greater control over the placement of right-hand fingerings by setting a specific property, as demonstrated in the following example.

    #(define RH rightHandFinger)

    \relative c {
      \clef "treble_8"

      \set strokeFingerOrientations = #'(up down)
      <c-\RH #1 e-\RH #2 g-\RH #3 c-\RH #4 >4

      \set strokeFingerOrientations = #'(up right down)
      <c-\RH #1 e-\RH #2 g-\RH #3 c-\RH #4 >4

      \set strokeFingerOrientations = #'(left)
      <c-\RH #1 e-\RH #2 g-\RH #3 c-\RH #4 >2
    }

## Polyphony in tablature

Polyphony is created the same way in a `TabStaff` as in a regular staff.

    upper = \relative c' {
      \time 12/8
      \key e \minor
      \voiceOne
      r4. r8 e, fis g16 b g e e' b c b a g fis e
    }

    lower = \relative c {
      \key e \minor
      \voiceTwo
      r16 e d c b a g4 fis8 e fis g a b c
    }

    \score {
      <<
        \new StaffGroup = "tab with traditional" <<
          \new Staff = "guitar traditional" <<
            \clef "treble_8"
            \context Voice = "upper" \upper
            \context Voice = "lower" \lower
          >>
          \new TabStaff = "guitar tab" <<
            \context TabVoice = "upper" \upper
            \context TabVoice = "lower" \lower
          >>
        >>
      >>
    }

## Stem and beam behavior in tablature

The direction of stems is controlled the same way in tablature as in traditional notation. Beams can be made horizontal, as shown in this example.

    \new TabStaff {
      \relative c {
        g16 b d g b d g b
        \stemDown
        \override Beam #'damping = #+inf.0
        g,,16 b d g b d g b
      }
    }

#### Snippets List