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: Jan-Peter Voigt
Subject: Re: music function with access to context properties like currentBarNumber?
Date: Thu, 16 Jul 2015 09:05:00 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0

Hi Malte, Abraham,

if I knew how to achieve it, it would already be part of the edition-engraver. 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. Another feature I'd like to add, but leads to the same problem, would be to add cue-notes with in a manner the edition-engraver adds overrides.

You can reach the context-properties thru apply-context, but then still the duration set to late, as you can see in the (not working) example below.

Well, this is just a quick shot, that might lead someone else to an answer ;)

Cheers, Jan-Peter

%%%%
% 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' }
%%%%


Am 15.07.2015 um 20:20 schrieb Malte Meyn:
Hello list,

I would like to have somthing like

\version "2.19.22"
{
  \time 3/4
  % bar 1
  c'2.
  \skipUntil #5 % s2.*4
  % bar 5
  c'2.
  \restUntil #8 % R2.*2
  % bar 8
  c'2.
}

so I don’t have to count bars every time an instrument has a long rest (could also be helpful when composing, or, in a more advanced version, when skipping several bars with many time signature changes).

My first thought was “I need a music function that accesses currentBarNumber” but that (and, for the more advanced version, measureLength) is a context property. Now I don’t know how to get the context to this music function and making it return a (make-music 'MultiMeasureRestMusic …). Attached is my first attempt but that returns only (make-music 'ApplyContext …).

Is this the correct approach? Or do I have to write an engraver? If so, where can I learn how to do that?

Thanks in advance,
Malte


_______________________________________________
lilypond-user mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/lilypond-user




reply via email to

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