lilypond-user
[Top][All Lists]
Advanced

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

Re: missing glissando features (bugs?)


From: Marc Hohl
Subject: Re: missing glissando features (bugs?)
Date: Sun, 10 May 2009 22:37:20 +0200
User-agent: Thunderbird 2.0.0.21 (X11/20090318)

Marc Hohl schrieb:
Neil Puttock schrieb:
2009/5/9 Marc Hohl <address@hidden>:

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.

And here's my solution for tablature:

#(define (glissando::calc-tab-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))
(left-staff-position (ly:grob-property left-bound 'staff-position)) (right-staff-position (ly:grob-property right-bound 'staff-position))
         (extra-dy
            (if (and (= left-staff-position right-staff-position)
                     (ly:pitch<? right-pitch left-pitch))
                -1
1 ))) ;; I don't know why, but "0" doesn't work properly in tablature, compare glissando::calc-extra-dy
         (set! (ly:grob-property grob 'extra-dy) extra-dy)
         (ly:line-spanner::print grob)))

tabs = \relative c {
  \set TabStaff.minimumFret = #2
  c4 \glissando d \glissando c2
  c4 \glissando d \glissando c2
  c'4 \glissando d \glissando e, \glissando f
  \bar "|."
}

\score {
  <<
     \new TabStaff { \clef "tab" \tabs
                     \break
\override Glissando #'stencil = #glissando::calc-tab-extra-dy
                     \tabs }
  >>
}


     0))

Regards,
Neil




_______________________________________________
lilypond-user mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/lilypond-user






reply via email to

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