#(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 ;; (strangely, jazzmen tend to ;; 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= 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' {2 \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 "||" }