lilypond-user
[Top][All Lists]
Advanced

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

Add an arbitrary music property


From: Urs Liska
Subject: Add an arbitrary music property
Date: Fri, 8 Jun 2018 21:26:21 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

Hi,

is there anything wrong with adding an arbitrary property to a SequentialMusic like that:

\version "2.19.80"

someNote = { c' d' }

#(set! (ly:music-property someNote 'foo) "bar")

\displayMusic \someNote
?

The following is a MWE of a new extension I plan for scholarLY, and it seems to work. \sic and \corr add such an arbitrary property to the music while \choice uses that to retrieve one element out of a list of music expressions.
\version "2.19.80"

#(define selection 'sic)
%#(define selection 'corr)

choice =
#(define-music-function (mus) (ly:music?)
   (let*
    ((elts
      (map
       (lambda (expr)
         (cons (ly:music-property expr 'choiceType) expr))
       (ly:music-property mus 'elements)))
      (chosen (assq-ref elts selection)))
    (if chosen 
        chosen 
        (first (ly:music-property mus 'elements)))))

tagMusic =
#(define-void-function (mus tag)(ly:music? symbol?)
   (set! (ly:music-property mus 'choiceType) tag))

sic =
#(define-music-function (mus) (ly:music?)
   (tagMusic mus 'sic)
   mus)

corr =
#(define-music-function (mus) (ly:music?)
   (tagMusic mus 'corr)
   mus)

\relative {
  c' c g' g |
  \choice {
    \sic { g }
    \corr { a }
  }
  a g2
}
But before proceeding I'd like to know if I'm not doing anything stupid by injecting two list items like so:

    

(make-music

'SequentialMusic

'choiceType

'sic

'elements

(list (make-music

'NoteEvent

'pitch

(ly:make-pitch -1 4)

'duration

(ly:make-duration 2))))


Urs

reply via email to

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