Han-Wen Nienhuys <[EMAIL PROTECTED]> writes: > [EMAIL PROTECTED] writes:
>> The code in molecule-hacking.ly for adding parentheses is, umm, >> non-intuitive. Can you provide a function, say, \parenthesize (or a >> scheme equivalent) which does this? > That's an interesting idea. It could be done with an \applyoutput call > that inspects the current print-callback and adds the override. I've been trying to write a \parenthesize function, but can't find a satisfying solution. Here is what I have come to: -------------------- parenthesize.ly ---------------------- \version "2.3.12" #(define (parenthesize-print-function print-function) (lambda (grob) (let* ((fn (ly:get-default-font grob)) (callback (ly:grob-property grob 'print-function)) (pclose (ly:find-glyph-by-name fn "accidentals-rightparen")) (popen (ly:find-glyph-by-name fn "accidentals-leftparen")) (subject (print-function grob)) ;; remember old size (subject-dim-x (ly:stencil-extent subject 0)) (subject-dim-y (ly:stencil-extent subject 1))) ;; add parens (set! subject (ly:stencil-combine-at-edge (ly:stencil-combine-at-edge subject 0 1 pclose 0.2) 0 -1 popen 0.2)) ;; revert old size. (ly:stencil-set-extent! subject 0 subject-dim-x) (ly:stencil-set-extent! subject 1 subject-dim-y) subject))) parenthesizeA=#(def-music-function (location grob-type music) (symbol? ly:music?) "Adds parenthesize around the grobs of type `grob-type' in `music'. A shortcut for (if applied to NoteHeads): \\applyoutput #(lambda (grob origin context) (if (eqv? 'NoteHead (cdr (assoc 'name (ly:grob-property grob 'meta)))) (set! (ly:grob-property grob 'print-function) (parenthesize-print-function (ly:grob-property grob 'print-function))) ..music.. " (make-sequential-music (list (make-music 'ApplyOutputEvent 'procedure (lambda (grob origin context) (if (eqv? grob-type (cdr (assoc 'name (ly:grob-property grob 'meta)))) ;; [1] (set! (ly:grob-property grob 'print-function) (parenthesize-print-function (ly:grob-property grob 'print-function)))))) music))) parenthesizeB=#(def-music-function (location grob-type music) (symbol? ly:music?) "Adds parenthesize around the grobs of type `grob-type' in `music'. A shortcut for (if applied to NoteHeads): \\override 'NoteHead #'print-function = (parenthesize-print-function Note_Head::print) ..music.. \\revert 'NoteHead #'print-function " (make-sequential-music (list (make-music 'ContextSpeccedMusic 'context-type 'Bottom 'element (make-music 'OverrideProperty 'pop-first #t 'grob-property 'print-function 'grob-value (parenthesize-print-function ;; [2] (cdr (assoc 'print-function (cdr (assoc grob-type all-grob-descriptions))))) 'symbol grob-type)) music (make-music 'ContextSpeccedMusic 'context-type 'Bottom 'element (make-music 'RevertProperty 'grob-property 'print-function 'symbol grob-type))))) \relative c' { c \parenthesizeA #'NoteHead { d e } \parenthesizeB #'NoteHead { f g } } -------------------- parenthesize.ly ---------------------- I have a few questions: 1) Why, with \parenthesizeA which uses an \applyoutput, only the first "d" note is parenthesized, and not the second? 2) If I remove the first "c" note, a warning occurs and the first \parenthesizeA has no effect. 3) In [1], I would like to test if the current grob has the given type. It seems that the idiomatic way to conditionaly apply an output function on a specific grob type is to test if MY-GROB-TYPE-interface is a member of (ly:grob-property grob 'interfaces). Is there a way get 'note-head-interface from 'NoteHead, for instance? I guess that a specialized NoteHead, with an other name metafield, would not satisfy test [1]... 4) In [2], I would like to get the 'print-function of a grob of the given type. Something like: (ly:grob-property (make-grob grob-type) 'print-function) or: (default-grob-property grob-type 'print-function) Is there a better/prefered way to do this? 5) Which one, between \parenthesizeA, using \applyoutput, or \parenthesizeB, with \override of print-function, would be better? 6) If one try: \parenthesizeB #'DynamicText { c\p } one get the following warning: programming error: Stencil::moved_to_edge: adding empty stencil. twice. I'm not sure I understand the internals of the parenthesize-print-function procedure. nicolas _______________________________________________ lilypond-devel mailing list [EMAIL PROTECTED] http://lists.gnu.org/mailman/listinfo/lilypond-devel