Jump to content

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

From LilyPond wiki
Add "See also"
Tags: Reverted Visual edit
m Reverted edit by Ksnortum (talk) to last revision by Lemzwerg
Tag: Rollback
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. See also [[Clef change at the beginning of a piece (alternative)]] and [[Initial clef change]].
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.


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


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

Revision as of 17:27, 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.

\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
}