%% http://lsr.di.unimi.it/LSR/Item?id=773 % by Gilles Thibault % Y/M/D = 2014/01/14 %here starts the snippet: #(define (pitch>? p1 p2) (ly:pitch? ly:pitch or { c g' } #(define (correct-out-of-range music range) (let ((low #f) (high #f)) (music-map ; first pitch -> low, second pitch -> high (lambda (evt) (let ((p (ly:music-property evt 'pitch))) (if (ly:pitch? p) (cond ((not low)(set! low p)) ((not high)(set! high p)))) evt)) range) (music-map (lambda (evt) (let ((p (ly:music-property evt 'pitch))) (if (ly:pitch? p) (ly:music-set-property! evt 'pitch (pitch-octavize (pitch-octavize p low 'below) high 'above))) evt)) (ly:music-deep-copy music)))) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% tests music = \relative c' { c4 d e f g^"g'" a b c d e f g^"g''" a b c2 } \score {<< \new Staff \with { instrumentName = "1"} \music % staff 1 \new Staff \with { instrumentName = "2"} \correctOctave #'above g'' \music % staff 2 \new Staff \with { instrumentName = "3"} \correctOctave #'below g' \music % staff 3 \new Staff \with { instrumentName = "4"} \correctOctaveOutOfRange g' g'' \music % staff 4 \new Staff \with { instrumentName = "5"} \colorizeOutOfRange g' g'' \music % staff 5 \new Staff \with { instrumentName = "6"} \parenthesizeOutOfRange g' g'' \music % staff 6 >> } %{ %%uncomment for testing correct-out-of-range range = < g' g'' > #(define musicII (correct-out-of-range music range)) \new Staff \with { instrumentName = "6"} \musicII % staff 6 %} \paper { tagline = ##f }