Re: improving Janek's \dynamic function (for combo dynamics)

2019-09-15 Thread Kieren MacMillan
Hi Harm,

> sorry for the late reply.

No worries!

> You likely mean this thread:
> http://lilypond.1069038.n5.nabble.com/improving-Janek-s-dynamic-function-for-combo-dynamics-td205071.html

Yes — sorry I didn’t link.

> I hardly find time to work with or on LilyPond these days.

Our loss.  =)

> Attached you'll find the file which I used for some serious
> typesetting work (thus the file-name).
> Not sure how much it goes beyond what I already had posted.

A little… and that little is quite helpful!

>> 2. How can I eliminate the resulting grob from quoted material? The normal 
>> attempts (e.g., \omit DynamicText) don’t seem to work all the time.
> Could you post a minimal?

Will do, the moment I’ve got this commission out the door!  =)

> The spacing between dynamic and normal text could be set in the attached file 
> with
> DynamicText.details.outer-x-space

Great!

> Not sure what you mean with your last question. Could you give an example?

Well, for example, dynamic f and p have different kerning needs, because of how 
far over to the right the top of the f hangs; I’d like to be able to 
(?auto-)adjust the kerning before/after a given dynamic text. When I find a 
really obviously example, I’ll get back to you — for now, this improved version 
is great.

Thanks!
Kieren.


Kieren MacMillan, composer (he/him/his)
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: improving Janek's \dynamic function (for combo dynamics)

2019-09-15 Thread Thomas Morley
Hi Kieren,

sorry for the late reply.

Am So., 8. Sept. 2019 um 21:29 Uhr schrieb Kieren MacMillan
:
>
> Hi Harm,
>
> Three questions on this [seemingly-ancient!] thread about your (wonderful) 
> "dynamics on the fly" function:

You likely mean this thread:
http://lilypond.1069038.n5.nabble.com/improving-Janek-s-dynamic-function-for-combo-dynamics-td205071.html

>
> 1. Have you, as you implied might happen, found better ways to do the same 
> thing(s) in light of recent development efforts in the basecode?

