Jump to content

Key signatures for small staves: Difference between revisions

From LilyPond wiki
No edit summary
Revised.
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Traditionally, smaller staves key signature spacing is slightly different than full size staves ones.
Traditionally, the spacing of key signatures in smaller staves is larger in comparison to full-size staves.


Here's a function that automatically calculates the right key signature spacing according to the staff size.
Here is a function that extends <code>\magnifyStaff</code> to automatically calculate the right key signature spacing according to the staff size.


<lilypond version="2.24" full>
<lilypond version="2.24">
%% => http://lsr.di.unimi.it/LSR/Item?id=1094
scaleStaff =
 
#(define-music-function (scaleFac) (number?)
%% This extends \staffSize as defined in
%% "Changing the size of a staff with a music function"
%% http://lsr.di.unimi.it/LSR/Item?id=862
staffSize = #(define-music-function (new-size) (number?)
   #{
   #{
     \set fontSize = #new-size
     \magnifyStaff #scaleFac
    \override StaffSymbol.staff-space = #(magstep new-size)
     \override KeySignature.padding = #(* 2/3 (- 1 scaleFac))
    \override StaffSymbol.thickness = #(magstep new-size)
     \override KeySignature.padding = #(* 2/3 (- 1 (magstep new-size)))
   #})
   #})


Line 21: Line 15:
\markup\italic "Default output:"
\markup\italic "Default output:"
<<
<<
   \new Staff \with {  
   \new Staff \with { \magnifyStaff #5/7 } \keyTest
    fontSize = #-3
   \new Staff \keyTest
    \override StaffSymbol.staff-space = #(magstep -3)
    \override StaffSymbol.thickness = #(magstep -3)
  } \keyTest  
   \new Staff \keyTest  
 
>>
>>


\markup\italic "Traditional output:"
\markup\italic "Traditional output:"
<<
<<
   \new Staff \with { \staffSize #-3 } \keyTest
   \new Staff \with { \scaleStaff #5/7 } \keyTest
  \new Staff \keyTest
 
>>
 
%{
% For v.2.19 and higher:
 
scaleStaff = #(define-music-function (scaleFac) (number?)
                #{
                  \magnifyStaff #scaleFac
                  \override KeySignature.padding = #(* 2/3 (- 1 scaleFac))
                #})
 
sizeTest = #5/7
keyTest = { \key cis\major s4*4 \bar "" }
 
<<
  \new Staff \with { \scaleStaff #sizeTest } \keyTest
   \new Staff \keyTest
   \new Staff \keyTest
>>
>>
%}
\paper { tagline = ##f }
</lilypond>
</lilypond>


Line 61: Line 29:
[[Category:Vocal music]]
[[Category:Vocal music]]
[[Category:Spacing]]
[[Category:Spacing]]
[[Category:Contexts and engravers]]
[[Category:Tweaks and overrides]]
[[Category:Tweaks and overrides]]
[[Category:Specific notation]]
[[Category:Specific notation]]
[[Category:Workaround]][[Category:Snippet]]
[[Category:Workaround]]
[[Category:Snippet]]

Latest revision as of 18:11, 18 March 2026

Traditionally, the spacing of key signatures in smaller staves is larger in comparison to full-size staves.

Here is a function that extends \magnifyStaff to automatically calculate the right key signature spacing according to the staff size.

\version "2.24"

scaleStaff =
#(define-music-function (scaleFac) (number?)
  #{
    \magnifyStaff #scaleFac
    \override KeySignature.padding = #(* 2/3 (- 1 scaleFac))
  #})

keyTest = { \key cis\major s4*4 \bar "" }

\markup\italic "Default output:"
<<
  \new Staff \with { \magnifyStaff #5/7 } \keyTest
  \new Staff \keyTest
>>

\markup\italic "Traditional output:"
<<
  \new Staff \with { \scaleStaff #5/7 } \keyTest
  \new Staff \keyTest
>>