lilypond-user
[Top][All Lists]
Advanced

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

Re: Accessing context properties (e.g. the current key) from a music fun


From: David Nalesnik
Subject: Re: Accessing context properties (e.g. the current key) from a music function?
Date: Thu, 30 Apr 2015 18:41:32 -0500

Hi Harm,

On Thu, Apr 30, 2015 at 6:36 PM, Thomas Morley <address@hidden> wrote:
2015-05-01 1:23 GMT+02:00 David Nalesnik <address@hidden>:

 
> %%%%%%%%%%%%%%%%%%%%%%%%%%
>
> \version "2.18"
>
> \language "italiano" % the closest preset :)
>
> test =
> #(define-music-function (parser location music)
>    (ly:music?)
>    (let ((t (ly:make-pitch 0 0))) ; C is the default tonic
>      (music-map
>       (lambda (mus)
>         (if (music-is-of-type? mus 'key-change-event)
>             (set! t (ly:music-property mus 'tonic)))
>         (if (music-is-of-type? mus 'note-event)
>             #{
>               \transpose #(ly:make-pitch 0 0) #t #mus
>             #})
>         mus)
>       music)
>      music))
>

This seems to work as well, or am I missing something?

\test
\new Staff {
  \new Voice {
     {
      \key re \major
      do'4 mi' sol' do'' <do' mi' sol'>1
    }
     {
      \key fa \major
       do'4 mi' sol' do'' <do' mi' sol'>1
    }
     {
      \key sol \minor
       do'4 mib' sol' do'' <do' mib' sol'>1
    }
  }
}


Cheers,
  Harm

Huh.  I tried to make it easy on myself and purposely write something that wouldn't work like that :)

Thanks!

David

P.S.  Now I'm going to set out to break it...

reply via email to

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