As you may have imagined from the delayed response I hardly find time
to work with or on LilyPond these days.
Attached you'll find the file which I used for some serious
typesetting work (thus the file-name).
Not sure how much it goes beyond what I already had posted.
But it contains no really new approach.
There are explanations in the file, mostly in the comments in \layout
of the example and in the doc-string of `dynamicH´

>
> 2. How can I eliminate the resulting grob from quoted material? The normal 
> attempts (e.g., \omit DynamicText) don’t seem to work all the time.

Could you post a minimal?

>
> 3. When the custom dynamic consists of a dynamic text and normal text, I’d 
> like to add a tiny bit more space/padding between them. Where in the function 
> can I do this? And would it be possible to adjust the kerning depending on 
> which dynamic text is present?

The spacing between dynamic and normal text could be set in the
attached file with
DynamicText.details.outer-x-space

Not sure what you mean with your last question. Could you give an example?


I general I'm not sure when I'll find the time to look at it again.
But you never know ...

Best,
  Harm
 written for 2.19.65


%% To test the example below uncomment:
%\include "etym-III-scheme.ly"

#(define (note-column::main-extent grob)
"Return extent of the noteheads in the 'main column', (i.e. excluding any
suspended noteheads), or extent of the rest (if there are no heads)."
  (let* ((note-heads (ly:grob-object grob 'note-heads))
 (stem (ly:grob-object grob 'stem))
 (rest (ly:grob-object grob 'rest)))
(cond ((ly:grob-array? note-heads)
   (let (;; get the cdr from all note-heads-extents, where the car
 ;; is zero
 (n-h-right-coords
   (filter-map
 (lambda (n-h)
   (let ((ext (ly:grob-extent n-h grob X)))
  (and (= (car ext) 0) (cdr ext
 (ly:grob-array->list note-heads
 ;; better be paranoid, find the max of n-h-right-coords and return
 ;; a pair with (cons 0 )
 (cons 0.0 (reduce max 0 n-h-right-coords
  ((ly:grob? rest)
   (ly:grob-extent rest grob X))
  ;; better be paranoid
  (else '(0 . 0)
  
#(define remove-empty
  ;; Remove empty strings and empty lists from the given list 'lst'
  (lambda (lst)
(remove
  (lambda (e)
(or
  (and (string? e) (string-null? e))
  (and (list? e) (null? e
  lst)))
  
#(define char-set:dynamics
  (char-set #\f #\m #\p #\r #\s #\z))


 DynamicText, created on the fly

 Reads
  DynamicText.details.separator-pair
  DynamicText.details.dyn-rest-font-sizes
  DynamicText.details.markup-commands
  DynamicText.details.inner-x-space
  DynamicText.details.outer-x-space


#(use-modules (srfi srfi-11))
#(use-modules (ice-9 regex))

#(define (make-reg-exp separator-pair)
  (format #f "\\~a[^~a~a]*\\~a"
(car separator-pair)
(car separator-pair)
(cdr separator-pair)
(cdr separator-pair)))

#(define (dynamics-list separator-pair strg)
  (let ((reg-exp (make-reg-exp separator-pair))
(separators (char-set (car separator-pair) (cdr separator-pair
(map
  (lambda (s)
(let* ((match (string-match reg-exp s)))
   (if match
   (let* ((poss-dyn (match:substring match))
  (cand (string-trim-both poss-dyn separators)))
 (if (string-every char-set:dynamics cand)
   (list
 (match:prefix match)
 cand
 (match:suffix match))
 s))
   s)))
  (string-split strg #\space

#(define (dynamic-text::format-text
   fontsizes inner-kern outer-kern text-markup-command lst)
  (let* ((mrkp-cmnd
   (lambda (arg) (make-normal-text-markup (text-markup-command arg
 (txt-font-size (if (pair? fontsizes) (cdr fontsizes) #f))
 (txt-mrkp-cmnd
   (lambda (txt)
 (if (number? txt-font-size)
 (make-fontsize-markup txt-font-size (mrkp-cmnd txt))
 (mrkp-cmnd txt
 (left-out (if (pair? outer-kern) (car outer-kern) #f))
 (left-inner (if (pair? 

Re: improving Janek's \dynamic function (for combo dynamics)

2019-09-08 Thread Kieren MacMillan
Hi Harm,

Three questions on this [seemingly-ancient!] thread about your (wonderful) 
"dynamics on the fly" function:

1. Have you, as you implied might happen, found better ways to do the same 
thing(s) in light of recent development efforts in the basecode?

2. How can I eliminate the resulting grob from quoted material? The normal 
attempts (e.g., \omit DynamicText) don’t seem to work all the time.

3. When the custom dynamic consists of a dynamic text and normal text, I’d like 
to add a tiny bit more space/padding between them. Where in the function can I 
do this? And would it be possible to adjust the kerning depending on which 
dynamic text is present?

Thanks!
Kieren.


Kieren MacMillan, composer (he/him/his)
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-13 Thread Kieren MacMillan
Hi Harm,

> Well, it's a sketch of an idea.
> Elaborating it will blow up the amount of needed code again.
> Right now, predicting any performance of a possible final state is not 
> possible.

Understood.

> At least I'd expect no need for string searching/selection
> and at least less list-selections.

That's what I was thinking…

> Not sure what you mean with above.

Me neither, in retrospect. Please ignore it.

Cheers,
Kieren.


Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-12 Thread Thomas Morley
2017-09-12 21:58 GMT+02:00 Kieren MacMillan :
> Hi Harm,
>
> Is
>
> \dynamicH "text only"
>
> (or something like that) supposed to work?

Well, it did work in a previous version. So it's a regression.

Thanks spotting it.

For a quick fix, change here:

#(define (get-list-parts lst dyn-indices idx)
;; Relying on @var{idx}, which selects from @var{dyn-indices} return a new
;; list containing sublists with stuff before the selected dynamic, the
;; dynamic itself and stuff after the dynamic.
  (if (null? dyn-indices)
-  (list '() '() '())
+  (list lst '() '())

Not sure whether it's the best fix, though.
Will need to test.

Cheers,
  Harm

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-12 Thread Thomas Morley
2017-09-12 2:03 GMT+02:00 Kieren MacMillan :
> Harm,
>
>> A very first shot.
>
> You never cease to amaze me!
>
> 1. Is this, speed-wise, any more or less efficient [e.g., on very large 
> scores with lots of combo dynamics] than your other approach?

Well, it's a sketch of an idea.
Elaborating it will blow up the amount of needed code again.

Right now, predicting any performance of a possible final state is not
possible. At least I'd expect no need for string searching/selection
and at least less list-selections.

> 2. If it's [much] more efficient, how easily can the 
> "center-align-on-dynamic" be implemented? Given that the dynamic is already 
> separated (by virtue of the construction), and we (or at least I) almost 
> always want the horizontal spacing engine to ignore the final combined grob,

Not sure what you mean with above.

> can one just "tack on" the markup to the [already aligned] dynamic, rather 
> than combining and then attaching [center-aligned]?

Currently I've no idea, will think about it.

Cheers,
  Harm

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-12 Thread Thomas Morley
2017-09-12 13:57 GMT+02:00 Kieren MacMillan :
> Hi David,
>
>>> 1. Is this, speed-wise, any more or less efficient [e.g., on very
>>> large scores with lots of combo dynamics] than your other approach?
>>
>> So much for:
>>
 No security, no conditions, don't use it for typesetting serious
 stuff, just an idea:
>>
>> Throwing out stuff is just dangerous...
>
> Why?
>
> As requested (warned), I'm not using it for typesetting serious stuff…
>
> Why can't Harm throw out stuff — and/or why can't I ask questions about it?
>
> Kieren.


Well, my code was more the sketch of an idea.
Currently it will break very fast, making it safe will be some serious
work and will extend the amount of needed code.
Also, I'm not sure if it's the best idea ...

The risk is that someone will use it, disregarding the warnings, ok,
this would be on own risk. But someone else may read that code and
take it for own work without even noticing that the was a warning.
Next time I'll post something like that on the user-list I'll probably
hardcode a printed markup (or a headersetting) inside the code
emphasizing the warning.
If someone is able to remove that from the code, it's more likely
he/she notices the weaknesses as well.

Cheers,
  Harm

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-12 Thread Thomas Morley
2017-09-12 10:08 GMT+02:00 David Kastrup :
> Thomas Morley  writes:
>
>> 2017-09-12 1:23 GMT+02:00 Kieren MacMillan :
>>> Hi Harm,
>>>
 you could already use 'details.markup-commands
 to add space to _both_ sides of a dynamic:
>>>
>>> um… Which version does this require? With 2.19.65, I get
>>>
>>> error: syntax error, unexpected '='
>>> \markup customize-dyn
>>>   =
>>
>> Ah, sorry.
>
> Ugh.  I'm not finished with the \repeat mess (actually, with wrapping my
> head around it to properly begin), but this may be relevant enough to
> make another 2.20 prerelease anyway.

Now that I actually used it, I fully get aware _how_ great this stuff is.

In any case I'd like to see it in 2.20.
Another prerelease with it would probably gets us more feedback, so I
vote for it.

Cheers,
  Harm

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-12 Thread Thomas Morley
2017-09-12 9:25 GMT+02:00 David Kastrup :
> Thomas Morley  writes:
>
>> 2017-09-10 14:43 GMT+02:00 David Kastrup :
>>
>>> More like a nightmare.  Some markup expression with some \etc somewhere
>>> in the middle?  How many arguments is it supposed to stand for?  And
>>> which markup command is it supposed to complete?  And when is the
>>> definition supposed to be complete when \etc is not necessarily the last
>>> part?
>>>
>>> And here you put \etc in a position where it could replace an arbitrary
>>> number of markups, but my-concat magically does not get a markup list as
>>> its argument but a single markup?
>>>
>>> This is solidly "do what I mean, not what I say" realm, and computers
>>> have nothing to go by but what you say.
>>
>>
>> Yeah, I do understand the programmers point of view, at least enough
>> to get the nightmare.
>> But from a user's perspective is "do what I mean, not what I say"
>> still sort of a dream. ;)
>
> Hey, it's not like I am bad at making naïve expectations work.

Indeed !!

> If you
> take a look at the recently committed issue 5181, it's probably good for
> making a good amount of stuff "just work" as expected that previously
> led to a lot of Scheme programming and list help.  It's such a biggie
> that I haven't felt up to doing regtests, documentation of the feature,
> and undocumentation of having to work around its non-existence.  Well,
> I started with the undocumentation in issue 5192 but there is a whole
> lot else to do.
>
> But your \etc example?  Too many inconsistencies.  One would to need to
> break it down into indivual elements, see how any of them can be cast
> into a framework, throw out those that don't fit and come up with
> something that covers enough ground to make some sense.  And then you'll
> still have people asking why their attempts of hand-waving at an
> interface designed for hand-waving does not work and explain to them
> just what hand angles they can expect to use for what result.

Understood.

Cheers,
  Harm

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-12 Thread Kieren MacMillan
Hi Harm,

Is

\dynamicH "text only"

(or something like that) supposed to work? I know I could use 
#(make-dynamic-script …) to define a dynamic without any real dynamic font/text 
in it — and that's what I'll do in the short-term — but I'd prefer a single 
interface for all dynamics, if it's not too difficult.

Thanks,
Kieren.


Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-12 Thread Kieren MacMillan
Hi David,

>> 1. Is this, speed-wise, any more or less efficient [e.g., on very
>> large scores with lots of combo dynamics] than your other approach?
> 
> So much for:
> 
>>> No security, no conditions, don't use it for typesetting serious
>>> stuff, just an idea:
> 
> Throwing out stuff is just dangerous...

Why?

As requested (warned), I'm not using it for typesetting serious stuff…

Why can't Harm throw out stuff — and/or why can't I ask questions about it?

Kieren.


Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-12 Thread David Kastrup
Thomas Morley  writes:

> 2017-09-12 1:23 GMT+02:00 Kieren MacMillan :
>> Hi Harm,
>>
>>> you could already use 'details.markup-commands
>>> to add space to _both_ sides of a dynamic:
>>
>> um… Which version does this require? With 2.19.65, I get
>>
>> error: syntax error, unexpected '='
>> \markup customize-dyn
>>   =
>
> Ah, sorry.

Ugh.  I'm not finished with the \repeat mess (actually, with wrapping my
head around it to properly begin), but this may be relevant enough to
make another 2.20 prerelease anyway.

-- 
David Kastrup

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-12 Thread David Kastrup
Kieren MacMillan  writes:

> Harm,
>
>> A very first shot.
>
> You never cease to amaze me!
>
> 1. Is this, speed-wise, any more or less efficient [e.g., on very
> large scores with lots of combo dynamics] than your other approach?

So much for:

>> No security, no conditions, don't use it for typesetting serious
>> stuff, just an idea:

Throwing out stuff is just dangerous...

-- 
David Kastrup

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-12 Thread David Kastrup
Thomas Morley  writes:

> 2017-09-10 14:43 GMT+02:00 David Kastrup :
>
>> More like a nightmare.  Some markup expression with some \etc somewhere
>> in the middle?  How many arguments is it supposed to stand for?  And
>> which markup command is it supposed to complete?  And when is the
>> definition supposed to be complete when \etc is not necessarily the last
>> part?
>>
>> And here you put \etc in a position where it could replace an arbitrary
>> number of markups, but my-concat magically does not get a markup list as
>> its argument but a single markup?
>>
>> This is solidly "do what I mean, not what I say" realm, and computers
>> have nothing to go by but what you say.
>
>
> Yeah, I do understand the programmers point of view, at least enough
> to get the nightmare.
> But from a user's perspective is "do what I mean, not what I say"
> still sort of a dream. ;)

Hey, it's not like I am bad at making naïve expectations work.  If you
take a look at the recently committed issue 5181, it's probably good for
making a good amount of stuff "just work" as expected that previously
led to a lot of Scheme programming and list help.  It's such a biggie
that I haven't felt up to doing regtests, documentation of the feature,
and undocumentation of having to work around its non-existence.  Well,
I started with the undocumentation in issue 5192 but there is a whole
lot else to do.

But your \etc example?  Too many inconsistencies.  One would to need to
break it down into indivual elements, see how any of them can be cast
into a framework, throw out those that don't fit and come up with
something that covers enough ground to make some sense.  And then you'll
still have people asking why their attempts of hand-waving at an
interface designed for hand-waving does not work and explain to them
just what hand angles they can expect to use for what result.

Yes, it's likely that one can extend \etc usage in some manner.  But we
won't likely read the stage where people jot down just anything
including \etc and have it do what they expect.

-- 
David Kastrup

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-11 Thread Kieren MacMillan
Hi Harm,

> Ah, sorry.
> The syntax needs next release. I'm on current master, i.e. 2.21.0.

Cool.

> Below should work:

It does.

Many thanks!!
Kieren.


Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-11 Thread Kieren MacMillan
Harm,

> A very first shot.

You never cease to amaze me!

1. Is this, speed-wise, any more or less efficient [e.g., on very large scores 
with lots of combo dynamics] than your other approach?

2. If it's [much] more efficient, how easily can the "center-align-on-dynamic" 
be implemented? Given that the dynamic is already separated (by virtue of the 
construction), and we (or at least I) almost always want the horizontal spacing 
engine to ignore the final combined grob, can one just "tack on" the markup to 
the [already aligned] dynamic, rather than combining and then attaching 
[center-aligned]?

Thanks,
Kieren.


Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-11 Thread Thomas Morley
2017-09-10 14:43 GMT+02:00 David Kastrup :
> Thomas Morley  writes:
>
>> 2017-09-03 18:30 GMT+02:00 Thomas Morley :
>>
>>> I think I know how to proceed,
>>
>> @Kieren
>> Attached the newest and heavily revised version.
>> Please read comments for usage.
>>
>> @David
>> For one example I use predefined markup-commands like
>>   \markup with-red = \markup \with-color #red \etc
>>
>> I seem to remember there was some even simpler possibility.
>
> That is the simpler possibility.  Or rather, the most straightforward
> one.

Ah, ok.

> The previous suggestion was to use
>
> with-red-markup = \markup \with-color #red \etc
>
> (?) but that would not have created a make-with-red-markup convenience
> function and/or made (markup #:with-red ...) do anything useful.

And I wanted to use make-with-red-markup ...

>> Btw,
>> \markup my-concat = \markup \concat { \etc "!" }
>> \markup \my-concat "foo"
>> fails, no surprise, just a dream ...
>
> More like a nightmare.  Some markup expression with some \etc somewhere
> in the middle?  How many arguments is it supposed to stand for?  And
> which markup command is it supposed to complete?  And when is the
> definition supposed to be complete when \etc is not necessarily the last
> part?
>
> And here you put \etc in a position where it could replace an arbitrary
> number of markups, but my-concat magically does not get a markup list as
> its argument but a single markup?
>
> This is solidly "do what I mean, not what I say" realm, and computers
> have nothing to go by but what you say.


Yeah, I do understand the programmers point of view, at least enough
to get the nightmare.
But from a user's perspective is "do what I mean, not what I say"
still sort of a dream. ;)

Thanks,
  Harm

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-11 Thread Thomas Morley
2017-09-12 1:23 GMT+02:00 Kieren MacMillan :
> Hi Harm,
>
>> you could already use 'details.markup-commands
>> to add space to _both_ sides of a dynamic:
>
> um… Which version does this require? With 2.19.65, I get
>
> error: syntax error, unexpected '='
> \markup customize-dyn
>   =

Ah, sorry.
The syntax needs next release. I'm on current master, i.e. 2.21.0.

Below should work:

\score {
  \new Staff {
c''1\dynamicH ##t 1 "text before {p} text after"
c''1\dynamicH ##t 1 "text before {p}"
c''1\dynamicH ##t 1 "text before {p}!"
  }
  \layout {
\override DynamicText.details.markup-commands =
  #(cons
(lambda (arg)
  (make-pad-x-markup 2
(make-dynamic-markup arg)))
make-italic-markup)
%% inserted to demonstrate a problem
\override DynamicText.after-line-breaking =
  #(lambda (grob)
(ly:grob-set-property! grob 'stencil
  (box-stencil
(ly:grob-property grob 'stencil)
0 0)))
ragged-right = ##f
indent = 0
  }
}

Cheers,
  Harm

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-11 Thread Kieren MacMillan
Hi Harm,

> you could already use 'details.markup-commands
> to add space to _both_ sides of a dynamic:

um… Which version does this require? With 2.19.65, I get

error: syntax error, unexpected '='
\markup customize-dyn 
  =

> Though, this gives sufficient output only if the dynamic
> is in the middle of the expression.

>95% of the time, it's at the beginning.

I'll play around and see what pops out.

Thanks!
Kieren.


Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-11 Thread Thomas Morley
2017-09-12 0:03 GMT+02:00 Thomas Morley :
> Hi Xavier,
>
> 2017-09-11 22:05 GMT+02:00 Xavier Scheuer :
>> Thank you Thomas for working on this.
>>
>> Personally I came recently to think that "Doing The Right Thing™"
>> would be to have on option to **align** texts on dynamics.
>>
>> Something like
>>
>>   \override TextScript.align-on-simultaneous-dynamic = ##t
>>
>> and then
>>
>>   c'1\mp_\markup \italic "dolce"  % would give "mp dolce"
>>
>> We could even have an option to place text right or left from dynamics
>
> Well, I would need to do some tests.
> Reading out DynamicText and TextScript and joining them into a single
> expression for DynamicText.
> Probably not impossible ...

A very first shot.
No security, no conditions, don't use it for typesetting serious
stuff, just an idea:

#(define merge-dyn-txt
  (lambda (grob)
(let* ((nc (ly:grob-parent grob X))
   (pap-col (ly:item-get-column grob))
   (elts-array (ly:grob-object pap-col 'elements))
   (elts
 (if (ly:grob-array? elts-array)
 (ly:grob-array->list elts-array)
 '()))
   (dyn
 (filter
   (lambda (d)
 (grob::has-interface d 'dynamic-text-interface)
 )
   elts))
   (txt-scrpt
 (filter
   (lambda (txt)
 (eq? (grob::name txt) 'TextScript))
   elts)))
(ly:grob-set-property! (car txt-scrpt) 'stencil #f)
(grob-interpret-markup grob
  (make-line-markup
(list
  (ly:grob-property (car dyn) 'text)
  (make-normal-text-markup
(ly:grob-property (car txt-scrpt) 'text

foo =
\once \override DynamicText.stencil = #merge-dyn-txt

{
  \foo
  c'1\mp_\markup \italic "dolce"
  d'-\tweak stencil #merge-dyn-txt \-\markup \italic "barbaro"
}

Have fun, lol,
  Ham

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-11 Thread Thomas Morley
Hi Xavier,

2017-09-11 22:05 GMT+02:00 Xavier Scheuer :
> Thank you Thomas for working on this.
>
> Personally I came recently to think that "Doing The Right Thing™"
> would be to have on option to **align** texts on dynamics.
>
> Something like
>
>   \override TextScript.align-on-simultaneous-dynamic = ##t
>
> and then
>
>   c'1\mp_\markup \italic "dolce"  % would give "mp dolce"
>
> We could even have an option to place text right or left from dynamics

Well, I would need to do some tests.
Reading out DynamicText and TextScript and joining them into a single
expression for DynamicText.
Probably not impossible ...

> or also decouple texts from dynamics if desired.

Here I'm not that confident, though

>
> I'm dreaming.

Nothing to say against it, as long as you're aware about the
difference to reality LOL

Though, I'll follow current route for now. Please remind me in case
current coding approach has boiled down to something real usable to
have a closer look at your proposal above.

And please continue with feed back. I highly appreciate it !!


Cheers,
  Harm

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-11 Thread Thomas Morley
2017-09-11 18:08 GMT+02:00 Kieren MacMillan :

> One new question: Is there an easy way to increase the kerning between a 
> dynamic and any non-dynamic text that follows it? (I find the current space 
> just a little narrow.) I looked through the code to try to find the right 
> place to add a small \hspace, but couldn't find it. (Obviously, changing the 
> list-splitting " " to "  " adds space between *every* chunk, which isn't what 
> I want.)

Well, you could already use 'details.markup-commands to add space to
_both_ sides of a dynamic:

\markup customize-dyn =
  \markup \pad-x #2 \dynamic \etc

\markup with-red =
  \markup \with-color #red \etc

\score {
  \new Staff {
c''1\dynamicH ##t 1 "text before {p} text after"
c''1\dynamicH ##t 1 "text before {p}"
c''1\dynamicH ##t 1 "text before {p}!"
  }
  \layout {
\override DynamicText.details.markup-commands =
  #(cons make-customize-dyn-markup make-italic-markup)
%% inserted to demonstrate a problem
\override DynamicText.after-line-breaking =
  #(lambda (grob)
(ly:grob-set-property! grob 'stencil
  (box-stencil
(ly:grob-property grob 'stencil)
0 0)))
ragged-right = ##f
  }
}


Though, this gives sufficient output only if the dynamic is in the
middle of the expression.
Being at the end, unwanted space is added (I made this visible by
overriding 'after-line-breaking)
-> second example
If punctuation is used probably unwanted space is added as well.
-> third example


Neverheless I'm pretty confident to find a better solution.
Probably by introducing other subproperties to 'details, called/used
under certain conditions.

Cheers,
  Harm

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-11 Thread Kieren MacMillan
Hi Xavier,

> Personally I came recently to think that "Doing The Right Thing™"
> would be to have on option to **align** texts on dynamics.
> 
> Something like
> 
>   \override TextScript.align-on-simultaneous-dynamic = ##t
> 
> and then
> 
>   c'1\mp_\markup \italic "dolce"  % would give "mp dolce"

o_O

Wow. Harm's [amazing] function solves many *other* problems that your suggested 
implementation probably doesn't/can't… But for 95% (or probably more) of the 
real-world situations, your suggestion is a stunningly elegant solution to the 
problem, at least in terms of UI. (Of course, getting Lily to actually *do* 
what you're suggesting might be frighteningly difficult!)

Thanks,
Kieren.


Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-11 Thread Xavier Scheuer
Thank you Thomas for working on this.

Personally I came recently to think that "Doing The Right Thing™"
would be to have on option to **align** texts on dynamics.

Something like

  \override TextScript.align-on-simultaneous-dynamic = ##t

and then

  c'1\mp_\markup \italic "dolce"  % would give "mp dolce"

We could even have an option to place text right or left from dynamics
or also decouple texts from dynamics if desired.

I'm dreaming.

Anyway I'll probably use the function developed as soon as I have a
released version with it implemented and if I can find how to use it
in the documentation.

So thanks everyone.

Cheers,
Xavier


On 29 August 2017 at 22:31, Kieren MacMillan 
wrote:
>
> Hi Xavier,
>
> > For correct alignment of "dynamic + text" (or "text + dynamic") I used
> > to rely on Graham's "make-dynamic-extra" function, which worked well.
>
> It's hardly perfect, though — for example, the dynamic isn't centred
correctly here:
>
> %%%  SNIPPET BEGINS
> \version "2.19.64"
> #(define (make-dynamic-extra dynamic string)
>  (make-music
>'AbsoluteDynamicEvent
>'tweaks
>  ;; calculate centering for text
>  (list (cons (quote X-offset)
>(+ -0.5 (* -0.5 (string-length dynamic)
>'text
>  (markup #:whiteout
>#:line (
>dynamic
>#:hspace 0.5
>#:normal-text #:italic string))
>   ))
>
> test = #(make-dynamic-extra "fmf" "dolce")
>
> { a1\test }
> %%%  SNIPPET ENDS
>
> > Is your new \dynamic function an improved version of this?
> > And what does it add more?
>
> I'm hoping this conversation ends with us having a function that will
truly Do The Right Thing™, in all reasonable situations.
>
> Cheers,
> Kieren.
> 
>
> Kieren MacMillan, composer
> ‣ website: www.kierenmacmillan.info
> ‣ email: i...@kierenmacmillan.info
>



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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-11 Thread Kieren MacMillan
Hi Harm,

I've had a chance to test some of this new code… and it seems to be working 
great! Thank you so much for your amazing work. I'll keep testing and get back 
to you.

One new question: Is there an easy way to increase the kerning between a 
dynamic and any non-dynamic text that follows it? (I find the current space 
just a little narrow.) I looked through the code to try to find the right place 
to add a small \hspace, but couldn't find it. (Obviously, changing the 
list-splitting " " to "  " adds space between *every* chunk, which isn't what I 
want.)

Thanks,
Kieren.


Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-10 Thread David Kastrup
Thomas Morley  writes:

> 2017-09-03 18:30 GMT+02:00 Thomas Morley :
>
>> I think I know how to proceed,
>
> @Kieren
> Attached the newest and heavily revised version.
> Please read comments for usage.
>
> @David
> For one example I use predefined markup-commands like
>   \markup with-red = \markup \with-color #red \etc
>
> I seem to remember there was some even simpler possibility.

That is the simpler possibility.  Or rather, the most straightforward
one.

The previous suggestion was to use

with-red-markup = \markup \with-color #red \etc

(?) but that would not have created a make-with-red-markup convenience
function and/or made (markup #:with-red ...) do anything useful.

> Btw,
> \markup my-concat = \markup \concat { \etc "!" }
> \markup \my-concat "foo"
> fails, no surprise, just a dream ...

More like a nightmare.  Some markup expression with some \etc somewhere
in the middle?  How many arguments is it supposed to stand for?  And
which markup command is it supposed to complete?  And when is the
definition supposed to be complete when \etc is not necessarily the last
part?

And here you put \etc in a position where it could replace an arbitrary
number of markups, but my-concat magically does not get a markup list as
its argument but a single markup?

This is solidly "do what I mean, not what I say" realm, and computers
have nothing to go by but what you say.

-- 
David Kastrup

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-10 Thread Thomas Morley
2017-09-03 18:30 GMT+02:00 Thomas Morley :

> I think I know how to proceed,

@Kieren
Attached the newest and heavily revised version.
Please read comments for usage.

@David
For one example I use predefined markup-commands like
  \markup with-red = \markup \with-color #red \etc

I seem to remember there was some even simpler possibility. Or was it
just a proposal? I can't find it at the moment.

Btw,
\markup my-concat = \markup \concat { \etc "!" }
\markup \my-concat "foo"
fails, no surprise, just a dream ...

Cheers,
  Harm
\version "2.19.64"

#(use-modules (ice-9 regex))

#(define (note-column::main-extent grob)
"Return extent of the noteheads in the 'main column', (i.e. excluding any 
suspended noteheads), or extent of the rest (if there are no heads)."
  (let* ((note-heads (ly:grob-object grob 'note-heads))
 (stem (ly:grob-object grob 'stem))
 (rest (ly:grob-object grob 'rest)))
(cond ((ly:grob-array? note-heads)
   (let (;; get the cdr from all note-heads-extents, where the car 
 ;; is zero
 (n-h-right-coords
   (filter-map
 (lambda (n-h)
   (let ((ext (ly:grob-extent n-h grob X)))
  (and (= (car ext) 0) (cdr ext
 (ly:grob-array->list note-heads
 ;; better be paranoid, find the max of n-h-right-coords and return
 ;; a pair with (cons 0 )
 (cons 0.0 (reduce max 0 n-h-right-coords
  ((ly:grob? rest)
   (ly:grob-extent rest grob X))
  ;; better be paranoid
  (else '(0 . 0)

%% TODO #\space as well?
#(define char-set:dynamics
  (char-set #\f #\m #\p #\r #\s #\z)) 

%% TODO
%% There's the scheme-procedure `make-regexp', I'm not confident with reg-exps 
%% to use it, though
#(define (make-reg-exp separator-pair)
  (format #f "\\~a[^~a~a]*\\~a"
(car separator-pair)
(car separator-pair)
(cdr separator-pair)
(cdr separator-pair)))

