acess to a note's pitch, using Scheme

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

acess to a note's pitch, using Scheme

danjiun
This post has NOT been accepted by the mailing list yet.
Hello frog-friends.
I want write a Scheme-function which according to the pitch of a note (octave, ...) add a corresponding fingering (for a violin) and write this above the note.
For example for add a "4" above a note disregarding which pitch i write :
{ \relative c' {
\applyMusic #(lambda (x) (music-map addFingering4 x )) {c d}
}}
(this write  a 4 above a 'c' and a 'd' note)
I define addFingering4 with :
#(define (addFingering4 m)
         (add-firstpos-fingering m 4))
#(define (make-fingering-script i)
         (make-music 'FingeringEvent 'digit i))
#(define (add-firstpos-fingering m i)
         (if
           (equal? (ly:music-property m 'name) 'EventChord)
           (set! (ly:music-property m 'elements)
                 (cons (make-fingering-script i)
                       (ly:music-property m 'elements))))
         m)
But, now my problem if how i can access to the notes pitch. So i can make like
(if ("note" = "c'")
(addFingeringX...)

Please for help. I am fascinate with LilyPond and i need to know something more. May be after this help i not have any more problems.

Daniel
Reply | Threaded
Open this post in threaded view
|

Re: acess to a note's pitch, using Scheme

danjiun
This post has NOT been accepted by the mailing list yet.
Hi friends.
I already discover how to access to the pitch members.
It is using the first element of <ly:music-property music 'elements> (music is ly:music?) and later
(pitch (ly:music-property event 'pitch))
so
(pitch (ly:music-property (ly:music-property music 'elements) 'pitch))

After do everything i do a test. But strange is the 4. note have a octave change (and i don't do nothing diferent). Here is the code :
#(define (make-fingering-script i)
         (make-music 'FingeringEvent 'digit i))

#(define (add-firstpos-fingering music i)
 (if
           (equal? (ly:music-property music 'name) 'EventChord)
           (begin
(set! (ly:music-property music 'elements)
                 (cons
                       (make-fingering-script i)
                       (ly:music-property music 'elements)
                   ))
  )
)
music)

addFingeringX =
#(define-music-function (parser location music) (ly:music?)
   (music-map (lambda (x) (addFingeringY x)) music))

#(define (addFingeringY music)
   (if (eq? (ly:music-property music 'name) 'EventChord)
     (let* ((i (length (ly:music-property music 'elements)))
            (event (car (ly:music-property music 'elements)))
            (dur (ly:music-property event 'duration))
            (pitch (ly:music-property event 'pitch))
            (pitch-name (ly:pitch-notename pitch))
            (pitch-octave (ly:pitch-octave pitch)))
           (begin
            (if (and (= pitch-name 1) (= pitch-octave -1))
            (add-firstpos-fingering music 0))
            (if (and (= pitch-name 2) (= pitch-octave -1))
            (add-firstpos-fingering music 1))
            (if (and (= pitch-name 3) (= pitch-octave -1))
            (add-firstpos-fingering music 2))
            (if (and (= pitch-name 4) (= pitch-octave -1))
            (add-firstpos-fingering music 3))
            )
            )
       )
   music)

\score
{
  \relative c' {
  \addFingeringX { d4 e f g}
}
}

Here must be only make a scale from d to a g, but after 'f' he go down one octave for print a g.

What is happen ?
He show the corresponent fingerings, but he step in one octave.
I please for help.

Greatings, Daniel
Reply | Threaded
Open this post in threaded view
|

Re: acess to a note's pitch, using Scheme

danjiun
This post has NOT been accepted by the mailing list yet.
Hi friends.
I find a solution for the "change of octave".
It's wrong to write \relative c' before \addFingeringsX.
If i put \relative c' inside \addFingeringsX it works, like :
\score
{
  \addFingeringX {
    \relative c' {
      d4 e f g a b c d e f g a b c d
    d c b a g f e d c b a g f e d c
  }
}
}

may be if not, he not take in account previous note for a pitch, everything is respect a c'  .
I hope, this can help somebody.
Daniel