lilypond-user
[Top][All Lists]
Advanced

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

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


From: Simon Albrecht
Subject: Re: Apply a music-function script to all elements of a list
Date: Sun, 7 May 2017 02:04:04 +0200

Hi Ewen,

I’m sorry, but there are multiple issues with your post.

First, you promised to do better next time, but your Scheme code formatting did not improve…

Second, it’s necessary to give full, compilable examples of your code, so that anybody trying to help doesn’t have to assemble pieces from all over the e-mail thread. I found the definition for make-dot-list relatively quickly, but I finally halted my work of the code when I realised that the definition for make-dot is hidden even better. Also, ‘highlighting’ code with ** // is not helpful at all. Use comments for that purpose (in Scheme they begin with ; instead of % in LilyPond code).

Third, I can’t actually understand what you are trying to achieve. Could you explain the context more or at best just give a mockup image of what you’re aiming at?

Here’s what I _could_ make out of your first function. Note the code formatting, which is consistent with the rules here. For documentation on apply and map see <https://www.gnu.org/software/guile/docs/docs-1.8/guile-ref/Fly-Evaluation.html#index-apply-2230> and <https://www.gnu.org/software/guile/docs/docs-1.8/guile-ref/List-Mapping.html#index-map-1089>. The procedure index in this manual is very helpful.

%%%%%%%%%%%%%%%%%%%%%
\version "2.19.58"

#(define (make-dot-list l1)
   (if (null? l1)
       empty-stencil
       (ly:stencil-add
        (make-dot (pitch->symbol (car l1)))
        (make-dot-list (cdr l1)))))

#(define-markup-command (complete layout props the-chord)
   (ly:music?)
   (let ((circle (lambda (p) (ly:stencil-in-color
                              (ly:stencil-translate
                               (make-circle-stencil 0.4 0 #f)
                               p)
                              0
                              0
                              0))))
     (ly:stencil-scale
      (apply ly:stencil-add
        (append
         (map circle '((0 . 0)
                       (0 . 1)
                       (0 . 2)
                       (0 . 3)
                       (1 . 0)
                       (1 . 1)
                       (1 . 2)
                       (1 . 3)))
         (make-dot-list (map (lambda (m) (ly:music-property m 'pitch))
                          (extract-named-music the-chord 'NoteEvent)))))
      1
      1)))
%%%%%%%%%%%%%%%%%%%%%%

HTH, Simon


Am 06.05.2017 um 19:19 schrieb zaord:
Hi,

I have a new (small ?) question :

I have define a markup command (below) and this command is calling the
differents functions .
Actually this command is making the differents elements of my customs
diagrams. Firsly the unvariants circles (representing the keyboard of the
instrument in bold) and then the differents colored dots (in itallic on the
code below) depends on the notes of the différents chords.

Now I would like to split this into two differents function, one which
engrave the keybord layout and the other which makes the colored dots since
I need sometines only the colored dots.


#(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))/


I tried to make a other function like this :

#(define (make-background )
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 )
       )

But this make only one dot of the background and not the full keyboard.

Thanks by advance !

Ewen




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

_______________________________________________
lilypond-user mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/lilypond-user




reply via email to

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