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: Aaron Hill
Subject: Re: "compound music expression" to "music" expression"
Date: Fri, 23 Apr 2021 02:29:48 -0700
User-agent: Roundcube Webmail/1.4.9

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

Attachment: extract-music.cropped.png
Description: PNG image


reply via email to

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