]> git.donarmstrong.com Git - lilypond.git/commitdiff
Fix 763 Fretboards don't transpose properly
authorCarl Sorensen <c_sorensen@byu.edu>
Sun, 15 Mar 2009 03:34:58 +0000 (21:34 -0600)
committerCarl Sorensen <c_sorensen@byu.edu>
Sun, 15 Mar 2009 03:43:24 +0000 (21:43 -0600)
A transpose that took a chord out of the default octave broke the
default fretboards.

The code is now modified to look both an octave up and an octave down
from the given octave if no entry is found for the given octave.

Documentation/user/fretted-strings.itely
input/regression/predefined-fretboards-transpose.ly [new file with mode: 0644]
scm/music-functions.scm
scm/translation-functions.scm

index 614c0c15def4bcf08d859f72f683a3b66561b6a1..1ba998a800b58fb7b287e48f901be4c806218e3d 100644 (file)
@@ -880,17 +880,19 @@ mychords = \chordmode{
 @end lilypond
 
 Different fret diagrams for the same chord name can be stored using different
-octaves of pitches.
+octaves of pitches.  The different octave should be at least two octaves
+above or below the default octave, because the octaves above and  below the
+default octave are used for transposing fretboards.
 
 @lilypond[verbatim, ragged-right, quote]
 \include "predefined-guitar-fretboards.ly"
 
-\storePredefinedDiagram \chordmode {c'}
+\storePredefinedDiagram \chordmode {c''}
                         #guitar-tuning
                         #(offset-fret 2 (chord-shape 'bes guitar-tuning))
 
 mychords = \chordmode{
-  c1 c'
+  c1 c''
 }
 
 <<
@@ -930,15 +932,15 @@ marking lists.
 
 % add some new chords based on the power chord shape
 
-\storePredefinedDiagram \chordmode {f'}
+\storePredefinedDiagram \chordmode {f''}
                         #guitar-tuning
                         #(chord-shape 'powerf guitar-tuning) 
-\storePredefinedDiagram \chordmode {g'}
+\storePredefinedDiagram \chordmode {g''}
                         #guitar-tuning
                         #(offset-fret 2 (chord-shape 'powerf guitar-tuning))
 
 mychords = \chordmode{
-  f1 f' g g'
+  f1 f'' g g''
 }
 
 <<
diff --git a/input/regression/predefined-fretboards-transpose.ly b/input/regression/predefined-fretboards-transpose.ly
new file mode 100644 (file)
index 0000000..091c492
--- /dev/null
@@ -0,0 +1,27 @@
+\version "2.13.0"
+\header{
+
+  texidoc="
+Transposition by less than one octave up or down should not affect
+predefined fretboards.
+
+"
+}
+
+
+\include "predefined-guitar-fretboards.ly"
+
+myChords = \chordmode { c1 d }
+
+mySequence = {
+
+  \myChords
+  \transpose c c' {\myChords}
+  \transpose c c, { \myChords}
+}
+
+<<
+  \new ChordNames {\mySequence}
+  \new FretBoards {\mySequence}
+>>
+
index de8b5973fb67f0101a741a58c2d51803187707e2..0263d498e94038890c7ce4a30af0e4561e03f5e1 100644 (file)
@@ -951,6 +951,16 @@ Syntax:
      (skip-as-needed x parser)
    )))
 
+;;;;;;;;;;
+;;; general purpose music functions
+
+(define (shift-octave pitch octave-shift)
+  (_i "Add @var{octave-shift} to the octave of @var{pitch}.")
+  (ly:make-pitch
+     (+ (ly:pitch-octave pitch) octave-shift)
+     (ly:pitch-notename pitch)
+     (ly:pitch-alteration pitch)))
+
 
 ;;;;;;;;;;;;;;;;;
 ;; lyrics
index 902da1287d3390fc0fdd757df6773ca1bfbecb48..eefa9c0806a3b18088219b88cf413e7bccf45e5f 100644 (file)
                      ))
                  string-frets)
        (vector->list desc)))
+    
+  (define (get-predefined-fretboard predefined-fret-table tuning pitches)
+;   (_i "Search through @var{predefined-fret-table} looking for a predefined
+;fretboard with a key of @var{(tuning . pitches)}.  The search will check
+;both up and down an octave in order to accomodate transposition of the
+;chords.")
+   (define (get-fretboard key)
+    (let ((hash-handle
+           (hash-get-handle predefined-fret-table key)))
+     (if hash-handle
+         (cdr hash-handle)  ; return table entry
+         '())))
+
+   (let ((test-fretboard (get-fretboard (cons tuning pitches))))
+    (if (not (null? test-fretboard))
+        test-fretboard
+        (let ((test-fretboard 
+               (get-fretboard
+                (cons tuning (map (lambda (x) (shift-octave x 1)) pitches)))))
+         (if (not (null? test-fretboard))
+             test-fretboard
+             (get-fretboard 
+              (cons tuning (map (lambda (x) (shift-octave x -1)) pitches))))))))
 
 ;; body.
   (let*
               (acons 'string-count (length tunings) details)))
     (set! (ly:grob-property grob 'dot-placement-list)
         (if predefined-frets
-            (let ((hash-handle 
-                    (hash-get-handle
+            (let ((predefined-fretboard 
+                    (get-predefined-fretboard
                       predefined-frets
-                      (cons tunings pitches))))
-              (if hash-handle 
-                  (cdr hash-handle)  ;found default diagram
+                      tunings
+                      pitches)))
+              (if (null? predefined-fretboard)
                   (string-frets->dot-placement 
-                        string-frets my-string-count)))
+                        string-frets my-string-count)  ;no predefined diagram
+                  predefined-fretboard)) ;found default diagram
             (string-frets->dot-placement string-frets my-string-count)))))
 
 (define-public (determine-frets-mf notes string-numbers