[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to pass an ApplyOutputEvent to a music function? (Vertical bracket i
From: |
Valentin Villenave |
Subject: |
How to pass an ApplyOutputEvent to a music function? (Vertical bracket indicating which hand should play) |
Date: |
Mon, 27 Sep 2010 13:14:52 +0200 |
Greetings everybody,
(Neil: please forgive me for directly Ccing you, but your input is
always of such great help to me :)
I'm trying to address a question that's sometimes asked on the list:
http://lists.gnu.org/archive/html/lilypond-user/2008-08/msg00903.html
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 0))
; 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.
(Of course, the bracket length algorithm should also be improved and
the vspace hack is dirty as hell, but you get the picture.)
I suspect a solution would be to code a whole engraver in Scheme, but
I still am kinda new to this :-(
I hope someone can help!
Cheers,
Valentin
toto.png
Description: PNG image
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- How to pass an ApplyOutputEvent to a music function? (Vertical bracket indicating which hand should play),
Valentin Villenave <=