[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Passing the result of an ApplyOutputEvent to a music-function
From: |
Valentin Villenave |
Subject: |
Passing the result of an ApplyOutputEvent to a music-function |
Date: |
Tue, 28 Sep 2010 21:07:58 +0200 |
Greetings everybody,
I've asked this question on -user but I suspect it got lost in the
flow. (Besides, it *might* belong on -devel since I'm actually trying
to implement a missing feature, see for instance
http://lists.gnu.org/archive/html/lilypond-user/2008-08/msg00903.html ).
What I'm trying to achieve is a shortcut for brackets commonly found
in piano scores, that indicate which hand should play a particular
note (see attached).
Basically, here's what I've been able to come up with: it's a dirty
hack around the Fingering object.
lhBracket =
#(define-music-function (parser location music) (ly:music?)
(let ((current-staff-position #f))
; this shouldn't be needed!!!
(set! current-staff-position 1)
(make-music 'ApplyOutputEvent
'origin location
'context-type 'Voice
'procedure
(lambda (grob grob-origin context)
(let ((staff-pos (ly:grob-property grob 'staff-position)))
(if (number? staff-pos)
(set! current-staff-position staff-pos)))))
#{ \once \set fingeringOrientations = #'(left)
$(add-bracket current-staff-position music "l.h.")
$music #}))
#(define (add-bracket pos music text)
(if
(equal? (ly:music-property music 'name) 'EventChord)
(let ((note (car (ly:music-property music 'elements))))
(set! (ly:music-property note 'articulations)
(append (ly:music-property note 'articulations)
(list
(let ((obj (make-music 'FingeringEvent))
(bracket-length (- (* pos -0.5) 7))
(v-space (/ (+ 7 pos) 7.0)))
(set! (ly:music-property obj 'tweaks)
(acons 'self-alignment-Y 1
(acons 'text (markup #:normal-text #:fontsize 3
#:center-column (
#:postscript (format #f "
.5 0 -.5 0 lineto
-.5 0 -.5 ~a lineto
stroke" bracket-length)
#:vspace v-space
#:with-dimensions '(0 . 0) '(0 . 0)
#:center-align text
))
(ly:music-property obj 'tweaks))))
obj))))
)))
{
\lhBracket
c''1
d'
% This bracket shouldn't be too long!
\lhBracket
c'
}
It works well, but the bracket's length isn't computed automatically.
This would depend on the notehead's staff-position, which I can
retrieve using an ApplyOutputEvent, but I suspect by then the
music-function has already been evaluated, and therefore the
current-staff-position property isn't updated.
Ideally, perhaps it would be best as a post-fix command (but I can't
see how to do it without creating a whole new engraver -- which I
suspect might actually be the way to go anyway).
(Of course, the bracket length algorithm should also be improved and
the vspace hack is dirty as hell, but you get the picture.)
I hope someone can help!
Cheers,
Valentin
toto.png
Description: PNG image
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Passing the result of an ApplyOutputEvent to a music-function,
Valentin Villenave <=