lilypond-user
[Top][All Lists]
Advanced

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

Re: music function with access to context properties like currentBarNumb


From: Malte Meyn
Subject: Re: music function with access to context properties like currentBarNumber?
Date: Sat, 18 Jul 2015 12:55:32 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0


Am 16.07.2015 um 09:05 schrieb Jan-Peter Voigt:
The problem is, that one has to unfold the music expression during
iteration, so he may need to build a parallel music iterator, that
creates the needed grobs. That sounds misleading.


I don’t understand this completely (never heard of music iterators) but this does simply mean that it’s hard or impossible to change something early enough in the compilation process, doesn’t it?

> % non-functional example
\version "2.18.2"

fun = #(define-music-function (parser location bars)(integer?)
          (let ((cbn 0)
                (ml (ly:make-moment 4 4))
                (rest #{ R1 #}))
            #{
              \applyContext #(lambda (context)
                               (set! cbn (ly:context-property context
'currentBarNumber))
                               (ly:message "bar-number: ~A" cbn)
                               (set! ml (ly:context-property context
'measureLength))
                               (ly:message "measure-length: ~A" ml)
                               (ly:music-set-property! rest 'duration ml))
              $rest
            #}
            ))

{ \time 3/4 bes'4 a' c''8 b' | \fun 3 | bes'4 a' c''8 b' }

I wrote a very simple engraver today which tries to modify the duration of rests. It seems to have the same problem: The duration of events can be changed but it doesn’t shift the following events.

%%%%
% another non-functional example

\version "2.19.22"

#(define Modify_rests_engraver
   (make-engraver
    (listeners
     ((rest-event engraver event)
      (ly:event-set-property!
       event
       'duration
       (ly:make-duration 3 1 1)) ; 8.*1
      (ly:message "rest in measure ~A"
       (ly:context-property
        (ly:translator-context engraver)
        'currentBarNumber))))))

\new Voice \with {
  \consists #Modify_rests_engraver
} \relative {
  r4 g'16
  a a a a
  b b b b
  c c c c |
  r2 r16 r
}

%%%%

If this worked, one could ‘abuse’ fingering numbers for telling the target bar.

\displayMusic { r-125 }



reply via email to

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