X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Ffret-diagrams.scm;h=7a6e6febd91b61a85bec1e921cfb1fb311f01071;hb=52b2991eb4ecb24cbdc5fbdde59e04f1bd80f4b3;hp=558c11ebf679a8067617fcd90c93a0546ed2a7df;hpb=1528c75809ebc59d93018dbf59559436f75f082b;p=lilypond.git diff --git a/scm/fret-diagrams.scm b/scm/fret-diagrams.scm index 558c11ebf6..7a6e6febd9 100644 --- a/scm/fret-diagrams.scm +++ b/scm/fret-diagrams.scm @@ -1,6 +1,6 @@ ;;;; This file is part of LilyPond, the GNU music typesetter. ;;;; -;;;; Copyright (C) 2004--2011 Carl D. Sorensen +;;;; Copyright (C) 2004--2012 Carl D. Sorensen ;;;; ;;;; LilyPond is free software: you can redistribute it and/or modify ;;;; it under the terms of the GNU General Public License as published by @@ -15,10 +15,7 @@ ;;;; You should have received a copy of the GNU General Public License ;;;; along with LilyPond. If not, see . -; -; Utility functions -; -; +;; Utility functions (define (string-x-extent start-point end-point) "Return the x-extent of a string that goes from start-point @@ -72,10 +69,20 @@ to end-point." (if (null? dot-list) '() (let ((this-list (car dot-list))) - (cons* (list (car this-list) (- (second this-list) base-fret) - (if (null? (cddr this-list)) - '() - (third this-list))) + (cons* (list + ;; string + (car this-list) + ;; fret + (- (second this-list) base-fret) + ;; finger + (if (null? (cddr this-list)) + '() + (third this-list)) + ;; color modifier + (if (or (null? (cddr this-list)) + (null? (cdddr this-list))) + '() + (fourth this-list))) (subtract-base-fret base-fret (cdr dot-list)))))) (define (drop-paren item-list) @@ -120,20 +127,18 @@ found." (helper key alist-list (if (pair? default) (car default) #f))) -; -; Conversions between fret/string coordinate system and x-y coordinate -; system. -; -; Fret coordinates are measured down the fretboard from the nut, -; starting at 0. -; -; String coordinates are measured from the lowest string, starting at 0. -; -; The x-y origin is at the intersection of the nut and the lowest string. -; -; X coordinates are positive to the right. -; Y coordinates are positive up. -; +;; Conversions between fret/string coordinate system and x-y coordinate +;; system. +;; +;; Fret coordinates are measured down the fretboard from the nut, +;; starting at 0. +;; +;; String coordinates are measured from the lowest string, starting at 0. +;; +;; The x-y origin is at the intersection of the nut and the lowest string. +;; +;; X coordinates are positive to the right. +;; Y coordinates are positive up. (define (negate-extent extent) "Return the extent in an axis opposite to the axis of @code{extent}." @@ -149,7 +154,7 @@ direction." (negate-extent (ly:stencil-extent stencil X))) (else (negate-extent (ly:stencil-extent stencil Y)))) - ; else -- eq? fretboard-axis 'string + ;; else -- eq? fretboard-axis 'string (cond ((eq? orientation 'landscape) (ly:stencil-extent stencil Y)) ((eq? orientation 'opposing-landscape) @@ -168,9 +173,7 @@ in the @code{fretboard-axis} direction." (define (string-thickness string thickness-factor) (expt (1+ thickness-factor) (1- string))) -; -; Functions that create stencils used in the fret diagram -; +;; Functions that create stencils used in the fret diagram (define (sans-serif-stencil layout props mag text) "Create a stencil in sans-serif font based on @var{layout} and @var{props} @@ -181,12 +184,7 @@ with magnification @var{mag} of the string @var{text}." (prepend-alist-chain 'font-family 'sans props)))) (interpret-markup layout my-props text))) -;; -;; ;; markup commands and associated functions -;; -;; -;; (define (fret-parse-marking-list marking-list my-fret-count) "Parse a fret-diagram-verbose marking list into component sublists" @@ -219,13 +217,13 @@ with magnification @var{mag} of the string @var{text}." (if (> fretval maxfret) (set! maxfret fretval)) (if (< fretval minfret) (set! minfret fretval)) (updatemax (cdr fret-list))))) - (if (> maxfret my-fret-count) + (if (or (> maxfret my-fret-count) (> capo-fret 1)) (set! fret-range (cons minfret (let ((upfret (- (+ minfret my-fret-count) 1))) (if (> maxfret upfret) maxfret upfret))))) (set! capo-fret (1+ (- capo-fret minfret))) - ; subtract fret from dots + ;; subtract fret from dots (set! dot-list (subtract-base-fret (- (car fret-range) 1) dot-list))) (acons 'fret-range fret-range (acons 'barre-list barre-list @@ -236,47 +234,46 @@ with magnification @var{mag} of the string @var{text}." (define (make-fret-diagram layout props marking-list) "Make a fret diagram markup" (let* ( - ; note: here we get items from props that are needed in this routine, - ; or that are needed in more than one of the procedures - ; called from this routine. If they're only used in one of the - ; sub-procedure, they're obtained in that procedure + ;; note: here we get items from props that are needed in this routine, + ;; or that are needed in more than one of the procedures + ;; called from this routine. If they're only used in one of the + ;; sub-procedure, they're obtained in that procedure (size (chain-assoc-get 'size props 1.0)) ; needed for everything - ;TODO -- get string-count directly from length of stringTunings; - ; from FretBoard engraver, but not from markup call + ;;TODO -- get string-count directly from length of stringTunings; + ;; from FretBoard engraver, but not from markup call (details (merge-details 'fret-diagram-details props '())) (string-count - (assoc-get 'string-count details 6)) ; needed for everything + (assoc-get 'string-count details 6)) ;; needed for everything (my-fret-count - (assoc-get 'fret-count details 4)) ; needed for everything + (assoc-get 'fret-count details 4)) ;; needed for everything (orientation - (assoc-get 'orientation details 'normal)) ; needed for everything + (assoc-get 'orientation details 'normal)) ;; needed for everything (finger-code (assoc-get - 'finger-code details 'none)) ; needed for draw-dots and draw-barre + 'finger-code details 'none)) ;; needed for draw-dots and draw-barre (default-dot-radius - (if (eq? finger-code 'in-dot) 0.425 0.25)) ; bigger dots if labeled + (if (eq? finger-code 'in-dot) 0.425 0.25)) ;; bigger dots if labeled (default-dot-position (if (eq? finger-code 'in-dot) (- 0.95 default-dot-radius) 0.6)) ; move up to make room for bigger dot if labeled (dot-radius (assoc-get - 'dot-radius details default-dot-radius)) ; needed for draw-dots - ; and draw-barre + 'dot-radius details default-dot-radius)) + ;; needed for draw-dots and draw-barre (dot-position (assoc-get - 'dot-position details default-dot-position)) ; needed for - ; draw-dots and draw-barre + 'dot-position details default-dot-position)) + ;; needed for draw-dots and draw-barre (th (* (ly:output-def-lookup layout 'line-thickness) - (chain-assoc-get 'thickness props 0.5))) ; needed for draw-frets - ; and draw-strings + (chain-assoc-get 'thickness props 0.5))) + ;; needed for draw-frets and draw-strings (sth (* size th)) (thickness-factor (assoc-get 'string-thickness-factor details 0)) (alignment - (chain-assoc-get 'align-dir props -0.4)) ; needed only here - (xo-padding - (* size (assoc-get 'xo-padding details 0.2))) ; needed only here + (chain-assoc-get 'align-dir props -0.4)) ;; needed only here + (xo-padding (assoc-get 'xo-padding details 0.2)) ;; needed only here (parameters (fret-parse-marking-list marking-list my-fret-count)) (capo-fret (assoc-get 'capo-fret parameters 0)) (dot-list (assoc-get 'dot-list parameters)) @@ -287,7 +284,7 @@ with magnification @var{mag} of the string @var{text}." (barre-type (assoc-get 'barre-type details 'curved)) (fret-diagram-stencil '())) - ; + ;; Here are the fret diagram helper functions that depend on the ;; fret diagram parameters. The functions are here because the ;; diagram parameters are part of the lexical scope here. @@ -346,10 +343,11 @@ baseline at fret coordinate @var{base}, a height of (right-lower-control-point (stencil-coordinates bottom-control-point-height cp-right-width))) - ; order of bezier control points is: - ; left cp low, right cp low, right end low, left end low - ; right cp high, left cp high, left end high, right end high. - ; + + ;; order of bezier control points is: + ;; left cp low, right cp low, right end low, left end low + ;; right cp high, left cp high, left end high, right end high. + (list left-lower-control-point right-lower-control-point right-end-point @@ -519,10 +517,9 @@ fret-diagram overall parameters." (+ (* size end-string-coordinate) half-thickness))) (x-extent (cons (car box-lower-left) (car box-upper-right))) (y-extent (cons (cdr box-lower-left) (cdr box-upper-right)))) - (ly:make-stencil - (list 'bezier-sandwich - `(quote ,bezier-list) - (* size bezier-thick)) + (make-bezier-sandwich-stencil + bezier-list + (* size bezier-thick) x-extent y-extent))) @@ -531,7 +528,7 @@ fret-diagram overall parameters." (let* ( (scale-dot-radius (* size dot-radius)) (scale-dot-thick (* size th)) - (dot-color (assoc-get 'dot-color details 'black)) + (default-dot-color (assoc-get 'dot-color details 'black)) (finger-label-padding 0.3) (dot-label-font-mag (* scale-dot-radius @@ -555,6 +552,11 @@ fret-diagram overall parameters." (extent (cons (- scale-dot-radius) scale-dot-radius)) (finger (caddr mypair)) (finger (if (number? finger) (number->string finger) finger)) + (inverted-color (eq? 'inverted (cadddr mypair))) + (dot-color (if (or (and (eq? default-dot-color 'black) inverted-color) + (and (eq? default-dot-color 'white) (not inverted-color))) + 'white + 'black)) (dot-stencil (if (eq? dot-color 'white) (ly:stencil-add (make-circle-stencil @@ -633,20 +635,20 @@ fret-diagram overall parameters." (stencil-coordinates end-fret-coordinate end-string-coordinate))) (ly:round-filled-box - (cons (car lower-left) (car upper-right)) - (cons (cdr lower-left) (cdr upper-right)) + ;; Put limits in order, or else the intervals are considered empty + (ordered-cons (car lower-left) (car upper-right)) + (ordered-cons (cdr lower-left) (cdr upper-right)) sth))) (define (draw-xo xo-list) "Put open and mute string indications on diagram, as contained in @var{xo-list}." (let* ((xo-font-mag - (* size (assoc-get - 'xo-font-magnification details + (assoc-get 'xo-font-magnification details (cond ((or (eq? orientation 'landscape) (eq? orientation 'opposing-landscape)) 0.4) - (else 0.4))))) + (else 0.4)))) (mypair (car xo-list)) (restlist (cdr xo-list)) (glyph-string (if (eq? (car mypair) 'mute) @@ -709,6 +711,11 @@ at @var{fret}." (fancy-format #f "~@r" base-fret)) ((equal? 'arabic number-type) (fancy-format #f "~d" base-fret)) + ((equal? 'custom number-type) + (fancy-format #f + (assoc-get 'fret-label-custom-format + details "~a") + base-fret)) (else (fancy-format #f "~(~@r~)" base-fret)))) (label-stencil (centered-stencil @@ -723,14 +730,12 @@ at @var{fret}." (ly:stencil-translate label-stencil (stencil-coordinates - (1+ (* size label-vertical-offset)) + (* size (+ 1.0 label-vertical-offset)) (if (eq? label-dir LEFT) (- label-outside-diagram) (+ (* size (1- string-count)) label-outside-diagram)))))) - - ; Here is the body of make-fret-diagram - ; + ;; Here is the body of make-fret-diagram (set! fret-diagram-stencil (ly:stencil-add (draw-strings) (draw-frets))) @@ -804,6 +809,8 @@ a fret-indication list with the appropriate values" (case (car (string->list (substring test-string 0 1))) ((#\s) (let ((size (get-numeric-from-key test-string))) (set! props (prepend-alist-chain 'size size props)))) + ((#\t) (let ((th (get-numeric-from-key test-string))) + (set! props (prepend-alist-chain 'thickness th props)))) ((#\f) (let* ((finger-code (get-numeric-from-key test-string)) (finger-id (case finger-code ((0) 'none) @@ -847,7 +854,7 @@ a fret-indication list with the appropriate values" (list 'open (string->number (car this-list))) output-list))))))) (parse-item (cdr myitems))))) - ; add the modified details + ;; add the modified details (set! props (prepend-alist-chain 'fret-diagram-details details props)) `(,props . ,output-list))) ;ugh -- hard-coded spell -- procedure better @@ -859,7 +866,7 @@ return a pair containing: @var{props}, modified to include the string-count determined by the definition-string, and a fret-indication list with the appropriate values" -;TODO -- change syntax to fret\string-finger +;; TODO -- change syntax to fret\string-finger (let* ((details (merge-details 'fret-diagram-details props '())) (barre-start-list '()) @@ -966,12 +973,15 @@ Place a capo indicator (a large solid bar) across the entire fretboard at fret location @var{fret-number}. Also, set fret @var{fret-number} to be the lowest fret on the fret diagram. -@item (place-fret @var{string-number} @var{fret-number} @var{finger-value}) +@item (place-fret @var{string-number} @var{fret-number} [@var{finger-value} [@var{color-modifier}]]) Place a fret playing indication on string @var{string-number} at fret -@var{fret-number} with an optional fingering label @var{finger-value}. +@var{fret-number} with an optional fingering label @var{finger-value}, +and an optional color modifier @var{color-modifier}. By default, the fret playing indicator is a solid dot. This can be -changed by setting the value of the variable @var{dot-color}. If the -@var{finger} part of the @code{place-fret} element is present, +globally changed by setting the value of the variable @var{dot-color}. +Setting @var{color-modifier} to @code{inverted} inverts the dot color +for a specific fingering. +If the @var{finger} part of the @code{place-fret} element is present, @var{finger-value} will be displayed according to the setting of the variable @var{finger-code}. There is no limit to the number of fret indications per string. @@ -1009,8 +1019,9 @@ spaces). Default:@tie{}1. @item -@code{t:}@var{number} -- Set the line thickness (in staff spaces). -Default:@tie{}0.05. +@code{t:}@var{number} -- Set the line thickness (relative to normal +line thickness). +Default:@tie{}0.5. @item @code{h:}@var{number} -- Set the height of the diagram in frets. @@ -1095,13 +1106,13 @@ If there are multiple fret indicators desired on a string, they should be separated by spaces. @item -Fingerings are given by following the fret number with a @code{-}, +Fingerings are given by following the fret number with a @w{@code{-},} followed by the finger indicator, e.g. @samp{3-2} for playing the third fret with the second finger. @item Where a barre indicator is desired, follow the fret (or fingering) symbol -with @code{-(} to start a barre and @code{-)} to end the barre. +with @w{@code{-(}} to start a barre and @w{@code{-)}} to end the barre. @end itemize" ;; TODO -- change syntax to fret\string-finger