lilypond-user
[Top][All Lists]
Advanced

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

Re: select a note in a chord


From: Davide Bonetti
Subject: Re: select a note in a chord
Date: Thu, 17 Jan 2019 20:12:44 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0

I worked on your example, and here is the result.

The "\drop n" function drop the nth note from above, an can be nested (to do drop 2 drop 4)

The funcion "\rise n" function rise the nth note from below, an can be nested too

The "\inversion n" function do the inversions of the chord.

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.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


#(define (move-a-note n direction)
   (lambda (music)
     (let* ((elts (ly:music-property music 'elements))
            (l (length elts))
            ;; if the direction is up, we count from the bottom note upward,             ;; if the direction is down, we count from the top note downward
            (count-from (cond ((= direction up) (- n 1))
                          ((= direction down) (- l n))))
            ;; The user may not have entered the notes
            ;; from the lowest to the uppermost;
            ;; let’s extract the pitches…
            (pitches (map (lambda (x) (ly:music-property x 'pitch))
                       (filter
                        (lambda (y)
                          (music-is-of-type? y 'note-event))
                        elts)))
            ;; … and put them in order.
            (sorted (sort pitches ly:pitch<?))
            )
       (if (and (music-is-of-type? music 'event-chord)
                (>= l n))
           (begin
            ;; first apply the sorted pitches
            ;; to the actual notes.
            (map
             (lambda (e p)
               (ly:music-set-property! e 'pitch p))
             elts sorted)
            ;; then transpose the specified note
            (list-set! elts count-from
              (ly:music-transpose
               (list-ref elts count-from)
               (ly:make-pitch (cond
                               ;; transpose the note up or down,
                               ;;depending on direction
                               ((= direction up) +1)
                               ((= direction down) -1)) 0)))))
       music)))

%% drop a note of a chord, in num position from above
drop =
#(define-music-function (parser location num music) (integer? ly:music?)
   #{ \musicMap #(move-a-note num down) $music #})

%% rise a note of a chord, in num position from below
rise =
#(define-music-function (parser location num music) (integer? ly:music?)
   #{ \musicMap #(move-a-note num up) $music #})

inversion =
#(define-music-function (parser location num music) (integer? ly:music?)
   (cond ((= num 1) #{ \rise 1 $music #})
     ((= num 2) #{ \rise 1 \rise 1 $music #})
     ((= num 3) #{ \rise 1 \rise 1 \rise 1 $music #})
     ((= num 4) #{ \rise 1 \rise 1 \rise 1 \rise 1 $music #})
     ((= num 5) #{ \rise 1 \rise 1 \rise 1 \rise 1 \rise 1 $music #})
     ((= num 6) #{ \rise 1 \rise 1 \rise 1 \rise 1 \rise 1 \rise 1 $music #})
     ((= num -1) #{ \drop 1 $music #})
     ((= num -2) #{ \drop 1 \drop 1 $music #})
     ((= num -3) #{ \drop 1 \drop 1 \drop 1 $music #})
     ((= num -4) #{ \drop 1 \drop 1 \drop 1 \drop 1 $music #})
     ((= num -5) #{ \drop 1 \drop 1 \drop 1 \drop 1 \drop 1 $music #})
     ((= num -6) #{ \drop 1 \drop 1 \drop 1 \drop 1 \drop 1 \drop 1 $music #})
     (else #{ $music #})
     ))


ac = \relative c' {<c es g bes>2 <d as' f c'> \chordmode {c:maj es:6}}

{
  <>^\markup "chords"
  \ac
  \bar "||"
  <>^\markup "drop 2"
  \drop 2 \ac
  \bar "||"
  <>^\markup "drop 4"
  \drop 4 \ac
  \bar "||"
  <>^\markup "drop 2 and 4"
  \drop 2 \drop 4 \ac
  \bar "||"
  <>^\markup "rise 1"
  \rise 1 \ac
  \bar "||"
  <>^\markup "rise 3"
  \rise 3 \ac
  \bar "||"
  <>^\markup "2nd inversion"
  \inversion 2 \ac
  \bar "||"
  <>^\markup "\"down\" inversion"
  \inversion -1 \ac
  \bar "||"
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Cheers.
Davide

Il 16/01/2019 00:15, David Kastrup ha scritto:
Valentin Villenave <address@hidden> writes:

On 1/15/19, Davide Bonetti <address@hidden> wrote:
I modified
         (if (and (music-is-of-type? music 'event-chord)
                  (> l n))
with
         (if (and (music-is-of-type? music 'event-chord)
                  (>= l n))
Nice catch! I’ve updated the snippet as well.

Additionally, beware that the LSR version uses
#(define-music-function (parser location music)
whereas the syntax for LilyPond 2.19 would be
#(define-music-function (music)
Not much to beware here since convert-ly knows its way around this and
2.19 will do argument counting in order to provide backwards
compatibility.



---
Questa e-mail è stata controllata per individuare virus con Avast antivirus.
https://www.avast.com/antivirus

Attachment: move-a-note.ly
Description: Text Data


reply via email to

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