From 5df4a8d103ef1105e479bc102b7305a7149834e9 Mon Sep 17 00:00:00 2001 From: Carl Sorensen Date: Sat, 14 Mar 2009 21:34:58 -0600 Subject: [PATCH] Fix 763 Fretboards don't transpose properly 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 | 14 ++++---- .../predefined-fretboards-transpose.ly | 27 ++++++++++++++ scm/music-functions.scm | 10 ++++++ scm/translation-functions.scm | 36 +++++++++++++++---- 4 files changed, 75 insertions(+), 12 deletions(-) create mode 100644 input/regression/predefined-fretboards-transpose.ly diff --git a/Documentation/user/fretted-strings.itely b/Documentation/user/fretted-strings.itely index 614c0c15de..1ba998a800 100644 --- a/Documentation/user/fretted-strings.itely +++ b/Documentation/user/fretted-strings.itely @@ -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 index 0000000000..091c492474 --- /dev/null +++ b/input/regression/predefined-fretboards-transpose.ly @@ -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} +>> + diff --git a/scm/music-functions.scm b/scm/music-functions.scm index de8b5973fb..0263d498e9 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -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 diff --git a/scm/translation-functions.scm b/scm/translation-functions.scm index 902da1287d..eefa9c0806 100644 --- a/scm/translation-functions.scm +++ b/scm/translation-functions.scm @@ -195,6 +195,29 @@ )) 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* @@ -219,14 +242,15 @@ (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 -- 2.39.2