lilypond-devel
[Top][All Lists]
Advanced

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

Re: music function refactoring


From: Erik Sandberg
Subject: Re: music function refactoring
Date: Wed, 1 Feb 2006 12:57:11 +0100
User-agent: KMail/1.8.3

On Monday 30 January 2006 01.01, Han-Wen Nienhuys wrote:
> Erik Sandberg wrote:
> > It could maybe be fixed by viewing variables as zero-parameter functions
> > somehow (but it would require "declaring" them globally before using
> > them).
>
> It's still a large change. I'm not yet convinced that getting cute
> \relative hacks is worth the breakage, and doing it from
> toplevel-music-functions does not seem very elegant to me.

I have a feeling that \relative hacks is something very relevant (I believe 
that shorthands such as the \interpolate{} thing can be very valuable in the 
hands of an experienced lily user). The important thing is that \relative 
should recurse into the parameters, not the return value, of a function.

My initial idea was to do a pure hack, where the partcombine function would 
insert a \relative c' around its arguments (guessing that the previous note 
was a c'), and then use a to-relative-callback which transposed the return 
value if the guess was incorrect. That hack is a lot dirtier, and it only 
works for functions that are 'linear' in transposition (i.e., functions f 
such that \transpose p1 p2 \f mus = \f \transpose p1 p2 mus).

An alternative is to hard-code \relative into the parser, always remembering 
the last entered pitch. That'd however be rather inelegant, and break 
backward compatibility.

I haven't figured out _anything_ except the new local variable assignment 
thing, that would break by postponing function calls to after parsing. (this 
is a good reason to make a final decision pretty soon, before 2.8)

With some minor chanes, the postponing of function calls would also make it 
possible to create recursive music expressions:

% music function written in quasi-code
func = #(lamda (m) (if (> (highest-pitch m) c'') (d''8) (\transpose c d \m)))
\forwardDeclare "foo"
foo = \relative { c8 \func \foo c8 }

=> foo = { c'8 d' e' fis' gis' ais' bis' cisis'' d'' cisis'' bis' ais' gis' 
fis' e' d' c' }

I'm not sure if this kind of feature would ever be useful, though.

It would also be possible to could construct a \for function with a rather 
clean syntax, something like:

\forwardDeclare "i"
\for "i" { c d e f} { e \i e e}
=> { { e c e e } { e d e e } {e e e e } {e f e e } }

A similar function can be written already, but it will have to work in a 
slightly different way, and the usefulness of the command is limited as long 
as \relative doesn't recurse into function parameters.

-- 
Erik




reply via email to

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