Neil Puttock schrieb:
2009/5/9 Marc Hohl <m...@hohlart.de>:
I tried to receive the informations needed by overriding the Glissando
#'stencil with
a function which simply displays the values obtained by the ly:spanner-bound
call
before calling ly:line-spanner::print, but I get only #<Grob NoteHead > on
the terminal.
What am I doing wrong here?
Nothing, though to be on the safe side, it's best to ensure you're
dealing with the unbroken spanner by using ly:grob-original: if a user
decides to have a glissando over a line break, it won't be possible to
get noteheads for both bounds.
Once you have the NoteHead grobs, you can retrieve their pitches from
the events which created them:
Neil, thank you, I wasn't aware of this connection between grobs and events.
Now it seems rather logical (not surprising as we talk about computing
languages :-)
\relative c' {
\override NoteHead #'stencil = #(lambda (grob)
;; event-cause is a convenient shorthand in this case for
(ly:grob-property grob 'cause)
(display (event-cause grob))
(ly:note-head::print grob))
c4
}
#<Prob: Stream_event C++: Stream_event((music-cause . #<Prob: Music
C++: Music((length . #<Mom 1/4>) (elements) (duration . #<Duration 4
) (pitch . #<Pitch c' >) (origin . #<location
/home/neil/Documents/test.ly:254:5>))((display-methods #<procedure #f
(note parser)>) (name . NoteEvent) (types general-music event
note-event rhythmic-event melodic-event)) >
) (length . #<Mom 1/4>) (elements) (duration . #<Duration 4 >) (pitch
. #<Pitch c' >) (origin . #<location
/home/neil/Documents/test.ly:254:5>))((class . note-event)) >
>From the event, you can get the pitch using ly:event-property event 'pitch.
Putting it all together:
#(define (glissando::calc-extra-dy grob)
(let* ((original (ly:grob-original grob))
(left-bound (ly:spanner-bound original LEFT))
(right-bound (ly:spanner-bound original RIGHT))
(left-pitch (ly:event-property (event-cause left-bound) 'pitch))
(right-pitch (ly:event-property (event-cause right-bound) 'pitch)))
;; work out return value based on pitches here
I came up with the following definition:
#(define (glissando::calc-extra-dy grob)
(let* ((original (ly:grob-original grob))
(left-bound (ly:spanner-bound original LEFT))
(right-bound (ly:spanner-bound original RIGHT))
(left-pitch (ly:event-property (event-cause left-bound) 'pitch))
(right-pitch (ly:event-property (event-cause right-bound) 'pitch))
(extra-dy
(if (and (= (ly:pitch-octave left-pitch) (ly:pitch-octave
right-pitch))
(= (ly:pitch-notename left-pitch)
(ly:pitch-notename right-pitch)))
(- (ly:pitch-alteration right-pitch)
(ly:pitch-alteration left-pitch))
0 )))
(set! (ly:grob-property grob 'extra-dy) extra-dy)
(ly:line-spanner::print grob)))
noten = \relative c {
c4 \glissando cis
c4 \glissando cis
c4 \glissando ces
c4 \glissando ces
c4 \glissando d \glissando e \glissando f
}
\score {
<<
\new Staff { \clef "G_8"
\noten \break
\override Glissando #'stencil = #glissando::calc-extra-dy
\noten}
>>
}
and it works! Lilypond is just great; the deeper I get into it, the more
impressed I am.
So I will try and solve the tablature problem, too.
Marc
0))
Regards,
Neil
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-user