Jump to content

Forcing a note to a particular staff line: Difference between revisions

From LilyPond wiki
Import snippet from LSR
 
m New category
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Occasionally, it is necessary to move a note's pitch to a certain staff line or space, with no regard to the clef (e.g. to indicate percussion on a non-percussive instrument.) The built-in <code>Pitch_squash_engraver</code> does just that. This snippet provides two Scheme shortcut functions, <code>\squashTo</code> and <code>\middleLine</code>. Don't forget to include the correct engraver in the Voice context.
Occasionally, it is necessary to move a note's pitch to a certain staff line or space, with no regard to the clef (e.g. to indicate percussion on a non-percussive instrument.) The built-in <code>Pitch_squash_engraver</code> does just that. This snippet provides two Scheme shortcut functions, <code>\squashTo</code> and <code>\middleLine</code>. Don't forget to include the correct engraver in the Voice context.


<lilypond version="2.24.0">
<lilypond version="2.24">
%% http://lsr.di.unimi.it/LSR/Item?id=778
%% http://lsr.di.unimi.it/LSR/Item?id=778


Line 36: Line 36:
[[Category:Percussion]]
[[Category:Percussion]]
[[Category:Staff notation]]
[[Category:Staff notation]]
[[Category:Snippet]]

Latest revision as of 23:19, 21 November 2025

Occasionally, it is necessary to move a note's pitch to a certain staff line or space, with no regard to the clef (e.g. to indicate percussion on a non-percussive instrument.) The built-in Pitch_squash_engraver does just that. This snippet provides two Scheme shortcut functions, \squashTo and \middleLine. Don't forget to include the correct engraver in the Voice context.

\version "2.24"

%% http://lsr.di.unimi.it/LSR/Item?id=778

squashTo = #(define-music-function
  (position music)
  (number? ly:music?)
  #{
    \set squashedPosition = $position
    $music
    \unset squashedPosition
  #})

middleLine = #(define-music-function
  (music)
  (ly:music?)
  #{
    \squashTo #0 $music
  #})

\new Voice 
\with { \consists "Pitch_squash_engraver"} 
\relative c' {
  \clef treble
  \squashTo #1 { c4 d e f }
  \clef alto
  \squashTo #0 { c4 d e f }
  \clef bass
  \squashTo #-1 { c4 d e f }
  \middleLine { c4 d e f }
}