[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Catch direction operators
From: |
Thomas Morley |
Subject: |
Re: Catch direction operators |
Date: |
Sun, 29 Sep 2013 16:40:22 +0200 |
2013/9/29 David Kastrup <address@hidden>:
> Urs Liska <address@hidden> writes:
>
>>>You can write:
>>>
>>>#(define-music-function (parser location item)
>>> (symbol-list-or-music?)
>>> (define (grob-colorize-dir grob)
>>> (let ((ev (event-cause grob)))
>>> (case (ly:event-property ev 'direction)
>>> ((1) red)
>>> ((-1) blue)
>>> (else '())))))
>>> #{ \tweak color #grob-colorize-dir #item #})
>>
>> Thanks, this works perfectly.
>>
>> I would like to add this to a Frescobaldi addition and later (once
>> 2.18 is out) to a LilyPond addition proposal. Do you have any
>> objections?
>
> You can add it wherever you want. I don't see it making any sense as an
> addition to LilyPond proper as it is a rather special use case. It may
> still be nice as a snippet as it is simple, flexible, and powerful. The
> use cases also show \tweak as an internal workhorse for both tweaks and
> overrides.
>
> As a snippet, it makes sense _in_ 2.18 as it illustrates current
> programming techniques.
>
> --
> David Kastrup
Hi,
I thought it would be nice to apply such a function to not only one
grob, but rather a list of grobs or all possible grobs.
Though, I didn't manage to generalize David K's tweak-function.
Instead I come up with the code below.
Frankly, I now have the problem that I don't know how to revert it in
a music-expression or how to apply it once. :(
\version "2.17.26"
%#(define highlighting-colors `(,(rgb-color 0 1 1) ,(x11-color 'SlateBlue2)))
#(cond ((not (defined? 'highlighting-colors))
(define highlighting-colors `(,red ,green))))
#(define grob-colorize-dir
(lambda (grob)
(let* ((ev (event-cause grob))
(color (if (ly:prob? ev)
(case (ly:event-property ev 'direction)
((1) (car highlighting-colors))
((-1) (cadr highlighting-colors))
(else '()))
'())))
(ly:grob-set-property! grob 'color color))))
#(define (apply-colored-if-changed l)
(let* ((grobs-copy all-grob-descriptions)
(grobs-to-consider
(cond ((eq? l 'all-grobs)
grobs-copy)
((symbol? l)
(list (assoc l grobs-copy)))
((list? l)
(map
(lambda (grob)
(assoc grob grobs-copy))
l))
(else '()))))
(lambda (context)
(let loop ((x grobs-to-consider))
(if (not (null? x))
(let ((grob-name (caar x)))
(ly:context-pushpop-property
context
grob-name
;; TODO: Go for 'color directly?
'after-line-breaking
grob-colorize-dir)
(loop (cdr x))))))))
colorChanges =
#(define-music-function (parser location s-or-l)
(symbol-list-or-symbol?)
#{
\applyContext #(apply-colored-if-changed s-or-l)
#})
%%%%%%%%%%%%%%%
% EXAMPLE
%%%%%%%%%%%%%%%
\layout {
\context {
\Voice
%% possible use-cases:
%\colorChanges #'all-grobs
\colorChanges #'(Slur StringNumber TextScript)
%\colorChanges #'Slur
}
}
{
a4-( b)
a4^( b)
a''4_( b)
c''-3\4-"xy"
c''_3^\4^"xy"
c''^3_\4_"xy"
}
Nevertheless, hth
Harm
- Catch direction operators, Urs Liska, 2013/09/28
- Re: Catch direction operators, David Nalesnik, 2013/09/28
- Re: Catch direction operators, Urs Liska, 2013/09/29
- Re: Catch direction operators, David Kastrup, 2013/09/29
- Re: Catch direction operators, David Kastrup, 2013/09/29
- Re: Catch direction operators, Urs Liska, 2013/09/29
- Re: Catch direction operators, David Kastrup, 2013/09/29
- Re: Catch direction operators, Urs Liska, 2013/09/29
- Re: Catch direction operators, David Kastrup, 2013/09/29
- Re: Catch direction operators,
Thomas Morley <=
- Re: Catch direction operators, David Kastrup, 2013/09/29
- Re: Catch direction operators, David Kastrup, 2013/09/29