lilypond-user
[Top][All Lists]
Advanced

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

Re: LSR snippet "Controlling of the pitch range in a score" broken at 2.


From: David Kastrup
Subject: Re: LSR snippet "Controlling of the pitch range in a score" broken at 2.15.40
Date: Fri, 06 Jul 2012 18:18:32 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux)

Patrick or Cynthia Karl <address@hidden> 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




reply via email to

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