lilypond-user
[Top][All Lists]
Advanced

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

Re: overriding voiceOne to add properties to that specific voice context


From: Maurits Lamers
Subject: Re: overriding voiceOne to add properties to that specific voice context
Date: Thu, 20 Aug 2020 11:10:25 +0200

Hi, 

Great! This is the perfect solution. I had to adjust the 
(define-scheme-function) call a bit to run also under 2.18:

setStructuralVoice = #(define-scheme-function (parser location num) (integer?)
  (make-apply-context
    (lambda (context)
        (ly:context-set-property! context 'structuralVoice (if (> num 0) num 
'())))))

It might need even more tweaks to run under 2.14 which is my target. I know it 
is a very old version, but there is a large body of Lilypond code my work 
depends on and that is lilypond 2.14. I am afraid that it would distract the 
current effort and cost too much time at the moment to convert that body of 
work to a more recent version of lilypond.

So, it will probably end up like this, as I am unsure whether lilypond v20 can 
deal with v18 type calls to define-scheme-function.

setStructuralVoice = #(case (second (ly:version))
  ( (18)
      (define-scheme-function (parser location num) (integer?)
         (make-apply-context
           (lambda (context)
             (ly:context-set-property! context 'structuralVoice (if (> num 0) 
num '())))))
  )
  ( (20)
       (define-scheme-function (num) (integer?)
          (make-apply-context
             (lambda (context)
                (ly:context-set-property! context 'structuralVoice (if (> num 
0) num '())))))
   ))

Thanks a lot!

cheers

Maurits

> Op 20 aug. 2020, om 02:00 heeft Lukas-Fabian Moser <lfm@gmx.de> het volgende 
> geschreven:
> 
> 
>> I don't have much experience with custom engravers, but I think one can 
>> define a new context property and upgrade the \voiceX / \oneVoice commands 
>> to also set this context property:
> 
> ... I'm sorry, there's a superfluous (let ((fontSize .... ))) in my code, a 
> relic from a snippet by Harm that I started from. Please simplify to:
> 
> \version "2.21.0"
> 
> % tool for defining new context properties
> % (from https://www.mail-archive.com/lilypond-user@gnu.org/msg133263.html)
> 
> #(define (define-translator-property symbol type? description)
>    (if (not (and (symbol? symbol)
>                  (procedure? type?)
>                  (string? description)))
>        (ly:error "error in call of define-translator-property"))
>    (if (not (equal? (object-property symbol 'translation-doc) #f))
>        (ly:error (_ "symbol ~S redefined") symbol))
> 
>    (set-object-property! symbol 'translation-type? type?)
>    (set-object-property! symbol 'translation-doc description)
>    symbol)
> 
> % define a new context property "structuralVoice"
> #(for-each
>   (lambda (x)
>     (apply define-translator-property x))
>   `((structuralVoice
>      ,integer?
>      "The current voice is a first/second/... voice (1,2,3,4) or single voice 
> (empty list)")))
> 
> setStructuralVoice =
> #(define-scheme-function (num) (integer?)
>    (make-apply-context
>     (lambda (context)
>       (ly:context-set-property! context 'structuralVoice (if (> num 0) num 
> '())))))
> 
> oneVoice = { \setStructuralVoice 0 \oneVoice }
> voiceOne = { \setStructuralVoice 1 \voiceOne }
> voiceTwo = { \setStructuralVoice 2 \voiceTwo }
> voiceThree = { \setStructuralVoice 3 \voiceThree }
> voiceFour = { \setStructuralVoice 4 \voiceFour }
> 
> displayCurrentStructuralVoice = \applyContext
> #(lambda (context)
>    (pretty-print
>     (ly:context-property context 'structuralVoice)))
> 
> \relative {
>   \displayCurrentStructuralVoice % not yet defined
>   a'4
>   \voiceTwo e f
>   \displayCurrentStructuralVoice % should be 2
>   \voiceOne e' f
>   \displayCurrentStructuralVoice % should be 1
>   \oneVoice e d c b a g f
>   \displayCurrentStructuralVoice
> }
> 
> 




reply via email to

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