[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Chord Diagram markup
From: |
Jan Nieuwenhuizen |
Subject: |
Re: Chord Diagram markup |
Date: |
Mon, 19 Apr 2004 20:48:25 +0200 |
User-agent: |
Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux) |
Carl D. Sorensen writes:
> 1. (*) text/plain ( ) text/html
[please omit html stuff next time]
> I have developed a very rudimentary chord diagram markup, thanks to the
> def-markup-command created by Nicolas Sceaux.
Great!
> ("scripts-open"). But when I tried it, I got nothing -- no output and
> no errors. Any suggestions?
>My code is still in the file, but
> commented out.
Try this:
#(define (draw-strings stringcount fretcount th size)
(let ((sl (* (+ fretcount 1) size))
(halfthick (* th 0.5)))
(if (= stringcount 1)
(ly:make-stencil (list 'draw-line th 0 0 0 sl)
(cons (- halfthick) halfthick)
(cons (- halfthick) (+ sl halfthick)))
(ly:stencil-combine-at-edge
(draw-strings (- stringcount 1) fretcount th size) 0 1
(ly:make-stencil
(list 'draw-line th 0 0 0 sl)
(cons (- halfthick) halfthick)
(cons (- halfthick) (+ sl halfthick)))
(- size th) 0))))
#(define (draw-frets fretcount stringcount th size)
(let ((fretlength (* (- stringcount 1) size))
(halfthick (* th 0.5)))
(if (= fretcount 0)
(ly:make-stencil (list 'draw-line th 0 size fretlength size)
(cons 0 fretlength)
(cons (- size halfthick) (+ size halfthick)))
(ly:stencil-combine-at-edge
(draw-frets (- fretcount 1) stringcount th size) 1 1
(ly:make-stencil (list 'draw-line th 0 0 fretlength 0)
(cons 0 fretlength)
(cons (- halfthick) (+ halfthick)))
(- size th) 0))))
#(define (draw-dots stringcount fretcount size dotlist)
"Make dots for fret diagram."
(let ((dotrad (* size 0.25))
(xpos (* (- stringcount (caar dotlist)) size))
(ypos (* (+ 1.5 (- fretcount (cdar dotlist))) size))
(extent (cons (- (* size 0.25)) (* size 0.25))))
(if (null? (cdr dotlist))
(ly:make-stencil (list 'dot xpos ypos dotrad ) extent extent)
(ly:stencil-add
(draw-dots stringcount fretcount size (cdr dotlist))
(ly:make-stencil (list 'dot xpos ypos dotrad) extent
extent)))))
#(define (draw-xo stringcount fretcount size font xolist)
"Put x and o on chord diagram."
(let ((dotrad (* size 0.25))
(mypair (car xolist))
(restlist (cdr xolist))
(glyphname (if (char=? (cdar xolist) #\x) "accidentals-4"
"scripts-open"))
(tmpdot (if (char=? (cdar xolist) #\x) 0 (* size 0.25)))
(xpos (* (- stringcount (caar xolist)) size))
(ypos (* (+ 1.5 fretcount) size))
(extent (cons (- (* size 0.25)) (* size 0.25))))
;; FIXME, what exacly do you want here?
(if (null? restlist)
(ly:find-glyph-by-name font glyphname)
(ly:stencil-add
(ly:find-glyph-by-name font glyphname)
;;(ly:make-stencil (list 'dot xpos ypos tmpdot) extent extent)
(ly:stencil-add
(draw-xo stringcount fretcount size font (cdr xolist))
(ly:make-stencil (list 'dot xpos ypos tmpdot) extent extent))))))
#(define (char->num char)
(- (char->integer char) (char->integer #\0)))
#(define (string-xo string chord-list)
"convert ordered list of frets and xo's into list of (string (x
or o)) pairs"
(if (null? chord-list)
(list)
(let ((fret (car chord-list)) (rest (cdr chord-list)))
(if (char-numeric? fret)
(string-xo (- string 1) rest)
(list* (cons string fret)
(string-xo (- string 1) rest))))))
#(define (string-dot string chord-list)
"convert ordered list of frets into list of (string fret) pairs"
(if (null? chord-list)
(list )
(let ((fret (car chord-list)) (rest (cdr chord-list)))
(if (or (char=? fret #\x) (char=? fret #\o))
(string-dot (- string 1) rest)
(list* (cons string (char->num fret))
(string-dot (- string 1) rest))))))
#(define (xo-list chord-string stringcount)
"Convert a chord string into an xo-list"
(string-xo stringcount (string->list chord-string)))
#(define (dot-list chord-string stringcount)
"Convert a chord string into a dot-list"
(string-dot stringcount (string->list chord-string)))
#(define (make-chord-diagram chord-string stringcount fretcount
th size font)
"Make a chord diagram"
(ly:stencil-add
(draw-strings stringcount fretcount th size)
(draw-frets fretcount stringcount th size)
(draw-dots stringcount fretcount size
(dot-list chord-string stringcount))
(draw-xo stringcount fretcount size font
(xo-list chord-string stringcount))))
#(def-markup-command (chord-diagram paper props size defstring)
(number? string?)
"Syntax: \\chord-diagram size defstring
eg: \\markup-fret-diagram #0.75 #\\"xxo232\\"
for fret spacing 3/4 of staff space, D chord diagram"
(let ((font (ly:paper-get-font paper '(((font-family . music))))))
(format (current-error-port) "FONT: ~S\n" font)
(make-chord-diagram defstring 6 4 .05 size font)))
\score {
\notes {
a'2.^\markup \chord-diagram #1 #"x33211"
c'' ^\markup \chord-diagram #0.5 #"o221oo"
c' ^\markup \chord-diagram #0.75 #"xxo232"
}
\paper{ raggedright = ##t }
}
--
Jan Nieuwenhuizen <address@hidden> | GNU LilyPond - The music typesetter
http://www.xs4all.nl/~jantien | http://www.lilypond.org