[frogs] Guitar capo code in scheme

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


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)
  (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)))
;; call the chordNameFunction as of old
    (chord-function pitches bass inversion context)
;; else transpose the pitches and do the chord twice
    ((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))
      (if (capo-vertical)
        (make-column-markup (list markup capo-markup))
        (make-line-markup (list markup (make-hspace-markup 1) capo-markup))
      )
    )
  )
)

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 ...

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.

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 :-)

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.

Thanks,
Wol

---
----
Join the Frogs!


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