lilypond-user
[Top][All Lists]
Advanced

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

Re: "compound music expression" to "music" expression"


From: Gianmaria Lari
Subject: Re: "compound music expression" to "music" expression"
Date: Sat, 24 Apr 2021 07:34:37 +0200

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_". 
But Aaron code and Jean code behave differently. Have a look here
This does not work.

\version "2.23.2"
#(define (extract music)
   (first (ly:music-property music 'elements)))

{ #(first-element #{ \chordmode {c} #}) }

And this work as expected:

\version "2.23.2"
extract =
#(define-music-function
   (which what music)
   (symbol? symbol? ly:music?)
   (let ((extracted (extract-typed-music music what)))
    (case which
     ((first) (first extracted))
     ((last) (last extracted))
     ((all all-as-sequence) (make-sequential-music extracted))
     ((all-as-chord) (make-event-chord extracted))
     (else (ly:input-warning (*location*)
            "\\extract does not understand '~s'" which)
           music))))

{ \extract first event-chord \chordmode {c} }

why?
Sorry if the question is very trivial.
g.

On Fri, 23 Apr 2021 at 11:29, Aaron Hill <lilypond@hillvisions.com> wrote:
On 2021-04-23 1:58 am, Jean Abou Samra wrote:
> If you have it at hand in Scheme:
>
> \version "2.23.
>
> #(define (first-element music)
>    (first (ly:music-property music 'elements)))
>
> { #(first-element #{ { c'1 } #}) }
>
> It would be helpful to understand your use
> case; this sounds like you may not necessarily
> need to unpack a sequential music _expression_.

In my usual fashion, here's an over-engineered option showing off some
of the built-in functions in an easily extensible pattern:

%%%%
\version "2.22.0"

extract =
#(define-music-function
   (which what music)
   (symbol? symbol? ly:music?)
   (let ((extracted (extract-typed-music music what)))
    (case which
     ((first) (first extracted))
     ((last) (last extracted))
     ((all all-as-sequence) (make-sequential-music extracted))
     ((all-as-chord) (make-event-chord extracted))
     (else (ly:input-warning (*location*)
            "\\extract does not understand '~s'" which)
           music))))

foo = { c <e g> }

\fixed c' {
   \extract first event-chord \foo
   \extract last note-event \foo
   \extract all note-event \foo
   \extract all-as-chord note-event \foo
}
%%%%

-- Aaron Hill

reply via email to

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