5

Consider the following scores below. I would have thought Lilypond would apply a consistent transposition to the notes without the need to reformat the interval notations.

The first stave is the phrase in the original key as intended. I then apply a transpose down one semitone on the next stave and find the relative intervals are being interpreted differently.

The third and fourth staves demonstrate that without a \relative marking, the intervals would have behaved similar to the transposed version.

I am not sure if this is a bug in the Lilypond system, or if there is some reason why \transpose does not just apply an predictable pitch change when using a \relative marking?

Can anyone advise how I can use transpose to just shift my music in a consistent way?

global= {
  \time 4/4
  \key g \major
}

\version "2.16.2"
{
    \relative c''{
        bes'4-^ g16 ees8. bes'4-^ fis16 d8. 
    }
}

\version "2.16.2"
{
    \relative c''{
         \transpose  c b {
            bes'4-^ g16 ees8. bes'4-^ fis16 d8.
        }
    }
}

\version "2.16.2"
{
    bes'4-^ g16 ees8. bes'4-^ fis16 d8. 
}

\version "2.16.2"
{
     \transpose  c b {
        bes'4-^ g16 ees8. bes'4-^ fis16 d8.
    }   
}

image of above compilation

1
  • 1
    Gordon: It looks like you have two accounts open, and that's why you can't edit your post (which you can do when you're on the same account). Consider using the Contact link on the bottom of the page to have your accounts merged.
    – Richard
    Apr 27, 2018 at 3:32

2 Answers 2

8

It was actually designed to work this way. From the documentation:

Music inside a \transpose block is absolute unless a \relative is included in the block.

So instead of having transpose within the relative block, you want to switch it:

\version "2.16.2"
{
    \transpose c b, {
         \relative c'' {
            bes'4-^ g16 ees8. bes'4-^ fis16 d8.
        }
    }
}

enter image description here

Note that, since the pitches are absolute, you may have to specify \transpose c b, instead of just \transpose c b. (This may depend on how you organize your score.)

2
  • Thanks - putting \relative inside the \transpose is the fix I was after. Apr 25, 2018 at 6:05
  • So the problem is how \relative interacts with something. One thing that'll help: don't use \relative.
    – Rosie F
    Jan 4, 2020 at 21:58
6

I’d like to offer a suggestion for future endeavors: you may find it easier to use variables to control certain aspects of your melody—transposition, in this case. While you may gain an understanding of how they operate together through the snippet you posted, you may avoid some degree of trial-and-error altogether by making use of some of the suggestions the authors make in the Learning document.

Here’s how we can look at the piece you posted:

Certainly, your version statement is required only once in the .ly input file. (Side note: 2.18.2 is the most recent stable version; is there a reason your code indicates a previous version, 2.16.2?)

Then, you have your global statement cleanly set—although, I recommend placing them in the order in which they appear on the page (personal preference):

global = {
  \key g \major
  \time 4/4
}

Next, your melody, using \relative mode:

melody = \relative c'' {
  bes'4-^ g16 ees8. bes'4-^ fis16 d8.
}

At this point, you have two self-contained variables that are ready for use:

\global
\melody

Putting the score together is simple:

\score {
  \new Staff { \global \melody }
}

which tells LilyPond to make one staff with two variables, one following immediately after the other.

Therefore, to your question of how to shift your music in a consistent way, I offer the following:

\score {
  \new Staff \transpose c a, { \global \melody }
}

\score {
  \new Staff { \global \transpose c fis, \melody }
}

The first of these two examples tells LilyPond to transpose both variables—the one with the key and time signatures and the one with the actual music. The second tells LilyPond to transpose only the melody, leaving the key and time signatures alone.

You can handle changes like these with greater ease when your music is put together in a way that can facilitate it.

Showing transpositions easily controllable in LilyPond

3
  • This is a really helpful exposition on variables and cleaning up one's LilyPond score; great answer!
    – Richard
    Apr 26, 2018 at 14:31
  • Why would you recommend { \global \melody } with braces? That way, the music expression has the value of global followed by the value of melody. Why not << \global \melody >>? Granted, in this little example, global contained nothing which occupies any musical time, but in a real-life example, things that occupy musical time will belong in global -- such as the s elements which space the changes of key- and time-signature, tempo indications, rehearsal marks, etc.
    – Rosie F
    Jan 4, 2020 at 21:55
  • That's true. The way you describe it is almost always how I use global. I've seen others call the variable keyTime to denote only key and meter. That's probably what this should've been named. However, in this case, I did want to show that \transpose can be independently applied to both global and melody as well as melody alone. Furthermore, I was following the variable convention that the user had posted in the original question. I figured it would be too much to also introduce the << >> syntax.
    – Neal
    Jan 5, 2020 at 23:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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