lilypond-user
[Top][All Lists]
Advanced

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

Re: Get the pitch as number


From: Gilles THIBAULT
Subject: Re: Get the pitch as number
Date: Fri, 11 Feb 2011 15:10:27 +0100


It appears to me that I'm getting a list rather than an integer, but if I
run (get-text texts (ly:pitch-semitones (ly:make-pitch 0 1 0)))
So get-pitch was probably the culprit ...

%%%%%%%%%%%%%%%%%%%%%
#(define (make-text-script x)
(make-music 'TextScriptEvent
           'direction DOWN
           'text (get-text texts x)))

#(define (add-text-script m)
 (if (equal? (ly:music-property m 'name) 'EventChord)
     (ly:music-set-property! m 'elements
           (cons (make-text-script (get-pitch m))
                 (ly:music-property m 'elements)))
     (let ((es (ly:music-property m 'elements))
            (e (ly:music-property m 'element)))
       (if (pair? es)(ly:music-set-property! m 'elements
          (map add-text-script es)))
       (if (ly:music? e)(ly:music-set-property! m 'element
          (add-text-script e)))))
 m)

#(define (get-text ls n)
 (if (or (< n 0)(>= n (length ls)))
   ""
   (list-ref ls n)))

#(define (get-pitch music)  %% music as a eventChord
 (let* ((es (ly:music-property music 'elements))
        (p  (ly:music-property (car es) 'pitch)))
    ;(display "\npitch : ")(ly:pitch-semitones p)(newline)
    (if (ly:pitch? p)(ly:pitch-semitones p) -1)))
    %%(if (ly:pitch? p)(ly:pitch-notename p) -1)))

#(define texts '("zero" "one" "two" "three" "four"))
%%#(define texts '("zero" "one" "two" "three" "four"))%% with use of
ly:pitch-notename

addText = #(define-music-function(parser location m)(ly:music?)
(add-text-script m))

music = \relative c' { b c cis d dis e f r}
%% music = \relative c' { b c d e f g a r} %% with use of ly:pitch-notename

\score {
  \new Staff \addText \music
}
%%%%%%%%%%%%%%%%%%%%%%%%

NB
You use : ly:pitch-semitones. You'll get first only a number from a note
above the middle C, then your texts list will be very extensive. Are you sure you
don't want ly:pitch-notename instead ?

Gilles





reply via email to

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