----- Original Message -----
From: "Jim Tisdall" <supp...@jimtisdall.com>
To: <lilypond-user@gnu.org>
Sent: Wednesday, June 01, 2016 3:14 PM
Subject: keyboard graphic
I need to display small graphics of a piano keyboard with selected
notes indicated by color.
It will be used similarly as the guitar fret diagrams and actually
in conjunction with them (and with standard and tablature notation,
and explanatory comments) as guitarists examine chord voicings.
I've found a few things but thought I'd ask here if some lilypond user
has developed such a graphic in the system. Or, an expert advice on
where to begin to develop one myself within lilypond, would be most
appreciated.
My wish list is parameters for range, width/height, and pressed keys;
labels under the pressed keys would be a nice plus.
Thanks,
Jim
Attached is a piano-key version, which is nowhere near as cleverly automatic
as I remember David's version being, but may give you some further pointers
about how this can be done.
(I used this at college when I had to play the marimba, xylophone or
glockenspiel.)
--
Phil Holmes
\version "2.17.28"
\pointAndClickOff
#(define KEY-POS-LIST '(
(c . 1) (cis . 1.5) (des . 1.5) (d . 2) (dis . 2.5) (ees . 2.5) (e . 3)
(f . 4) (fis . 4.5) (ges . 4.5) (g . 5) (gis . 5.5) (aes . 5.5) (a . 6)
(ais . 6.5) (bes . 6.5) (b . 7)))
#(define (black-key? num )
(member num '(cis des dis ees fis ges gis aes ais bes)) )
#(define (key-to-pos key ypos scale)
(let ((keypos (assq key KEY-POS-LIST)))
(if (not keypos)
(ly:error (_ "keyboard diagram error - unknown note '~a'") key)
(cons (* (- (cdr (assq key KEY-POS-LIST)) 0.5) scale) (+ (* (- scale 1) 0.32) ypos)))))
#(define (make-keys l1 width off height scale)
(if (null? l1)
empty-stencil
(ly:stencil-add
(ly:stencil-translate
(make-line-stencil 0.1 0 0 0 height)
(cons (* (- (car l1) 1) scale) off ))
(make-keys (cdr l1) width off height scale))))
#(define (make-keys-black l1 width off height scale)
(if (null? l1)
empty-stencil
(ly:stencil-add
(ly:stencil-translate
(ly:round-filled-box `(0 . ,(* width scale)) `(0 . ,height) 0)
(cons (* (- (car l1) (/ width 2)) scale ) off))
(make-keys-black (cdr l1) width off height scale))))
#(define (make-dot key scale)
(if (black-key? key)
(ly:stencil-in-color
(ly:stencil-translate (make-circle-stencil (* 0.27 scale) 0 #t) (key-to-pos key 2.5 scale)) 1 1 1)
(ly:stencil-translate (make-circle-stencil (* 0.32 scale) 0 #t) (key-to-pos key 0.5 scale)) ))
#(define (make-dot-list l1 scale)
(if (null? l1)
empty-stencil
(ly:stencil-add
(make-dot (car l1) scale)
(make-dot-list (cdr l1) scale ))))
#(define-markup-command (keys layout props arg1 arg2) (list? number?)
(ly:stencil-add
(make-line-stencil 0.1 0 0 (* 7 arg2) 0)
(make-line-stencil 0.1 0 6 (* 7 arg2) 6)
(make-keys '(1 2 3 4 5 6 7 8) 1 0 6 arg2)
(make-keys-black '(1 2 4 5 6 ) 0.65 2 4 arg2)
(make-dot-list arg1 arg2)))
key_scale=1.9
\relative c' {
\textLengthOn
c4 ^\markup \keys #'(c) #key_scale
cis ^\markup \keys #'(cis) #key_scale
d ^\markup \keys #'(d) #key_scale
ees ^\markup \keys #'(ees) #key_scale
e ^\markup \keys #'(e) #key_scale
f ^\markup \keys #'(f) #key_scale
fis ^\markup \keys #'(fis) #key_scale
g ^\markup \keys #'(g) #key_scale
gis ^\markup \keys #'(gis) #key_scale
a ^\markup \keys #'(a) #key_scale
bes ^\markup \keys #'(bes) #key_scale
b ^\markup \keys #'(b) #key_scale
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user