Re: Identifying non-chord notes in Scheme
Aaron, thanks a million for the solution (with the convincing demo). I'm examining note data rather than tweaking output, but with your example as a guide the rest will be 'easy' (as easy as Scheme goes for me). If you have time for a question: The "for-some-music" function is new to me. Any quick comments when to use each of the different functions/methods for recursion through input music? Or do you know of any tutorials/explications of recursion through music? LilyPond offers 'music-map,' 'map-some-music,' and 'for-some-music,' and I've also seen code based on plain old 'map.' Steve From: Aaron Hill Subject:Re: Identifying non-chord notes in Scheme Date: Wed, 27 Nov 2019 11:09:12 -0800 User-agent: Roundcube Webmail/1.3.8 Hi Steve, Sorry for the delay in responding to your original query. But as some say, "better late, than never." (: \version "2.19.83" colorNonChordNotes = #(define-music-function (color music) (color? ly:music?) (define (color-stop? mus) (if (music-is-of-type? mus 'note-event) (let* ((curr (ly:music-property mus 'tweaks '())) (new `((color . ,color) ((Accidental . color) . ,color))) (tweaks (append curr new))) (set! (ly:music-property mus 'tweaks) tweaks)) ;; Stop recursion on chords. (music-is-of-type? mus 'event-chord))) (for-some-music color-stop? music) music) soprano = \fixed c' { 4 b8 d' 2 } alto = \fixed c' { e8 d 4 dis2 } tenor = \fixed c { 4 b2 } bass = \fixed c { c4 d 2 } \score { \colorNonChordNotes #(x11-color 'tomato) \new ChoirStaff << \new Staff \voices 1,2 << \clef "treble" \soprano \\ \alto >> \new Staff \voices 1,2 << \clef "bass" \tenor \\ \bass >> >> } Not knowing *what* you intended to do with non-chord notes, I just simply appended a few \tweaks to those notes to demonstrate the technique of using for-some-music with a custom stop? procedure. -- Aaron Hill non-chord-notes.cropped.png* *
Re: Identifying non-chord notes in Scheme
Hi Steve, Sorry for the delay in responding to your original query. But as some say, "better late, than never." (: \version "2.19.83" colorNonChordNotes = #(define-music-function (color music) (color? ly:music?) (define (color-stop? mus) (if (music-is-of-type? mus 'note-event) (let* ((curr (ly:music-property mus 'tweaks '())) (new `((color . ,color) ((Accidental . color) . ,color))) (tweaks (append curr new))) (set! (ly:music-property mus 'tweaks) tweaks)) ;; Stop recursion on chords. (music-is-of-type? mus 'event-chord))) (for-some-music color-stop? music) music) soprano = \fixed c' { 4 b8 d' 2 } alto = \fixed c' { e8 d 4 dis2 } tenor = \fixed c { 4 b2 } bass = \fixed c { c4 d 2 } \score { \colorNonChordNotes #(x11-color 'tomato) \new ChoirStaff << \new Staff \voices 1,2 << \clef "treble" \soprano \\ \alto >> \new Staff \voices 1,2 << \clef "bass" \tenor \\ \bass >> >> } Not knowing *what* you intended to do with non-chord notes, I just simply appended a few \tweaks to those notes to demonstrate the technique of using for-some-music with a custom stop? procedure. -- Aaron Hill
RE: Identifying non-chord notes in Scheme
Steve, I'm not familiar with music-map, but I know you can modify music using music-map. How about doing it twice: First time you add a (ly:music-set-property! note 'my-chord 'yes) to the notes inside the EventChord, and the second time you can identify the notes from the chords using the music property my-chord Jaap Van: lilypond-user Namens Steve Cummings Verzonden: Wednesday, November 27, 2019 6:22 PM Aan: lilyp...@de-wolff.org; lilypond-user@gnu.org Onderwerp: Re: Identifying non-chord notes in Scheme Jaap, thank you for taking this up but I'm not sure whether your answer helps--yes, I can find notes within chords because they are branches of EventChord, but those same notes also occur as individual NoteEvent events *before* the EventChord event. If I'm trying to extract or otherwise process only notes that *don't* belong to any chord, waiting for the ChordEvent that follows and then backtracking would be complicated. I should think I could check some property of a NoteEvent ("parent" or "chord" would be nice). So is there any way to tell that a note is *not* a branch (a leaf?) on any EventChord event? Notice that I'm using "music-map" to get a list of the events, and the list it generates includes chord notes twice: first as separate NoteEvents and then again as members of the Chord of which they are branches/members. If there's no simple way to look at a NoteEvent and tell whether it is part of a chord, maybe there's a different way to get a list of music events that doesn't have this duplication of chord notes. Or maybe there's a different way entirely to approach the problem of processing/extracting non-chord notes. Thanks for pointing out ContextSpeccedMusic. lilyp...@de-wolff.org <mailto:lilyp...@de-wolff.org> wrote on 11/27/2019 8:45 AM: Steve, When you see the music expression as a tree, then the NoteEvent's belonging to a chord are branches of an EventChord. This is for all chords including 4 etc. And as an extra bonus: When you have chords like "c:7+" the EventChord's are branches (or sub-branches) of an ContextSpeccedMusic event with the music-attribute 'context-type' = "ChordsName" Jaap Van: lilypond-user <mailto:lilypond-user-bounces+lilypond=de-wolff@gnu.org> Namens Steve Cummings Verzonden: Tuesday, November 26, 2019 7:31 PM Aan: lilypond-user@gnu.org <mailto:lilypond-user@gnu.org> Onderwerp: Identifying non-chord notes in Scheme 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 { 4 c'4 d'4 \transpose f c {2 c'}} \showNotesAndChords \someNotes
Re: Identifying non-chord notes in Scheme
Jaap, thank you for taking this up but I'm not sure whether your answer helps--yes, I can find notes within chords because they are branches of EventChord, but those same notes also occur as individual NoteEvent events *before* the EventChord event. If I'm trying to extract or otherwise process only notes that *don't* belong to any chord, waiting for the ChordEvent that follows and then backtracking would be complicated. I should think I could check some property of a NoteEvent ("parent" or "chord" would be nice). So is there any way to tell that a note is *not* a branch (a leaf?) on any EventChord event? Notice that I'm using "music-map" to get a list of the events, and the list it generates includes chord notes twice: first as separate NoteEvents and then again as members of the Chord of which they are branches/members. If there's no simple way to look at a NoteEvent and tell whether it is part of a chord, maybe there's a different way to get a list of music events that doesn't have this duplication of chord notes. Or maybe there's a different way entirely to approach the problem of processing/extracting non-chord notes. Thanks for pointing out ContextSpeccedMusic. lilyp...@de-wolff.org wrote on 11/27/2019 8:45 AM: Steve, When you see the music expression as a tree, then the NoteEvent’s belonging to a chord are branches of an EventChord. This is for all chords including 4 etc. And as an extra bonus: When you have chords like “c:7+” the EventChord’s are branches (or sub-branches) of an ContextSpeccedMusic event with the music-attribute ‘context-type’ = “ChordsName” Jaap *Van:*lilypond-user *Namens *Steve Cummings *Verzonden:* Tuesday, November 26, 2019 7:31 PM *Aan:* lilypond-user@gnu.org *Onderwerp:* Identifying non-chord notes in Scheme 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 { 4 c'4 d'4 \transpose f c {c''>2 c'}} \showNotesAndChords \someNotes
RE: Identifying non-chord notes in Scheme
Steve, When you see the music expression as a tree, then the NoteEvent's belonging to a chord are branches of an EventChord. This is for all chords including 4 etc. And as an extra bonus: When you have chords like "c:7+" the EventChord's are branches (or sub-branches) of an ContextSpeccedMusic event with the music-attribute 'context-type' = "ChordsName" Jaap Van: lilypond-user Namens Steve Cummings Verzonden: Tuesday, November 26, 2019 7:31 PM Aan: lilypond-user@gnu.org Onderwerp: Identifying non-chord notes in Scheme 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 { 4 c'4 d'4 \transpose f c {2 c'}} \showNotesAndChords \someNotes