lilypond-user
[Top][All Lists]
Advanced

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

Re: function to fit music within a given range?


From: Gilles THIBAULT
Subject: Re: function to fit music within a given range?
Date: Fri, 6 Feb 2009 00:17:07 +0100



Is there an existing function/snipped that will adjust the octave of
music to within a given range of notes? For example, I have a melody
played by many instruments in a score, but some instruments can't
reach the higher notes, so those notes must be shifted to a lower
octave; I'd like to avoid copying & rewriting that part (and
quoteDuring has become just as messy).


Here is a function that seems to work but i am not sure that it will produce nices melodies ...


%%%%%%%%%%%%%%%%%%%
#(define (check-pitch limit-pitch p)
(if (ly:pitch<? p limit-pitch )
p
(begin
 (set! p (ly:make-pitch
  (1- (ly:pitch-octave p))
  (ly:pitch-notename p)
  (ly:pitch-alteration p)))
 (check-pitch limit-pitch p))))


checkPitch = #(define-music-function (parser location note music )(ly:music? ly:music?)
(let* (
(elts (ly:music-property note 'elements))
(limit-pitch (ly:music-property (car elts) 'pitch)))
(if (ly:pitch? limit-pitch)
 (music-map
 (lambda (evt)
  (let ((p (ly:music-property evt 'pitch)))
   (if (ly:pitch? p)
    (ly:music-set-property! evt 'pitch
     (check-pitch limit-pitch p)))
   evt))
 music)
music)))

music = \relative {
c4 d e f g a b c
d \mark "limit note" e f g a b c d
e f g f e d c b
a g f e d c b a
g f e d c1}
\score {<<
\new Staff \music
\new Staff \checkPitch  d'' \music >>}


%%%%%%%%%%%%%%%%%%%%%%%%

Gilles




reply via email to

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