lilypond-user
[Top][All Lists]
Advanced

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

Re: Harp Pedals?


From: Reinhold Kainhofer
Subject: Re: Harp Pedals?
Date: Thu, 14 Aug 2008 23:51:34 +0200
User-agent: KMail/1.9.9

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am Donnerstag, 14. August 2008 schrieb Carl D. Sorensen:
> >> 2 - The implementation I provide is very dirty, as I said. [...]
> >> and  inside the function I don't know how I can increment the values for
> >> the horizontal placement of the boxes in an elegant way.
> >
> > I think the easiest and most Scheme-like way would be to loop through the
> > seven entries of the pedal list using recursive calls of a named let
> > clause... In particular:
> >
> > (let process-pedal ((remaining-pedals initial-pedals)
> >                             (xpos 0))
> >     ; print the box for the (car remaining-pedals)
> >     ;
> >     ; now call the process-pedal loop with the cdr (unless we are
> > finished) ;
> >     (if (not (empty? (cdr remaining-pedals)))
> >       (process-pedal (cdr remaining-pedals) (+ xpos width-of-this-pedal))
> >     )
> > )
>
> This is a nice Scheme-like way to do it.  However, the problem is that you
> can't just do a recursive call.  You have to do a stencil-add for each
> pedal.  And you can't have a null list as an argument to stencil-add.

Hehe, you are right of course, but that's easily resolved in a Scheme-like 
fashion: simply collect the list of stencils created so far as a third 
variable in the let clause. And the whole let clause returns (cons 
final-x-pos created-stencils), so that one can then draw the horizontal line 
and combine all stencils for the final markup.

> The key here is that you can't just return a stencil (which would be very
> easy to do recursively); you need to return an add-stencil function.

Or you can simply return a list of stencils, to which you add one stencil 
after the other. No set! required here, since I do the prepending right in 
the next call to the let clause.

> Another way to do it, while less Scheme-like, is more straightforward.
> You initialize the stencil with the first element, then do a set! for
> the rest of the elements.  Abelson and Sussman would have a heart attack
> about doing it, but this seems to be the LilyPond way of doing it.
> LilyPond is full of set! assignments.

I started off like this, but then I realized how I could do it with recursion 
and the code got significantly easier...

> However, I can see that you (Reinhold) are a better LilyPond programmer
> than me, so you may know how to do it better than I do.  

Looking at your fret diagrams, I sincerely doubt your statement. You are 
definitely more versed in scheme programming than I am.
I have hardly any Scheme experience (learned it only for lilypond), I simply 
saw some nice scheme constructs in a patch for the part-combiner that Kristof 
Bastiaensen sent to the list three years ago... That's my whole experience!


> If I were starting from scratch, I would have only the terse format for
> markups, and the list format for internal LilyPond grob calls.

That's what I intended to do, too. But since internally everything is 
implemented with the list-based definitions, it's trivial to provide a 
list-based command, too. Given that harp pedals are a lot simpler than fret 
diagrams, it doesn't add any complexity, it simply saves one loop over the 
characters of the string.

Cheers,
Reinhold

- -- 
- ------------------------------------------------------------------
Reinhold Kainhofer, Vienna University of Technology, Austria
email: address@hidden, http://reinhold.kainhofer.com/
 * Financial and Actuarial Mathematics, TU Wien, http://www.fam.tuwien.ac.at/
 * K Desktop Environment, http://www.kde.org, KOrganizer maintainer
 * Chorvereinigung "Jung-Wien", http://www.jung-wien.at/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIpKjnTqjEwhXvPN0RAuF1AJ9iMbfLG+pby+vSpOAThkNSo1eFowCcCX1S
rt3e7SpkMff3rU3/CMlyc1w=
=YtyN
-----END PGP SIGNATURE-----




reply via email to

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