Ok, now it works well!
D.
Il 28/01/2019 21:11, Valentin Villenave ha scritto:
On 1/28/19, Davide Bonetti <d...@davidebonetti.it> wrote:
It reminds me something that happens when a variable in lilypond is
called with $ instead of # , but in scheme I don't see this difference.
Could it be something like that?
Nope, it turned out to be a lot more idiotic: I was modifying the
'octavation property of some notes… then not taking that into account
when sorting the pitches. (And, as David noted, I was displacing the
pitches onto the notes without moving any articulations they might
have attached.)
Here’s the new updated function, now it sort of works!
#(define-public (move-chord-note n direction)
(_i "Transpose a note (numbered as @var{n}) by one octave in
@var{direction}.")
(lambda (music)
(let* ((elts (ly:music-property music 'elements))
(l (length elts))
;; if direction is up, count from the bottom note upward,
;; if direction is down, count from the top note downward.
(count-from (cond ((= direction UP) (- n 1))
((= direction DOWN) (- l n))))
;; Notes may not have been entered from bottom to top;
;; extract the pitches and their possible octavation.
(pitches (map
(lambda (x)
(let ((oct (ly:music-property x 'octavation))
(p (ly:music-property x 'pitch)))
(if (null? oct) p
(ly:pitch-transpose p
(ly:make-pitch oct 0 0)))))
(filter
(lambda (y)
(music-is-of-type? y 'note-event))
elts))))
(if (and (music-is-of-type? music 'event-chord)
(not (zero? n)) (>= l n))
(begin
;; Sort the actual notes, depending on their pitch.
(set! elts
(sort elts
(lambda (a b)
(ly:pitch<?
(ly:music-property a 'pitch)
(ly:music-property b 'pitch)))))
;; then transpose the note up or
;; down, depending on direction.
(let* ((note (list-ref elts count-from))
(oct (ly:music-property note 'octavation)))
(list-set! elts count-from
(ly:music-transpose note
(ly:make-pitch
(cond
((= direction UP) +1)
((= direction DOWN) -1))
0)))
(ly:music-set-property! note 'octavation
(+ (cond
((= direction UP) 1)
((= direction DOWN) -1))
(if (null? oct) 0 oct))))
))
music)))
V.
---
Questa e-mail è stata controllata per individuare virus con Avast antivirus.
https://www.avast.com/antivirus
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user