Currently I write lilypond code that looks like this:
\version "2.14.2"
P = #parenthesize
\relative c, {
\clef bass
<c \P c'> <e \P e'> <g \P g'>2 <c, \P c'>4 <d \P d'> <e \P e'>2
}
where I repeatedly mean 'this note, together with the same note one octave higher, parenthesized'.
I'd like a way to abbreviate this, so that I can write something like this:
\version "2.14.2"
poct = ...
\relative c, {
\clef bass
\poct c \poct e \poct g2 \poct c,4 \poct d \poct e2
}
As suggested in a helpful answer to an earlier question of mine, I have tried to use a music function, but there is no way I can get this to work. The closest I can get is
poct = #(define-music-function
(parser location note)
(ly:music?)
#{
<< $note \transpose c c \parenthesize $note >>
#})
but this uses <<
.. >>
instead of <
.. >
, which does not render the way I want (and with warnings), and I have no idea why the \transpose c c
actually transposes anything.
Finally, tangentially related, when experimenting with music functions I found it even impossible just to create a music function that mimicks \repeat unfold 2
; the following jumps down an octave between the third and fourth c
:
\version "2.14.2"
double = #(define-music-function
(parser location note)
(ly:music?)
#{
$note $note
#})
\relative c, {
\clef bass
\double c \double e \double g2 \double c,4 \double d \double e2
}
In scientific pitch notation, a specific octave is indicated by a numerical subscript number after note name. In this notation, middle C is C4, because of the note's position as the fourth C key on a standard 88-key piano keyboard, while the C an octave higher is C5.
When two musical notes are an octave apart, one has double the frequency of the other yet we hear them as the “same” note – a “C” for example. Why is this? This question has a false premise. I hear two notes an octave apart as different notes.
We hear this low C note as the strongest note, but it has a series of harmonic overtones. The sound also contains a C one octave higher, a G a fifth higher than that, a C two octaves higher and many more overtones and dissonances reaching eventually beyond the range of the human ear. These overtones become progressively weaker as they go higher.
As such, these notes share a unique mathematical relationship with each other that they don’t share with other notes. Since the brain creates pitch perception based on grouping harmonically related sounds, it isn’t surprising that we perceive related notes similarly. There are some exceptions to this.
I just got this answer from David Kastrup, one of the developers of LilyPond:
The "octave transposition" happens because basically \transpose c c is the same as \absolute (as LilyPond does not apply \relative to transposed music).
\absolute is not necessary in connection with \repeat unfold: \repeat unfold knows how to deal with relative music.
Version 2.14.2 is awfully old. At any rate, there is currently issue http://code.google.com/p/lilypond/issues/detail?id=3673 in the LilyPond tracker, and the respective code can be found at https://codereview.appspot.com/30890043/diff/40001/scm/music-functions.scm
And there we get indeed into Scheme programming. The respective defmacro-public would likely work even in 2.14 though #{ #} might not work properly.
With that definition, your double definition would become:
double = #(define-music-function (parser location note) (ly:music?) (make-relative (note) note #{ $note $note #}))
and would then work in both absolute and relative mode. If the 2.14 #{ #} does not jibe with make-relative, writing (make-sequential-music (list (ly:music-deep-copy note) (ly:music-deep-copy note))) should serve as a Scheme replacement.
The original problem becomes easier to understand once you realize that it's just a simple code replacement, so \relative { \double c' } becomes \relative { c' c' } using different octaves. The make-relative macro will to the \relative operation only on a single note, and then paste the results into the music expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With