Re: Catch direction operators

2020-02-27 Thread Pierre Perol-Schneider
Thank you David.

Le jeu. 27 févr. 2020 à 11:33, David Kastrup  a écrit :

> Schneidy  writes:
>
> > Hi Paul et all,
> > I'd like to get your function work with v2.19.
> > convert-ly gives the following error:
> > Expecting music, found (list (quote Slur))
> > Any idea?
>
> Use \propertyTweak rather than \tweak in the function.
>
> --
> David Kastrup
>


Re: Catch direction operators

2020-02-27 Thread David Kastrup
Schneidy  writes:

> Hi Paul et all,
> I'd like to get your function work with v2.19.
> convert-ly gives the following error: 
> Expecting music, found (list (quote Slur))
> Any idea?

Use \propertyTweak rather than \tweak in the function.

-- 
David Kastrup



Re: Catch direction operators

2020-02-27 Thread Schneidy
Hi Paul et all,
I'd like to get your function work with v2.19.
convert-ly gives the following error: 
Expecting music, found (list (quote Slur))
Any idea?
TIA, cheers,
Pierre



--
Sent from: http://lilypond.1069038.n5.nabble.com/User-f3.html



Re: Catch direction operators

2013-10-09 Thread Paul Morris
David Kastrup wrote
 Might make more sense to add it to LilyPond's own snippet base, I guess.
 Obviously, we have no limitations how new any snippets may be there.

Sounds good.


David Kastrup wrote
 Well, I try keeping the global name space uncluttered, but if you see an
 actual potential for use outside of \colorizeDir, that's certainly a
 small price to pay.

That makes sense.  I can't think of any use for it outside of \colorizeDir,
so I've changed it back to its original form in that LSR snippet.

-Paul



--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/Catch-direction-operators-tp151552p152031.html
Sent from the User mailing list archive at Nabble.com.

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-10-08 Thread Paul Morris
dak wrote
 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.

This is great!  I'd be glad to add it to the LSR.  I have the following
which shows how to use it for both all grobs and just for certain grobs.

-Paul


%% BEGIN SNIPPET %%

\version 2.17

