lilypond-user
[Top][All Lists]
Advanced

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

Re: How to create a music function properly?


From: Neil Puttock
Subject: Re: How to create a music function properly?
Date: Mon, 27 Sep 2010 20:48:06 +0100

On 27 September 2010 20:02, Marc Hohl <address@hidden> wrote:

> harmonicTestOne = #(define-music-function (parser location music)
> (ly:music?)
>  (let* ((test 2)
>         (result (/ test 2)))
>
>  #{
>    \override TabNoteHead #'transparent = ##t
>  #}
>  (make-harmonic music)
>  (display "\nDummy output to check the let-block: ")(display result)
>  #{
>    \revert TabNoteHead #'transparent
>  #}))

This swallows the music, since the (make-harmonic music) part isn't
last in the list: it returns the \revert only.

> harmonicTestTwo = #(define-music-function (parser location music)
> (ly:music?)
>  (let* ((test 4)
>         (result (/ test 2)))
>  #{
>    \override TabNoteHead #'transparent = ##t
>
>  #(begin
>     (display "\nDummy output to check the let-block: ")
>     (display result)
>     (make-harmonic $music))
>    \revert TabNoteHead #'transparent
>  #}))

Here the \override and \revert are both included, since the #{ #}
block creates a sequential music section.  Unfortunately, the
(make-harmonic music) part never gets processed by the parser: as a
scheme object, it's ignored unless treated like an identifier via
`ly:export'.  It can't be part of the `begin' in this case.

harmonicTestTwo =
#(define-music-function (parser location music) (ly:music?)
   (let* ((test 4)
          (result (/ test 2)))
     #{
       \override TabNoteHead #'transparent = ##t
       #(begin
         (display "\nDummy output to check the let-block: ")
         (display $result))
       #(ly:export (make-harmonic $music))
       \revert TabNoteHead #'transparent
     #}))

> harmonicTestThree = #(define-music-function (parser location music)
> (ly:music?)
>  (let* ((test 6)
>         (result (/ test 2)))
>
>  #{
>    \override TabNoteHead #'transparent = ##t
>  #}
>  (begin
>     (display "\nDummy output to check the let-block: ")
>     (display result)
>     (make-harmonic music))))

You're on the right track here: now you're actually returning the
correct music, but it's also junking the \override, since it's not
part of the returned music.  If you wrap it in make-sequential-music,
both actions will take place in sequence:

harmonicTestThree =
#(define-music-function (parser location music) (ly:music?)
   (let* ((test 6)
          (result (/ test 2)))
     (make-sequential-music
      (list
       #{
         \override TabNoteHead #'transparent = ##t
       #}
       (begin
        (display "\nDummy output to check the let-block: ")
        (display result)
        (make-harmonic music))))))

I suggest you stay in scheme for this kind of music function rather
than switching into lily code (which can't be auto-indented properly).

Cheers,
Neil



reply via email to

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