|
From: | Gianmaria Lari |
Subject: | Re: "compound music expression" to "music" expression" |
Date: | Sat, 24 Apr 2021 07:34:37 +0200 |
\displayLilyMusic \chordmode {c}
{ < c' e' g' >4 }
\version "2.23.2"#(define (extract music)(first (ly:music-property music 'elements))){ #(first-element #{ \chordmode {c} #}) }
\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} }
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
[Prev in Thread] | Current Thread | [Next in Thread] |