Hello Paolo, hello Carl,

This is actually very easy to fix. By default the algorithm works like this: 
We try to put each note to the lowest possible fret. To do this we assume the 
strings are in falling pitch and then we just walk through all strings and 
stop once we get one that works.

To get this to work with non-monotonous strings, one has to simply change this 
to: Instead of always getting the next string, try to find the next highest 
string. And then you’re done.

I’ve included a quick and moderately unefficient (but then, how many strings 
might we get?) patch for scm/translation-functions.scm which solves this 
issue.

Cheers,
Valentin

Am Freitag, 13. August 2021, 00:03:47 CEST schrieb Carl Sorensen:
> Dear Paulo,
> 
> The automatic fret generation code only works for instruments with monotonic
> (steadily increasing or decreasing) string pitches.  Since the ukulele has
> non-monotonic string pitches, the algorithms do not work.  See Known issues
> and warnings under
> https://lilypond.org/doc/v2.22/Documentation/notation/common-notation-for-f
> retted-strings#automatic-fret-diagrams
 
> 
> You can work around this by using the predefined fret diagrams for ukulele.
> 
> \include "predefined-ukulele-fretboards.ly"
> 
> See
> https://lilypond.org/doc/v2.22/Documentation/notation/common-notation-for-f
> retted-strings#predefined-fret-diagrams
 
> Hope this helps,
> 
> Carl
> 
>     
> 
--- translation-functions.scm~	2021-08-13 01:01:57.847581707 +0200
+++ translation-functions.scm	2021-08-13 01:20:24.542215309 +0200
@@ -465,6 +465,17 @@
                  (list string #f finger)))
            defined-strings defined-fingers))
 
+    (define (find-next-open-string free-strings pitch)
+      (define (iter-strings strings best-string best-pitch)
+         (if (null? strings)
+             best-string
+             (if (and best-pitch (ly:pitch<? (list-ref tuning (- (car strings) 1)) best-pitch))
+                 (iter-strings (cdr strings) best-string best-pitch)
+                 (if (string-qualifies (car strings) pitch)
+                     (iter-strings (cdr strings) (car strings) (list-ref tuning (- (car strings) 1)))
+                     (iter-strings (cdr strings) best-string best-pitch)))))
+         (iter-strings free-strings #f #f))
+
     ;;; body of determine-frets-and-strings
     (let* ((pitches (map note-pitch notes))
            (pitch-alist (map cons pitches (iota (length pitches)))))
@@ -544,9 +555,7 @@
                             '()))
                 (pitch (car pitch-entry))
                 (fit-string
-                 (find (lambda (string)
-                         (string-qualifies string pitch))
-                       free-strings)))
+                 (find-next-open-string free-strings pitch)))
            (if (not (list-ref string-fret-finger 1))
                (if fit-string
                    (set-fret! pitch-entry fit-string finger)

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to