lilypond-user
[Top][All Lists]
Advanced

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

Identifying non-chord notes in Scheme


From: Steve Cummings
Subject: Identifying non-chord notes in Scheme
Date: Tue, 26 Nov 2019 10:31:18 -0800
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1

What's the test for differentiating between non-chord notes and notes within a chord, when iterating through events in music? I can examine the notes within a chord individually, but I can't been able to find the way to capture notes that don't belong to a chord (or alternatively, to discard note events do belong to a chord).

Leaning heavily on code from Giles T, here's a simple routine that displays pitches of note events when they are encountered as such, and also when they occur within a chord. If the goal is to process non-chord notes only, how can I pick them out? In the listing below I've marked relevant places with "<<--"

Thanks,
Steve

\version "2.19"

#(use-modules (ice-9 receive)) %% so 'receive' can be used

#(define (noteEvent? music)
(eq? (name-of music) 'NoteEvent))

#(define (name-of music)
" (display-scheme-music (ly:music-property music 'name))"
   (ly:music-property music 'name)
   )

#(define* (music-to-console music #:optional (strict-comp? #t))
  (music-map
    (lambda(mus)
     (display (name-of mus))
     (newline)
     (cond
      ((eq? 'EventChord (name-of mus))
       (display "Chord")(newline)
        (receive (notes others)
          (partition noteEvent? (ly:music-property mus 'elements))                                        <<--Examine different music property?
          (map(lambda(note)(display (ly:music-property note 'pitch))) notes) (newline)))
      ((eq? 'NoteEvent (name-of mus))                                                                                         <<----- Test here?
        (display "A note event, but does it stand alone, or is it part of a chord?")                 <<----- or here?
        (newline) (display (ly:music-property mus 'pitch))(newline))
      (else (display "(Not a note or a chord)")(newline))    
     )
     (newline)
    #{
      #mus
    #})
    music))

showNotesAndChords = #(define-music-function (music) (ly:music?)
    (music-to-console music #t))

someNotes = \transpose c f { <g b d'>4 c'4 d'4 \transpose f c {<f' a' c''>2 c'}}
\showNotesAndChords \someNotes


reply via email to

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