lilypond-user
[Top][All Lists]
Advanced

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

Apply a music-function script to all elements of a list


From: zaord
Subject: Apply a music-function script to all elements of a list
Date: Mon, 20 Feb 2017 08:31:01 -0700 (MST)

Hello,

I coded a script that adds markup. This function \ diag allows me to display
a customized diagram (here left hand "button board" of an accordion) and I
would like to apply it to all the elements of a chordmode {}.
The script below works very well but only for a chordmode with 1 element. If
the Chordmode have two elements, then the diagram is writing over himself
but don't follow the score !

In another hand, lilypond does not recreate new diagrams and the diagrams
are superpozed ...

My code  bellow is inspired by  : http://lsr.di.unimi.it/LSR/Item?id=1042  





%------------------------------------------------------ 

% 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-semitones (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-POS-LIST    '(       
   (-8   .  '( 0  . 0)) 
   (-7   .  '( 0  . 1)) 
   (-6   .  '( 0  . 2)) 
   (-5   .  '( 0  . 3)) 
   (-4   .  '( 1  . 0)) 
   (-3   .  '( 1  . 1)) 
   (-2   .  '( 1  . 2)) 
   (-1   .  '( 1  . 3)) 
   (0   .  '( 0  . 0)) 
   (1   .  '( 0  . 1)) 
   (2   .  '( 0  . 2)) 
   (3   .  '( 0  . 3)) 
   (4   .  '( 1  . 0)) 
   (5   .  '( 1  . 1)) 
   (6   .  '( 1  . 2)) 
   (7   .  '( 1  . 3)) 
   (8   .  '( 0.71  . 1)) 
   (9   .  '( 0.71  . 1)) 
   (10  .  '( 0.71  . 1)) 
   (11  .  '( 0.71  . 1)) 
   (12  .  '( 0.71  . 1)) 
   (13  .  '( 0.71  . 1)) 
   (14  .  '( 0.71  . 1)) 
   (15  .  '( 0.71  . 1)) 
   (16  .  '( 0.71  . 1)) 
   (17  .  '( 0.71  . 1)) 
   (18  .  '( 0.71  . 1)) 
   (19  .  '( 0.71  . 1)) 
   (20  .  '( 0.71  . 1)) 
   (21  .  '( 0.71  . 1)) 
   (22  .  '( 0.71  . 1)) 
   (23  .  '( 0.71  . 1)) 
   )) 


#(define Color-KEY-LIST    '(       
   (-11 .  '( 0.71     1    1)) 
   (-10 .  '( 0.71     1    1)) 
   (-9  .  '( 0.71     1    1)) 
   (-8  .  '( 0.71     1    1)) 
   (-7  .  '( 0.71     1    1)) 
   (-6  .  '( 0.71   0.2   1)) 
   (-5  .  '( 0.71   0.2   1)) 
   (-4  .  '( 0.71   0.2   1)) 
   (-3  .  '( 0.71   0.2   1)) 
   (-2  .  '( 0.71   0.2   1)) 
   (-1  .  '( 0.71   0.2   1)) 
   (0   .  '( 0.71     1    1)) 
   (1   .  '( 0.71     1    1)) 
   (2   .  '( 0.71     1    1)) 
   (3   .  '( 0.71     1    1)) 
   (4   .  '( 0.71     1    1)) 
   (5   .  '( 0.71   0.2   1)) 
   (6   .  '( 0.71   0.2   1)) 
   (7   .  '( 0.71   0.2   1)) 
   (8   .  '( 0.71   0.2   1)) 
   (9   .  '( 0.71   0.2   1)) 
   (10  .  '( 0.71   0.2   1)) 
   (11  .  '( 0.71   0.2   1)) 
   (12  .  '( 0.71   0.2   1)) 
   (13  .  '( 0.71   0.2   1)) 
   (14  .  '( 0.71   0.2   1)) 
   (15  .  '( 0.71   0.2   1)) 
   (16  .  '( 0.71   0.2   1)) 
   (17  .  '( 0.71   0.2   1)) 
   (18  .  '( 0.71   0.2   1)) 
   (19  .  '( 0.71   0.2   1)) 
   (20  .  '( 0.71   0.2   1)) 
   (21  .  '( 0.71   0.2   1)) 
   (22  .  '( 0.71   0.2   1)) 
   (23  .  '( 0.71   0.2   1)) 
   )) 


% ici on défini les positions des points du clavier en y 
#(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) )))) 



#(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.4 0 #f)
(cons 0 0)) 0 0 0 ) 
      (ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.4 0
#f) (cons 0 1)) 0 0 0 ) 
      (ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.4 0
#f) (cons 0 2)) 0 0 0 )   
      (ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.4 0
#f) (cons 0 3)) 0 0 0 ) 
      (ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.4 0
#f) (cons 1 0)) 0 0 0 ) 
      (ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.4 0
#f) (cons 1 1)) 0 0 0 ) 
      (ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.4 0
#f) (cons 1 2)) 0 0 0 )   
      (ly:stencil-in-color(ly:stencil-translate (make-circle-stencil 0.4 0
#f) (cons 1 3)) 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 the-chord) 
  (ly:music?) 
  #{ <>^\markup \complete #the-chord $the-chord #}) 




global = { 
  \time 4/4 
  \key a \minor 
  \tempo 4=80 
} 

% ici on écrit la parto 
melody = \relative c'' { 
  \global 
  
  \bar ".|:"a8 a16 b a g e g a8 g16 a c b a g d'8 d c16 b a g c d b8. b16 c
b |   
    a8 a16 b a g e g a8 g16 a c b a g d'8 d c16 b a g c d b8. b16 c d 
\break|   
    e8 e d16 c b a d8 c16 d e c a b c8 b16 a d8  c16 b a b c d b8   c16 d|   
    e8 e d16 c b a d8 c16 d e c a b | c8  b16 a d c d e b8 a16 g a r8 r16| 
    \bar ":|." 
} 


chordNames =  \chordmode  { 
  \global 
  
  a8:m5^5.3 a4:m5 g8:5 a8:m5 a:m5 a:m5 a:m5 d:m5 d4:m7 d8:m7 f:5 g4:5 e8:m/b 
  a8:m5 a4:m5 g8:5 a8:m5 a:m5 a:m5 a:m5 d:m5 d4:m7 d8:m7 f:5 g4:5 g8:5 
  a8:m5 a4:m5 a8:m5 g8:5 a4:m5 a8:m5 f:5 f:5 d4:m7  f:5 g8:5 g8:5 
  c4:5  c4:5 d8:m7 d4:m7 d8:m7 f4:5 g4:5 f8:5 g8:5 a,4:m } 


\score { 
  << 
    \new ChordNames {  \diag{\chordNames}  } 
    \new Staff { \melody } 
  >> 
  \layout {} 
  \midi { } 
} 


So, if you knew how I can run an instance of the \ diag function for each
item in my chordmode list, that would be great!

My aim is to have a 'button diagram' below each chord name.

Thank you for your help !



--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/Apply-a-music-function-script-to-all-elements-of-a-list-tp200313.html
Sent from the User mailing list archive at Nabble.com.



reply via email to

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