#(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=2.0 \relative c'' { \textLengthOn b4^\markup\keys #'(b) #1 r r2 r1 b4^\markup\keys #'(b) #1.5 r r2 r1 b4^\markup\keys #'(b) #key_scale r r2 r1 a4^\markup\keys #'(a) #2.5 r r2 r1 bes4^\markup\keys #'(bes) #3 r r2 }