Home
Random
Log in
Settings
About LilyPond wiki
LilyPond wiki
Search
Editing
Music within an octave ambitus
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
Function to keep the music within an octave ambitus, starting from a reference pitch.<br /> It may be useful for the left-hand of accordion. <lilypond version="2.24.0" full> \paper { tagline = ##f } #(define (within-octave-pitch pitchReference p) (let ((o (ly:pitch-octave p)) (a (ly:pitch-alteration p)) (n (ly:pitch-notename p)) (s (ly:pitch-semitones p)) (r (ly:pitch-semitones pitchReference))) (let loop () (cond ((< s r) (set! o (1+ o)) (set! p (ly:make-pitch o n a)) (set! s (ly:pitch-semitones p)) (loop)) ((> s (+ r 11)) (set! o (1- o)) (set! p (ly:make-pitch o n a)) (set! s (ly:pitch-semitones p)) (loop)))) (ly:make-pitch o n a))) #(define (within-octave pitchReference music) (let ((es (ly:music-property music 'elements)) (e (ly:music-property music 'element)) (p (ly:music-property music 'pitch))) (if (pair? es) (ly:music-set-property! music 'elements (map (lambda (x) (within-octave pitchReference x)) es))) (if (ly:music? e) (ly:music-set-property! music 'element (within-octave pitchReference e))) (if (ly:pitch? p) (begin (set! p (within-octave-pitch pitchReference p)) (ly:music-set-property! music 'pitch p))) music)) withinOctave = #(define-music-function (pitchReference music) (ly:pitch? ly:music?) (within-octave pitchReference music)) %usage: \withinOctave pitch-reference (pitch) music (muscial expression) \withinOctave g { a4 b c' d' e' f' g' a' b' c'' } \withinOctave e' \chordmode { a:m b:dim c:7 } </lilypond> [[Category:Pitches]] [[Category:Pitches]] [[Category:Staff notation]]
Summary:
Please note that all contributions to LilyPond wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Meta:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)