On 31/07/11 00:22, Carl Sorensen wrote:
> 
> 
> 
> On 7/30/11 5:15 PM, "Wols Lists" <antli...@youngman.org.uk> wrote:
> 
>> On 30/07/11 23:52, Wols Lists wrote:
>>> On 30/07/11 22:49, pkx1...@gmail.com wrote:
>>>> Doesn't pass a make check.
>>>>
>>>> I get an error on
>>>>
>>>> regression/fret-diagrams-string-thickness.ly
>>>>
>>>> log file shows:
>>>>
>>>> Renaming input to:
>>>>
> `/home/jlowe/lilypond-git/input/regression/fret-diagrams-string-thickness.ly>>>
> '
>>>>
>>>> Interpreting music... ERROR: In procedure ly:pitch-transpose:
>>>> ERROR: Wrong type argument in position 2 (expecting Pitch): ()
>>>>
>>>> http://codereview.appspot.com/4800051/
>>>>
>>> I've just modified my sample code to print straight chords at the start,
>>> and it now fails. So it looks like the problem is in the trap that says
>>> "no transpose, just fall straight through to the formatter like it did
>>> before".
>>>
>>> Bad error to miss ... if anybody can help me with the necessary scheme...
>>>
>> Following up to my own post ... the relevant snippet of code is
>>
>> +        (capo-pitch (ly:context-property context 'capoPitch '())))
>> +    (if (not capo-pitch)
>> +        (chord-function pitches bass inversion context)  ;; call the
>> chordNameFunction as of old
>> +        (let* ((new-pitches   ;; else transpose the pitches and do the
>> chord twice
>>
>> What does ly:context-property return if capoPitch hasn't been set? If
>> I've got it right, I've told it to return '() as the default, and then
>> I'm testing for #f. Oops. How do I fix that? Either get context-property
>> to return #f (I've tried just swapping '() for #f, and it doesn't seem
>> to work) or change the if to test for '()?
> 
> It returns '() (because you've told it to do so).
> 
> Change the if to test for
> 
> if (null? capoPitch)
> 
> HTH,
> 
It helps a lot :-)

Revised patch attached ...

Cheers,
Wol
>From 788e84dfcde232ff096c0502958ae2a95a78d03b Mon Sep 17 00:00:00 2001
From: Wol <anth...@youngman.org.uk>
Date: Fri, 29 Jul 2011 22:43:13 +0100
Subject: [PATCH] Modify chord handling to handle guitar capos

chord-name-engraver now calls a shim between it and the chord formatter
in order to print capo chords

chord-name-scm has had capo-handler added. If requested it prints both
the original chord, and the transposed chord.

define-context-properties adds the properties capoPitch to declare the
capo transposition, and capoVertical to make the chords print in column
rather than row form.
---
 lily/chord-name-engraver.cc       |    4 ++--
 scm/chord-name.scm                |   28 ++++++++++++++++++++++++++++
 scm/define-context-properties.scm |    2 ++
 3 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/lily/chord-name-engraver.cc b/lily/chord-name-engraver.cc
index d0ced5a..2442cdb 100644
--- a/lily/chord-name-engraver.cc
+++ b/lily/chord-name-engraver.cc
@@ -124,8 +124,8 @@ Chord_name_engraver::process_music ()
 
       pitches = scm_sort_list (pitches, Pitch::less_p_proc);
 
-      SCM name_proc = get_property ("chordNameFunction");
-      markup = scm_call_4 (name_proc, pitches, bass, inversion,
+      SCM capo_proc = ly_lily_module_constant ("capo-handler");
+      markup = scm_call_4 (capo_proc, pitches, bass, inversion,
           context ()->self_scm ());
     }
   /*
diff --git a/scm/chord-name.scm b/scm/chord-name.scm
index 79b0189..98506d0 100644
--- a/scm/chord-name.scm
+++ b/scm/chord-name.scm
@@ -170,3 +170,31 @@ FOOBAR-MARKUP) if OMIT-ROOT is given and non-false.
         (alist (map chord-to-exception-entry elts)))
     (filter (lambda (x) (cdr x)) alist)))
 
+(define-public (capo-handler pitches bass inversion context)
+  (let ((chord-function
+          (ly:context-property context 'chordNameFunction 'jazz-chord-names))
+        (capo-pitch (ly:context-property context 'capoPitch #f)))
+    (if (not capo-pitch)
+        (chord-function pitches bass inversion context)  ;; call the 
chordNameFunction as of old
+        (let* ((new-pitches   ;; else transpose the pitches and do the chord 
twice
+               (map (lambda (p)
+                       (ly:pitch-transpose p capo-pitch))
+                    pitches))
+               (new-bass
+                 (if (ly:pitch? bass)
+                     (ly:pitch-transpose bass capo-pitch)
+                     '()))
+               (new-inversion
+                 (if (ly:pitch? inversion)
+                     (ly:pitch-transpose inversion capo-pitch)
+                     '()))
+               (capo-markup
+                 (make-parenthesize-markup
+                   (chord-function new-pitches new-bass new-inversion 
context)))
+               (name-markup (chord-function pitches bass  inversion context))
+               (capo-vertical (ly:context-property context 'capoVertical #f)))
+          (if capo-vertical
+              (make-column-markup (list name-markup capo-markup))
+              (make-line-markup (list name-markup
+                                      (make-hspace-markup 1)
+                                      capo-markup)))))))
diff --git a/scm/define-context-properties.scm 
b/scm/define-context-properties.scm
index dab5211..d17f72f 100644
--- a/scm/define-context-properties.scm
+++ b/scm/define-context-properties.scm
@@ -135,6 +135,8 @@ that normally end on beats.")
      (beatStructure ,list? "List of @code{baseMoment}s that are combined
 to make beats.")
 
+     (capoPitch ,ly:pitch? "The pitch to transpose chords down by when using 
the capo.")
+     (capoVertical ,boolean? "Whether to display actual and transposed pitches 
above each other or not.")
      (chordChanges ,boolean? "Only show changes in chords scheme?")
      (chordNameExceptions ,list? "An alist of chord exceptions.
 Contains @code{(@var{chord} . @var{markup})} entries.")
-- 
1.7.3.4

_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to