Re: [frogs] Guitar capo code in scheme

[ Thread Index | Date Index | More lilynet.net/frogs Archives ]




On 7/19/11 5:47 PM, "Wols Lists" <antlists@xxxxxxxxxxxxxxx> wrote:

> Finally dragged myself back to it. Looking at Neil's sample code, it
> looked like it modified the formatters, which I didn't want to do ... so
> I've created the shim.
> 
> So chord-name-engraver.cc will need to be modified (ll127) to call my
> shim rather than the chordNameFunction. I've called the shim
> capo-handler and defined it in chord-name.scm. I quite deliberately
> haven't done a patch quite yet, because my scheming is "monkey see
> monkey do" and I shall be VERY surprised if it doesn't need some fixing....
> 
> Anyways, shim function follows ...
> 
> (define-public (capo-handler pitches bass inversion context)

  This needs to be in a let block.

    (let ((chord-function ....)
          (capo-pitch ...))
       (if (not capo-pitch)
....
>   (chord-function (ly:context-property context 'chordNameFunction #f))
>   (capo-pitch (ly:context-property context 'capoPitch #f))
> ;; if there's no capo pitch or no chord
>   (if
>     (or (not (capo-pitch) not (chord)))

The test is not correct.  Also, it should be on the same line as the if:

   (if (not capo-pitch)

> ;; call the chordNameFunction as of old
>     (chord-function pitches bass inversion context)
> ;; else transpose the pitches and do the chord twice

The code below needs to be in a let block:
    (let ((new-pitches....
>     ((new-pitches
>         (map (lambda (p)
>           (ly:pitch-transpose p capo-pitch))
>       pitches))
>       (new-bass
>         (and (ly:pitch? bass)
>           (ly:pitch-transpose bass capo-pitch)))
>       (new-inversion
>         (and (ly:pitch? inversion)
>           (ly:pitch-transpose inversion
>       capo-pitch)))
> 
>       (capo-markup (make-parenthesize-markup (chord-function new-pitches
> new-bass new-inversion context)))
>       (markup (chord-function pitches bass  inversion context))
> 
>       (capo-vertical (ly:context-property context 'capoVertical #f))

This will be the end of your let block definitions, so it will need another
)

>       (if (capo-vertical)
>         (make-column-markup (list markup capo-markup))
>         (make-line-markup (list markup (make-hspace-markup 1) capo-markup))

Style -- never ever ever leave a right parenthesis by itself on a line.

>       )
>     )
>   )
> )
> 
> I've got (not (chord)), which Carl said he thought was actually encoded
> as a rest, but I haven't got a clue how to test for it ...

You don't need to test for it.  The shim function will be called at line 128
of lily/chord-name-engraver.cc.  This code is never executed if it's a rest
event (see lines 79-85).
> 
> I've done the code a bit differently from Neil's sample patch too.
> Basically, if the capo is irrelevant, it detects that at the start and
> simply drops straight into the chord formatter.
> 

Great!  Details like this are not too important to us.  You're free to do
the code the way you'd like to.  We're more concerned about the
architecture.

> Otherwise, it transposes its arguments, calls the chord formatter twice,
> and checks capoVertical to see whether the two chords are to be printed
> one after the other, or one above the other.
> 
> I've assumed "context" is the engraver so I can extract things like the
> chord formatter, the pitch to transpose, etc from it. If I've guessed
> wrong, then that'll need a rework too :-)

"context" isn't the engraver.  context is the context in which the music
function is being evaluated.  context is where you get the properties
chordNameFunction and capoPitch.

So you've done it right, but the terminology was off a bit.

> 
> Anyways, does this look okay? I haven't done any scheme sillies? How do
> I test for a rest? And if you think this looks sensible, I'll modify
> chord-name-engraver to call it and test it tomorrow - it's midnight and
> time for bed here now.

With the exceptions I've noted above, it looks great!  I think this will do
exactly what you want done, and it will satisfy my concerns and Neil's
concerns.  Great job!

Thanks,

Carl


---
----
Join the Frogs!


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/