[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to create a music function properly?
From: |
David Kastrup |
Subject: |
Re: How to create a music function properly? |
Date: |
Mon, 27 Sep 2010 21:50:30 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
Marc Hohl <address@hidden> writes:
> Hello list,
>
> after having written mails way too early to this list recently
> while overlooking the obvious, I think I stumbled upon a *real*
> problem now :-/
>
> Please have a look at the attached file. This is not the real world problem,
> but I boiled it down to a nearly minimal example.
>
> Only version 3 is giving the desired output in standard notation,
> but ignoring the \override.
>
> What am I doing wrong here?
>
> Thanks in advance!
>
> Marc
>
> \version "2.13.32"
>
> % thanks to Neil for this function
> #(define (make-harmonic mus)
> (let ((elts (ly:music-property mus 'elements))
> (elt (ly:music-property mus 'element)))
> (cond
> ((pair? elts)
> (map make-harmonic elts))
> ((ly:music? elt)
> (make-harmonic elt))
> ((music-is-of-type? mus 'note-event)
> (set! (ly:music-property mus 'articulations)
> (append
> (ly:music-property mus 'articulations)
> (list (make-music 'HarmonicEvent))))))
> mus))
>
>
> 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
> #}))
Uh, #{ #} creates and returns a value. Only the last value in a Scheme
function is the return value of the function.
> 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)
Uh, you need $result here, or the global result will be used. Also, a #
expression is evaluated when it is encountered. That may be before the
\override is considered complete.
> (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 don't return your override as the resulting music function
expression. Expressions in #{ ... #} don't "happen" when encountered.
They "happen" by returning them to the music function caller. So the #{
#} is a do-nothing here.
> %{
> harmonicTestFour = #(define-music-function (parser location music) (ly:music?)
> #{
> #(let* ((test 8)
> (result (/ test 2)))
>
> \override TabNoteHead #'transparent = ##t
> #(begin
> (display "\nDummy output to check the let-block: ")
> (display result)
> (make-harmonic music)))
> #})
> %}
Outcommented.
>
> test = {
> c2^"Test 0" < c g >2
> \harmonicTestOne { c4^"Test 1" < c g >4 }
> \harmonicTestTwo { c4^"Test 2" < c g >4 }
> \harmonicTestThree { c4^"Test 3" < c g >4 }
> %\harmonicTestFour { c4^"Test 4" < c g >4 }
> }
>
> \score {
> <<
> \new Staff {
> \new Voice {
> \clef "treble_8"
> \test
> }
> }
> \new TabStaff {
> \new TabVoice {
> \test
> }
> }
> >>
> }
--
David Kastrup