lilypond-user-fr
[Top][All Lists]
Advanced

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

Re: Un peu de couleur...


From: Jean Abou Samra
Subject: Re: Un peu de couleur...
Date: Sun, 12 Dec 2021 14:48:35 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.1

Le 12/12/2021 à 13:54, Vincent Gay a écrit :
Bonjour,

j'ai vu comment coloriser certains objets (têtes de notes, hampes, barres de mesures...) mais serait-il possible de coloriser l’intérieur de la portée, entre les lignes, pour une mesure en particulier ?

j'ai quelques élèves débutants en jazz et je tente de leur indiquer comment préparer leur grille d'impro. Voilà un exemple de ce que j'aimerai obtenir. Pour l'instant j'importe le pdf dans gimp pour coloriser.


En voilà une question qu'elle est intéressante !

Voici une solution possible :

\version "2.22.1"

#(define (define-grob! grob-name grob-entry)
   (set! all-grob-descriptions
         (cons ((@@ (lily) completize-grob-entry)
                (cons grob-name grob-entry))
               all-grob-descriptions)))

#(define (staff-colorizer::text grob)
   (let* ((staff-symbol (ly:grob-object grob 'staff-symbol))
          (left (ly:spanner-bound grob LEFT))
          (right (ly:spanner-bound grob RIGHT))
          (refp (ly:grob-common-refpoint
                 grob
                 (ly:grob-common-refpoint left right X)
                 X))
          (spacing-pair (ly:grob-property grob 'spacing-pair))
          (coord-adjust (ly:grob-relative-coordinate grob refp X))
          (x-span (cons (+ (ly:grob-relative-coordinate left refp X)
                           (interval-end (ly:paper-column::break-align-width left (car spacing-pair)))
                           (- (ly:grob-relative-coordinate left
(ly:grob-parent left X)
                                                           X))
                           (- coord-adjust))
                        (+ (ly:grob-relative-coordinate right refp X)
                           (interval-start (ly:paper-column::break-align-width right (cdr spacing-pair)))
                           (- (ly:grob-relative-coordinate right
(ly:grob-parent right X)
                                                           X))
                           (- coord-adjust))))
          (y-span (ly:grob-extent staff-symbol staff-symbol Y)))
     (make-filled-box-markup x-span y-span 0)))

#(define-grob!
   'StaffColorizer
   `((stencil . ,ly:text-interface::print)
     (layer . -1)
     (text . ,staff-colorizer::text)
     (spacing-pair . (staff-bar . staff-bar))
     (meta . ((class . Spanner)
              (interfaces . (text-interface))))))

#(set-object-property! 'staffColor 'translation-type? color?)

#(define (Staff_colorizer_engraver context)
   (let ((current-color #f)
         (spanner #f))
     (make-engraver
       ((process-music engraver)
          (let ((color (ly:context-property context 'staffColor)))
            (if (not (equal? color current-color))
                (let ((column (ly:context-property context 'currentCommandColumn)))
                  (set! current-color color)
                  (if spanner
                      (ly:spanner-set-bound! spanner RIGHT column))
                  (set! spanner (ly:engraver-make-grob engraver 'StaffColorizer '()))
                  (ly:grob-set-property! spanner 'color current-color)
                  (ly:spanner-set-bound! spanner LEFT column)))))
       ((finalize engraver)
          (if spanner
            (let ((column (ly:context-property context 'currentCommandColumn)))
              (ly:spanner-set-bound! spanner RIGHT column)))))))

\layout {
  \context {
    \Global
    \grobdescriptions #all-grob-descriptions
  }
  \context {
    \Staff
    \consists #Staff_colorizer_engraver
  }
}

staffColor = \set Staff.staffColor = \etc

{
  \staffColor red
  c'1
  \staffColor green
  c'2 4 \staffColor cornflowerblue 4
}

Cordialement,
Jean




reply via email to

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