[Top][All Lists]

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

\apply nest-props Re: constructive criticism

From: Nicolas Sceaux
Subject: \apply nest-props Re: constructive criticism
Date: Sat, 10 Jan 2004 18:39:18 +0100
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux)

Thu, 8 Jan 2004 12:00:14 +0100, Han-Wen a dit : 

 > Come to think of it, this form of \with is superfluous. It is possible
 > to write it with something like

 >  \apply #(nest-props '((Stem thickness 4) (Slur transparent #t)))
 >    { .. }

 > where nest-props takes care of pre- and appending the appropriate
 > settings.

for the record, here is a possible implementation (using lily 2.1.0):

#(use-modules (ice-9 optargs))

#(define-public (nthcdr n source)
  (do ((rest source (if (pair? rest) (cdr rest)))
       (i 0 (1+ i)))
      ((= i n) rest)))

#(define-public (group source n)
  (if (zero? n) (error "zero length"))
  (letrec ((rec (lambda (source acc)
                  (let ((rest (nthcdr n source)))
                    (if (pair? rest)
                        (rec rest (cons (list-head source n) acc))
                        (reverse! (cons source acc)))))))
    (if (null? source) '() (rec source '()))))

#(defmacro* make-music (name #:rest props)
  "Make a music expression, of type `name' (a non quoted symbol).
`props' describe the music expression properties. For isntance:
  (make-music PropertySet 
              symbol 'autoBeaming
              value #f)"
  (let ((prop-clauses (group props 2))
        (gmus (gensym)))
    `(let ((,gmus (make-music-by-name ',name)))
       ,@(map (lambda (clause)
                `(ly:set-mus-property! ,gmus ',(car clause) ,(cadr clause)))

#(defmacro* context-override (context property setting value #:key (once #f))
  "Make a ContextSpeccedMusic with OverrideProperty element, similar to:
  [\\once] \\property \override #'setting = #value"
    (make-music OverrideProperty 
                once ,once
                symbol ',property
                grob-property ',setting
                grob-value ,value)

#(defmacro context-revert (context property setting)
  "Make a ContextSpeccedMusic with RevertProperty element, similar to:
\\property \revert #'setting"
    (make-music RevertProperty
                symbol ',property
                grob-property ',setting)

#(defmacro* nest-props (#:rest prop-clauses)
  `(lambda (mus)
    (ly:set-mus-property! mus 'elements 
      ,@(map (lambda (prop-clause)
               `(context-override ,@prop-clause))
      (make-music SequentialMusic elements (ly:get-mus-property mus 'elements))
      ,@(map (lambda (prop-clause)
               `(context-revert ,(car prop-clause) ,(cadr prop-clause) ,(caddr 

titi = \notes { c'8( d') e'( f') g'4( a') }

\score {
  \notes {
      \apply #(nest-props (Voice Stem thickness 4)
                          (Voice Slur transparent #t)) 
             { \titi }

Attachment: test-nest-props.preview.png
Description: PNG image


reply via email to

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