[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: select a note in a chord
From: |
David Kastrup |
Subject: |
Re: select a note in a chord |
Date: |
Fri, 18 Jan 2019 00:05:06 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
Valentin Villenave <address@hidden> writes:
> On 1/17/19, Davide Bonetti <address@hidden> wrote:
>> I worked on your example, and here is the result.
>
> Nice!
>
>> I'm sure there is a better way to write the inversion function, but I
>> haven't find a way to program the repetition of a function in scheme.
>
> This is certainly not the most elegant way, but it seems to work:
>
> inversion =
> #(define-music-function (num music) (integer? ly:music?)
> (let ((str "")
> (up? (> num 0)))
> (map (lambda (x)
> (set! str
> (string-append str
> (if up? "\\rise 1 " "\\drop 1 ")))
> str)
> (iota (abs num)))
There is append-map but seriously?
(string-concatenate (make-list (abs num)
(if (negative? num) "\\drop 1 " "\\rise 1 ")))
> #{ $(ly:parser-include-string str) $music #}))
This is not really an issue for string-manipulation.
> Can you verify that it works as you intended? (If you’re running 2.18,
> you’ll need to add "parser" after ly:parser-include-string.)
And parser location before num in (num music).
Let's rather do this in a sane manner:
inversion =
#(define-music-function (num music) (integer? ly:music?)
(let loop ((num num) (music music))
(cond ((zero? num) music)
((negative? num) (loop (1+ num) (drop 1 music))
(else (loop (1- num) (rise 1 music)))))))
Assuming 2.18, music functions are not directly callable from Scheme
which would render this as
inversion =
#(define-music-function (parser location num music) (integer? ly:music?)
(let loop ((num num) (music music))
(cond ((zero? num) music)
((negative? num) (loop (1+ num) #{ \drop 1 #music #}))
(else (loop (1- num) #{ \rise 1 #music #})))))
This does not mess with internal parsers. And the 2.19 version does not
even engage the parser for the looping.
--
David Kastrup
- select a note in a chord, Davide Bonetti, 2019/01/14
- Re: select a note in a chord, Malte Meyn, 2019/01/14
- Re: select a note in a chord, Valentin Villenave, 2019/01/14
- Re: select a note in a chord, Valentin Villenave, 2019/01/15
- Re: select a note in a chord, Davide Bonetti, 2019/01/15
- Re: select a note in a chord, Davide Bonetti, 2019/01/15
- Re: select a note in a chord, Valentin Villenave, 2019/01/15
- Re: select a note in a chord, David Kastrup, 2019/01/15
- Re: select a note in a chord, Davide Bonetti, 2019/01/17
- Re: select a note in a chord, Valentin Villenave, 2019/01/17
- Re: select a note in a chord,
David Kastrup <=
- Re: select a note in a chord, Valentin Villenave, 2019/01/17
- Re: select a note in a chord, David Kastrup, 2019/01/17
- Re: select a note in a chord, David Kastrup, 2019/01/17
- Re: select a note in a chord, Davide Bonetti, 2019/01/18
- Re: select a note in a chord, David Kastrup, 2019/01/18
- Re: select a note in a chord, Valentin Villenave, 2019/01/19
- Re: select a note in a chord, Davide Bonetti, 2019/01/19
- Re: select a note in a chord, Davide Bonetti, 2019/01/19
- Re: select a note in a chord, Aaron Hill, 2019/01/19
- Re: select a note in a chord, Valentin Villenave, 2019/01/23