colorizeDir =
#(define-music-function (parser location item)
   (symbol-list-or-music?)
   (define (grob-colorize-dir grob)
 (let ((ev (event-cause grob)))
   (case (and ev (ly:event-property ev 'direction))
 ((1) red)
 ((-1) blue)
 (else '()
   #{ \tweak color #grob-colorize-dir #item #})

mapList =
#(define-music-function (parser location fun lst)
   (ly:music-function? list?)
   #{ $@(map (lambda (s) #{ $fun $s #}) lst) #})


%% EXAMPLES %%

music =
{
  a2-( b)
  a^( b)
  a''_( b)

  c''-3\4-xy
  c''_3^\4^xy
  c''^3_\4_xy
}

\new Voice \with { \mapList #colorizeDir Slur.TextScript }
{ \music }

\new Voice \with { \mapList #colorizeDir #(map car all-grob-descriptions) }
{ \music }



--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/Catch-direction-operators-tp151552p151994.html
Sent from the User mailing list archive at Nabble.com.

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-10-08 Thread David Kastrup
Paul Morris p...@paulwmorris.com writes:

 dak wrote
 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.

 This is great!  I'd be glad to add it to the LSR.  I have the following
 which shows how to use it for both all grobs and just for certain grobs.

Looks fine.  \colorizeDir is not actually being used as a tweak here,
but then that makes pretty little sense anyway.

-- 
David Kastrup


___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-10-08 Thread Paul Morris
David Kastrup wrote
 Looks fine.  \colorizeDir is not actually being used as a tweak here,
 but then that makes pretty little sense anyway.

Ok, I've added it here:
http://lsr.dsi.unimi.it/LSR/Item?id=889

Since it requires 2.17 I had to comment out the whole thing, and add a
single note to get the LSR to accept it.  

I also split colorizeDir up into two parts, as shown below.  This seemed
easier to understand and avoids (re-)defining grob-colorize-dir for every
grob that gets colored.  Let me know if that's not a good call.

HTH,
-Paul


#(define (grob-colorize-dir grob)
   (let ((ev (event-cause grob)))
 (case (and ev (ly:event-property ev 'direction))
   ((1) red)
   ((-1) blue)
   (else '()

colorizeDir =
#(define-music-function (parser location item)
   (symbol-list-or-music?)
   #{ \tweak color #grob-colorize-dir #item #})



--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/Catch-direction-operators-tp151552p152012.html
Sent from the User mailing list archive at Nabble.com.

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-10-08 Thread David Kastrup
Paul Morris p...@paulwmorris.com writes:

 David Kastrup wrote
 Looks fine.  \colorizeDir is not actually being used as a tweak here,
 but then that makes pretty little sense anyway.

 Ok, I've added it here:
 http://lsr.dsi.unimi.it/LSR/Item?id=889

 Since it requires 2.17 I had to comment out the whole thing, and add a
 single note to get the LSR to accept it.

Might make more sense to add it to LilyPond's own snippet base, I guess.
Obviously, we have no limitations how new any snippets may be there.

 I also split colorizeDir up into two parts, as shown below.  This seemed
 easier to understand and avoids (re-)defining grob-colorize-dir for every
 grob that gets colored.  Let me know if that's not a good call.

Well, I try keeping the global name space uncluttered, but if you see an
actual potential for use outside of \colorizeDir, that's certainly a
small price to pay.

 #(define (grob-colorize-dir grob)
(let ((ev (event-cause grob)))
  (case (and ev (ly:event-property ev 'direction))
((1) red)
((-1) blue)
(else '()

 colorizeDir =
 #(define-music-function (parser location item)
(symbol-list-or-music?)
#{ \tweak color #grob-colorize-dir #item #})

-- 
David Kastrup


___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-10-01 Thread Urs Liska

Am 29.09.2013 17:04, schrieb David Kastrup:

\new Voice \with { \mapList #colorizeDir Slur.StringNumber.TextScript }


\new Voice \with { \mapList #colorizeDir #(map (lambda (x) (car x)) 
all-grob-descriptions) }

Adds the option of coloring all grobs with a 'direction property.

Urs

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-10-01 Thread David Kastrup
Urs Liska u...@openlilylib.org writes:

 Am 29.09.2013 17:04, schrieb David Kastrup:
 \new Voice \with { \mapList #colorizeDir Slur.StringNumber.TextScript }

 \new Voice \with { \mapList #colorizeDir #(map (lambda (x) (car x))
 all-grob-descriptions) }

 Adds the option of coloring all grobs with a 'direction property.

I cringe whenever I see something like (lambda (x) (car x)).  You are
aware that this is just an obfuscated version of car itself?

-- 
David Kastrup


___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-10-01 Thread Urs Liska

Am 01.10.2013 12:04, schrieb David Kastrup:

Urs Liska u...@openlilylib.org writes:


Am 29.09.2013 17:04, schrieb David Kastrup:

\new Voice \with { \mapList #colorizeDir Slur.StringNumber.TextScript }

\new Voice \with { \mapList #colorizeDir #(map (lambda (x) (car x))
all-grob-descriptions) }

Adds the option of coloring all grobs with a 'direction property.

I cringe whenever I see something like (lambda (x) (car x)).  You are
aware that this is just an obfuscated version of car itself?


No. But I'm ready to learn.
What I want to achieve here (with the map) is a list of all cars of 
all-grob-descriptions.


#(map (lambda (x) (car x)) all-grob-descriptions)

gives me what I want. So what would I have to do to make it cleaner/less 
obfuscated?


Urs

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-10-01 Thread Franciszek Boehlke
lambda (x) (car x) is exactly the same as car. You should be able to write
just
  #(map car all-grob-descriptions)
instead.


2013/10/1 Urs Liska u...@openlilylib.org

 Am 01.10.2013 12:04, schrieb David Kastrup:

  Urs Liska u...@openlilylib.org writes:

  Am 29.09.2013 17:04, schrieb David Kastrup:

 \new Voice \with { \mapList #colorizeDir Slur.StringNumber.TextScript }

 \new Voice \with { \mapList #colorizeDir #(map (lambda (x) (car x))
 all-grob-descriptions) }

 Adds the option of coloring all grobs with a 'direction property.

 I cringe whenever I see something like (lambda (x) (car x)).  You are
 aware that this is just an obfuscated version of car itself?

  No. But I'm ready to learn.
 What I want to achieve here (with the map) is a list of all cars of
 all-grob-descriptions.


 #(map (lambda (x) (car x)) all-grob-descriptions)

 gives me what I want. So what would I have to do to make it cleaner/less
 obfuscated?

 Urs


 __**_
 lilypond-user mailing list
 lilypond-user@gnu.org
 https://lists.gnu.org/mailman/**listinfo/lilypond-userhttps://lists.gnu.org/mailman/listinfo/lilypond-user

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-10-01 Thread Urs Liska

Am 01.10.2013 12:17, schrieb Franciszek Boehlke:
lambda (x) (car x) is exactly the same as car. You should be able to 
write just

  #(map car all-grob-descriptions)
instead.



Thanks. Now I see that it didn't _seem_ to work because I ran the wrong 
LilyPond version :-[


___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-10-01 Thread Urs Liska

Am 01.10.2013 12:19, schrieb Urs Liska:

Am 01.10.2013 12:17, schrieb Franciszek Boehlke:
lambda (x) (car x) is exactly the same as car. You should be able to 
write just

  #(map car all-grob-descriptions)
instead.



Thanks. Now I see that it didn't _seem_ to work because I ran the 
wrong LilyPond version :-[




Hi again,

sorry to have to insist on perhaps basic questions.
As it is the function now works as I want, but not in 2.16.
From the versions I have available to test it works with 2.17.6 onwards 
and not with 2.17.3 and less.

Somehow I suspect the change between 2.17.3 and .4

My best bet is that

  #{ $@(map (lambda (s) #{ $colorizeDir $s #}) debug-direction-grob-list) #})


in the mapList function is the offending piece of code.


Is there a way to write this so it compiles both with 2.16.2 and with 
current versions?
If that's not possible how would I achieve the same with 2.16.2 (I can 
do a conditional include if necessary)?



Please refer to the attached version of the function.


TIA
Urs


\version 2.17.4

% Define appearance
#(cond ((not (defined? 'debug-direction-up-color))
(define debug-direction-up-color darkgreen)))
#(cond ((not (defined? 'debug-direction-down-color))
(define debug-direction-down-color blue)))
#(cond ((not (defined? 'debug-direction-grob-list))
(define debug-direction-grob-list 
  (map car all-grob-descriptions

%%%
% Directions set with ^ and _ %
%%%

colorizeDir =
#(define-music-function (parser location item)
  (symbol-list-or-music?)
  (define (grob-colorize-dir grob)
(let ((ev (event-cause grob)))
  (case (and ev (ly:event-property ev 'direction))
  ((1) debug-direction-up-color)
  ((-1) debug-direction-down-color)
  (else '()
  #{ \tweak color #grob-colorize-dir #item #})

mapList =
#(define-music-function (parser location)()
  #{ $@(map (lambda (s) #{ $colorizeDir $s #}) debug-direction-grob-list) #})


\layout {
  \context {
\Voice
\mapList
  }
}

%%%
% Usage example
%%%

{
  a4-.( b)
  a4^( b)
  \stemUp
  a''8 g''( b)\noBeam c' \stemNeutral
  c''4-3\4-xy
  c''_3^\4^xy
  c''^3_\4_xy
  a'-. a'^.
  g'\mf g'^\mf\
  a' b'\!^\ c''
  b'\!
}
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-10-01 Thread David Kastrup
Urs Liska u...@openlilylib.org writes:

 Am 01.10.2013 12:19, schrieb Urs Liska:
 Am 01.10.2013 12:17, schrieb Franciszek Boehlke:
 lambda (x) (car x) is exactly the same as car. You should be able
 to write just
   #(map car all-grob-descriptions)
 instead.


 Thanks. Now I see that it didn't _seem_ to work because I ran the
 wrong LilyPond version :-[


 Hi again,

 sorry to have to insist on perhaps basic questions.
 As it is the function now works as I want, but not in 2.16.
 From the versions I have available to test it works with 2.17.6
 onwards and not with 2.17.3 and less.
 Somehow I suspect the change between 2.17.3 and .4

 My best bet is that

   #{ $@(map (lambda (s) #{ $colorizeDir $s #}) debug-direction-grob-list) #})


 in the mapList function is the offending piece of code.

No, that one's fine (uses 2.15.41+ functionality).  But \tweak is quite
less versatile before 2.17.6.

 Is there a way to write this so it compiles both with 2.16.2 and with
 current versions?

You'll probably need to provide your own symbol-or-music? predicate (or
symbol-list-or-music?) and then split into \override and \tweak
depending on the argument.  Or decide whether colorizeDir should do a
tweak or override, and then use it only for one of the two.

 Please refer to the attached version of the function.

Here is a rework based on the only override theory.  Quite uglier and
less versatile.  Also turns out that it barfs under 2.16.0 due to an
unsolved issue 2808, but it would appear that 2.16.1 already contains
the fix.

\version 2.16.1

% Define appearance
#(cond ((not (defined? 'debug-direction-up-color))
(define debug-direction-up-color darkgreen)))
#(cond ((not (defined? 'debug-direction-down-color))
(define debug-direction-down-color blue)))
#(cond ((not (defined? 'debug-direction-grob-list))
(define debug-direction-grob-list 
  (map car all-grob-descriptions

%%%
% Directions set with ^ and _ %
%%%

colorizeDir =
#(define-music-function (parser location item)
  (symbol?)
  (define (grob-colorize-dir grob)
(let ((ev (event-cause grob)))
  (case (and ev (ly:event-property ev 'direction))
  ((1) debug-direction-up-color)
  ((-1) debug-direction-down-color)
  (else '()
  #{ \override $(symbol-string item) #'color = #grob-colorize-dir #})

mapList =
#(define-music-function (parser location)()
  #{ $@(map (lambda (s) #{ $colorizeDir $s #}) debug-direction-grob-list) #})


\layout {
  \context {
\Voice
\mapList
  }
}

%%%
% Usage example
%%%

{
  a4-.( b)
  a4^( b)
  \stemUp
  a''8 g''( b)\noBeam c' \stemNeutral
  c''4-3\4-xy
  c''_3^\4^xy
  c''^3_\4_xy
  a'-. a'^.
  g'\mf g'^\mf\
  a' b'\!^\ c''
  b'\!
}

-- 
David Kastrup
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-09-29 Thread Urs Liska

Hi David,

Am 29.09.2013 00:36, schrieb David Nalesnik:

Hi Urs,

...

I couldn't get any results with a music function, but a little 
experimenting got me a tiny engraver which responds to the directional 
operators.  Not sure how useful this is,


It is very useful, thank you.
I


___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-09-29 Thread Urs Liska

Am 29.09.2013 09:23, schrieb Urs Liska:

Hi David,

Am 29.09.2013 00:36, schrieb David Nalesnik:

Hi Urs,

...

I couldn't get any results with a music function, but a little 
experimenting got me a tiny engraver which responds to the 
directional operators.  Not sure how useful this is,


It is very useful, thank you.
I


[edit: Sorry, accidentally hit reply]

I modified your engraver to color up and down independently and uploaded 
it to

https://github.com/openlilylib/snippets/blob/master/custom-engravers/display-directions.ly

One thing I would love to see but didn't succeed myself is making this 
work with more or all grobs that can be switched with ^ and _.


If you have an idea how to improve that please update it in the Git 
repository and not by email (if possible).


Thanks
Urs
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-09-29 Thread David Kastrup
David Nalesnik david.nales...@gmail.com writes:

 Hi Urs,


 On Sat, Sep 28, 2013 at 12:13 PM, Urs Liska u...@openlilylib.org wrote:

 Hi,

 I have a 'function' that redefines commands like \slurUp to color the
 corresponding grob (highlighting manual interventions during score
 development).

 Is it possible to 'catch' instances of grobs whose direction has been set
 by the ^ and _ operators and call a music function on the affected object.
 I'd like to write

 a^(

 and as a result get

 \once \override Slur #'color = red
 a^(

 Any ideas?


 I couldn't get any results with a music function, but a little
 experimenting got me a tiny engraver which responds to the directional
 operators.  Not sure how useful this is, but here goes:

 \version 2.17.25

 #(define (Color_explicit_direction_engraver ctx)
 (make-engraver
  (acknowledgers
   ((slur-interface trans grob source)
(let* ((event (event-cause grob))
   (dir (ly:event-property event 'direction)))
  (if (not (null? dir))
  (set! (ly:grob-property grob 'color) red)))

 \new Staff {
   c''^(
   d'')
   c''(
   d'')
   c''_(
   d'')
   c'' e''^(
   d'' f'')
 }

 \layout {
   \context {
 \Staff
 \consists #Color_explicit_direction_engraver
   }
 }

Well, that triggers the it's easier to manipulate grobs than music
expression complaint of Harm.

Now actually, in this case the simplest and most versatile course to me
seems like using _neither_ an engraver _nor_ a music expression
manipulation.  Instead something like

colorizeDir =
#(define-music-function (parser location item)
  (symbol-list-or-music?)
  (define (grob-colorize-dir grob)
(let ((ev (event-cause grob)))
  (and ev (ly:event-property ev 'direction #f)
  red)))
  #{ \tweak color #grob-colorize-dir #item #})

\new Staff \with { \colorizeDir Slur } {
  c''^(
  d'')
  c''(
  d'')
  \undo \colorizeDir Staff.Slur
  c''_(
  d'')
  c'' e''-\once \colorizeDir ^(
  d'' f'')
}

It's easy to use on multiple grob types, individual music expressions
and other stuff.

-- 
David Kastrup
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-09-29 Thread David Kastrup
David Kastrup d...@gnu.org writes:

 colorizeDir =
 #(define-music-function (parser location item)
   (symbol-list-or-music?)
   (define (grob-colorize-dir grob)
 (let ((ev (event-cause grob)))
   (and ev (ly:event-property ev 'direction #f)
   red)))
   #{ \tweak color #grob-colorize-dir #item #})

Not everything might be prepared to deal with a color #f, so it may be
safer to write the slightly more complex

(if (and ev (ly:event-property ev 'direction #f))
red '())

expression inside.

-- 
David Kastrup


___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-09-29 Thread Urs Liska

Hi David,

this is great!

Am 29.09.2013 09:51, schrieb David Kastrup:

David Kastrup d...@gnu.org writes:


colorizeDir =
#(define-music-function (parser location item)
   (symbol-list-or-music?)
   (define (grob-colorize-dir grob)
 (let ((ev (event-cause grob)))
   (and ev (ly:event-property ev 'direction #f)
   red)))
   #{ \tweak color #grob-colorize-dir #item #})

Not everything might be prepared to deal with a color #f, so it may be
safer to write the slightly more complex

(if (and ev (ly:event-property ev 'direction #f))
 red '())

expression inside.

Could you please explain to me (or give a few hints) what this last 
(and) expression does exactly?

I would like to extend this to treat up/down independently


I tried to modify it as follows:

colorizeDir =

#(define-music-function (parser location item)

  (symbol-list-or-music?)

  (define (grob-colorize-dir grob)

(let ((ev (event-cause grob)))

  (if (and ev (ly:event-property ev 'direction #f))

  (cond ((equal? 'direction 1) red)

((equal? 'direction -1) blue))

  '(

  #{ \tweak color #grob-colorize-dir #item #})


and hoped if would work like this:
if we are dealing with the right grob, and this grob has a 'direction then
execute the 'cond' expression and assign grob-colorize-dir 'red' or 
'blue' depending on the 'direction being 1 or -1



It compiles without complaints but doesn't color anything.
So I assume that either the if expression or both cond expressions 
return false.



TIA
Urs

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-09-29 Thread David Kastrup
Urs Liska u...@openlilylib.org writes:

 Hi David,

 this is great!

 Am 29.09.2013 09:51, schrieb David Kastrup:
 David Kastrup d...@gnu.org writes:

 colorizeDir =
 #(define-music-function (parser location item)
(symbol-list-or-music?)
(define (grob-colorize-dir grob)
  (let ((ev (event-cause grob)))
(and ev (ly:event-property ev 'direction #f)
red)))
#{ \tweak color #grob-colorize-dir #item #})
 Not everything might be prepared to deal with a color #f, so it may be
 safer to write the slightly more complex

 (if (and ev (ly:event-property ev 'direction #f))
  red '())

 expression inside.

 Could you please explain to me (or give a few hints) what this last
 (and) expression does exactly?

if ev is non-#f and the property with the name 'direction in ev is
non-#f (while considering an unset direction as defaulting to #f), then
red is returned, otherwise '().

 I would like to extend this to treat up/down independently


 I tried to modify it as follows:

 colorizeDir =

 #(define-music-function (parser location item)

   (symbol-list-or-music?)

   (define (grob-colorize-dir grob)

 (let ((ev (event-cause grob)))

   (if (and ev (ly:event-property ev 'direction #f))

   (cond ((equal? 'direction 1) red)

The symbol 'direction is a symbol and never equal to a number.  You
forgot to look up the property, instead comparing with the _name_ of the
property.

Any reason for the double-spacing here?  It's a nuisance to quote and
comment on.

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 #})

-- 
David Kastrup


___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-09-29 Thread Urs Liska




David Kastrup d...@gnu.org schrieb:
Urs Liska u...@openlilylib.org writes:

 Hi David,

 this is great!

 Am 29.09.2013 09:51, schrieb David Kastrup:
 David Kastrup d...@gnu.org writes:

 colorizeDir =
 #(define-music-function (parser location item)
(symbol-list-or-music?)
(define (grob-colorize-dir grob)
  (let ((ev (event-cause grob)))
(and ev (ly:event-property ev 'direction #f)
red)))
#{ \tweak color #grob-colorize-dir #item #})
 Not everything might be prepared to deal with a color #f, so it may
be
 safer to write the slightly more complex

 (if (and ev (ly:event-property ev 'direction #f))
  red '())

 expression inside.

 Could you please explain to me (or give a few hints) what this last
 (and) expression does exactly?

if ev is non-#f and the property with the name 'direction in ev is
non-#f (while considering an unset direction as defaulting to #f), then
red is returned, otherwise '().

Ok, that's how I understood it (seems I'm slowly getting into the topic).


 I would like to extend this to treat up/down independently


 I tried to modify it as follows:

 colorizeDir =

 #(define-music-function (parser location item)

   (symbol-list-or-music?)

   (define (grob-colorize-dir grob)

 (let ((ev (event-cause grob)))

   (if (and ev (ly:event-property ev 'direction #f))

   (cond ((equal? 'direction 1) red)

The symbol 'direction is a symbol and never equal to a number.  You
forgot to look up the property, instead comparing with the _name_ of
the
property.

Any reason for the double-spacing here?  

No idea how that happened. Before sending the message looked completely normal.

 It's a nuisance to quote and
comment on.

Sorry!


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?
Of course we can attribute it to you, and you can review it before release if 
you want.

Best
Urs


___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-09-29 Thread David Kastrup
Urs Liska u...@openlilylib.org 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

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-09-29 Thread MING TSANG
I was following the caption subject in lily user list.I run the following (copy 
from the lists).  I got error, please see the log at the end of lily code.
Thanks,
Ming

%lily code starts %
\version 2.17.27
colorizeDir =
#(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 #})
\new Staff \with { \colorizeDir Slur } {
c''^(
d'')
c''(
d'')
\undo \colorizeDir Staff.Slur
c''_(
d'')
c'' e''-\once \colorizeDir ^(
d'' f'')
}
% lily code ends %%


log file messAGE:
Starting lilypond-windows.exe 2.17.27 [Untitled (2)]...
Processing 
`c:/users/tsang/appdata/local/temp/frescobaldi-ylykff/tmpad4njh/document.ly'
Parsing...
c:/users/tsang/appdata/local/temp/frescobaldi-ylykff/tmpad4njh/document.ly:12:5:
 error: GUILE signaled an error for the expression beginning here
#
{ \tweak color #grob-colorize-dir #item #})
c:/users/tsang/appdata/local/temp/frescobaldi-ylykff/tmpad4njh/document.ly:12:21:
 error: GUILE signaled an error for the expression beginning here
#{ \tweak color #
grob-colorize-dir #item #})
c:/users/tsang/appdata/local/temp/frescobaldi-ylykff/tmpad4njh/document.ly:12:40:
 error: GUILE signaled an error for the expression beginning here
#{ \tweak color #grob-colorize-dir #
item #})
c:/users/tsang/appdata/local/temp/frescobaldi-ylykff/tmpad4njh/document.ly:12:39:
 error: wrong type for argument 3.  Expecting symbol list or music, found 
#unspecified
#{ \tweak color #grob-colorize-dir 
#item #})
c:/users/tsang/appdata/local/temp/frescobaldi-ylykff/tmpad4njh/document.ly:12:46:
 error: GUILE signaled an error for the expression beginning here
#{ \tweak color #grob-colorize-dir #item #
})
c:/users/tsang/appdata/local/temp/frescobaldi-ylykff/tmpad4njh/document.ly:12:47:
 error: syntax error, unexpected EVENT_IDENTIFIER
#{ \tweak color #grob-colorize-dir #item #}
)
Unbound variable: {
Unbound variable: grob-colorize-dir
Unbound variable: item
Unbound variable: }
C:/Users/Tsang/Dropbox/LilyPond/usr/share/lilypond/current/scm/ly-syntax-constructors.scm:56:23:
 In procedure memoization in expression (apply (ly:music-function-extract fun) 
parser ...):
C:/Users/Tsang/Dropbox/LilyPond/usr/share/lilypond/current/scm/ly-syntax-constructors.scm:56:23:
 Missing body expression in ((define (grob-colorize-dir grob) (let ((ev 
(event-cause grob))) (case (ly:event-property ev (quote direction)) ((1) red) 
((-1) blue) (else (quote ())).
Exited with return code 1.___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-09-29 Thread David Nalesnik
Hi Ming,


On Sun, Sep 29, 2013 at 8:37 AM, MING TSANG tsan...@rogers.com wrote:

 I was following the caption subject in lily user list. I run the
 following (copy from the lists).  I got error, please see the log at the
 end of lily code.
 Thanks,
 Ming

 %lily code starts %
 \version 2.17.27
 colorizeDir =
 #(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)


Remove one of the parentheses at the end of this line:


 (else '())


[...]

--David
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-09-29 Thread Thomas Morley
2013/9/29 David Kastrup d...@gnu.org:
 Urs Liska u...@openlilylib.org 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

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-09-29 Thread David Kastrup
Thomas Morley thomasmorle...@gmail.com writes:

You can write:
colorizeDir =
#(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.

 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.

Here is a generalization:

colorizeDir =
#(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 #})

mapList =
#(define-music-function (parser location fun lst)
  (ly:music-function? list?)
  #{ $@(map (lambda (s) #{ $fun $s #}) lst) #})

\new Voice \with { \mapList #colorizeDir Slur.StringNumber.TextScript }
{
a4-( b)
a4^( b)
a''4_( b)

c''-3\4-xy
c''_3^\4^xy
c''^3_\4_xy
}


-- 
David Kastrup
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-09-29 Thread David Kastrup
David Kastrup d...@gnu.org writes:

 Thomas Morley thomasmorle...@gmail.com writes:

You can write:
colorizeDir =
#(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.

Actually, it's oversimplified.  It has to have

(case (and ev (ly:event-property ev 'direction))

or it will bomb out in the cases of coloring grobs not traceable to a
music event.

-- 
David Kastrup


___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-09-29 Thread MING TSANG
David Nalesnik,
Thank you.  By reading the log message, I cannot decipher what it means.
Emanuel,
Ming



 From: David Nalesnik david.nales...@gmail.com
To: MING TSANG tsan...@rogers.com 
Cc: lilypond-user@gnu.org lilypond-user@gnu.org 
Sent: Sunday, September 29, 2013 9:43:59 AM
Subject: Re: Catch direction operators
 


Hi Ming,



On Sun, Sep 29, 2013 at 8:37 AM, MING TSANG tsan...@rogers.com wrote:

I was following the caption subject in lily user list.I run the following (copy 
from the lists).  I got error, please see the log at the end of lily code.
Thanks,
Ming


%lily code starts %
\version 2.17.27
colorizeDir =
#(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)

Remove one of the parentheses at the end of this line:
 
(else '())

[...] 

--David ___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Catch direction operators

2013-09-28 Thread David Nalesnik
Hi Urs,


On Sat, Sep 28, 2013 at 12:13 PM, Urs Liska u...@openlilylib.org wrote:

 Hi,

 I have a 'function' that redefines commands like \slurUp to color the
 corresponding grob (highlighting manual interventions during score
 development).

 Is it possible to 'catch' instances of grobs whose direction has been set
 by the ^ and _ operators and call a music function on the affected object.
 I'd like to write

 a^(

 and as a result get

 \once \override Slur #'color = red
 a^(

 Any ideas?


I couldn't get any results with a music function, but a little
experimenting got me a tiny engraver which responds to the directional
operators.  Not sure how useful this is, but here goes:

\version 2.17.25

#(define (Color_explicit_direction_engraver ctx)
(make-engraver
 (acknowledgers
  ((slur-interface trans grob source)
   (let* ((event (event-cause grob))
  (dir (ly:event-property event 'direction)))
 (if (not (null? dir))
 (set! (ly:grob-property grob 'color) red)))

\new Staff {
  c''^(
  d'')
  c''(
  d'')
  c''_(
  d'')
  c'' e''^(
  d'' f'')
}

\layout {
  \context {
\Staff
\consists #Color_explicit_direction_engraver
  }
}


%%%

HTH,
David
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user