Thank you David for your help. I made some tests with \displayMusic and I have seen the situation :)
Thank you Aaron for the detailed explanation and also for the other code! I will continue to use your \extract code but I keep also the new one for the future :) Have a nice w/e. Ciao, g On Sat, 24 Apr 2021 at 11:40, Aaron Hill <lilyp...@hillvisions.com> wrote: > On 2021-04-23 11:32 pm, David Kastrup wrote: > > Gianmaria Lari <gianmarial...@gmail.com> writes: > > > >> Thank you Aaron and Jean, your code works! > >> > >> But I have some trivial questions. > >> If I write: > >> > >> \displayLilyMusic \chordmode {c} > >> > >> > >> I get: > >> > >> { < c' e' g' >4 } > >> > >> > >> It looks a good "compound music expression". > > > > Try \displayMusic rather than \displayLilyMusic for more details. > > In case David's hint was not sufficient, there is an additional layer of > complexity when using \chordmode. Unfortunately, that layer is not > visible when using \displayLilyMusic, and this is where the confusion > arises. > > \chordmode produces UnrelativableMusic that contains SequentialMusic and > then EventChords of NoteEvents. > > Jean's first-element assumes that the music argument has a property > called elements and resolves to the first value within the collection. > UnrelativableMusic only has an element property, so first-element gets > stuck. Here is a modified version of first-element that does not: > > %%%% > #(define (first-element music) > (or (ly:music-property music 'element #f) > (first (ly:music-property music 'elements)))) > > % This works, but you get a SequentialMusic. > { #(first-element #{ \chordmode {c} #}) } > > % This grabs the EventChord from the SequentialMusic. > { #(first-element (first-element #{ \chordmode {c} #})) } > %%%% > > My \extract uses the built-in extract-typed-music procedure to do the > heavy lifting, including the logic necessary to traverse nested music > expressions with both element and elements properties. > > > -- Aaron Hill >