lilypond-user
[Top][All Lists]
Advanced

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

RE: Argument transfer?


From: Fairchild
Subject: RE: Argument transfer?
Date: Sat, 16 Jul 2005 17:03:09 -0500

Nicolas -

A delayed "thank you" for your comprehensive and detailed response -- it is
very much appreciated.

Even though the information is still largely beyond my ken, I've been able
to implement successfully.

The documenters should find grist in this thread, especially your message.

                                - Bruce

-----Original Message-----
From: Nicolas Sceaux [mailto:address@hidden 
Sent: Monday, July 11, 2005 10:15 AM
To: Fairchild
Cc: address@hidden; address@hidden
Subject: Re: Argument transfer?


"Fairchild" <address@hidden> writes:

> 3)  I don't understand some elements, and hope for enlightenment about:
>        a)  def-music-function (location MagArg) (number?)

This is the way to define new LilyPond "keywords", eg functions manipulating
their argument in order to build some music expression programatically. See
the LilyPond manual, 
http://lilypond.org/doc/v2.4/Documentation/user/out-www/lilypond/Extending-m
usic-syntax.html
http://lilypond.org/doc/v2.6/Documentation/user/out-www/lilypond/Extending-m
usic-syntax.html

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

this asks to load a module, which makes it possible to define functions with
variable number of arguments, keyword arguments, etc. Note that in the
example that you show, it is not necesarry. Just change 'define*' by
'define'. See the guile manual, chapter on modules:
http://www.gnu.org/software/guile/docs/guile-ref/Using-Guile-Modules.html

>        c)  #(define* (AltOn MagArg)

This should be define, not define*.
define* is for defining function with more complex arguments, eg. keyword,
rest or optional arguments. See the guile manual:
http://www.gnu.org/software/guile/docs/guile-ref/define--Reference.html

>        d)  (ly:export #{ . . . #}

See the LilyPond-internal manual:
http://lilypond.org/doc/v2.6/Documentation/user/out-www/lilypond-internals/S
cheme-functions.html

> %%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> \version "2.4.6"
> AltOn = #( def-music-function
>   (location MagArg) (number?) #{
>   #( define Mag $MagArg )
>   #( define SizeIE (*(/ 6.0 (log 2.0)) (log Mag)))
>   #( define Size (inexact->exact SizeIE ))
>   \override Stem #'length = #(* 7.0 Mag)
>   \override NoteHead #'font-size = #Size #})
> AltOff = {
>   \revert Stem #'length
>   \revert NoteHead #'font-size }
> { c' \AltOn #0.5 c' c' \AltOff c' }
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> \version "2.4.6"
> #(use-modules (ice-9 optargs))
>   #(define* (AltOn MagArg) (ly:export #{
>   #( define Mag $MagArg )
>   #( define SizeIE (*(/ 6.0 (log 2.0)) (log Mag)))
>   #( define Size (inexact->exact SizeIE ))
>   \override Stem #'length = #(* 7.0 Mag)
>   \override NoteHead #'font-size = #Size #}))
> #(define* (AltOff) (ly:export #{
>   \revert Stem #'length
>   \revert NoteHead #'font-size #}))
> { c' #(AltOn 0.65) c' c' #(AltOff) c' }
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%

The first of your two solutions is the more LilyPond-idiomatic. However, the
style is not very clean, here is how it could be rephrased:

  \version "2.4.6"
  
  AltOn = #(def-music-function (location mag) (number?) 
            #{ \override Stem #'length = #$(* 7.0 mag)
               \override NoteHead #'font-size = 
                 #$(inexact->exact (* (/ 6.0 (log 2.0)) (log mag))) #})
  AltOff = {
    \revert Stem #'length
    \revert NoteHead #'font-size 
  }
  
  { c' \AltOn #0.5 c' c' \AltOff c' }

Or, with LilyPond 2.6 (note the extra 'parser' argument):

  \version "2.6.0"
  
  AltOn = #(def-music-function (parser location mag) (number?) 
            #{ \override Stem #'length = #$(* 7.0 mag)
               \override NoteHead #'font-size = 
                 #$(inexact->exact (* (/ 6.0 (log 2.0)) (log mag))) #})
  AltOff = {
    \revert Stem #'length
    \revert NoteHead #'font-size 
  }
  
  { c' \AltOn #0.5 c' c' \AltOff c' }

However, I would rather write like this:

  \version "2.6.0"
  
  withAlt = #(def-music-function (parser location mag music) (number?
ly:music?) 
            #{ \override Stem #'length = #$(* 7.0 mag)
               \override NoteHead #'font-size = 
                 #$(inexact->exact (* (/ 6.0 (log 2.0)) (log mag)))
               $music
               \revert Stem #'length
               \revert NoteHead #'font-size #})
  
  { c' \withAlt #0.5 { c' c' } c' }

For LilyPond 2.4.6, remove the 'parser' argument after def-music-function.

nicolas







reply via email to

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