lilypond-user
[Top][All Lists]
Advanced

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

Re: How to pass an ApplyOutputEvent to a music function? (Vertical brack


From: Valentin Villenave
Subject: Re: How to pass an ApplyOutputEvent to a music function? (Vertical bracket indicating which hand should play)
Date: Sun, 10 Oct 2010 20:43:25 +0200

On Mon, Sep 27, 2010 at 1:14 PM, Valentin Villenave
<address@hidden> wrote:
> Basically, here's what I've been able to come up with: it's a dirty
> hack around the Fingering object.

New version. I'm not adding it to the LSR because I hope that
http://code.google.com/p/lilypond/issues/detail?id=1318 will be
addressed and make this kind of hacks irrelevant.


%%%%

#(define (add-bracket pos up? text music)
  (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)))
                      (set! (ly:music-property obj 'tweaks)
                            (acons 'self-alignment-Y (if up? -1 1)
                                   (acons 'text
                                          (markup #:bracketText pos up? text)
                                          (ly:music-property obj 'tweaks))))
                      obj)))))
   music))

#(define-markup-command (bracketText layout props num up? arg)
(number? boolean? markup?)
  (let* ((pos (max 3 (- 10 (- num))))
         (text (markup #:with-dimensions '(0 . 0)'(0 . 0) arg))
         (stack (lambda (x)
                   (markup #:normal-text #:fontsize 3
                           #:center-column
                           ((if up? text "")
                           #:with-dimensions
                           '(0 . .5)
                           (if up?
                               (cons 0 (+ x .2))
                               (cons (- x .2) 0))
                           #:postscript (format #f "
                             .12 setlinewidth
                             .5 0 -.5 0 lineto
                             -.5 0 -.5 ~a lineto
                             stroke" x)
                           (if up? "" text))))))
    (if (not up?) (set! pos (- pos)))
    (interpret-markup layout props (stack pos))))

#(define bracketUp
  (define-music-function (parser location music) (ly:music?)
    (let ((current-staff-position 0))
      ; this shouldn't be needed!!!
      (set! current-staff-position -4)
      (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)
         \once \override Fingering #'X-extent = #'(-2.0 . 0.0)
         $(add-bracket current-staff-position #t "m.d." music)
         $music #})))

#(define bracketDown
  (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)
         \once \override Fingering #'X-extent = #'(-2.0 . 0.0)
         $(add-bracket current-staff-position #f "m.s." music)
         $music #})))
{
  \bracketUp
  c''1
  d'
  % This bracket shouldn't be too long!
  \bracketDown
  c'
}

Valentin



reply via email to

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