Jump to content

Clef change at the beginning of a piece: Difference between revisions

From LilyPond wiki
m New category
Tags: Mobile edit Mobile web edit
Add "See also"
Tags: Reverted Visual edit
Line 1: Line 1:
When changing the clef at the beginning of the first measure, Lilypond just changes the clef for the staff. This is how to keep the staff clef and add an extra clef after the time signature and before the first note.
When changing the clef at the beginning of the first measure, Lilypond just changes the clef for the staff. This is how to keep the staff clef and add an extra clef after the time signature and before the first note. See also [[Clef change at the beginning of a piece (alternative)]] and [[Initial clef change]].


<lilypond version="2.24">
<span></span>
%% http://lsr.di.unimi.it/LSR/Item?id=792
\version "2.24"
%% see also http://lilypond.org/doc/stable/Documentation/notation/displaying-pitches
 
%% <nowiki>http://lsr.di.unimi.it/LSR/Item?id=792</nowiki>
% Append markup in the text property to the grob
%% see also <nowiki>http://lilypond.org/doc/stable/Documentation/notation/displaying-pitches</nowiki>
#(define (append-markup grob old-stencil)
  (ly:stencil-combine-at-edge
% Append markup in the text property to the grob
    old-stencil X RIGHT (ly:text-interface::print grob)))
#(define (append-markup grob old-stencil)
 
  (ly:stencil-combine-at-edge
trebleToBass = {
    old-stencil X RIGHT (ly:text-interface::print grob)))
  \clef bass
   % Fake staff clef appearance
trebleToBass = {
  \once \override Staff.Clef.glyph-name = #"clefs.G"
  \clef bass
  \once \override Staff.Clef.Y-offset = #-1
    % Fake staff clef appearance
   % Make sure any key signatures will printed with respect to
  \once \override Staff.Clef.glyph-name = #"clefs.G"
   % correct middle c position expected for treble clef
  \once \override Staff.Clef.Y-offset = #-1
  \once \set Staff.middleCClefPosition = -6
    % Make sure any key signatures will printed with respect to
   % Append change clef to the time signature
    % correct middle c position expected for treble clef
  \once \override Staff.TimeSignature.text = \markup {
  \once \set Staff.middleCClefPosition = -6
    \hspace #1.2
    % Append change clef to the time signature
    \raise #1
  \once \override Staff.TimeSignature.text = \markup {
    \musicglyph "clefs.F_change"
    \hspace #1.2
  }
    \raise #1
  \once \override Staff.TimeSignature.stencil = #(lambda (grob)
    \musicglyph "clefs.F_change"
    (append-markup grob (ly:time-signature::print grob)))
  }
}
  \once \override Staff.TimeSignature.stencil = #(lambda (grob)
 
    (append-markup grob (ly:time-signature::print grob)))
bassToTreble = {
}
  \clef treble
   % Fake staff clef appearance
bassToTreble = {
  \once \override Staff.Clef.glyph-name = #"clefs.F"
  \clef treble
  \once \override Staff.Clef.Y-offset = #1
    % Fake staff clef appearance
   % Make sure any key signatures will printed with respect to
  \once \override Staff.Clef.glyph-name = #"clefs.F"
   % correct middle c position expected for bass clef
  \once \override Staff.Clef.Y-offset = #1
  \once \set Staff.middleCClefPosition = 6
    % Make sure any key signatures will printed with respect to
   % Append change clef to the time signature
    % correct middle c position expected for bass clef
  \once \override Staff.TimeSignature.text = \markup {
  \once \set Staff.middleCClefPosition = 6
    \hspace #1.2
    % Append change clef to the time signature
    \lower #1
  \once \override Staff.TimeSignature.text = \markup {
    \musicglyph "clefs.G_change"
    \hspace #1.2
  }
    \lower #1
  \once \override Staff.TimeSignature.stencil = #(lambda (grob)
    \musicglyph "clefs.G_change"
    (append-markup grob (ly:time-signature::print grob)))
  }
}
  \once \override Staff.TimeSignature.stencil = #(lambda (grob)
 
    (append-markup grob (ly:time-signature::print grob)))
\relative c {
}
  \trebleToBass
  \key f \major
\relative c {
  c4 d e f
  \trebleToBass
   % This should not be visible
  \key f \major
  \clef bass
  c4 d e f
  g a b c
    % This should not be visible
   % This should be visible
  \clef bass
  \clef treble
  g a b c
  d e f g
    % This should be visible
}
  \clef treble
</lilypond>
  d e f g
}
<span></span>


[[Category:Staff notation]]
[[Category:Staff notation]]

Revision as of 16:47, 8 April 2026

When changing the clef at the beginning of the first measure, Lilypond just changes the clef for the staff. This is how to keep the staff clef and add an extra clef after the time signature and before the first note. See also Clef change at the beginning of a piece (alternative) and Initial clef change.

\version "2.24"

%% http://lsr.di.unimi.it/LSR/Item?id=792
%% see also http://lilypond.org/doc/stable/Documentation/notation/displaying-pitches

% Append markup in the text property to the grob
#(define (append-markup grob old-stencil)
  (ly:stencil-combine-at-edge
    old-stencil X RIGHT (ly:text-interface::print grob)))

trebleToBass = {
  \clef bass
  % Fake staff clef appearance
  \once \override Staff.Clef.glyph-name = #"clefs.G"
  \once \override Staff.Clef.Y-offset = #-1
  % Make sure any key signatures will printed with respect to
  % correct middle c position expected for treble clef
  \once \set Staff.middleCClefPosition = -6
  % Append change clef to the time signature
  \once \override Staff.TimeSignature.text = \markup {
    \hspace #1.2
    \raise #1
    \musicglyph "clefs.F_change"
  }
  \once \override Staff.TimeSignature.stencil = #(lambda (grob)
    (append-markup grob (ly:time-signature::print grob)))
}

bassToTreble = {
  \clef treble
  % Fake staff clef appearance
  \once \override Staff.Clef.glyph-name = #"clefs.F"
  \once \override Staff.Clef.Y-offset = #1
  % Make sure any key signatures will printed with respect to
  % correct middle c position expected for bass clef
  \once \set Staff.middleCClefPosition = 6
  % Append change clef to the time signature
  \once \override Staff.TimeSignature.text = \markup {
    \hspace #1.2
    \lower #1
    \musicglyph "clefs.G_change"
  }
  \once \override Staff.TimeSignature.stencil = #(lambda (grob)
    (append-markup grob (ly:time-signature::print grob)))
}

\relative c {
  \trebleToBass
  \key f \major
  c4 d e f
  % This should not be visible
  \clef bass
  g a b c
  % This should be visible
  \clef treble
  d e f g
}