Message: 2
Date: Sat, 30 May 2015 13:40:13 +0200
From: Marc Hohl <[email protected]>
To: [email protected]
Subject: Re: Color note heads outside nominal  instrument range
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed

Am 30.05.2015 um 12:38 schrieb Peter Gentry:
>
> FWIW
>
> I have attached a slightly simplified and better version of 
> instrument_ranges.ly

I haven't tested your code, but I like the idea of defining instrument-specific 
tonal ranges quite a lot!

Some ideas/proposals:

1)
Can you store the tone range for each instrument in an alist?

(define range-alist
  '((
   ("clarinet" . ( -10 . 34 ))
   ("bass-clarinet-c" . ( ...
)))

or even better, use pitches? You can extract upper and lower bounds from this 
alist and don't have to write a conditional check for
each instrument.

2)
IIUC, the line
(if (or ( > op 34) (< op -10) ) (begin (set! o (+ o 1))) ))

adds one octave to the pitch if the note is lower than the lowest possible note 
OR higher than the highest possible note?
The latter doesn't seem quite right to me ;-)

(and (< op -10)
      (set! o (+ o 1)))
(and (> op 34)
      (set! o (- o 1)))

seems to do the trick (untested).

Apart from that, such a function is a valuable extension for lilypond IMHO.

Cheers,

Marc

Actually Marc I have revised and simplified the calculation (see attached)  - I 
simply wanted to indicate notes outside the range
modify then to fall inside the range. The colour then gives engraver/player the 
option to play within range or if that is awkward
play rests. I haven't sent to list before to save everyone the fag of looking 
at it again.

regards
Peter Gentry 

\version "2.19.15"
% -------------------------------------------------------------------------------------------------
% include function file instrument_ranges.ly
% usuage include --> \include "./ranges/instrument_ranges.ly"
% usuage call -->       \naturalizeInstrumentRange "instrument" music
% this function will confine all pitches to the individual instruments range
% Note the ranges refer to music transposed for each instrument not the true pitches.
% use % for comment outside scheme function -  use ; inside scheme functions
% -------------------------------------------------------------------------------------------------

#(define (naturalize-instrument-range p instrument ) 
    (let ((o (ly:pitch-octave p))
            (a (* 4 (ly:pitch-alteration p)))
            (n (ly:pitch-notename p)))

            (define op (+ (+ (+ (* 14 o) ) (* n 2) ) (/ a 2)))

            (cond
 ;; clarinet range e to f'  -1 2 0  to 1 3 0  (-10 to 34)

                ((equal? instrument "clarinet" )
                    (if   (< op -10)  (begin (set! o (+ o 1))))
                    (if  ( > op 34)   (begin (set! o (- o 1 ))))
                )
; bass clarinet range eb to f'  -1 1 2  (-1 2 -2)  to 1 3 0 (-11 to 34)

                ((equal? instrument "bass clarinet eb" )
                    (if   (< op -11)  (begin (set! o (+ o 1))) )
                    (if  ( > op 34)  (begin (set! o (- o 1))) )
                )
; bass clarinet range c to f'  -1 1 2  (-1 2 -2)  to 1 3 0 (-14 to 34)

                ((equal? instrument "bass clarinet c" )
                   (if (< op -14)  (begin (set! o (+ o 1))))
                  (if  ( > op 34)  (begin (set! o (- o 1))))
                )
;; flute range c to f'  0 0 0   to 1 3 0  (0 to 34)

                ((equal? instrument "flute")
                  (if   (< op 0)    (begin (set! o (+ o 1))) )
                  (if  ( > op 34)  (begin (set! o (- o 1))) )
                ) 
;; alto range c to f'  1 0 0   to 1 3 0

                ((equal? instrument "alto")
                 (if   (< op 0)  (begin (set! o (+ o 1))) )
                 (if  ( > op 34)  (begin (set! o (- o 1))) )
                )
            )

            (ly:make-pitch o n (/ a 4)) 

    )
 )
 
% -------------------------------------------------------------------------------------------------
% a variable for the notehaed color on pitch change
% -------------------------------------------------------------------------------------------------

my-color = #(x11-color 'red)
 
% -------------------------------------------------------------------------------------------------
% this function rebuilds the music object optionally changing pitch and notehead color
% -------------------------------------------------------------------------------------------------
#(define (instrumentrange music instrument ) 
               (  ly:music? string? ) 
; extract the various portions of the music object
   (let ((es (ly:music-property music 'elements))      
           (e   (ly:music-property music 'element)) 
           (p   (ly:music-property music 'pitch)))
 
; rebuild any 'elements unchanged
        (if (pair? es)
            (ly:music-set-property! music 'elements
                 (map (lambda (x) (instrumentrange x instrument)) es)
            )
        )  

; rebuild any 'element unchanged
        (if (ly:music? e) (ly:music-set-property! music 'element
             (instrumentrange e instrument ))
        )

;rebuild the pitch and if a changed pitch add the color tweak
        (if (ly:pitch? p)
            (let ((new-pitch (naturalize-instrument-range p instrument)))
                   (ly:music-set-property! music 'pitch new-pitch)
                   (if (and (not (equal? p new-pitch)) (color? my-color))
                        (ly:music-set-property! music 'tweaks
                            (acons
                                'color my-color
                                (ly:music-property music 'tweaks)
                           )
                      )
                   )
             )
        )
     music
     )
   )
 
% -------------------------------------------------------------------------------------------------
% the Lily file calling function \naturalizeInstrumentRange  "clarinet"  followed by sequential music
% -------------------------------------------------------------------------------------------------
naturalizeInstrumentRange =
#(define-music-function (parser location  instrument m ) 
  ( string? ly:music? )  
  (instrumentrange m instrument ))
 
\score {
  \naturalizeInstrumentRange "alto"
  \new Staff \relative c' {
   c,,8  cis des d dis ees e eis fes f fis ges g gis aes a ais bes b bis ces
   c8  cis des d dis ees e eis fes f fis ges g gis aes a ais bes b bis ces
   c8  cis des d dis ees e eis fes f fis ges g gis aes a ais bes b bis ces
   c8  cis des d dis ees e eis fes f fis ges g gis aes a ais bes b bis ces
  c8  cis des d dis ees e eis fes f fis ges g gis aes a ais bes b bis ces
    
  }
}
\score {
 \new Staff \relative c' {
    c,,8  cis des d dis ees e eis fes f fis ges g gis aes a ais bes b bis ces
   c8  cis des d dis ees e eis fes f fis ges g gis aes a ais bes b bis ces
   c8  cis des d dis ees e eis fes f fis ges g gis aes a ais bes b bis ces
   c8  cis des d dis ees e eis fes f fis ges g gis aes a ais bes b bis ces
  c8  cis des d dis ees e eis fes f fis ges g gis aes a ais bes b bis ces
    
  }
}
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to