lilypond-user
[Top][All Lists]
Advanced

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

Re: Chords: How to show chords without suffixes


From: Thomas Morley
Subject: Re: Chords: How to show chords without suffixes
Date: Wed, 16 Nov 2011 00:40:33 +0100

Hi Stjepan,

2011/11/15 Stjepan Horvat <address@hidden>
(...)
What i wanted is:

\chordmode  {
c1:7
a1:min
d1:min
g1:sus4  }

That will give me:

C            A           D          G

(...)

I  don't understand your goal, too.

But using (or abusing) some functions from
http://lists.gnu.org/archive/html/lilypond-user/2009-01/msg00685.html
and
http://lsr.dsi.unimi.it/LSR/Item?id=761
you could work with:

\version "2.14.2"

% http://lists.gnu.org/archive/html/lilypond-user/2009-01/msg00685.html

#(define (has-duration? music)
(ly:duration? (ly:music-property music 'duration)))

#(define (not-has-duration? music)
(not (has-duration? music)))

keepsOnlyFirstNote = #(define-music-function (parser location music) (ly:music?)
(music-map
  (lambda (evt)
   (if (eq? 'EventChord (ly:music-property evt 'name))
      (let ((elts (ly:music-property evt 'elements)))
       (if (has-duration? (car elts))
            (ly:music-set-property! evt 'elements (cons
                 (car elts)
                 (filter not-has-duration? (cdr elts)))))))
  evt)
music))

deleteFirstNote = #(define-music-function (parser location music) (ly:music?)
(music-map
  (lambda (evt)
   (if (eq? 'EventChord (ly:music-property evt 'name))
      (let ((elts (ly:music-property evt 'elements)))
           (if (has-duration? (car elts))
                (ly:music-set-property! evt 'elements  (cdr elts)))))
  evt)
music)
)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% http://lsr.dsi.unimi.it/LSR/Item?id=761
%%%%%%%%%%%%%%%%%%%%% addNote

#(define-macro (add! lst elt)
"Add element `elt to the list `lst."
`(set! ,lst (append ,lst (list ,elt))))

#(define (join-list notes notes-to-add)
(let ((dur  (ly:music-property (car notes) 'duration)))
 (append
   (filter
     (lambda (elt) (and
       (eq? 'NoteEvent (ly:music-property elt 'name)) ; keeps only notes
       (ly:music-set-property! elt 'duration dur))); one duration for all notes
     notes-to-add)
   notes)))
 
addNote = #(define-music-function (parser location music notes)
                                                          (ly:music? ly:music?)
"Adds to the first chord found in `music, all the notes contained in the first
chord found in `notes, and then continues successively with the next chords."
(let ((chords-list '())
      (relative-notes  #{\relative { $notes } #})  ; the 2 music-parameters will
      (relative-music  #{\relative { $music  } #})) ; be seen in \relative mode
  (let loop ((evt relative-notes))    ; fills chords-list with chords 'elements
    (let ((elt (ly:music-property evt 'element))
          (elts (ly:music-property evt 'elements)))
      (if (ly:music? elt) (loop elt))
      (if (pair? elts)(cond
        ((eq? 'EventChord (ly:music-property evt 'name))  ; if evt is a
           (if (memq (ly:music-property (car elts) 'name) ; note,
                            (list 'NoteEvent))               ; (but not a rest)
             (add! chords-list elts)))                    ; add evt 'elements
        (else (for-each loop elts))))))                
  (let loop ((evt relative-music))   ; joins notes of `music and `notes. 
    (let ((elt (ly:music-property evt 'element))
          (elts (ly:music-property evt 'elements)))
      (if (ly:music? elt) (ly:music-set-property! evt 'element (loop elt)))
      (if (pair? elts)
        (cond
          ((eq? 'EventChord (ly:music-property evt 'name))(and
             (eq? 'NoteEvent (ly:music-property (car elts) 'name))                                           
             (pair? chords-list)
             (ly:music-set-property! evt 'elements
                                             (join-list elts (car chords-list)))
             (set! chords-list (cdr chords-list)))) ; next chords-list elt ...
          (else (ly:music-set-property! evt 'elements (map loop elts)))))
       evt))))
 
makeMajorChord = #(define-music-function (parser location music) (ly:music?)
 #{
   \addNote \transpose c g \relative { $music }
     \addNote \transpose c e
       \relative { $music }
         $music
 #})

%----- test

normalChords = \chordmode {
        r \deleteFirstNote { c2/b } s g:m r4 f8:sus2 d8:m7
        r4 g:m r4 f8 d8:m7 d1:11 ees:m13
}

changedChords = \chordmode { \makeMajorChord \keepsOnlyFirstNote \normalChords }

\score {
        \chords { \changedChords }
        \layout {
            \context {
                    \ChordNames
                        noChordSymbol = ##f
                        chordChanges = ##t
            }
        }
}

\score {
        \chords { \normalChords }
        \midi {}
}


Please notice that it will not work with an added bass. I didn't manage to find the correct condition to do so. But you may want to work-around with:

\chordmode {  \deleteFirstNote { c2/b } }

as shown above.


HTH,
  Harm

reply via email to

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