lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question about transposing an interval of a 4th


From: Carl D. Sorensen
Subject: Re: question about transposing an interval of a 4th
Date: Tue, 23 Dec 2008 11:21:17 -0700

Johan,


On 12/23/08 3:18 AM, "Johan Vromans" <address@hidden> wrote:

> "Carl D. Sorensen" <address@hidden> writes:
> 
>> Examples of how LilyPond uses scheme are found in [...]
> 
> It would be nice to have a boilerplate scheme function that processes
> an arbitrary music expression and returns a new expression that is an
> identical copy of the original expression.

You're right, it would be nice to have this.  And fortunately, we do.

Please look in the file scm/music-functions.scm.  Search for
music->make-music.  In scheme, it does just what your pseudo-code below
does.  Except that it works in the scheme language mode, which means it
works slightly differently that your pseudocode.

1.  Z is not a separate variable, but stored in the return value of the
function.

2.  Instead of "for each" to handle the music expression in a loop, it's
handled by recursion with the map function.


But you can see in the body of the function what the data structure is for
moments, durations, and pitches.

It would be possible copy this function and use it as you have suggested.
But a better way to accomplish something like the diatonic transposition
that started all of this would be to define a function that diatonically
transposes a single pitch, and apply it to the music with the function
music-map, which is also defined in scm/music-functions.scm.

So you'd have something like

(define (diatonic-transpose interval music)
  (if (ly:pitch? music)
      (diatonic-transposition interval music)
      (music)))

And you'd apply it as

(music-map (lambda(x) (diatonic-transpose interval x)) music)

Which would recursively apply your diatonic transpose function to every
element of the music expression -- and it does nothing to anything but
pitches.

Note that I still haven't said how the transposition happens -- that magic
takes place in diatonic-transposition.  And I don't know how to do that yet.
But it sounds like John is working on it.

My main reason for this email is to address your request for a music
expression copier, and show how in general one would play with a music
expression.

Thanks,

Carl





reply via email to

[Prev in Thread] Current Thread [Next in Thread]