From 8ab4967c376fc54b96601b7533d1e3e9af92bbfa Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sat, 15 Oct 2011 10:50:18 +0200 Subject: [PATCH] Issue 1976: Handle full rational pitch differences in fingering calculations. Defines and uses ly:pitch-tones for rational pitch extraction. --- lily/pitch-scheme.cc | 12 +++++++++++- scm/tablature.scm | 2 +- scm/translation-functions.scm | 10 +++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lily/pitch-scheme.cc b/lily/pitch-scheme.cc index ad1753251f..a188469fbd 100644 --- a/lily/pitch-scheme.cc +++ b/lily/pitch-scheme.cc @@ -92,7 +92,7 @@ LY_DEFINE (ly_pitch_alteration, "ly:pitch-alteration", return ly_rational2scm (q); } -LY_DEFINE (pitch_notename, "ly:pitch-notename", +LY_DEFINE (ly_pitch_notename, "ly:pitch-notename", 1, 0, 0, (SCM pp), "Extract the note name from pitch @var{pp}.") { @@ -102,6 +102,16 @@ LY_DEFINE (pitch_notename, "ly:pitch-notename", return scm_from_int (q); } +LY_DEFINE (ly_pitch_tones, "ly:pitch-tones", + 1, 0, 0, (SCM pp), + "Calculate the number of tones of@tie{}@var{pp} from" + " middle@tie{}C as a rational number.") +{ + LY_ASSERT_SMOB (Pitch, pp, 1); + return ly_rational2scm (unsmob_pitch (pp)->tone_pitch ()); +} + + LY_DEFINE (ly_pitch_quartertones, "ly:pitch-quartertones", 1, 0, 0, (SCM pp), "Calculate the number of quarter tones of@tie{}@var{pp} from" diff --git a/scm/tablature.scm b/scm/tablature.scm index 2adaaa6ed6..3304e24af7 100644 --- a/scm/tablature.scm +++ b/scm/tablature.scm @@ -107,7 +107,7 @@ (left-pitch (ly:event-property (event-cause left-bound) 'pitch)) (right-pitch (ly:event-property (event-cause right-bound) 'pitch))) - (if (< (ly:pitch-semitones right-pitch) (ly:pitch-semitones left-pitch)) + (if (< (ly:pitch-tones right-pitch) (ly:pitch-tones left-pitch)) -0.75 0.75))) diff --git a/scm/translation-functions.scm b/scm/translation-functions.scm index 2dd8d2d92c..33acfbc7b4 100644 --- a/scm/translation-functions.scm +++ b/scm/translation-functions.scm @@ -286,7 +286,7 @@ along with @var{minimum-fret}, @var{maximum-stretch}, and (define (calc-fret pitch string tuning) "Calculate the fret to play @var{pitch} on @var{string} with @var{tuning}." - (- (ly:pitch-semitones pitch) (ly:pitch-semitones (list-ref tuning (1- string))))) + (* 2 (- (ly:pitch-tones pitch) (ly:pitch-tones (list-ref tuning (1- string)))))) (define (note-pitch note) "Get the pitch (in semitones) from @var{note}." @@ -342,6 +342,7 @@ notes?" (and (or (and (not restrain-open-strings) (eq? fret 0)) (>= fret minimum-fret)) + (integer? fret) (close-enough fret)))) (define (open-string string pitch) @@ -356,7 +357,10 @@ the current tuning?" tuning))) (if (< this-fret 0) (ly:warning (_ "Negative fret for pitch ~a on string ~a") - (car pitch-entry) string)) + (car pitch-entry) string) + (if (not (integer? this-fret)) + (ly:warning (_ "Missing fret for pitch ~a on string ~a") + (car pitch-entry) string))) (delete-free-string string) (set! specified-frets (cons this-fret specified-frets)) (list-set! string-fret-fingers @@ -415,7 +419,7 @@ the current tuning?" (ly:context-property context 'handleNegativeFrets 'recalculate))) - (cond ((or (>= this-fret 0) + (cond ((or (and (>= this-fret 0) (integer? this-fret)) (eq? handle-negative 'include)) (set-fret! pitch-entry string finger)) ((eq? handle-negative 'recalculate) -- 2.39.5