0

I have some Lilypond files that I put together for vocals and guitar; I need to do capo for some of them. I am using the code in Carl Sorensen-3's reply in http://lilypond.1069038.n5.nabble.com/Newbie-Question-verse-and-chorus-td46241i20.html to get the capo'd chords printed.

This works:

\version "2.18.2"

\include "predefined-guitar-fretboards.ly"

% Carl Sorensen-3's reply in
% http://lilypond.1069038.n5.nabble.com/Newbie-Question-verse-and-chorus-td46241i20.html
parenthesizeAll =
 #(define-music-function (parser loc myMusic) (ly:music?)
  (music-map
    (lambda (ev)
      (if (or (memq 'note-event (ly:music-property ev 'types))
              (memq 'rest-event (ly:music-property ev 'types)))
          (set! (ly:music-property ev 'parenthesize) #t))
      ev)
    myMusic)
  myMusic)

theMelody = \relative g' { c1 }
theChords = \chordmode { c1 }
verseI = \lyricmode { See }

\score {
  <<
    \context ChordNames {
      \set instrumentName = #"Capo 3"
      \parenthesizeAll
      \transpose c a { \theChords }
    }
    \new FretBoards { \transpose c a { \theChords } }
    \new ChordNames { \theChords }
    \new Staff {\context Voice = "voiceMelody" { \theMelody }
    }
    \new Lyrics = "lyricsI"   { \lyricsto "voiceMelody" \verseI }
  >>

  \layout {
    % make the "Capo x" show up
    \context {
      \ChordNames \consists Instrument_name_engraver
    }
  }
}

Now: I want to put the transpose into a macro (guaranteeing that I get the transpose settings on the Fretboards and transposed chords the same).

Replacing the \score block with this

% define once
tC = { \transpose c a }

\score {
  <<
    \context ChordNames {
      \set instrumentName = #"Capo 3"
      \parenthesizeAll
      \tC { \theChords }
    }
    \new FretBoards { \tC { \theChords } }
    \new ChordNames { \theChords }
    \new Staff {\context Voice = "voiceMelody" { \theMelody } }
    \new Lyrics = "lyricsI"   { \lyricsto "voiceMelody" \verseI }
  >>

  \layout {
    % make the "Capo x" show up
    \context {
      \ChordNames \consists Instrument_name_engraver
    }
  }
}

Results in:

/home/wegscd/mup/CapoTest.ly:23:23: error: syntax error, unexpected '}'
tC = { \transpose c a 
                      }
/home/wegscd/mup/CapoTest.ly:26:3: error: errors found, ignoring music expression

It's a small thing, but I can get this transpose into a macro so I can define it just once?

fovea1959
  • 43
  • 7

1 Answers1

0

I had the same question and got my answer from http://lsr.di.unimi.it/LSR/Item?id=787

I'm using a small modification of it:

MyTranspose = 
#(define-music-function (parser location m)
  (ly:music?)
  #{ \transpose c c $m #})  % transposing c to c does nothing. Adjust as needed.