6

I'm scoring Mozart's first piece, K1 - Minuet and Trio. The structure is essentially 4 repeats. After the first two repeats, the key signature changes from G Major to C Major.

I've split the right hand into two variables: rh-g and rh-c and am using \key c \major at the beginning of the second variable.

However by default, lilypond (2.23) adds the naturals in the new key signature to the end of the prior repeat.

enter image description here

Is there a way to have the naturals appear at the beginning of the next section where a key signature would normally be?

The code I'm using is:

\version "2.23"

\header {
  title = "Minuet and Trio"
  subtitle = "K1"
  composer = "Wolfgang Amadeus Mozart (1756-1791)"
  style = "Classical"
  license = "Public Domain"
  maintainer = "Tim Burgess"
  maintainerEmail = "timburgess@mac.com"
}

global = {
  \time 3/4
  \tempo 4 = 80
}

rh-g =  {
  \key g \major
  \relative g' {
    \repeat volta 2 {
      \partial 4 b'8(\mf g8 b,4)-. c4-. d4-. d4( c4)    a'8( fis8 a,4)-. b4-. c4-. c4( b4) b'8( g8 \break

      e4) g8( e8 cis4)  e8( cis8 a8 g8 fis4)  \tuplet 3/2 { b8( a8 g8 } fis4)-. e4-. | d2 \break
    }

    \repeat volta 2 {
      \partial 4 d'8(\mp b8 gis4)-. f'4-. e4-. d4( c4) c8( a8 fis4)-. e'4-. d4-. c4( b4) e8(\mf c8 \break
    
      a4) c8( a8 fis4) d8( fis8 a8 c8 b4) \tuplet 3/2 { e8( c8 a8 } g4)-. fis4-. g2 \break
    }
  }
}

rh-c =  {
  \key c \major
  \relative g' {
    % bar 18
    \repeat volta 2 {
      \partial 4 c8( g8 e4)-. e4-. d8( e8) e4( f4) d'8( b8 f4)-. f4-.  e8( d8) d4( e4) e'16( d c b \break

      a4 a'4) d,16( c b a g4 g'4) d16( b a g e'4 d4)-.  fis,4-. a4( g4) s4 \break
    }
  }
}

rh = {
  \clef "treble"
  \rh-g
  \rh-c
  \bar "|."
}

lh =  {
  \clef "bass"
  \relative g {
    \key g \major
    \partial 4 r4
    g4-. a4-. b4-. | b4( a4) r4 |
    fis4-. g4-. a4-. | a4( g4) r4 |
    g2 e4 | cis4 a4 d4 | g4 a4-. a,4-. | d4-. d,4-.

    \partial 4 r4
    e'4-. d'4-. c4-. | b4 a4 a8 fis8 | d4-. c'4-. b4-. | a4 g4 r4 |
    c2 a4 | fis4 d4 g4 | c4 d4-. d,4-. | g2

    \key c \major
    \partial 4 c,8 e8
    R2.*8

  }
}
4
  • 2
    As a clarification, LilyPond is doing things according to standard practice. Is there some reason you need your score to deviate from that?
    – Aaron
    Jul 18 at 23:47
  • Just personal preference. I have seen non-public scores which have been annotated this way.
    – timbo
    Jul 18 at 23:52
  • Just like @Aaron I am puzzled about this. It makes life so much easier for the musician if the standard notation is kept when there is no nonstandard things going on. The picture you posted has the change written at the end of the G major section which is good. Then on the next line where a key signature would normally be you do in fact have the key signature, because the key signature for C major is nothing, no sharps no flats, just nothing. And nothing is exactly what you have written. Thus you do have the key signature completely correctly written in that image. Jul 19 at 13:22
  • 1
    The naturals cancelling the previous key signature make the change very obvious; without them, it'd be very easy to miss the lack of sharps at the start of the next line.
    – gidds
    Jul 19 at 17:04
6

Line 475 at ./usr/share/lilypond/current/scm/define-grobs.scm shows where break-align-orders is defined. Essentially, it controls the order in which certain elements will appear. In your layout, add this:

\layout {
  \context {
    \Score
      \override BreakAlignment.break-align-orders =
  #(make-vector 3 '(
                    left-edge
                    cue-end-clef
                    ambitus
                    breathing-sign
                    clef
                    cue-clef
                    staff-bar
                    key-cancellation
                    key-signature
                    time-signature
                    custos))
    }
}

Switch the order of these two:

                staff-bar
                key-cancellation

Or, if you don't want this to occur every time, use this in a variable with \once to ensure it only happens once.

temp_change = \once \override Score.BreakAlignment.break-align-orders =
  ...

music = \relative c'' {
  g2 \temp_change \break
  ...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.