opensubscriber
   Find in this group all groups
 
Unknown more information…

l : lilypond-user@gnu.org 7 July 2012 • 12:18AM -0400

Re: LSR snippet "Controlling of the pitch range in a score" broken at 2.15.40
by David Kastrup

REPLY TO AUTHOR
 
REPLY TO GROUP




Patrick or Cynthia Karl <pckarl@mac....> writes:

> The LSR snippet "Controlling of the pitch range in a score" contains
> the code for a function, colorizeOutOfRange.  This function works at
> 2.14.2, but doesn't at 2.15.40.
>
> This can be demonstrated by compiling the following:
>
>> \include "./colorize.ly"
>>
>> music = \relative c' { c d e f g a b }
>>
>> \new Staff { \colorizeOutOfRange d' a' \music }
>
> where the file colorize.ly contains the following code from the cited snippet:
>
>> colorizeOutOfRange = #(define-music-function (parser location
>>                        low-note high-note music )(ly:music? ly:music? ly:music?)
>> "Colorizes in red notes out of range `low-note `high-note"                      
>> (let* (
>>   (low-elts (ly:music-property low-note 'elements))
>>   (high-elts (ly:music-property high-note 'elements))
>>   (low-pitch (and (pair? low-elts)
>>                   (ly:music-property (car low-elts) 'pitch)))
>>   (high-pitch (and (pair? high-elts)
>>                    (ly:music-property (car high-elts) 'pitch))))
>>  (if (and (ly:pitch? low-pitch)
>>           (ly:pitch? high-pitch)
>>           (ly:pitch<? low-pitch high-pitch))
>>     (music-map
>>       (lambda (evt)
>>         (let ((p (ly:music-property evt 'pitch)))
>>           (if (and (ly:pitch? p)
>>                    (or (ly:pitch<? p low-pitch)
>>                        (ly:pitch<? high-pitch p)))
>>             (let ((tweaks (ly:music-property evt 'tweaks)))
>>                 (ly:music-set-property! evt 'tweaks
>>                     (acons 'color red tweaks))))
>>           evt))
>>       music)
>>     music)))
>
> When compiled with lilypond 2.14.2 the notes c and b are colored red.
> When compiled with lilypond 2.15.40, all notes are black.
>
> Does anyone know a fix for colorizeOutOfRange?

It relies on a complex structure of music internals to pick out pitches
from its arguments.  This structure has changed.  Fortunately, 2.15.40
makes it much much easier to get pitches from music function arguments,
so the following reduction of the complex original code will do the
trick:

colorizeOutOfRange =
#(define-music-function (parser location low-pitch high-pitch music)
  (ly:pitch? ly:pitch? ly:music?)
  "Colorizes in red notes out of range `low-pitch `high-pitch"
  (if (ly:pitch<? low-pitch high-pitch)
    (music-map
      (lambda (evt)
        (let ((p (ly:music-property evt 'pitch)))
          (if (and (ly:pitch? p)
                   (or (ly:pitch<? p low-pitch)
                       (ly:pitch<? high-pitch p)))
            (let ((tweaks (ly:music-property evt 'tweaks)))
                (ly:music-set-property! evt 'tweaks
                    (acons 'color red tweaks))))
          evt))
      music)
    music))


--
David Kastrup


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

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.