Dear everyone,
A possibly dumb question -- I'm having some difficulty working out how
to set the value of a given music property.
Here's a little piece of Lilypond Scheme adapted from the
naturalizeMusic.ly snippet:
naturalizeMusic =
#(define-music-function (parser location m)
(ly:music?)
(naturalize m (ly:music-property music 'naturalize-style)))
Now, naturalize-style I've defined in scm/define-music-properties.scm:
--------------------------------------------------------------------------
diff --git a/scm/define-music-properties.scm
b/scm/define-music-properties.scm
index 2af8f92..6709154 100644
--- a/scm/define-music-properties.scm
+++ b/scm/define-music-properties.scm
@@ -106,6 +106,7 @@ whether to allow, forbid or force a line break.")
(metronome-count ,number? "How many beats in a minute?")
(name ,symbol? "Name of this music object.")
+ (naturalize-style ,list? "The rules for what pitch-alterations are
permissible.")
(no-continuation ,boolean? "If set, disallow continuation lines.")
(numerator ,integer? "Numerator of a time signature.")
--------------------------------------------------------------------------
... but when I try some Lilypond code along the following lines,
> music = \relative c' { c4 d e g }
>
> \score {
> \new Staff {
> \set Staff.extraNatural = ##f
> \withMusicProperty #'naturalize-style #(list (cons >= 1) (cons <= -1)
> (cons >= SHARP) (cons <= FLAT))
> \naturalizeMusic \transpose c ais { \music }
> }
> \layout { }
> }
... I get an error:
> Parsing...code/lily/out/share/lilypond/current/scm/naturalize.scm:10:33: In
> procedure list-ref in expression (list-ref pitch-limits 0):
> code/lily/out/share/lilypond/current/scm/naturalize.scm:10:33: Argument 2 out
> of range: 0
... which suggests that 'naturalize-style is being taken as empty by the
ly:music-property function. Giving it a default value equal to an
actual list,
> naturalizeMusic =
> #(define-music-function (parser location m)
> (ly:music?)
> (naturalize m (ly:music-property music 'naturalize-style (list (cons >= 1)
> (cons <= -1) (cons >= SHARP) (cons <= FLAT)))))
... means it parses without error, so it looks like the
ly:music-property function is currently just using the default value
given, and does not appreciate the 'naturalize-style property as already
having a set value.
So, the question comes down to, what am I doing wrong in trying to set
the 'naturalize-style property of the music? Putting brackets {} round
the music to which the \withMusicProperty statement should apply doesn't
help.
I tried more directly using the ly:music-set-property! function, but
could not work it out. :-(
Can anyone advise?
Thanks & best wishes,
-- Joe
P.S. naturalize.scm is not really relevant to this question (I think),
but just in case, I've attached it.
(define (naturalize-limit lim)
(define (limit a)
((car lim) a (cdr lim)))
limit)
(define-public (naturalize-pitch p pitch-limits)
(let ((o (ly:pitch-octave p))
(n (ly:pitch-notename p))
(a (ly:pitch-alteration p))
(high (naturalize-limit (list-ref pitch-limits 0)))
(low (naturalize-limit (list-ref pitch-limits 1)))
(higheb (naturalize-limit (list-ref pitch-limits 2)))
(lowcf (naturalize-limit (list-ref pitch-limits 3))))
(do ((aa 0))
((= aa a) (ly:make-pitch o n a))
(set! aa a)
(cond
((and (higheb a) (or (eq? n 2) (eq? n 6)))
(set! a (- a (/ 1 2)))
(set! n (+ n 1)))
((and (lowcf a) (or (eq? n 0) (eq? n 3)))
(set! a (+ a (/ 1 2)))
(set! n (- n 1))))
(cond
((high a) (set! a (- a 1)) (set! n (+ n 1)))
((low a) (set! a (+ a 1)) (set! n (- n 1))))
(if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
(if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7)))))))
(define-public (naturalize music pitch-limits)
(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) (naturalize x pitch-limits)) es)))
(if (ly:music? e)
(ly:music-set-property!
music 'element
(naturalize e pitch-limits)))
(if (ly:pitch? p)
(begin
(set! p (naturalize-pitch p pitch-limits))
(ly:music-set-property! music 'pitch p)))
music))
_______________________________________________
lilypond-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-devel