lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Keyboard chord figure in scheme


From: Morten Jagd Christensen
Subject: Keyboard chord figure in scheme
Date: Tue, 17 Jan 2012 22:30:46 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0) Gecko/20111105 Thunderbird/8.0

Hello all

I'm trying to make a scheme function that generates a keyboard with
black and white dots for showing specific chord layouts

The code below compiles and produces the keyboard figure

I then call a function (make-dot key) which works fine. What I really want is (make-dot-list '(1 5 8)) which should produce a black dot on c, a white dot on ees and a
black dot on g (for a C major chord).

I suspect that somehow only the last empty-stencil is returned but have been unable
to solve my problem.

Does anyone have a suggestion how to solve this?

Best regards

Morten (newbie scheme programmer)

%----------SNIPPET BELOW--------

\version "2.14.2"

#(define KEY-POS-LIST '((1 . 1) (2 . 1.5) (3 . 2) (4 . 2.5) (5 . 3) (6 . 4) (7 . 4.5) (8 . 5) (9 . 5.5) (10 . 6) (11 . 6.5) (12 . 7) (13 . 8)))

#(define (black-key num )
   (if (member num '(2 4 7 9 11 14 16 19))  #f #t))

#(define (key-to-pos key ypos)
   (cons (- (cdr (assv key KEY-POS-LIST)) 0.5) ypos))

#(define (make-dot key)
  (if (black-key key)
(ly:stencil-translate (make-circle-stencil 0.0 0.5 #f) (key-to-pos key 1) ) (ly:stencil-in-color (ly:stencil-translate (make-circle-stencil 0.0 0.5 #f) (key-to-pos key 3)) 1 1 1 )))

#(define (make-dot-list l1)
    (make-dot (car l1))
    (if (null? (cdr l1)) empty-stencil (make-dot-list (cdr l1))))

#(define (make-white-keys lt width height)
 (begin
  (ly:stencil-add
   (make-line-stencil lt 0     0 width 0)
    (make-line-stencil lt width 0 width height)
    (make-line-stencil lt width height  0     height )
    (make-line-stencil lt 0     height  0     0  )
    (make-line-stencil lt  1 0  1 height )
    (make-line-stencil lt  2 0  2 height )
    (make-line-stencil lt  3 0  3 height )
    (make-line-stencil lt  4 0  4 height )
    (make-line-stencil lt  5 0  5 height )
    (make-line-stencil lt  6 0  6 height )
    (make-line-stencil lt  7 0  7 height )
    (make-line-stencil lt  8 0  8 height )
    (make-line-stencil lt  9 0  9 height )
    (make-line-stencil lt 10 0 10 height )
    (make-line-stencil lt 11 0 11 height ))))

#(define (make-black-keys lt width height)
 (begin
  (ly:stencil-add
    (make-line-stencil lt  1 height  1 (/ height 2.5 ))
    (make-line-stencil lt  2 height  2 (/ height 2.5 ))
    (make-line-stencil lt  4 height  4 (/ height 2.5 ))
    (make-line-stencil lt  5 height  5 (/ height 2.5 ))
    (make-line-stencil lt  6 height  6 (/ height 2.5 ))
    (make-line-stencil lt  8 height  8 (/ height 2.5 ))
    (make-line-stencil lt  9 height  9 (/ height 2.5 ))
    (make-line-stencil lt 11 height 11 (/ height 2.5 )))))

#(define (keys-from-list-two l1 l2)
  (let* ((width 12)
         (height 6)
         (lt 0.15)
         (lttwo 0.7))
   (begin
    (ly:stencil-add
    (make-white-keys lt width height)
    (make-black-keys lttwo width height)
    (make-dot 7)
    (make-dot 12)
    (make-dot-list '(1 2 3))))))

#(define-markup-command (keystwo layout props arg1) (list?)
   (keys-from-list-two '() '() ))

dmajor=\markup\keystwo #'(1)

\relative c' {
  c4 c^\dmajor c
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]