2017-05-04 18:59 GMT+02:00 zaord <[email protected]>:
> Hi,
>
> I still have a little question :
>
> In my code, I use a define-music-function to exctract the nots of chords
> from a chordmode , and i compare each pitch of the notes events with a list
> to find x/y position of a colored dot making a custom diagram.
>
> My problem is that I can't get the name of the pitch, and when I compare the
> pitch and my list, the values didn't match.
Ofcourse, you try to compare a pitch with a symbol to get an entry
from an alist, so no result.
[...]
> I would like to extact from the varioable only c' in this case.
> Why the function ly:pitch-notename fails ?
It does not fail, though I understand it does not match your
expectations. You know it returns a number.
But then you try to compare a number with a symbol to get an entry
from an alist, so no result.
Brute-force, I sometimes do things like:
#(define (pitch->symbol pitch)
(string->symbol (second (string-split (object->string pitch) #\SPACE))))
The is code of type "Don't get on my nerves" ;)
Though, it works with:
#(define (make-dot-list l1)
(if (null? l1)
empty-stencil
(ly:stencil-add
(make-dot (pitch->symbol (car l1)))
(make-dot-list (cdr l1)))))
Nevertheless, your 'Color-KEY-LIST ' has no entries for c'' and
higher, nor for b,, and below so there are still errors.
> I join the ly file.
You didn't ;)
So I attached the file you sent me earlier. Had not the time to look
into it earlier.
In general I have the impression that things can be done much easier,
but formating/indenting of your file is terrible.
Makes it very hard to read and does not encourage to work on it ;)
Cheers,
Harm
% ici on défini les points qu'on fait sur le piano
#(define (make-dot-list l1)
(if (null? l1)
empty-stencil
(ly:stencil-add
(make-dot (ly:pitch-notename(car l1)))
(make-dot-list (cdr l1)))))
% ici on défini i on fait des ronds noirs ou blancs
#(define (make-dot key)
(let ((test (cons (key-to-pos key) ( key-to-pos key) )))
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.25 0.1 #f) ( key-to-pos key )) (car( key-to-color key ) )(car( key-to-color key ) )(car( key-to-color key )))
)) % pour les ronds noirs
% ici on défini les couleurs R V B associés à chaque notes
#(define (key-to-color key )
(let ((keycolor (caddr(assq key Color-KEY-LIST))))
(if (not keycolor)
(ly:error (_ "Color diagram error - unkown note '~a'") key)
( caddr (assq key Color-KEY-LIST) ))))
#(define (key-to-pos key )
(let ((keypos (assq key KEY-POS-LIST)))
(if (not keypos)
(ly:error (_ "keyboard diagram error - unkown note '~a'") key)
(caddr (assq key KEY-POS-LIST) ))))
% ici on associe un numéro aux touches
#(define Color-KEY-LIST '(
(c . '( 0.71 0.28 0.58) ) (cis . '( 0.4 0.4 0.4) ) (des . '( 0.4 0.4 0.4 ) ) (d . '( 0.15 0.33 0.68) )
(dis . '( 0.4 0.4 0.4 ) ) (ees . '( 0.4 0.4 0.4) ) (e . '( 0.58 0.73 0.91) ) (f . '( 0.71 0.86 0.69) ) (fis . '( 0.4 0.4 0.4 ) ) (ges . '( 0.4 0.4 0.4 ) )
(g . '( 1 0.87 0.4 ) ) (gis . '( 0.4 0.4 0.4) ) (aes . '( 0.4 0.4 0.4 ) ) (a . '( 1 0.58 0.55 ) )
(ais . '( 0.4 0.4 0.4 ) ) (bes . '( 0.4 0.4 0.4) ) (b . '( 0.93 0.15 0.2 ) )
(c' . '( 0.71 0.28 0.58) ) (cis' . '( 0.4 0.4 0.4) ) (des' . '( 0.4 0.4 0.4 ) ) (d' . '( 0.15 0.33 0.68) )
(dis' . '( 0.4 0.4 0.4 ) ) (ees' . '( 0.4 0.4 0.4) ) (e' . '( 0.58 0.73 0.91) ) (f' . '( 0.71 0.86 0.69) ) (fis' . '( 0.4 0.4 0.4 ) ) (ges' . '( 0.4 0.4 0.4 ) )
(g' . '( 1 0.87 0.4 ) ) (gis' . '( 0.4 0.4 0.4) ) (aes' . '( 0.4 0.4 0.4 ) ) (a' . '( 1 0.58 0.55 ) )
(ais' . '( 0.4 0.4 0.4 ) ) (bes' . '( 0.4 0.4 0.4) ) (b' . '( 0.93 0.15 0.2 ) )
(c, . '( 0.71 0.28 0.58) ) (cis, . '( 0.4 0.4 0.4) ) (des, . '( 0.4 0.4 0.4 ) ) (d, . '( 0.15 0.33 0.68) )
(dis, . '( 0.4 0.4 0.4 ) ) (ees, . '( 0.4 0.4 0.4) ) (e, . '( 0.58 0.73 0.91) ) (f, . '( 0.71 0.86 0.69) ) (fis, . '( 0.4 0.4 0.4 ) ) (ges, . '( 0.4 0.4 0.4 ) )
(g, . '( 1 0.87 0.4 ) ) (gis, . '( 0.4 0.4 0.4) ) (aes, . '( 0.4 0.4 0.4 ) ) (a, . '( 1 0.58 0.55 ) )
(ais, . '( 0.4 0.4 0.4 ) ) (bes, . '( 0.4 0.4 0.4) ) (b, . '( 0.93 0.15 0.2 ) )
))
% ici on défini les positions des points noirs du clavier
%-------------------------------------------------
#(define KEY-POS-LIST '(
(c . '( 0 . 0)) (cis . '( 1 . 0) ) (des . '( 1 . 0) ) (d . '( 2 . 0) )
(dis . '( -0.5 . 0.5) ) (ees . '( -0.5 . 0.5) ) (e . '( 0.5 . 0.5) ) (f . '( 1.5 . 0.5) ) (fis . '( 2.5 . 0.5) ) (ges . '( 2.5 . 0.5) )
(g . '( 0 . 1) ) (gis . '( 1 . 1) ) (aes . '( 1 . 1) ) (a . '( 2 . 1) )
(ais . '( -0.5 . 1.5) ) (bes . '( -0.5 . 1.5) ) (b . '( 0.5 . 1.5) ) (c' . '( 1.5 . 1.5) ) (cis' . '( 2.5 . 1.5) ) (des' . '( 2.5 . 1.5) )
(d' . '( 0 . 2) ) (dis'. '( 1 . 2) ) (ees' . '( 1 . 2) ) (e' . '( 2 . 2) )
(f' . '( -0.5 . 2.5) ) (fis' . '( 0.5 . 2.5) ) (ges' . '( 0.5 . 2.5) ) (g' . '( 1.5 . 2.5) ) (gis' . '( 2.5 . 2.5) ) (aes' . '( 2.5 . 2.5) )
(a' . '( 0 . 3) ) (ais' . '( 1 . 3) ) (bes' . '( 1 . 3) ) (b' . '( 2 . 3) ) ))
% ici on utilise les fonctions précédentes pour dessiner le piano
%%ligne du haut
%ligne du bas
%lignes de chaque touches noires
%ligne de chaque touches blanches
%chaque points
#(define-markup-command (complete layout props the-chord)
(ly:music?)
(ly:stencil-scale
(ly:stencil-add
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #f) (cons 0 0)) 0 0 0)
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #t) (cons 0 1)) 0 0 0 )
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #f) (cons 0 2)) 0 0 0 )
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #t) (cons 0.5 -0.5)) 0 0 0 )
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #f) (cons 0.5 0.5)) 0 0 0 )
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #f) (cons 0.5 1.5)) 0 0 0 )
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #t) (cons 0.5 2.5)) 0 0 0 )
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #f) (cons 1 0)) 0 0 0)
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #t) (cons 1 1)) 0 0 0 )
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #f) (cons 1 2)) 0 0 0 )
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #t) (cons 1.5 -0.5)) 0 0 0)
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #f) (cons 1.5 0.5)) 0 0 0 )
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #f) (cons 1.5 1.5)) 0 0 0 )
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #t) (cons 1.5 2.5)) 0 0 0 )
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #f) (cons 2 0)) 0 0 0)
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #t) (cons 2 1)) 0 0 0 )
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #f) (cons 2 2)) 0 0 0 )
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #f) (cons 2.5 -0.5)) 0 0 0 )
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #t) (cons 2.5 0.5)) 0 0 0 )
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #f) (cons 2.5 1.5)) 0 0 0 )
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #t) (cons 2.5 2.5)) 0 0 0 )
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #f) (cons 3 0)) 0 0 0)
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #t) (cons 3 1)) 0 0 0 )
(ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.3 0 #f) (cons 3 2)) 0 0 0 )
(make-dot-list
(map
(lambda (m) (ly:music-property m 'pitch))
(extract-named-music the-chord 'NoteEvent))))
1 1))
diag=
#(define-music-function (parser location music)
(ly:music?)
(music-map
(lambda (m)
(if (music-is-of-type? m 'event-chord)
#{ <>^\markup \complete #m $m #}
m))
music))
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user