[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: tiny function
From: |
Thomas Morley |
Subject: |
Re: tiny function |
Date: |
Fri, 1 Jul 2016 01:40:24 +0200 |
2016-07-01 0:05 GMT+02:00 Br. Gabriel-Marie | SSPX <address@hidden>:
> Thanks, Mr. Meyn,
>
> That certainly does the trick.
>
> So you can't write macros for \with{} statements?
> Why couldn't I do it this way, if I just want to create the \with statement?
Obviously a call of a scheme-function is not allowed instead of a
\with-expression, opposed to a static value stored in vavariable:
\version "2.19.44"
%% fails:
tstI =
#(define-scheme-function ()()
#{ \with { instrumentName = "foo" shortInstrumentName = "foo" } #})
\new Staff \tstI { r1 }
%% works:
tstII =
\with { instrumentName = "foo" shortInstrumentName = "foo" }
\new Staff \tstII { r1 }
There are other possibilities, though:
\version "2.19.44"
%% (1)
#(define (foo nmbr)
#{
\with {
instrumentName = #(format #f "~a." nmbr)
shortInstrumentName = #(format #f "~a." nmbr)
}
#})
\new Staff $(foo 1) { r1 }
%%(2)
buzz =
#(define-scheme-function (nmbr)(number?)
#{
\with {
instrumentName = #(format #f "~a." nmbr)
shortInstrumentName = #(format #f "~a." nmbr)
}
#})
\new Staff \with { \buzz #2 } { r1 }
%%(3)
#(define (set-instrument-names-to-number-string nmbr mus)
(if (eq? (ly:music-property mus 'name) 'ContextSpeccedMusic)
(ly:music-set-property! mus 'property-operations
(list
(list
'assign
'instrumentName
(format #f "~a." nmbr))
(list
'assign
'shortInstrumentName
(format #f "~a." nmbr))))
mus)
mus)
tst =
#(define-music-function (nmbr mus)(number? ly:music?)
(set-instrument-names-to-number-string nmbr mus))
\tst #3 \new Staff { r1 }
HTH,
Harm