X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Fchord-entry.scm;h=45c395ba4e6081d929580f0450a1825bcf98102d;hb=9e6f16dddf9e21b29eed1717efe4bac6c20774ba;hp=068078db968f5ce36c941b5752b5d19ca0bedf86;hpb=342fabd2d06666257dd41c8d38e8682949a04f36;p=lilypond.git diff --git a/scm/chord-entry.scm b/scm/chord-entry.scm index 068078db96..45c395ba4e 100644 --- a/scm/chord-entry.scm +++ b/scm/chord-entry.scm @@ -1,16 +1,16 @@ -;;; -;;; Generate chord names for the parser. -;;; -;;; +;;;; chord-entry.scm -- Generate chord names for the parser. +;;;; +;;;; source file of the GNU LilyPond music typesetter +;;;; +;;;; (c) 2004--2009 Han-Wen Nienhuys -(define-public (construct-chord root duration modifications) - " Build a chord on root using modifiers in MODIFICATIONS. NoteEvent -have duration DURATION.. +(define-public (construct-chord-elements root duration modifications) + " Build a chord on root using modifiers in MODIFICATIONS. NoteEvents +have duration DURATION. Notes: natural 11 is left from chord if not explicitly specified. -Entry point for the parser. - +Entry point for the parser. " (let* ((flat-mods (flatten-list modifications)) (base-chord (stack-thirds (ly:make-pitch 0 4 0) the-canonical-chord)) @@ -22,23 +22,23 @@ Entry point for the parser. (start-additions #t)) (define (interpret-inversion chord mods) - "Read /FOO part. Side effect: INVERSION is set." - (if (and (> (length mods) 1) (eq? (car mods) 'chord-slash)) + "Read /FOO part. Side effect: INVERSION is set." + (if (and (> (length mods) 1) (eq? (car mods) 'chord-slash)) (begin (set! inversion (cadr mods)) (set! mods (cddr mods)))) (interpret-bass chord mods)) - + (define (interpret-bass chord mods) - "Read /+FOO part. Side effect: BASS is set." - (if (and (> (length mods) 1) (eq? (car mods) 'chord-bass)) + "Read /+FOO part. Side effect: BASS is set." + (if (and (> (length mods) 1) (eq? (car mods) 'chord-bass)) (begin (set! bass (cadr mods)) (set! mods (cddr mods)))) (if (pair? mods) - (scm-error 'chord-format "construct-chord" "Spurious garbage following chord: ~A" mods #f)) + (scm-error 'chord-format "construct-chord" "Spurious garbage following chord: ~A" mods #f)) chord) - + (define (interpret-removals chord mods) (define (inner-interpret chord mods) (if (and (pair? mods) (ly:pitch? (car mods))) @@ -48,8 +48,8 @@ Entry point for the parser. (if (and (pair? mods) (eq? (car mods) 'chord-caret)) (inner-interpret chord (cdr mods)) (interpret-inversion chord mods))) - - (define (interpret-additions chord mods) + + (define (interpret-additions chord mods) "Interpret additions. TODO: should restrict modifier use?" (cond ((null? mods) chord) ((ly:pitch? (car mods)) @@ -70,14 +70,14 @@ Entry point for the parser. 0 -1)) (ly:pitch-notename p) (ly:pitch-alteration p))) - + (define (process-inversion complete-chord) "Take out inversion from COMPLETE-CHORD, and put it at the bottom. Return (INVERSION . REST-OF-CHORD). Side effect: put original pitch in INVERSION. If INVERSION is not in COMPLETE-CHORD, it will be set as a BASS, overriding -the bass specified. +the bass specified. " (let* ((root (car complete-chord)) @@ -99,11 +99,11 @@ the bass specified. rest-of-chord))) ;; root is always one octave too low. ;; something weird happens when this is removed, - ;; every other chord is octavated. --hwn... hmmm. + ;; every other chord is octavated. --hwn... hmmm. (set! root (ly:pitch-transpose root (ly:make-pitch 1 0 0))) ;; skip the leading : , we need some of the stuff following it. (if (pair? flat-mods) - (if (eq? (car flat-mods) 'chord-colon) + (if (eq? (car flat-mods) 'chord-colon) (set! flat-mods (cdr flat-mods)) (set! start-additions #f))) ;; remember modifier @@ -111,12 +111,12 @@ the bass specified. (begin (set! lead-mod (car flat-mods)) (set! flat-mods (cdr flat-mods)))) - ;; extract first number if present, and build pitch list. + ;; extract first number if present, and build pitch list. (if (and (pair? flat-mods) (ly:pitch? (car flat-mods)) (not (eq? lead-mod sus-modifier))) (begin - (if (= (pitch-step (car flat-mods)) 11) + (if (= (pitch-step (car flat-mods)) 11) (set! explicit-11 #t)) (set! base-chord (stack-thirds (car flat-mods) the-canonical-chord)) @@ -136,9 +136,9 @@ the bass specified. (get-step 3 complete-chord) (= 0 (ly:pitch-alteration (get-step 11 complete-chord))) (= 0 (ly:pitch-alteration (get-step 3 complete-chord)))) - (set! complete-chord (remove-step 11 complete-chord))) + (set! complete-chord (remove-step 11 complete-chord))) ;; must do before processing inversion/bass, since they are - ;; not relative to the root. + ;; not relative to the root. (set! complete-chord (map (lambda (x) (ly:pitch-transpose x root)) complete-chord)) (if inversion @@ -150,23 +150,22 @@ the bass specified. (write-me "\n*******\n" flat-mods) (write-me "root: " root) (write-me "base chord: " base-chord) - (write-me "complete chord: " complete-chord) + (write-me "complete chord: " complete-chord) (write-me "inversion: " inversion) (write-me "bass: " bass))) (if inversion - (make-chord (cdr complete-chord) bass duration (car complete-chord) + (make-chord-elements (cdr complete-chord) bass duration (car complete-chord) inversion) - (make-chord complete-chord bass duration #f #f)))) + (make-chord-elements complete-chord bass duration #f #f)))) -(define (make-chord pitches bass duration inversion original-inv-pitch) +(define (make-chord-elements pitches bass duration inversion original-inv-pitch) "Make EventChord with notes corresponding to PITCHES, BASS and DURATION, and INVERSION." (define (make-note-ev pitch) - (let ((ev (make-music-by-name 'NoteEvent))) - (set! (ly:music-property ev 'duration) duration) - (set! (ly:music-property ev 'pitch) pitch) - ev)) + (make-music 'NoteEvent + 'duration duration + 'pitch pitch)) (let ((nots (map make-note-ev pitches)) (bass-note (if bass (make-note-ev bass) #f)) (inv-note (if inversion (make-note-ev inversion) #f))) @@ -181,32 +180,32 @@ DURATION, and INVERSION." (- (ly:pitch-octave inversion) (ly:pitch-octave original-inv-pitch))) (set! nots (cons inv-note nots)))) - (make-event-chord nots))) + nots)) ;;;;;;;;;;;;;;;; ; chord modifiers change the pitch list. -(define (aug-modifier pitches) - (set! pitches (replace-step (ly:make-pitch 0 4 SHARP) pitches)) +(define (aug-modifier pitches) + (set! pitches (replace-step (ly:make-pitch 0 4 SHARP) pitches)) (replace-step (ly:make-pitch 0 2 0) pitches)) -(define (minor-modifier pitches) +(define (minor-modifier pitches) (replace-step (ly:make-pitch 0 2 FLAT) pitches)) -(define (maj7-modifier pitches) +(define (maj7-modifier pitches) (set! pitches (remove-step 7 pitches)) (cons (ly:make-pitch 0 6 0) pitches)) -(define (dim-modifier pitches) +(define (dim-modifier pitches) (set! pitches (replace-step (ly:make-pitch 0 2 FLAT) pitches)) (set! pitches (replace-step (ly:make-pitch 0 4 FLAT) pitches)) (set! pitches (replace-step (ly:make-pitch 0 6 DOUBLE-FLAT) pitches)) pitches) -(define (sus-modifier pitches) +(define (sus-modifier pitches) (remove-step (pitch-step (ly:make-pitch 0 2 0)) pitches)) -(define-public default-chord-modifier-list +(define-safe-public default-chord-modifier-list `((m . ,minor-modifier) (min . ,minor-modifier) (aug . , aug-modifier) @@ -219,6 +218,7 @@ DURATION, and INVERSION." (map (lambda (n) (define (nca x) (if (= x 7) FLAT 0)) + (if (>= n 8) (ly:make-pitch 1 (- n 8) (nca n)) (ly:make-pitch 0 (- n 1) (nca n)))) @@ -229,7 +229,7 @@ DURATION, and INVERSION." UPPER-STEP separately." (cond ((null? base) '()) ((> (ly:pitch-steps upper-step) (ly:pitch-steps (car base))) - (cons (car base) (stack-thirds upper-step (cdr base)))) + (cons (car base) (stack-thirds upper-step (cdr base)))) ((<= (ly:pitch-steps upper-step) (ly:pitch-steps (car base))) (list upper-step)) (else '())))