#(define (dynamics-list separator-pair strg)
;; Takes a string, which is splitted at space. Local reg-exp and separators are
;; processed from @var{separator-pair}.
;; Dynamic signs within the splitted string (which are rendered by separators)  
;; are selected by matching reg-exp and by containing only dynamic characters 
;; between the separators.  
;;
;; Returns a new list containing not-dynamic strings and sublists with always
;; three entries.  Before-the-dynamic - dynamic - after-dynamic.
;; 
;; Example:
;; (dynamics-list (cons #\{ #\}) "poco -{f}- piu"))
;; =>
;; (list "poco" (list "-" "f" "-") "piu")
;; 
  (let ((reg-exp (make-reg-exp separator-pair))
(separators (char-set (car separator-pair) (cdr separator-pair
(map
  (lambda (s)
(let* ((match (string-match reg-exp s)))
   (if match 
   (let* ((poss-dyn (match:substring match))
  (cand (string-trim-both poss-dyn separators)))
 (if (string-every char-set:dynamics cand)
   (list
 (match:prefix match)
 cand
 (match:suffix match))
 s))  
   s)))
  (string-split strg #\space
  
#(define (get-all-list-indices lst)
"Takes a list and returns a new list of all indices of sublists in @var{lst}"
  (filter-map
(lambda (e c) (if (list? e) c #f))
lst
(iota (length lst

#(define (dynamic-text::format-dynamics fontsize markup-command lst)
;; (1) Convert lst into a list where the targeted string is rendered
;; with dynamic-markup.  The targeted string is identified by being
;; second in a three-element-(sub-)list of lst.
;; (2) remove empty strings from (sub-)lists.
;; (3) insert " " between any element of lst but not between
;; elements of the (sub-)lists
;; (4) Return a new list, unfolded one level
;; TODO disentangle applying markup-commands from other stuff?
(append-map
  (lambda (y) (if (list? y) y (list y)))
  (list-insert-separator
(map
  (lambda (e)
(if (and (list? e) (= (length e) 3))
(remove
   (lambda (x) (and (string? x) (string-null? x)))
   (list
 (car e)
 (if (number? fontsize)
 (make-fontsize-markup fontsize
   (markup-command (second e)))
 (markup-command (second e)))
 (last e)))
e))
  lst)
" ")))

#(define (dynamic-text::format-text fontsize markup-command lst)
"Format string-parts of @var{lst} with @var{fontsize} and @var{markup-command}"
  (map
(lambda (arg)
  (if (string? arg)
  (if (number? fontsize)
  (make-fontsize-markup fontsize
(markup-command arg))
  (markup-command arg))
 

Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-07 Thread Thomas Morley
Hi Kieren,

I now found a conveniant method to adjust the fontsize for
italic/dynamic-font-parts separately.
Ofcourse the aligning was based on the same fontsize for both and is
broken now. So this is next on my TODO-list.
Not sure when I'll have the time to continue, though. I have to work
this weekend :((

2017-09-06 17:33 GMT+02:00 Kieren MacMillan :
> Hi Harm,
>
> One correction to my answers from last time:
>
>> Will you ever want to have this parts to be not italic but sth else?
>>> Ideally, I suppose, all 'usual' text properties could be adjusted… but in 
>>> my use-cases, I set the main document font, the dynamic 'normal-text' font 
>>> is always italic, and I only need to adjust the size (relative to the size 
>>> of the dynamic font) in my stylesheet.
>
> Can it take markup, instead of just a string?

Not with the current approach which needs a string.

> I could see that being quite useful — possibly even necessary (though I don't 
> have a concrete use-case right now).


The current task is to automate creation of a dynamic markup and to
automate aligning.
Every automatism will have to follow certain rules, which ofcourse are
limitations as well.

Right now string-parts which should become dynamics are flagged by
being inside {} and containing only characters from the
dynamic-charset.
It's thinkable to do the same with other sorts of flagging.
For example:
all between **-signs -> bold
all between __-signs -> underlined
etc.
Though, I think that would mean overdoing it and the more stuff of
this kind is coded, the more characters are preserved and longer
usable normally in the markup.
Well, one could use escaped signs and ...

I think I already wrote about overdoing and rules/limitations.

You can always do things manually.
make-dynamic-scripts accepts whatever markup you want. ;)

Ofcourse I could pass a user-created-markup unchanged as the original
function already did, but aligning it would be the duty of the user.


Cheers,
  Harm

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-06 Thread Kieren MacMillan
Hi Harm,

One correction to my answers from last time:

> Will you ever want to have this parts to be not italic but sth else?
>> Ideally, I suppose, all 'usual' text properties could be adjusted… but in my 
>> use-cases, I set the main document font, the dynamic 'normal-text' font is 
>> always italic, and I only need to adjust the size (relative to the size of 
>> the dynamic font) in my stylesheet.

Can it take markup, instead of just a string?
I could see that being quite useful — possibly even necessary (though I don't 
have a concrete use-case right now).

Thanks,
Kieren.


Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-03 Thread Thomas Morley
2017-09-03 18:14 GMT+02:00 Kieren MacMillan :
> Hi Harm,
>
>> The current structure makes it impossible in a convenient way.
>
> =(
>
>> Tbh, I didn't think of this.
>
> Neither has the Lilypond development team, as far as I can tell: I don't know 
> of any way to do it currently (i.e., independent of your new functionality).
>
>> You want to change fontsize of the italic parts, right?
>
> Correct.

ok

>> Will you ever want to have this parts to be not italic but sth else?
>
> Ideally, I suppose, all 'usual' text properties could be adjusted… but in my 
> use-cases, I set the main document font, the dynamic 'normal-text' font is 
> always italic, and I only need to adjust the size (relative to the size of 
> the dynamic font) in my stylesheet.

ok

>> Will you ever want to change fontsize of dynamic-font as well?
>
> That can be done by setting
>
>\override DynamicText.font-size

That's not exactly what I meant, because one could think of hardcoding
font-size of the dynamic, so that one could apply a different
font-size to the whole markup.
Look at the example below. The override doesn't change dynamic-font:

{
  \override DynamicText.font-size = #10
  a'_#(make-dynamic-script
   #{ \markup \italic { \normal-text "poco" \normalsize "f" } #})
}

Though, I take your reply as wanting to change both, the font-size of
the dynamic and the rest, independently.

>
>> Will you ever want to have this parts to be not dynamic but sth else?
>
> Don't know why that would ever happen? Maybe others have those use-cases…

ok

I think I know how to proceed, my weekend is mostly over, though :(


Cheers,
  Harm

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-03 Thread Kieren MacMillan
Hi Harm,

> The current structure makes it impossible in a convenient way.

=(

> Tbh, I didn't think of this.

Neither has the Lilypond development team, as far as I can tell: I don't know 
of any way to do it currently (i.e., independent of your new functionality).

> You want to change fontsize of the italic parts, right?

Correct.

> Will you ever want to have this parts to be not italic but sth else?

Ideally, I suppose, all 'usual' text properties could be adjusted… but in my 
use-cases, I set the main document font, the dynamic 'normal-text' font is 
always italic, and I only need to adjust the size (relative to the size of the 
dynamic font) in my stylesheet.

> Will you ever want to change fontsize of dynamic-font as well?

That can be done by setting

   \override DynamicText.font-size

> Will you ever want to have this parts to be not dynamic but sth else?

Don't know why that would ever happen? Maybe others have those use-cases…

Thanks,
Kieren.


Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-03 Thread Thomas Morley
2017-09-03 17:16 GMT+02:00 Kieren MacMillan :
> Hi Harm,
>
> First question: What's the best way to change the font size of the normal 
> text *independently* of the font size of the dynamics?
>
> I need (a.k.a. would like) to use this function in different stylesheets 
> (with different base fonts), and would prefer to be able to tweak that with a 
> parameter (rather than having to copy the entire function into each 
> stylesheet and independently adjust the font-size somewhere within it).
>
> Thanks!
> Kieren.

Hi Kieren

The current structure makes it impossible in a convenient way. Tbh, I
didn't think of this.
Needs some recoding. Not difficult, I assume, just some work...

Though let me ask detailed:

You want to change fontsize of the italic parts, right?
Will you ever want to have this parts to be not italic but sth else?

Will you ever want to change fontsize of dynamic-font as well?
Will you ever want to have this parts to be not dynamic but sth else?


Cheers,
  Harm

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-03 Thread Kieren MacMillan
Hi Harm,

First question: What's the best way to change the font size of the normal text 
*independently* of the font size of the dynamics?

I need (a.k.a. would like) to use this function in different stylesheets (with 
different base fonts), and would prefer to be able to tweak that with a 
parameter (rather than having to copy the entire function into each stylesheet 
and independently adjust the font-size somewhere within it).

Thanks!
Kieren.


Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-03 Thread Kieren MacMillan
Hi Harm,

> I've now taken this route. Full working code/pdf attached,
> though, there's surely wide room to improve it.
> Usage should be clear from comments and example,
> I'm too tired to do verbose explanations.

This is amazing!
Thank you so much for the hard work — and thanks to everyone who helped you.
I'll start using it immediately in my real-life engraving work, and report back.

Gratefully,
Kieren.


Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-09-02 Thread Thomas Morley
2017-08-29 14:27 GMT+02:00 Thomas Morley :
> 2017-08-27 22:34 GMT+02:00 David Kastrup :
>
>> You are right that fold-matches is probably not worth the trouble in
>> brain contortion here: processing the result from list-matches should be
>> good enough without overflowing memory.
>
[...]
>
> Though, if I split the string anyway (splitting at #\space should do
> no harm, imho), it's probably cheaper to go for string-match instead
> of list-matches.

I've now taken this route.
Full working code/pdf attached, though, there's surely wide room to improve it.
Usage should be clear from comments and example, I'm too tired to do
verbose explanations.

Cheers,
  Harm
\version "2.19.64"

#(use-modules (ice-9 regex))
%#(use-modules (ice-9 rdelim))

#(define char-set:dynamics
  (char-set #\f #\m #\p #\r #\s #\z)) 
  
#(define separator-pair (cons #\{ #\}))

%% TODO
%% There's the scheme-procedure `make-regexp', I'm not confident with reg-exps 
%% to use it, though
#(define (make-reg-exp separator-pair)
  (format #f "\\~a[^~a~a]*\\~a"
(car separator-pair)
(car separator-pair)
(cdr separator-pair)
(cdr separator-pair)))

#(define (dynamics-list separator-pair strg)
;; Takes a string, which is splitted at space. Local reg-exp and separators are
;; processed from separator-pair.
;; Dynamic signs within the splitted string (which are rendered by separators)  
;; are selected by matching reg-exp and by containing only dynamic characters 
;; between the separators.
;; Those list elements are formated as a list of italic-markups for the
;; (possible parts) before and after the dynamic and dynamic-markup for the 
;; dynamic itself. Other list elements are left untouched.
;; Returns a new list.
;; 
;; Example:
;; (dynamics-list "\\{[^{}]*\\}" "poco {f}")
;; =>
;; (list "poco"
;;   (list (markup #:italic "")
;; (markup #:dynamic "f")
;; (markup #:italic "")))
;; 
  (let ((reg-exp (make-reg-exp separator-pair))
(separators (char-set (car separator-pair) (cdr separator-pair

(map
  (lambda (s)
(let* ((match (string-match reg-exp s)))
   (if match 
   (let* ((poss-dyn (match:substring match))
  (cand (string-trim-both poss-dyn separators)))
 (if (string-every char-set:dynamics cand)
   (list
 (make-italic-markup (match:prefix match))
 (make-dynamic-markup cand)
 (make-italic-markup (match:suffix match)))
 s))  
   s)))
  (string-split strg #\space

#(define (compose-markup markup-proc lst)
;; Takes a list and formats its elements with concat-markup (for sublists) or
;; italic-markup.
;; The resulting list is processed by markup-proc, usually 'make-line-markup'
;; or 'make-concat-markup'
;; Return this markup.
;; TODO? a check whether 'lst' and/or its elements is suitable does not happen
  (markup-proc
(map
  (lambda (e)
(if (list? e)
(make-concat-markup e)
(make-italic-markup e)))
  lst)))
  
#(define (get-all-list-indices lst)
;; Takes a list and returns a new list of indices of sublists in 'lst'
  (filter-map
(lambda (e c) (if (list? e) c #f))
lst
(iota (length lst

#(define (note-column::main-extent grob)
;; Return extent of the noteheads in the "main column", (i.e. excluding any 
;; suspended noteheads), or extent of the rest (if there are no heads).
  (let* ((note-heads (ly:grob-object grob 'note-heads))
 (stem (ly:grob-object grob 'stem))
 (rest (ly:grob-object grob 'rest)))
(cond ((ly:grob-array? note-heads)
   (let (;; get the cdr from all note-heads-extents, where the car 
 ;; is zero
 (n-h-right-coords
   (filter-map
 (lambda (n-h)
   (let ((ext (ly:grob-extent n-h grob X)))
  (and (= (car ext) 0) (cdr ext
 (ly:grob-array->list note-heads
 ;; better be paranoid, find the max of n-h-right-coords and return
 ;; a pair with (cons 0 )
 (cons 0.0 (reduce max 0 n-h-right-coords
  ((ly:grob? rest)
   (ly:grob-extent rest grob X))
  ;; better be paranoid
  (else '(0 . 0)
  
#(define (get-some-markups lst idx)
;; 'lst' is a list of strings and/or markup-lists, usually processed by
;; 'dynamics-list'
;; 'idx' selects from (get-all-list-indices lst) 
;;
;;
;; Identify the dynamic expression, by 'idx'.  This dynamic expression may
;; contain other stuff, though.
;;
;; Get the stuff which is before the dynamic expression.
;; Get the stuff which may be before the dynamic, but should not rendered
;; with a dynamic font.
;; Get the dynamic, which should be centered below NoteColumn later.
;; Get the entire markup.
;;
;; Returns a 

Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-29 Thread Kieren MacMillan
Hi David,

> I like the chutzpah of this off-the-cuff approximation, though.

Agreed!
As I recall, Graham was never known for a conspicuous lack of chutzpah…  ;)

Cheers,
Kieren.


Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-29 Thread David Kastrup
Kieren MacMillan  writes:

> Hi Xavier,
>
>> For correct alignment of "dynamic + text" (or "text + dynamic") I used
>> to rely on Graham's "make-dynamic-extra" function, which worked well.
>
> It's hardly perfect, though — for example, the dynamic isn't centred 
> correctly here:
>
> %%%  SNIPPET BEGINS
> \version "2.19.64"
> #(define (make-dynamic-extra dynamic string)
>  (make-music
>'AbsoluteDynamicEvent
>'tweaks
>  ;; calculate centering for text
>  (list (cons (quote X-offset)
>(+ -0.5 (* -0.5 (string-length dynamic)
>'text
>  (markup #:whiteout
>#:line (
>dynamic
>#:hspace 0.5
>#:normal-text #:italic string))
>   ))
>
> test = #(make-dynamic-extra "fmf" "dolce")
>
> { a1\test }
> %%%  SNIPPET ENDS

I like the chutzpah of this off-the-cuff approximation, though.

-- 
David Kastrup

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-29 Thread Kieren MacMillan
Hi Xavier,

> For correct alignment of "dynamic + text" (or "text + dynamic") I used
> to rely on Graham's "make-dynamic-extra" function, which worked well.

It's hardly perfect, though — for example, the dynamic isn't centred correctly 
here:

%%%  SNIPPET BEGINS
\version "2.19.64"
#(define (make-dynamic-extra dynamic string)
 (make-music
   'AbsoluteDynamicEvent
   'tweaks
 ;; calculate centering for text
 (list (cons (quote X-offset)
   (+ -0.5 (* -0.5 (string-length dynamic)
   'text
 (markup #:whiteout
   #:line (
   dynamic
   #:hspace 0.5
   #:normal-text #:italic string))
  ))

test = #(make-dynamic-extra "fmf" "dolce")

{ a1\test }
%%%  SNIPPET ENDS

> Is your new \dynamic function an improved version of this?
> And what does it add more?

I'm hoping this conversation ends with us having a function that will truly Do 
The Right Thing™, in all reasonable situations.

Cheers,
Kieren.


Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-29 Thread Xavier Scheuer
On 16 August 2017 at 03:50, Kieren MacMillan 
wrote:
>
> Hello all,
>
> The snippet below includes Janek's \dynamic function, which has a rather
lovely interface.
> Unfortunately, it doesn't align leading dynamics as expected (i.e.,
centered on the notehead).
>
> What's the easiest way to fix the function so that it does?

Hello,

This discussion is far too high-level for me, but...

For correct alignment of "dynamic + text" (or "text + dynamic") I used
to rely on Graham's "make-dynamic-extra" function, which worked well.
http://lists.gnu.org/archive/html/lilypond-user/2011-06/msg00335.html

Dynamic was aligned on note head and was correctly recognized for MIDI
generation. There was also a corresponding "make-extra-dynamic"
function (for "più f" and other cases) but I cannot find it now.

Is your new \dynamic function an improved version of this?
And what does it add more?

Thanks!

Cheers,
Xavier

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-29 Thread Thomas Morley
2017-08-29 14:27 GMT+02:00 Thomas Morley :
> 2017-08-27 22:34 GMT+02:00 David Kastrup :
>
>> You are right that fold-matches is probably not worth the trouble in
>> brain contortion here: processing the result from list-matches should be
>> good enough without overflowing memory.
>
>
>
> I now come up with (only markup again):
>
> #(define-markup-command (dyn-test-II layout props strg)(string?)
> #:properties ((reg-exp "\\{[^{}]*\\}")
>   (separators (char-set #\{ #\}))
>   (dynamcs (char-set #\f #\m #\p #\r #\s #\z)))
>   (interpret-markup layout props
> (make-line-markup
>   (map
> (lambda (s)
>   (let* ((matches (list-matches reg-exp s)))
> (if (null? matches)
> s
> (let* ((poss-dyns (map match:substring matches)))
>   (append-map
> (lambda (p-d)
>   (let* ((cand (string-trim-both p-d separators)))
> (if (string-every char-set:dynamics cand)
> (make-concat-markup
>   (list
> (make-concat-markup
>   (map match:prefix matches))
> (make-dynamic-markup cand)
> (make-concat-markup
>   (map match:suffix matches
> p-d)))
> poss-dyns)
> (string-split strg #\space)
>
> \markup \dyn-test-II #"poco {f}, but {p} sub. {ma} non troppo"
>
> Though, if I split the string anyway (splitting at #\space should do
> no harm, imho), it's probably cheaper to go for string-match instead
> of list-matches.
>
> Not sure...
>
> Cheers,
>   Harm

Aaargh, some typos, plese use:

#(use-modules (ice-9 regex))

#(define-markup-command (dyn-test-II layout props strg)(string?)
#:properties ((reg-exp "\\{[^{}]*\\}")
  (separators (char-set #\{ #\}))
  (dynamics (char-set #\f #\m #\p #\r #\s #\z)))
  (interpret-markup layout props
(make-line-markup
  (map
(lambda (s)
  (let* ((matches (list-matches reg-exp s)))
(if (null? matches)
s
(let* ((poss-dyns (map match:substring matches)))
  (append-map
(lambda (p-d)
  (let* ((cand (string-trim-both p-d separators)))
(if (string-every dynamics cand)
(make-concat-markup
  (list
(make-concat-markup
  (map match:prefix matches))
(make-dynamic-markup cand)
(make-concat-markup
  (map match:suffix matches
p-d)))
poss-dyns)
(string-split strg #\space)

\markup \dyn-test-II #"poco {f}, but {p} sub. {ma} non troppo"

Cheers,
  Harm

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-29 Thread Thomas Morley
2017-08-27 22:34 GMT+02:00 David Kastrup :

> You are right that fold-matches is probably not worth the trouble in
> brain contortion here: processing the result from list-matches should be
> good enough without overflowing memory.



I now come up with (only markup again):

#(define-markup-command (dyn-test-II layout props strg)(string?)
#:properties ((reg-exp "\\{[^{}]*\\}")
  (separators (char-set #\{ #\}))
  (dynamcs (char-set #\f #\m #\p #\r #\s #\z)))
  (interpret-markup layout props
(make-line-markup
  (map
(lambda (s)
  (let* ((matches (list-matches reg-exp s)))
(if (null? matches)
s
(let* ((poss-dyns (map match:substring matches)))
  (append-map
(lambda (p-d)
  (let* ((cand (string-trim-both p-d separators)))
(if (string-every char-set:dynamics cand)
(make-concat-markup
  (list
(make-concat-markup
  (map match:prefix matches))
(make-dynamic-markup cand)
(make-concat-markup
  (map match:suffix matches
p-d)))
poss-dyns)
(string-split strg #\space)

\markup \dyn-test-II #"poco {f}, but {p} sub. {ma} non troppo"

Though, if I split the string anyway (splitting at #\space should do
no harm, imho), it's probably cheaper to go for string-match instead
of list-matches.

Not sure...

Cheers,
  Harm

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-27 Thread David Kastrup
Thomas Morley  writes:

> 2017-08-27 11:56 GMT+02:00 David Kastrup :
>
>> I was more thinking along the lines of
>>
>> #(define-markup-command (dyn-test layout props strg) (markup?)
>>   (define (fixstring arg)
>>  (let ((res (fold-matches "\\{[^{}*\\}" arg '(0)
>>  (lambda (m prev) ...
>>   (define (fixtree arg)
>> (cond ((pair? arg) (cons (fixtree (car arg)) (fixtree (cdr arg
>>   ((string? arg (fixstring arg)))
>>   (else arg)))
>>
>> Uh, well, you get the drift.
>
> I never really understood all the fold-xxx-procedures and I didn't
> find much usage-examples for fold-matches apart from the trivial one
> in the guile-manual.
> Also, I'm not really familiar with reg-exp.
> So, I'm afraid I'd need some further guidance.
>
> That said, your reg-exp above, "\\{[^{}*\\}", seems not be valid. I
> used: "\\{[^{}*]\\}" not sure whether it's really correct, tho'.

Ouch, sorry for that.  You almost got it:  "\\{[^{}]*\\}" would be
correct (opening brace, an arbitrary number of non-brace characters,
closing brace).

You are right that fold-matches is probably not worth the trouble in
brain contortion here: processing the result from list-matches should be
good enough without overflowing memory.

-- 
David Kastrup

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-27 Thread Thomas Morley
2017-08-27 11:56 GMT+02:00 David Kastrup :

> I was more thinking along the lines of
>
> #(define-markup-command (dyn-test layout props strg) (markup?)
>   (define (fixstring arg)
>  (let ((res (fold-matches "\\{[^{}*\\}" arg '(0)
>  (lambda (m prev) ...
>   (define (fixtree arg)
> (cond ((pair? arg) (cons (fixtree (car arg)) (fixtree (cdr arg
>   ((string? arg (fixstring arg)))
>   (else arg)))
>
> Uh, well, you get the drift.

I never really understood all the fold-xxx-procedures and I didn't
find much usage-examples for fold-matches apart from the trivial one
in the guile-manual.
Also, I'm not really familiar with reg-exp.
So, I'm afraid I'd need some further guidance.

That said, your reg-exp above, "\\{[^{}*\\}", seems not be valid. I
used: "\\{[^{}*]\\}" not sure whether it's really correct, tho'.

For now I did:

#(use-modules (ice-9 regex))

#(define (others number-pairs strg)
 (define (helper l1 l2)
   (if (null? (cdr l1))
   (reverse l2)
   (helper
 (cdr l1)
 (cons (cons (1+ (cdr (first l1))) (1- (car (second l1 l2
 (if (number-pair-list? number-pairs)
 (let* ((res (helper number-pairs '(
   (append
 (cons
   (cons 0 (1- (car (first number-pairs
   res)
 (list (cons (1+ (cdr (last number-pairs))) (string-length strg)
 '()))

#(define (xy reg-exp strg)
 (let* ((possible-dyns
  (reverse
(fold-matches reg-exp strg '()
  (lambda (match prev)
(let* ((res-1 (vector-ref match 1))
   (res-2 (cons res-1 prev)))
res-2)
(end-between-last
  (others possible-dyns strg)))
   (list
 "the following lists of pairs could be used to get substrings from strg"
 'possible-dynamics
 possible-dyns
 'others
 end-between-last)))

#(newline)
#(pretty-print
  (xy "\\{[^{}*]\\}" "poco {f}, but {p} sub. ma non troppo"))



displaying:


("the following lists of pairs could be used to get substrings from strg"
 possible-dynamics
 ((5 . 8) (14 . 17))
 others
 ((0 . 4) (9 . 13) (18 . 36)))

Is this the route to continue?


Cheers,
  Harm

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-27 Thread David Kastrup
Thomas Morley  writes:

> 2017-08-26 21:35 GMT+02:00 David Kastrup :
>> Thomas Morley  writes:
>>
>>> 2017-08-26 20:24 GMT+02:00 David Kastrup :

 Uh, this was a proposal for a user interface that does not need to look
 at punctuation etc but rather goes by [...] for figuring out where the
 "true" dynamics are, likely defaulting to taking the first pair for
 alignment as well as Midi dynamics.
>>>
>>> Ok, lol
>>>
>>> Valentins original code used underscores, iirc.
>>
>> Hm, [...] might actually be used for editorial annotations.  So maybe
>> not the best markup for this application.  {...} maybe?
>>
>> --
>> David Kastrup
>
> Do you mean something at the lines below?
> (Only the markup-part for now)
>
> #(define char-set:dynamics
>   (char-set #\f #\m #\p #\r #\s #\z))
>
> #(define (split-string strg char-pair)
> ;; split a string at all occurrences of both characters in char-pair
> ;; remark: with guilev2 string-split accepts a char-set as second argument
>   (append-map
> (lambda (s) (string-split s #\}))
> (string-split strg #\{)))
>
>
> #(define-markup-command (dyn-test layout props strg)(string?)
> #:properties ((chars (cons #\{ #\})))
>   (interpret-markup layout props
> (make-concat-markup
>   (map
> (lambda (word)
>   (if (string-every char-set:dynamics word)
>   (make-dynamic-markup word)
>   word))
>   (split-string strg chars)
>
> \markup \dyn-test #"poco {f}, but {p} sub. ma non troppo"

Well, it's partly too robust and partly too fragile...  silently not
using dynamic markup for {huh} while still removing the braces is never
going to be sensible behavior I think.  Treating opening and closing
braces (and parts left and right from them) equally is half-defeating
the principal idea of being more robust against wrong detection of
dynamics, admittedly not likely a big problem.

I was more thinking along the lines of

#(define-markup-command (dyn-test layout props strg) (markup?)
  (define (fixstring arg)
 (let ((res (fold-matches "\\{[^{}*\\}" arg '(0)
 (lambda (m prev) ...
  (define (fixtree arg)
(cond ((pair? arg) (cons (fixtree (car arg)) (fixtree (cdr arg
  ((string? arg (fixstring arg)))
  (else arg)))

Uh, well, you get the drift.  I just remembered that we still need the
relative positions in the string and the recursive approach wouldn't
really work with that.  Either way, fold-matches seems like something
one could work with here.

But, well, regarding the results of this particular call, yes that was
more or less what I meant.

-- 
David Kastrup

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-27 Thread Thomas Morley
2017-08-27 10:40 GMT+02:00 Thomas Morley :

> #(define (split-string strg char-pair)
> ;; split a string at all occurrences of both characters in char-pair
> ;; remark: with guilev2 string-split accepts a char-set as second argument
>   (append-map
> (lambda (s) (string-split s #\}))
> (string-split strg #\{)))

Ofcourse this should be:
#(define (split-string strg char-pair)
;; split a string at all occurrences of both characters in char-pair
;; remark: with guilev2 string-split accepts a char-set as second argument
  (append-map
(lambda (s) (string-split s (car char-pair)))
(string-split strg (cdr char-pair

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-27 Thread Thomas Morley
2017-08-26 21:35 GMT+02:00 David Kastrup :
> Thomas Morley  writes:
>
>> 2017-08-26 20:24 GMT+02:00 David Kastrup :
>>>
>>> Uh, this was a proposal for a user interface that does not need to look
>>> at punctuation etc but rather goes by [...] for figuring out where the
>>> "true" dynamics are, likely defaulting to taking the first pair for
>>> alignment as well as Midi dynamics.
>>
>> Ok, lol
>>
>> Valentins original code used underscores, iirc.
>
> Hm, [...] might actually be used for editorial annotations.  So maybe
> not the best markup for this application.  {...} maybe?
>
> --
> David Kastrup

Do you mean something at the lines below?
(Only the markup-part for now)

#(define char-set:dynamics
  (char-set #\f #\m #\p #\r #\s #\z))

#(define (split-string strg char-pair)
;; split a string at all occurrences of both characters in char-pair
;; remark: with guilev2 string-split accepts a char-set as second argument
  (append-map
(lambda (s) (string-split s #\}))
(string-split strg #\{)))


#(define-markup-command (dyn-test layout props strg)(string?)
#:properties ((chars (cons #\{ #\})))
  (interpret-markup layout props
(make-concat-markup
  (map
(lambda (word)
  (if (string-every char-set:dynamics word)
  (make-dynamic-markup word)
  word))
  (split-string strg chars)

\markup \dyn-test #"poco {f}, but {p} sub. ma non troppo"

Cheers,
  Harm

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-26 Thread David Kastrup
Thomas Morley  writes:

> 2017-08-26 20:24 GMT+02:00 David Kastrup :
>>
>> Uh, this was a proposal for a user interface that does not need to look
>> at punctuation etc but rather goes by [...] for figuring out where the
>> "true" dynamics are, likely defaulting to taking the first pair for
>> alignment as well as Midi dynamics.
>
> Ok, lol
>
> Valentins original code used underscores, iirc.

Hm, [...] might actually be used for editorial annotations.  So maybe
not the best markup for this application.  {...} maybe?

-- 
David Kastrup

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-26 Thread Thomas Morley
2017-08-26 20:24 GMT+02:00 David Kastrup :
> Thomas Morley  writes:
>
>> 2017-08-26 16:10 GMT+02:00 David Kastrup :
>>> Thomas Morley  writes:
>>
 the here so far proposed codes fail, if punctuation comes into the game.
 \new Staff { c''\dynamic  "poco f, but p sub. ma non troppo" }
>>>
>>> \dynamic "poco [f], but [p] sub. ma non troppo" ?
>>
>> Hi David,
>>
>> not sure what you want to say...
>>
>> I tested the input-string
>> "poco [f], but [p] sub. ma non troppo"
>> with Lukas-Fabian's code and my own proposal, See attached pdf.
>
> Uh, this was a proposal for a user interface that does not need to look
> at punctuation etc but rather goes by [...] for figuring out where the
> "true" dynamics are, likely defaulting to taking the first pair for
> alignment as well as Midi dynamics.
>
>> I'd say this case, bracketed dynamics together with normal text, would
>> need manual coding.
>>
>>
>> That said, I've no clue whether you meant something completely
>> different ... ;)
>
> The latter...
>
> --
> David Kastrup

Ok, lol

Valentins original code used underscores, iirc.

Not sure when I have the time to proceed on this, though...

Cheers,
  Harm

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-26 Thread David Kastrup
Thomas Morley  writes:

> 2017-08-26 16:10 GMT+02:00 David Kastrup :
>> Thomas Morley  writes:
>
>>> the here so far proposed codes fail, if punctuation comes into the game.
>>> \new Staff { c''\dynamic  "poco f, but p sub. ma non troppo" }
>>
>> \dynamic "poco [f], but [p] sub. ma non troppo" ?
>
> Hi David,
>
> not sure what you want to say...
>
> I tested the input-string
> "poco [f], but [p] sub. ma non troppo"
> with Lukas-Fabian's code and my own proposal, See attached pdf.

Uh, this was a proposal for a user interface that does not need to look
at punctuation etc but rather goes by [...] for figuring out where the
"true" dynamics are, likely defaulting to taking the first pair for
alignment as well as Midi dynamics.

> I'd say this case, bracketed dynamics together with normal text, would
> need manual coding.
>
>
> That said, I've no clue whether you meant something completely
> different ... ;)

The latter...

-- 
David Kastrup

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-26 Thread Thomas Morley
2017-08-26 16:10 GMT+02:00 David Kastrup :
> Thomas Morley  writes:

>> the here so far proposed codes fail, if punctuation comes into the game.
>> \new Staff { c''\dynamic  "poco f, but p sub. ma non troppo" }
>
> \dynamic "poco [f], but [p] sub. ma non troppo" ?

Hi David,

not sure what you want to say...

I tested the input-string
"poco [f], but [p] sub. ma non troppo"
with Lukas-Fabian's code and my own proposal, See attached pdf.

The first code doesn't recognize the dynamics.
The second does so, but the brackets collide with the forte-sign.

The third is a manually created markup to rebuild the appearance of the second.
The fourth points to a possible fix.

Though, the collision results out of the different fonts used for
"normal" text and dynamics. The forte-sign even sticks out of its
bounding-box. See: \markup \box \dynamic "f"

One could add a plethora of conditions to cope with the problem, but
wouldn't it be too ... much?
I've already mentioned the problem of overly automated code.
I'd say this case, bracketed dynamics together with normal text, would
need manual coding.


That said, I've no clue whether you meant something completely different ... ;)

Cheers,
  Harm


on-the-fly-dynamics.pdf
Description: Adobe PDF document
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-26 Thread David Kastrup
Thomas Morley  writes:

> 2017-08-25 0:01 GMT+02:00 Kieren MacMillan :
>> Hi Saul,
>>
>>> Personally, I think the behavior would be better if it aligned on
>>> the first dynamic to appear in the markup, rather than default to
>>> left.
>>
>> Perhaps better if this is a preference/parameter, with the default
>> being *left-aligned* not *dynamic-aligned*.
>> (I would personally keep it left-aligned, and then use the
>> edition-engraver to tweak the position of the rare "outliers".)
>>
>>> With something like "poco f", it can be visually unclear where the
>>> f is supposed to begin — at the beginning of "poco" or at the "f"?
>>> That's a bit clearer of the dynamic itself is always the alignment
>>> point (though I prefer to always have the dynamic first for maximum
>>> clarity).
>>
>> Gould (pg. 107) addresses this. There are definitely more
>> ambiguities and potential problems with dynamic-aligning such texts
>> than there are "safe situations" (e.g., with preceding rests) —
>> which is why, like you, I always prefer to have the dynamic first
>> (when possible).
>>
>> Cheers,
>> Kieren.
>
> Hi all,
>
> the here so far proposed codes fail, if punctuation comes into the game.
> \new Staff { c''\dynamic  "poco f, but p sub. ma non troppo" }

\dynamic "poco [f], but [p] sub. ma non troppo" ?

-- 
David Kastrup

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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-26 Thread Thomas Morley
2017-08-25 0:01 GMT+02:00 Kieren MacMillan :
> Hi Saul,
>
>> Personally, I think the behavior would be better if it aligned on the first 
>> dynamic to appear in the markup, rather than default to left.
>
> Perhaps better if this is a preference/parameter, with the default being 
> *left-aligned* not *dynamic-aligned*.
> (I would personally keep it left-aligned, and then use the edition-engraver 
> to tweak the position of the rare "outliers".)
>
>> With something like "poco f", it can be visually unclear where the f is 
>> supposed to begin — at the beginning of "poco" or at the "f"? That's a bit 
>> clearer of the dynamic itself is always the alignment point (though I prefer 
>> to always have the dynamic first for maximum clarity).
>
> Gould (pg. 107) addresses this. There are definitely more ambiguities and 
> potential problems with dynamic-aligning such texts than there are "safe 
> situations" (e.g., with preceding rests) — which is why, like you, I always 
> prefer to have the dynamic first (when possible).
>
> Cheers,
> Kieren.

Hi all,

the here so far proposed codes fail, if punctuation comes into the game.
\new Staff { c''\dynamic  "poco f, but p sub. ma non troppo" }

Thus I based my own code on the previous work of Valentin Villenave:
https://codereview.appspot.com/2220041/
https://codereview.appspot.com/20660044/

One problem for the event-function persists:
To get the first dynamic-word center-aligned under the NoteColumn you
need to do some calculations for tweaking X-offset or
self-alignment-X. (I choosed X-offset because the calculation is a
little easier ...)
Whatever you choose, a certain tweak is hardcoded now. And further
tweaking after applying the event-function will at first not work:
Having set a hardcoded tweak for X-offset makes it impossible to get a
tweak for self-alignment-X to work, neither would an additional
X-offset-tweak work. If I would have gone for self-alignment-X in the
event-function further tweaks of the same property would not work
either.

I think that's what David K explained here:
http://lists.gnu.org/archive/html/lilypond-user/2017-08/msg00194.html

Thus I coded a possibilty to lookup for an additional X-offset-tweak,
which will add it's value to the setting caused by the event-function.
Theoretically this could be done with self-alignment-X as well, but I
regarded the results from a users points of view too unpredictable.

Here's the code:


\version "2.19.64"

#(define (char-punctuation? ch)
  (char-set-contains? char-set:punctuation ch))

#(define char-set:dynamics
  (char-set #\f #\m #\p #\r #\s #\z))

#(define composite-chars
  (char-set-union char-set:dynamics char-set:punctuation))

#(define-markup-command (dynamic-text layout props str) (string?)
  "Takes a string, puts out a line-markup.
Parts of @var{strg} containing only characters used for dynamics are printed
using \\dynamic (punctuation-signs are disregarded.
Other parts are printed \\italic.

@lilypond[verbatim,quote]
\\markup {
  \\dynamic-text #\"poco f, but p sub. ma non troppo\"
}
@end lilypond
"
  (let* ((str-list (string-split str #\space))
 (text-markup
   (lambda (s) (make-normal-text-markup (make-italic-markup s)
(interpret-markup layout props
  (make-line-markup
;; iterate over 'str-list'
;; - parts only containing dynamics/punctuation are splitted.
;;   dynamics are printed \dynamic, others \italic
;;   and finally \concat is applied
;; - others are printed \italic
(map
  (lambda (word)
(if (string-every composite-chars word)
(let ((word-lst (string->list word)))
  (make-concat-markup
(map
  (lambda (ch)
(let ((print-ch (string ch)))
  (if (char-punctuation? ch)
  (text-markup print-ch)
  (make-dynamic-markup print-ch
  word-lst)))
(text-markup word)))
  str-list)

dynamicH =
#(define-event-function (strg) (string?)
"Takes a string and puts out a (composed) dynamic script.
If the first word of the composed string is a dynamic sign, the ready dynamic-
script center-aligns this word at the parent-grob.
Further adapting the result with additional tweaks for X-offset are possible.
"
  (let* ((first-word (car (string-split strg #\space)))
 ;; don't take punctuation into account
 (trimmed-first-word (string-trim-both first-word char-set:punctuation))
 (offset
   (lambda (grob)
 (let* (;; get previous tweaks for X-offset and add their values
;; they are added to the final result
(x-offset-tweaks
  (filter
(lambda (tw)
  (and (number? (cdr tw)) (eq? (car tw) 'X-offset)))
  

Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-24 Thread Kieren MacMillan
Hi Saul,

> Personally, I think the behavior would be better if it aligned on the first 
> dynamic to appear in the markup, rather than default to left.

Perhaps better if this is a preference/parameter, with the default being 
*left-aligned* not *dynamic-aligned*.
(I would personally keep it left-aligned, and then use the edition-engraver to 
tweak the position of the rare "outliers".)

> With something like "poco f", it can be visually unclear where the f is 
> supposed to begin — at the beginning of "poco" or at the "f"? That's a bit 
> clearer of the dynamic itself is always the alignment point (though I prefer 
> to always have the dynamic first for maximum clarity).

Gould (pg. 107) addresses this. There are definitely more ambiguities and 
potential problems with dynamic-aligning such texts than there are "safe 
situations" (e.g., with preceding rests) — which is why, like you, I always 
prefer to have the dynamic first (when possible).

Cheers,
Kieren.


Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-24 Thread Saul Tobin
Thanks for putting that together. I'm no Scheme expert, but it looks good
to me.

Personally, I think the behavior would be better if it aligned on the first
dynamic to appear in the markup, rather than default to left. With
something like "poco f", it can be visually unclear where the f is supposed
to begin — at the beginning of "poco" or at the "f"? That's a bit clearer
of the dynamic itself is always the alignment point (though I prefer to
always have the dynamic first for maximum clarity). The Scheme code to find
the first appearance of a dynamic would be a bit more intricate, though,
since it would have to keep track of the width of text on either side of
the alignment point.

On Aug 24, 2017 3:16 AM, "Lukas-Fabian Moser"  wrote:

> Hello,
>
> I'm almost embarassed to post this as it's the ugly result of "trying to
> learn scheme and lilypond internals all at the same time" - but at least it
> seems to work. I've tried to achieve exactly what you described: _If_ the
> first word is a dynamic expression, then Shevek's adjustment is applied.
>
> Best
> Lukas
>
>
> %%%  SNIPPET BEGINS
> \version "2.19.44"
>
> #(use-modules (ice-9 regex))
>
> dynamic =
> #(define-event-function (text) (markup?)
>(if (string? text)
>(let* ((underscores-replaced
>(string-map
> (lambda (x) (if (eq? x #\_) #\space x))
> text)
>)
>   (split-text (string-split underscores-replaced #\space))
>   (first-is-dynamic (string-match "^[mrzfps]*$" (car
> split-text)))
>   (formatted (map
>   (lambda (word)
> (if (string-match "^[mrzfps]*$" word)
> (markup #:dynamic word #:hspace 0.25)
> (markup #:normal-text #:fontsize 0.625
> #:italic word)))
>   split-text))
>   (offset (lambda (grob)
> (if first-is-dynamic
> (let* (
> (first-as-dynamic
>  (list (markup #:dynamic (car
> split-text)))
>  )
> (layout (ly:grob-layout grob))
> (props (ly:grob-alist-chain grob
>  (ly:output-def-lookup layout
> 'text-font-defaults)))
> (dyn-X-extent
>  (ly:stencil-extent
>
>   (ly:text-interface::interpret-markup
> layout props (make-line-markup first-as-dynamic))
>   X))
> (width (abs
> (- (cdr dyn-X-extent) (car
> dyn-X-extent
> )
>   (- 1 (/ width 2))
>   )
> 0)
> )))
>  #{
>-\tweak X-offset #offset
>#(make-dynamic-script (make-line-markup formatted))
>  #})
>
>;; user provided a full-blown markup, so we don't mess with it:
>#{
>  #(make-dynamic-script (markup #:normal-text #:fontsize 0.625
> text))
>#}))
>
> <<
>   \new Staff { c''\dynamic "f dramatically" }
>   \new Staff { c''\dynamic "slightly more pp" }
> >>
> %%%  SNIPPET ENDS
>
>
>
>
> 2017-08-20 22:24 GMT+02:00 Kieren MacMillan  >:
>
>> Hi Shevek,
>>
>> > I posted a snippet to do correct custom dynamic alignment a month or so
>> ago.
>>
>> Yes, I know. I like the alignment very much.
>>
>> But I prefer Janek's interface, which offers the ability to put an
>> arbitrary string (e.g., "poco f, but p sub. ma non troppo") and it Does The
>> Right Thing™… well, the Right Thing modulo alignment when the leading word
>> is a dynamic.  =\
>>
>> > I tried just copy and pasting my offset callback into Janek's snippet,
>> but
>> > it doesn't quite work because the callback relies on assuming the
>> dynamic is
>> > at the beginning, and any additional text follows it.
>>
>> I think a single "if" added to Janek's function would suffice: if the
>> word in question is a dynamic (which Janek's function already works out)
>> *AND* it's the first word (Janek's function *doesn't* do this), then apply
>> an appropriate X-offset adjustment (similar or identical to yours),
>> otherwise left-align (which Janek's function already does).
>>
>> I'm scrambling to get a commission engraving out the door — what else is
>> new!? — so I don't have time to climb the Scheme-fu learning curve to get
>> that done right now… If nobody's done it before this score gets sent off
>> (mid-week?), I'll try to tackle it myself.
>>
>> Thanks,
>> Kieren.
>> 
>>
>> Kieren MacMillan, composer
>> ‣ 

Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-24 Thread Lukas-Fabian Moser
Hello,

I'm almost embarassed to post this as it's the ugly result of "trying to
learn scheme and lilypond internals all at the same time" - but at least it
seems to work. I've tried to achieve exactly what you described: _If_ the
first word is a dynamic expression, then Shevek's adjustment is applied.

Best
Lukas


%%%  SNIPPET BEGINS
\version "2.19.44"

#(use-modules (ice-9 regex))

dynamic =
#(define-event-function (text) (markup?)
   (if (string? text)
   (let* ((underscores-replaced
   (string-map
(lambda (x) (if (eq? x #\_) #\space x))
text)
   )
  (split-text (string-split underscores-replaced #\space))
  (first-is-dynamic (string-match "^[mrzfps]*$" (car
split-text)))
  (formatted (map
  (lambda (word)
(if (string-match "^[mrzfps]*$" word)
(markup #:dynamic word #:hspace 0.25)
(markup #:normal-text #:fontsize 0.625
#:italic word)))
  split-text))
  (offset (lambda (grob)
(if first-is-dynamic
(let* (
(first-as-dynamic
 (list (markup #:dynamic (car
split-text)))
 )
(layout (ly:grob-layout grob))
(props (ly:grob-alist-chain grob
 (ly:output-def-lookup layout
'text-font-defaults)))
(dyn-X-extent
 (ly:stencil-extent

  (ly:text-interface::interpret-markup
layout props (make-line-markup first-as-dynamic))
  X))
(width (abs
(- (cdr dyn-X-extent) (car
dyn-X-extent
)
  (- 1 (/ width 2))
  )
0)
)))
 #{
   -\tweak X-offset #offset
   #(make-dynamic-script (make-line-markup formatted))
 #})

   ;; user provided a full-blown markup, so we don't mess with it:
   #{
 #(make-dynamic-script (markup #:normal-text #:fontsize 0.625 text))
   #}))

<<
  \new Staff { c''\dynamic "f dramatically" }
  \new Staff { c''\dynamic "slightly more pp" }
>>
%%%  SNIPPET ENDS




2017-08-20 22:24 GMT+02:00 Kieren MacMillan :

> Hi Shevek,
>
> > I posted a snippet to do correct custom dynamic alignment a month or so
> ago.
>
> Yes, I know. I like the alignment very much.
>
> But I prefer Janek's interface, which offers the ability to put an
> arbitrary string (e.g., "poco f, but p sub. ma non troppo") and it Does The
> Right Thing™… well, the Right Thing modulo alignment when the leading word
> is a dynamic.  =\
>
> > I tried just copy and pasting my offset callback into Janek's snippet,
> but
> > it doesn't quite work because the callback relies on assuming the
> dynamic is
> > at the beginning, and any additional text follows it.
>
> I think a single "if" added to Janek's function would suffice: if the word
> in question is a dynamic (which Janek's function already works out) *AND*
> it's the first word (Janek's function *doesn't* do this), then apply an
> appropriate X-offset adjustment (similar or identical to yours), otherwise
> left-align (which Janek's function already does).
>
> I'm scrambling to get a commission engraving out the door — what else is
> new!? — so I don't have time to climb the Scheme-fu learning curve to get
> that done right now… If nobody's done it before this score gets sent off
> (mid-week?), I'll try to tackle it myself.
>
> Thanks,
> Kieren.
> 
>
> Kieren MacMillan, composer
> ‣ website: www.kierenmacmillan.info
> ‣ email: i...@kierenmacmillan.info
>
>
> ___
> lilypond-user mailing list
> lilypond-user@gnu.org
> https://lists.gnu.org/mailman/listinfo/lilypond-user
>
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-20 Thread Kieren MacMillan
Hi Shevek,

> I posted a snippet to do correct custom dynamic alignment a month or so ago.

Yes, I know. I like the alignment very much.

But I prefer Janek's interface, which offers the ability to put an arbitrary 
string (e.g., "poco f, but p sub. ma non troppo") and it Does The Right Thing™… 
well, the Right Thing modulo alignment when the leading word is a dynamic.  =\

> I tried just copy and pasting my offset callback into Janek's snippet, but
> it doesn't quite work because the callback relies on assuming the dynamic is
> at the beginning, and any additional text follows it.

I think a single "if" added to Janek's function would suffice: if the word in 
question is a dynamic (which Janek's function already works out) *AND* it's the 
first word (Janek's function *doesn't* do this), then apply an appropriate 
X-offset adjustment (similar or identical to yours), otherwise left-align 
(which Janek's function already does).

I'm scrambling to get a commission engraving out the door — what else is new!? 
— so I don't have time to climb the Scheme-fu learning curve to get that done 
right now… If nobody's done it before this score gets sent off (mid-week?), 
I'll try to tackle it myself.

Thanks,
Kieren.


Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info


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


Re: improving Janek's \dynamic function (for combo dynamics)

2017-08-19 Thread Shevek
I posted a snippet to do correct custom dynamic alignment a month or so ago.
I haven't had time to integrate it into the OpenLilyLib snippet, but here's
my code:

\version "2.18.2"

dynText = #(define-event-function (parser location dyn expr) (markup?
markup?)
 (let* (
 (mark #{ \markup { \dynamic $dyn \normal-text\italic
$expr } #})
 (offset (lambda (grob)
   (let* (
   (layout (ly:grob-layout grob))
   (props (ly:grob-alist-chain grob
(ly:output-def-lookup layout
'text-font-defaults)))
   (dyn-X-extent
(ly:stencil-extent

(ly:text-interface::interpret-markup layout props dyn)
 X))
   (width (abs
   (- (cdr dyn-X-extent) (car
dyn-X-extent
   )
 (- 1 (/ width 2))
 )
   )
   )
 )
   #{
 \tweak DynamicText.X-offset #offset
 #(make-dynamic-script mark) 
   #}
   )
 )

%%  Example

\paper {
  ragged-right = ##f
  indent = 0\cm
}

\new Staff \with {
  \omit TimeSignature
} \relative c' {
  c1\dynText "p" "sub."
  c1\dynText "fff" "espressivo"
  c1\dynText "p" "espressivo"
  c1\dynText "f" "sub."
  \break
  c1\p
  c1\fff
  c1\p
  c1\f
}

I tried just copy and pasting my offset callback into Janek's snippet, but
it doesn't quite work because the callback relies on assuming the dynamic is
at the beginning, and any additional text follows it.




--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/improving-Janek-s-dynamic-function-for-combo-dynamics-tp205071p205179.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