[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: functions in \with
From: |
Trevor Daniels |
Subject: |
RE: functions in \with |
Date: |
Tue, 29 Aug 2006 16:06:24 +0100 |
> On Tuesday 29 August 2006 10:47, Erik Sandberg replied:
Thanks for responding, Erik
> On Monday 28 August 2006 13:55, Trevor Daniels wrote:
> > I'm happily creating and using music functions but so far my attempts to
> > define functions that can be used in \with or \context clauses
> have failed.
> > The suggested technique of making a void function using (make-music
> > 'SequentialMusic 'void #t) doesn't seem to help.
>
> What do you want to achieve, more precisely?
Being relatively new to lilypond I wanted to encapsulate useful expressions
in variables and functions as I came across them. For music-related
expressions I find these very useful, and I wanted to do the same for other
types of sequences. Here's a simple example (thanks, Kieren) to reduce the
size of a piano grand staff which I've failed to recast as a more general
function for use in a \with clause:
\new PianoStaff \with {
fontSize = #-2 % reduce size of all fonts
\override StaffSymbol #'staff-space = #(magstep -2) % reduce size of staves
by same amount
\override VerticalAlignment #'forced-distance = #11 % increase distance
between staves for piano dynamics
}
... rest of staves and music
I wanted to define a void function something like
staffSize=#(
define-music-function (parser location fontsize separation) (number?
number?) #{
fontSize = #$fontsize % change size of all fonts
\override StaffSymbol #'staff-space = #(magstep #$fontsize) % change size
of staves by same amount
\override VerticalAlignment #'forced-distance = #$separation % change
distance between staves for piano dynamics
#}
(make-music 'SequentialMusic 'void #t)
)
which could be used as:
\new PianoStaff \with { \staffSize #-2.0 #11.0 }
but attempts to use a function within \with {...} cause an 'unexpected
MUSIC_FUNCTION_SCM' error on \staffSize or leave the parser forlornly
'Parsing ...', depending on the contents of the function definition.
Using a variable without parametrisation gives an 'unexpected
MUSIC_IDENTIFIER' error.
I don't know whether it is possible to do this, or whether I simply haven't
learned how to do it properly yet.
> Note that \with uses a different lexical mode than music, so e.g. the
> \override keyword does not produce a music expression when used
> inside \with.
I had hoped (make-music 'SequentialMusic 'void #t) would prevent the parser
looking for music.
>
> You can probably perform operations on the whole \with block if you are
> clever, by applying a funciton on the \new expression, like
> \myFun \new Staff=foo \with {bla bla} {music}
>
As a relative newbie I don't have the confidence to try this yet - maybe one
day!
> --
> Erik
>
Trevor
>
>