stefano franchi <[email protected]> writes:
>>
>>
>> > Here is an example implementation. Negative numbers in the first
>> > element count from the end of the list, negative numbers in the second
>> > element indicate the elements to be removed from the right rather than
>> > taken from the left (-1 removes none, -2 removes 1, -3 removes 2:
>> > slightly awkward but 0 already means "leave no element" and so cannot
>> > simultaneously mean "remove no element").
>> >
>> > The music in question needs to actually be of a kind that has an
>> > 'elements field.
>>
>> Well, _here_ is the example implementation.
>>
>>
> Thanks, very much appreciated. I do not understand the output of the first
> example in your file, though.
> Why does lilypond stay within the same octave when going from item 2 to 3
> of the a min scale, i. b. to c ? Is absolute notation (is that the right
> term) the default behavior?
Without any other information, the notation used is absolute. And to be
honest, when using a function like \pick, anything but absolute notation
is going to end up a nightmare since you cannot predict which octave you
are going to land with. To add insult to injury, the given
implementation of \pick would fail with
\pick 0 3 \relative { ... }
To make this work, you'd need to treat "music wrappers" transparently.
That would give something like
pick =
#(define-music-function (a b m) (exact-integer? exact-integer? ly:music?)
(let loop ((m m))
(if (music-is-of-type? m 'music-wrapper-music)
(loop (ly:music-property m 'element))
(set! (ly:music-property m 'elements)
(let* ((l (ly:music-property m 'elements))
(t (list-tail l (if (negative? a) (+ (length l) a) a))))
(list-head t (if (negative? b) (+ (length t) b 1) b))))))
m)
scale = \relative { a b c d e f g}
\displayLilyMusic \pick 0 4 \scale
\displayLilyMusic \pick -2 -1 \scale
\displayLilyMusic \pick -3 -3 \scale
--
David Kastrup