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: Sat, 19 Jan 2019 18:32:52 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0

For the sake of the discussion, I copy there the code as it now is:

(thanks to Valentin and David)

D.

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

#(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 put them in order.
            (pitches (map (lambda (x) (ly:music-property x 'pitch))
                       (filter
                        (lambda (y)
                          (music-is-of-type? y 'note-event))
                        elts)))
            (sorted (sort pitches ly:pitch<?)))
       (if (and (music-is-of-type? music 'event-chord)
                (not (zero? n)) (>= 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 note up or
            ;; down, depending on direction.
            (list-set! elts count-from
              (ly:music-transpose
               (list-ref elts count-from)
               (ly:make-pitch
                (cond
                 ((= direction UP) +1)
                 ((= direction DOWN) -1))
                0)))))
       music)))

%% drop a note of a chord, in num position from above
dropNote =
#(define-music-function (parser location num music) (integer? ly:music?)
   (_i "Drop a note of any chords in @var{music}, in @var{num} position from abo
      ve.")
   (music-map (move-chord-note num down) music))

%% rise a note of a chord, in num position from below
riseNote =
#(define-music-function (parser location num music) (integer? ly:music?)
   (_i "Rise a note of any chords in @var{music}, in @var{num} position from bel
      ow.")
   (music-map (move-chord-note num up) music))

%% invert chords
invertChords =
#(define-music-function (num music) (integer? ly:music?)
   (_i "Invert any chords in @var{music} into their @var{num}-th position.
       (Chord inversions may be directed downwards using negative integers.)")
   (let loop ((num num) (music music))
     (cond ((zero? num) music)
       ((negative? num) (loop (1+ num) (dropNote 1 music)))
       (else (loop (1- num) (riseNote 1 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"
  \dropNote 2 \ac
  \bar "||"
  <>^\markup "drop 4"
  \dropNote 4 \ac
  \bar "||"
  <>^\markup "drop 2 and 4"
  \dropNote 2 \dropNote 4 \ac
  \bar "||"
  <>^\markup "rise 1"
  \riseNote 1 \ac
  \bar "||"
  <>^\markup "rise 3"
  \riseNote 3 \ac
  \bar "||"
  <>^\markup "2nd inversion"
  \invertChords 2 \ac
  \bar "||"
  <>^\markup "\"down\" inversion"
  \invertChords -1 \ac
  \bar "||"
}

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


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




reply via email to

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