lilypond-user
[Top][All Lists]
Advanced

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

Re: Help defining commands


From: Nicolas Sceaux
Subject: Re: Help defining commands
Date: Sun, 30 Nov 2003 20:19:28 +0100
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux)

Sun, 30 Nov 2003 11:24:53 -0700, Paul a dit : 

 > Guy Shaviv wrote:
 >> That's correct, I'm interested in how you can set up a command that takes a
 >> parameter. I actually even need two parameters as a partial barre has two
 >> parameters, on what fret and on how many strings. While for the full barre I
 >> can setup 12 commands (e.g. \barreI \barreII ...), its impractical to setup
 >> all the permutations for the partial barre, that would take 60 commands).
 >> 
 > I am trying to solve the same problem.  I have gotten this far:

 > #(define textPad( lambda( pad ) \property Score.TextScript \override
 > #'padding = pad ))

 > with several guessed variations of

 > (textPad 3)

 > Can someone help me finish the syntax?

In the following snippet, functions nthcdr and group are general
utilities. Macros mus:make-music and mus:context-override are
part of a LilyPond-specific toolkit. Function text-pad finally does
what you may want: it takes the padding value as a mandatory argument,
and a second optional argument which, if true, means that the property
override will happen only once. An example shows some variations of
its use.

---------------- toto.ly ------------------------
#(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*-public mus:make-music (name #:rest props)
  "Make a music expression, of type `name' (a non quoted symbol).
`props' describe the music expression properties. For isntance:
  (mus: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)))
                   prop-clauses)
       ,gmus)))

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

#(define*-public (text-pad pad #:optional once)
  (ly:export (mus:context-override Voice TextScript padding pad 
                                   #:once once)))

\score { \notes { c'^"salut" c' #(text-pad 3.0 #t) c'^"salut"
  c'^"salut" c' #(text-pad 3.0) c'^"salut" c'^"salut" }}
---------------- toto.ly ------------------------

You might take a look at 
http://nicolas.sceaux.free.fr/schemingly/scheme-hacks.html
where you will find few other utilities of that kind, that may help
you build other functions for LilyPond. Lily 2.0 is required.

Best regards,
Nicolas






reply via email to

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