Re: \parenthesize and optional arguments
On 4 July 2015 at 17:17, David Kastrup wrote: > You are thinking of LilyPond/Scheme as a procedural language here. (begin ( … ) ( … ) ( … ) ( … ) ( … ) ( … ) ( … )) Oops :-) Vaughan ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: \parenthesize and optional arguments
Marc Hohl writes: > Now I got > > \version "2.19.20" > > lparenthesize = > #(define-music-function (arg) (ly:music?) >(_i "Tag @var{arg} to be left parenthesized.) >(if (memq 'event-chord (ly:music-property arg 'types)) >;; arg is an EventChord -> set the parenthesize property >;; on all child notes and rests >(for-each > (lambda (ev) > (if (or (memq 'note-event (ly:music-property ev 'types)) > (memq 'rest-event (ly:music-property ev 'types))) > (set! (ly:music-property ev 'parenthesize) #t))) > (ly:music-property arg 'elements)) >;; No chord, simply set property for this expression: >(set! (ly:music-property arg 'parenthesize) #t)) > > #{ \tweak ParenthesesItem.stencils #(lambda (grob) > (let ((par-list (parentheses-item::calc-parenthesis-stencils > grob))) > (list (car par-list) point-stencil))) #arg #}) > > > { \parenthesize c } > > which results in an error message that I don't understand: > > Lilypond parenthesize.ly > GNU LilyPond 2.19.23 > »parenthesize.ly« wird verarbeitet > Analysieren... > parenthesize.ly:4:2: Fehler: GUILE signalisierte einen Fehler für den > hier beginnenden Ausdruck > # > (define-music-function (arg) (ly:music?) > parenthesize.ly:23:5: illegal character in escape sequence: #\p > parenthesize.ly:4:2: Fehler: syntax error, unexpected EVENT_IDENTIFIER > # > (define-music-function (arg) (ly:music?) > parenthesize.ly:23:4: Fehler: EOF innerhalb einer Zeichenkette gefunden > { \ >parenthesize c } > schwerer Fehler: gescheiterte Dateien: "parenthesize.ly" > > I remember getting such error messages in combination with some > unbalanced parentheses, but my editor tells me that this is not the > case here :-( Reread the penultimate error message (the last one with an error location). The other error messages are merely lead-up errors. Your parentheses don't balance, by the way. If I tell _my_ editor M-x check-parens RET, it flags the problematic location _exactly_. -- David Kastrup ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: \parenthesize and optional arguments
Am 04.07.2015 um 10:08 schrieb David Kastrup: [...] Well, I'm not enthusiastic about both code and interface. What about \version "2.19.20" #(define (set-paren-property arg) (if (memq 'event-chord (ly:music-property arg 'types)) ;; arg is an EventChord -> set the parenthesize property ;; on all child notes and rests (for-each (lambda (ev) (if (or (memq 'note-event (ly:music-property ev 'types)) (memq 'rest-event (ly:music-property ev 'types))) (set! (ly:music-property ev 'parenthesize) #t))) (ly:music-property arg 'elements)) ;; No chord, simply set property for this expression: (set! (ly:music-property arg 'parenthesize) #t))) lparenthesize = #(define-music-function (arg) (ly:music?) (_i "Tag @var{arg} to be left parenthesized.") (set-paren-property arg) #{ \tweak ParenthesesItem.stencils #(lambda (grob) (let ((par-list (parentheses-item::calc-parenthesis-stencils grob))) (list (car par-list) point-stencil))) #arg #}) rparenthesize = #(define-music-function (arg) (ly:music?) (_i "Tag @var{arg} to be right parenthesized.") (set-paren-property arg) #{ \tweak ParenthesesItem.stencils #(lambda (grob) (let ((par-list (parentheses-item::calc-parenthesis-stencils grob))) (list point-stencil (cadr par-list #arg #}) { \parenthesize c \lparenthesize d \rparenthesize e c-\parenthesize-1 d-\lparenthesize-2 e-\rparenthesize-3} I'd define set-paren-property globally at a appropriate place, rewrite the definition of \parenthesize using set-paren-property and add \[l|r]parenthesize. Would that warrant a patch? Cheers, Marc ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: \parenthesize and optional arguments
Am 04.07.2015 um 11:12 schrieb Marc Hohl: [...] I remember getting such error messages in combination with some unbalanced parentheses, but my editor tells me that this is not the case here :-( Found it! It was "unbalanced '"'s in the doc string here! Marc ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: \parenthesize and optional arguments
Am 04.07.2015 um 10:08 schrieb David Kastrup: [...] Well, I'm not enthusiastic about both code and interface. The problem with the code is that { c'8-\parenthesize-1 [ f'8] } will no longer compile. Ah, I see. The first reason for that is that one-paren parenthesize will not work for any articulation and/or post-event. You really should try to turn this into tweaks rather than an override. Otherwise it will be impossible anyway to parenthesize more than one thing differently at one time step. And of course the second reason is that -1 is no longer interpreted as a fingering here but rather as a direction indicator. Which changes the entire meaning. Of course. So I discarded the "optional argument" idea and went for \lparenthesize and \rparenthesize in combination with tweak. Now I got \version "2.19.20" lparenthesize = #(define-music-function (arg) (ly:music?) (_i "Tag @var{arg} to be left parenthesized.) (if (memq 'event-chord (ly:music-property arg 'types)) ;; arg is an EventChord -> set the parenthesize property ;; on all child notes and rests (for-each (lambda (ev) (if (or (memq 'note-event (ly:music-property ev 'types)) (memq 'rest-event (ly:music-property ev 'types))) (set! (ly:music-property ev 'parenthesize) #t))) (ly:music-property arg 'elements)) ;; No chord, simply set property for this expression: (set! (ly:music-property arg 'parenthesize) #t)) #{ \tweak ParenthesesItem.stencils #(lambda (grob) (let ((par-list (parentheses-item::calc-parenthesis-stencils grob))) (list (car par-list) point-stencil))) #arg #}) { \parenthesize c } which results in an error message that I don't understand: Lilypond parenthesize.ly GNU LilyPond 2.19.23 »parenthesize.ly« wird verarbeitet Analysieren... parenthesize.ly:4:2: Fehler: GUILE signalisierte einen Fehler für den hier beginnenden Ausdruck # (define-music-function (arg) (ly:music?) parenthesize.ly:23:5: illegal character in escape sequence: #\p parenthesize.ly:4:2: Fehler: syntax error, unexpected EVENT_IDENTIFIER # (define-music-function (arg) (ly:music?) parenthesize.ly:23:4: Fehler: EOF innerhalb einer Zeichenkette gefunden { \ parenthesize c } schwerer Fehler: gescheiterte Dateien: "parenthesize.ly" I remember getting such error messages in combination with some unbalanced parentheses, but my editor tells me that this is not the case here :-( Marc ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: \parenthesize and optional arguments
Marc Hohl writes: > \version "2.19.20" > > parenthesize = > #(define-music-function (dir arg) ((number? 0) ly:music?) >(_i "Tag @var{arg} to be parenthesized. @arg{dir} is optional and may be >set to @code{#LEFT} or @code{#RIGHT} for left/right parentheses only.") > >(if (memq 'event-chord (ly:music-property arg 'types)) >;; arg is an EventChord -> set the parenthesize property >;; on all child notes and rests >(for-each > (lambda (ev) > (if (or (memq 'note-event (ly:music-property ev 'types)) > (memq 'rest-event (ly:music-property ev 'types))) > (set! (ly:music-property ev 'parenthesize) #t))) > (ly:music-property arg 'elements)) >;; No chord, simply set property for this expression: >(set! (ly:music-property arg 'parenthesize) #t)) > >(case dir > ((-1) #{ \once\override ParenthesesItem.stencils = > #(lambda (grob) >(let ((par-list > (parentheses-item::calc-parenthesis-stencils grob))) >(list (car par-list) point-stencil ))) #arg #}) > ((1) #{ \once \override ParenthesesItem.stencils = >#(lambda (grob) > (let ((par-list > (parentheses-item::calc-parenthesis-stencils grob))) > (list point-stencil (cadr par-list #arg #}) > (else #{ #arg #}))) > > { \parenthesize c \parenthesize #LEFT d \parenthesize #RIGHT e} > > Would it make sense to enhance the parenthesize function like this, i.e. > create a patch for this? Well, I'm not enthusiastic about both code and interface. The problem with the code is that { c'8-\parenthesize-1 [ f'8] } will no longer compile. The first reason for that is that one-paren parenthesize will not work for any articulation and/or post-event. You really should try to turn this into tweaks rather than an override. Otherwise it will be impossible anyway to parenthesize more than one thing differently at one time step. And of course the second reason is that -1 is no longer interpreted as a fingering here but rather as a direction indicator. Which changes the entire meaning. -- David Kastrup ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: \parenthesize and optional arguments
Am 04.07.2015 um 09:17 schrieb David Kastrup: [...] You are thinking of LilyPond/Scheme as a procedural language here. What happens here is that you calculate a suitable override and, well, throw it away. The return value of this function, calculated later as "arg", does not care what you have calculated here. ... thanks a lot for the explanations (I forgot that in the first reply). [...] Any pointers in the right direction are highly appreciated! #UP (which is Lilypond-speak for +1). ;-) Marc ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: \parenthesize and optional arguments
Am 04.07.2015 um 09:17 schrieb David Kastrup: [...] You are thinking of LilyPond/Scheme as a procedural language here. What happens here is that you calculate a suitable override and, well, throw it away. The return value of this function, calculated later as "arg", does not care what you have calculated here. Ah, ok. Yes, I had the opinion that the override is something globally inserted and executed before Lilypond places 'arg'. Any pointers in the right direction are highly appreciated! #UP (which is Lilypond-speak for +1). Ok, it looks like this now: \version "2.19.20" parenthesize = #(define-music-function (dir arg) ((number? 0) ly:music?) (_i "Tag @var{arg} to be parenthesized. @arg{dir} is optional and may be set to @code{#LEFT} or @code{#RIGHT} for left/right parentheses only.") (if (memq 'event-chord (ly:music-property arg 'types)) ;; arg is an EventChord -> set the parenthesize property ;; on all child notes and rests (for-each (lambda (ev) (if (or (memq 'note-event (ly:music-property ev 'types)) (memq 'rest-event (ly:music-property ev 'types))) (set! (ly:music-property ev 'parenthesize) #t))) (ly:music-property arg 'elements)) ;; No chord, simply set property for this expression: (set! (ly:music-property arg 'parenthesize) #t)) (case dir ((-1) #{ \once\override ParenthesesItem.stencils = #(lambda (grob) (let ((par-list (parentheses-item::calc-parenthesis-stencils grob))) (list (car par-list) point-stencil ))) #arg #}) ((1) #{ \once \override ParenthesesItem.stencils = #(lambda (grob) (let ((par-list (parentheses-item::calc-parenthesis-stencils grob))) (list point-stencil (cadr par-list #arg #}) (else #{ #arg #}))) { \parenthesize c \parenthesize #LEFT d \parenthesize #RIGHT e} Would it make sense to enhance the parenthesize function like this, i.e. create a patch for this? Cheers, Marc ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: \parenthesize and optional arguments
Marc Hohl writes: > my scheme-fu is a bit rusty, so I tried to get a new start > by enhancing the parenthesize function defined in > ly/music-functions-init.ly with the code to be found in > > http://lsr.di.unimi.it/LSR/Snippet?id=902 > > Here is what I have so far: > > \version "2.19.20" > > parenthesize = > #(define-music-function (dir arg) ((number? 0) ly:music?) >(_i "Tag @var{arg} to be parenthesized. @arg{dir} is optional and may be >set to @code{#LEFT} or @code{#RIGHT} for left/right parentheses only.") > >(display dir) >(case dir > ((-1) #{ \once\override ParenthesesItem.stencils = #(lambda (grob) >(let ((par-list > (parentheses-item::calc-parenthesis-stencils grob))) > (list (car par-list) > point-stencil ))) #}) > ((1) #{ \once \override ParenthesesItem.stencils = #(lambda (grob) >(let ((par-list > (parentheses-item::calc-parenthesis-stencils grob))) > (list point-stencil (cadr > par-list #}) ) You are thinking of LilyPond/Scheme as a procedural language here. What happens here is that you calculate a suitable override and, well, throw it away. The return value of this function, calculated later as "arg", does not care what you have calculated here. It's probably better to switch this around with the below (imperative, namely using side effects) calculation of arg and then write #{ \once \override ... #arg #} in order to get the arg in after all. Don't forget an "else" branch returning only the unchanged arg. >(if (memq 'event-chord (ly:music-property arg 'types)) >;; arg is an EventChord -> set the parenthesize property >;; on all child notes and rests >(for-each > (lambda (ev) > (if (or (memq 'note-event (ly:music-property ev 'types)) > (memq 'rest-event (ly:music-property ev 'types))) > (set! (ly:music-property ev 'parenthesize) #t))) > (ly:music-property arg 'elements)) >;; No chord, simply set property for this expression: >(set! (ly:music-property arg 'parenthesize) #t)) > >arg) > > { \parenthesize c \parenthesize #LEFT d \parenthesize #RIGHT e} > > > It seems as if the \override does not have any effect, though, > but I don't understand why. Because you don't put it in the result of the music function. > Any pointers in the right direction are highly appreciated! #UP (which is Lilypond-speak for +1). -- David Kastrup ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user