Re: Workaround for (not-allowed) numbers in variable names?

2021-03-06 Thread 田村淳
Hello David,

> gamme.1 is not a variable name.  It takes gamme to be an alist, and the
> entry under key 1 is what is addressed here.

Since you showed the Scheme equivalent below, I guess the above is a part of 
LilyPond syntax, or something the LilyPond parser does. Is that documented 
elsewhere? I’d like to know a bit more details.

Best regards,

Jun

> 2021/03/06 23:29、David Kastrup のメール:
> 
> Silvain Dupertuis  writes:
> 
>> I still checked this use of variable with numbers.
>> *Wonderful to see that it works.*
>> 
>> One important note, though:
>> If you use a numbered variable, _you cannot use the same variable
>> without an additional number_.
> 
> gamme.1 is not a variable name.  It takes gamme to be an alist, and the
> entry under key 1 is what is addressed here.
> 
> You can equivalently write gamme . #(- 3 2) for example.
> 
> In contrast, "gamme1" (referenced as \"gamme1") _is_ a single variable
> name.
> 
> As to converting numbers to roman numerals: what is wrong with
> 
> #(format #f "~@r" 547)
> 
> ?
> 
> -- 
> David Kastrup
> 




Re: How to get bounding NoteColumns of the first of consecutive TextSpanners

2021-03-06 Thread Thomas Morley
Hi Jean,

Am Mi., 3. März 2021 um 23:05 Uhr schrieb Jean Abou Samra :
>
>
> Le 03/03/2021 à 13:55, Thomas Morley a écrit :

> > How to get the NoteColumn at first TextSpanner's end?

> This looks tricky indeed.
>
> Maybe an engraver operating in Voice context? Here's my attempt:
[...]
> Like David's solution, this of course won't give you the note columns
> for each of the broken pieces.

Well, I'm interested in the bounds of the unbroken spanner, probably
think of (ly.grob-original )
Especially in the Stems of the NoteColumns (if any can be found).
A more verbose description in my previous post.

> Well, I am in fact not sure that a notion
> of the bounding note columns for a broken text spanner can even be
> defined. Thoughts?
>
> Cheers,
> Jean
>

I took the liberty to modify your engraver, looking directly for Stems
and eliminating the custom-grob-property, replacing it with
details.subproperties.
Making for:

\version "2.23.1"

Set_bounding_stems_engraver =
#(lambda (context)
(let ((spanner-starting #f)
  (spanner-ending #f)
  (stem #f))
  (make-engraver
(acknowledgers
  ((line-spanner-interface engraver grob source-engraver)
 (set! spanner-starting grob))
  ((stem-interface engraver grob source-engraver)
 (set! stem grob)))
(end-acknowledgers
  ((line-spanner-interface engraver grob source-engraver)
 (set! spanner-ending grob)))
((stop-translation-timestep engraver)
  ;; TODO In polyphonic situations there may be more than one Stem at
  ;;  the same timestep
  ;;  How to select?
  (if spanner-starting
  (ly:grob-set-nested-property! spanner-starting
'(details stem-left) stem))
  (if spanner-ending
  (ly:grob-set-nested-property! spanner-ending
'(details stem-right) stem))
  (set! spanner-starting #f)
  (set! spanner-ending #f)
  (set! stem #f)

#(define (get-bounding-stem-dirs-jean spanner)
  (let* ((details (ly:grob-property spanner 'details))
 (stem-left (assoc-get 'stem-left details))
 (stem-left-dir
   (if (ly:grob? stem-left)
   (ly:grob-property stem-left 'direction)))
 (stem-right (assoc-get 'stem-right details))
 (stem-right-dir
   (if (ly:grob? stem-right)
   (ly:grob-property stem-right 'direction
(cons stem-left-dir stem-right-dir)))

#(define (text-stencil-jean txt)
  (lambda (grob)
(let* ((bounding-stem-dirs
 (get-bounding-stem-dirs-jean grob))
   (stem-left-dir
 (car bounding-stem-dirs))
   (stem-right-dir
 (cdr bounding-stem-dirs)))
  ;; adjust left/right padding and left/right attach-dir
  (if (and (number? stem-left-dir) (number? stem-right-dir))
  (begin
;; compensate Stem.thickness
;; IR says it's 1.3
(ly:grob-set-nested-property! grob
  '(bound-details right padding) 0.13)
(ly:grob-set-nested-property! grob
  '(bound-details left padding) 0)
;; always start at right edge of left bound
(ly:grob-set-nested-property! grob
  '(bound-details left attach-dir) 1)

(cond ((and (positive? stem-left-dir) (positive? stem-right-dir))
(ly:grob-set-nested-property! grob
  '(bound-details right attach-dir) 1))
  ((and (positive? stem-left-dir) (negative? stem-right-dir))
(ly:grob-set-nested-property! grob
  '(bound-details right attach-dir) 0))
  (else
(ly:grob-set-nested-property! grob
  '(bound-details right attach-dir) -1)

  (let* ((stil (ly:line-spanner::print grob))
 (stil-center (interval-center (ly:stencil-extent stil X)))
 (text-stil
   (grob-interpret-markup grob
 (if (not-first-broken-spanner? grob)
 (make-parenthesize-markup txt)
 txt)))
 (text-center (interval-center (ly:stencil-extent text-stil X

   (ly:stencil-add
;; for reference or visual debugging add:
;stil
(ly:stencil-translate-axis text-stil (- stil-center text-center) X)
)


%%%
%% EXAMPLEs
%%%

mus = <<
  { \repeat unfold 8 b4 }

  \new Voice \with {
\consists \Set_bounding_stems_engraver
\override TextSpanner.font-shape = #'upright
\override TextSpanner.style = #'solid
  }
  {
g'-\tweak stencil #(text-stencil-jean "1") \startTextSpan
a'\stopTextSpan
  -\tweak stencil #(text-stencil-jean "1½") \startTextSpan
c''\stopTextSpan
   -\tweak stencil #(text-stencil-jean "½") \startTextSpan
b'\stopTextSpan
  -\tweak stencil 

Re: How to get bounding NoteColumns of the first of consecutive TextSpanners

2021-03-06 Thread Thomas Morley
Hi David,

I don't understand the advantage of this coding compared with the one
from your post before.
Nevertheless I took the idea to separate a coding to find the wished
bound-objects, see below.

Am Do., 4. März 2021 um 14:08 Uhr schrieb David Nalesnik
:

>
> Right, the bounds of the broken pieces would be NonMusicalPaperColumn
> grobs.  I've adapted Harm's code to deal with this.  I don't know how
> you'd deal with this in an engraver--if using ly:item-break-dir would
> be an option, for example.  (@Harm: I don't know of course what the
> ultimate goal of your experiment is, so I hope I haven't taken this
> too far, or removed code you still want in place!)

The goal is to center a text between two notes.
Though, I made the experience wanting to calculate said centering with
different values depending on the combinations of the Stem directions.
Going for TextSpanner seemed to be an easy method. Well, until I
realised right-bound may be PaperColumn for consecutive TextSpanners.
Other possibilities for bounds not being a NoteColumn are more or less
trivial to filter or circumvent.
Also, TextSpanner seemed to be a nice grob to set different behaviour
for up/down-stemmed NoteColumns: simply adjust the relevant
'attach-dir

I'd be open open for other suggestions, though :)

For now I did:

\version "2.22.0"

#(define (get-bound-stem-dir spanner dir)
  "Get @code{Stem.direction} of the bounding @code{NoteColumn}. If @var{spanner}
is bound to @code{NonMusicalPaperColumn} or @code{PaperColumn} try to find a
a @code{Stem} grob in the same @code{Staff} at the same musical moment."
  (let* ((bound (ly:spanner-bound spanner dir)))
(if (grob::has-interface bound 'note-column-interface)
;; If bound is a NoteColumn, then it will surely be in the same Staff
;; as the `spanner'.
;; If it contains NoteHeads get Stem.direction
(let ((stem (ly:grob-object bound 'stem)))
  (and (ly:grob? stem)
   (ly:grob-array? (ly:grob-object bound 'note-heads))
   (ly:grob-property stem 'direction)))
;; Select Stems by comparing the 'staff-symbol of `spanner' with
;; 'staff-symbol of Stems, found in (NonMusical)PaperColumn at same
;; musical moment
(let* ((spanner-staff-symbol
(ly:grob-object spanner 'staff-symbol))
   (bound-elts (ly:grob-object bound 'elements))
   (stems-from-bound
 (filter
   (lambda (elt)
 (grob::has-interface elt 'stem-interface))
   (if (ly:grob-array? bound-elts)
   (ly:grob-array->list bound-elts)
   '(
   (stems
 (filter
   (lambda (stem)
 (equal? spanner-staff-symbol
 (ly:grob-object stem 'staff-symbol)))
   stems-from-bound)))
  ;; TODO In polyphonic situations there may be more than one Stem
  ;;  How to select?
  (if (pair? stems)
  (ly:grob-property (car stems) 'direction)
  #f)

#(define (text-stencil txt)
  "Hack @code{TextSpanner.stencil} to center a text between the bounds.
If bounds are @code{NoteColumn} grobs, we take @code{Stem.direction} into
account in order to get a nice output."
  (lambda (grob)
(let* (;; For consecutive TextSpanner or TextSpanner started/ended at
   ;; spacers or at line break left/right bound may be PaperColumn or
   ;; NonMusicalPaperColumn.
   ;; Though, we are interested in the Stems, if there's a bounding
   ;; NoteColumn or a NoteColumn at the same musical moment as
   ;; PaperColumn.
   ;; Thus we look up Stem in the bound's elements-array, in order
   ;; to specify bound-details.right.attach-dir depending on
   ;; Stem.direction.
   (stem-left-dir
 (get-bound-stem-dir grob LEFT))
   (stem-right-dir
 (get-bound-stem-dir grob RIGHT)))
  ;; adjust left/right padding and left/right attach-dir
  (if (and (number? stem-left-dir) (number? stem-right-dir))
  (begin
;; compensate Stem.thickness
;; IR says it's 1.3
(ly:grob-set-nested-property! grob
  '(bound-details right padding) 0.13)
(ly:grob-set-nested-property! grob
  '(bound-details left padding) 0)
;; always start at right edge of left bound
(ly:grob-set-nested-property! grob
  '(bound-details left attach-dir) 1)

(cond ((and (positive? stem-left-dir) (positive? stem-right-dir))
(ly:grob-set-nested-property! grob
  '(bound-details right attach-dir) 1))
  ((and (positive? stem-left-dir) (negative? stem-right-dir))
(ly:grob-set-nested-property! grob
  '(bound-details right 

Re: Workaround for (not-allowed) numbers in variable names?

2021-03-06 Thread David Kastrup
Silvain Dupertuis  writes:

> I still checked this use of variable with numbers.
> *Wonderful to see that it works.*
>
> One important note, though:
> If you use a numbered variable, _you cannot use the same variable
> without an additional number_.

gamme.1 is not a variable name.  It takes gamme to be an alist, and the
entry under key 1 is what is addressed here.

You can equivalently write gamme . #(- 3 2) for example.

In contrast, "gamme1" (referenced as \"gamme1") _is_ a single variable
name.

As to converting numbers to roman numerals: what is wrong with

#(format #f "~@r" 547)

?

-- 
David Kastrup



Re: Workaround for (not-allowed) numbers in variable names?

2021-03-06 Thread Silvain Dupertuis

I still checked this use of variable with numbers.
*Wonderful to see that it works.*

One important note, though:
If you use a numbered variable, _you cannot use the same variable without an additional 
number_.


*This should be added somewhere in the documentation!*


   Here is a snippet.

\version "2.20.0"

\paper { indent = 0 }

global = {
  \key g \major
}

% --- Definition of variables ---
gamme.1 = \relative c'' { r4^\markup { "major" } g4 a b c d e fis g1 }
gamme.2 = \relative c'' { r2^\markup { "minor" } g a bes c d ees fis g1 }

\markup "Numbered variables : gamme.1 and gamme.2"
\markup "Trying to define a variable named \"gamme\" will throw an error"
\score {
  {
    \global \gamme.1 \gamme.2
  }
}



Wow! This is something I’ve been looking for for a long time. Is this 
documented somewhere?


Best regards,

Jun
https://imslp.org/wiki/User:Jun_T 

2021/03/06 18:09、Richard Shann >のメール:


On Fri, 2021-03-05 at 10:15 -0800, Mogens Lemvig Hansen wrote:

I believe it was David K who made this magic work:

\version "2.20.0"

mus.1 = { c d e }

\score {
  \new Staff { \mus.1 }
}



This can be extended to cover the case where a variable has two numbers
associated with it:

8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><
\version "2.20.0"

Movement.1.Staff.1 = { c d e }
Movement.1.Staff.2 = { c' d' e' }
Movement.2.Staff.1 = { f g a }
Movement.2.Staff.2 = { f' g' a' }
\score {
  <<
\new Staff { \Movement.1.Staff.1 }
\new Staff { \Movement.1.Staff.2 }
  >>

}
\score {
  <<
  \new Staff { \Movement.2.Staff.1 }
\new Staff { \Movement.2.Staff.2 }
  >>

}

8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><

(cautionary note: I haven't examined the code or docs on this, but it
seems a dot before and after will do the trick mid-word and a single
dot at end of word)

A decade or so ago I resorted to converting all the numbers to Roman
numerals using a C routine that's knocking around on the interweb...
time I upgraded that.

Richard Shann




Regards,
Mogens

From: Silvain Dupertuis
Sent: March 5, 2021 10:12
To: lilypond-user@gnu.org 
Subject: Re: Workaround for (not-allowed) numbers in variable names?

I also wondered why numbers are not allowed in variables.
As for me, I used things like A, B, C instead... but it is less
practical.

My guess is that it may be linked to the way numbers are used in
notes and chords to indicate duration, otherwise it would be real
nice to be able to use digits in variable names...!

Le 05.03.21 à 17:37, stefano franchi a écrit :
Here is a question for anyone who may have been using lilypond for
projects involving text and many, many, short and similar musical
snippets.

I am putting together a book that will contain many (very brief)
exercises, grouped thematically. I had thought a convenient and
flexible way to organize the material and keep future maintenance
under control would be to create top level variables names for the
main musical categories and sub-categories and then assign each score
snippet to progressively numbered variable. So I would have, CategA-1
= {"code for one exercise"} , CategB-2 = "code for another
exercise"}, and so on. Clean structure, easy to maintain and
rearrange, etc.

Then I discovered that lilypond does not allow numbers in variable
names :-(

I'd be willing to bet my use case is not particularly weird---there
must have been other people encountering the same problem.

How have you guys managed it?

Cheers,

S.


--
__
Stefano Franchi

stefano.fran...@gmail.com 
https://www.researchgate.net/profile/Stefano_Franchi

--
Silvain Dupertuis
Route de Lausanne 335
1293 Bellevue (Switzerland)
tél. +41-(0)22-774.20.67
portable +41-(0)79-604.87.52
web: silvain-dupertuis.org







Re: Workaround for (not-allowed) numbers in variable names?

2021-03-06 Thread 田村淳
Wow! This is something I’ve been looking for for a long time. Is this 
documented somewhere?

Best regards,

Jun
https://imslp.org/wiki/User:Jun_T 

> 2021/03/06 18:09、Richard Shann のメール:
> 
> On Fri, 2021-03-05 at 10:15 -0800, Mogens Lemvig Hansen wrote:
>> I believe it was David K who made this magic work:
>>  
>> \version "2.20.0"
>>  
>> mus.1 = { c d e }
>>  
>> \score {
>>   \new Staff { \mus.1 }
>> }
>>  
> 
> This can be extended to cover the case where a variable has two numbers
> associated with it:
> 
> 8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><
> \version "2.20.0"
>  
> Movement.1.Staff.1 = { c d e }
> Movement.1.Staff.2 = { c' d' e' }
> Movement.2.Staff.1 = { f g a } 
> Movement.2.Staff.2 = { f' g' a' } 
> \score {
>   <<
> \new Staff { \Movement.1.Staff.1 }
> \new Staff { \Movement.1.Staff.2 }
>   >>
> 
> }
> \score {
>   <<
>   \new Staff { \Movement.2.Staff.1 }
> \new Staff { \Movement.2.Staff.2 }
>   >>
> 
> }
> 
> 8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><
> 
> (cautionary note: I haven't examined the code or docs on this, but it
> seems a dot before and after will do the trick mid-word and a single
> dot at end of word)
> 
> A decade or so ago I resorted to converting all the numbers to Roman
> numerals using a C routine that's knocking around on the interweb...
> time I upgraded that.
> 
> Richard Shann
> 
> 
> 
>> Regards,
>> Mogens
>>  
>> From: Silvain Dupertuis
>> Sent: March 5, 2021 10:12
>> To: lilypond-user@gnu.org
>> Subject: Re: Workaround for (not-allowed) numbers in variable names?
>>  
>> I also wondered why numbers are not allowed in variables.
>> As for me, I used things like A, B, C instead... but it is less
>> practical.
>>  
>> My guess is that it may be linked to the way numbers are used in
>> notes and chords to indicate duration, otherwise it would be real
>> nice to be able to use digits in variable names...!
>>  
>> Le 05.03.21 à 17:37, stefano franchi a écrit :
>> Here is a question for anyone who may have been using lilypond for
>> projects involving text and many, many, short and similar musical
>> snippets.
>>  
>> I am putting together a book that will contain many (very brief) 
>> exercises, grouped thematically. I had thought a convenient and
>> flexible way to organize the material and keep future maintenance
>> under control would be to create top level variables names for the
>> main musical categories and sub-categories and then assign each score
>> snippet to progressively numbered variable. So I would have, CategA-1 
>> = {"code for one exercise"} , CategB-2 = "code for another
>> exercise"}, and so on. Clean structure, easy to maintain and
>> rearrange, etc.
>>  
>> Then I discovered that lilypond does not allow numbers in variable
>> names :-(
>>  
>> I'd be willing to bet my use case is not particularly weird---there
>> must have been other people encountering the same problem.
>>  
>> How have you guys managed it?
>>  
>> Cheers,
>>  
>> S.
>>  
>> 
>> --
>> __
>> Stefano Franchi
>> 
>> stefano.fran...@gmail.com
>> https://www.researchgate.net/profile/Stefano_Franchi
>>  
>> -- 
>> Silvain Dupertuis
>> Route de Lausanne 335
>> 1293 Bellevue (Switzerland)
>> tél. +41-(0)22-774.20.67
>> portable +41-(0)79-604.87.52
>> web: silvain-dupertuis.org
>>  
> 



Re: Workaround for (not-allowed) numbers in variable names?

2021-03-06 Thread Richard Shann
On Fri, 2021-03-05 at 10:15 -0800, Mogens Lemvig Hansen wrote:
> I believe it was David K who made this magic work:
>  
> \version "2.20.0"
>  
> mus.1 = { c d e }
>  
> \score {
>   \new Staff { \mus.1 }
> }
>  

This can be extended to cover the case where a variable has two numbers
associated with it:

8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><
\version "2.20.0"
 
Movement.1.Staff.1 = { c d e }
Movement.1.Staff.2 = { c' d' e' }
Movement.2.Staff.1 = { f g a } 
Movement.2.Staff.2 = { f' g' a' } 
\score {
  <<
\new Staff { \Movement.1.Staff.1 }
\new Staff { \Movement.1.Staff.2 }
  >>

}
\score {
  <<
  \new Staff { \Movement.2.Staff.1 }
\new Staff { \Movement.2.Staff.2 }
  >>

}

8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><

(cautionary note: I haven't examined the code or docs on this, but it
seems a dot before and after will do the trick mid-word and a single
dot at end of word)

A decade or so ago I resorted to converting all the numbers to Roman
numerals using a C routine that's knocking around on the interweb...
time I upgraded that.

Richard Shann



> Regards,
> Mogens
>  
> From: Silvain Dupertuis
> Sent: March 5, 2021 10:12
> To: lilypond-user@gnu.org
> Subject: Re: Workaround for (not-allowed) numbers in variable names?
>  
> I also wondered why numbers are not allowed in variables.
> As for me, I used things like A, B, C instead... but it is less
> practical.
>  
> My guess is that it may be linked to the way numbers are used in
> notes and chords to indicate duration, otherwise it would be real
> nice to be able to use digits in variable names...!
>  
> Le 05.03.21 à 17:37, stefano franchi a écrit :
> Here is a question for anyone who may have been using lilypond for
> projects involving text and many, many, short and similar musical
> snippets.
>  
> I am putting together a book that will contain many (very brief) 
> exercises, grouped thematically. I had thought a convenient and
> flexible way to organize the material and keep future maintenance
> under control would be to create top level variables names for the
> main musical categories and sub-categories and then assign each score
> snippet to progressively numbered variable. So I would have, CategA-1 
> = {"code for one exercise"} , CategB-2 = "code for another
> exercise"}, and so on. Clean structure, easy to maintain and
> rearrange, etc.
>  
> Then I discovered that lilypond does not allow numbers in variable
> names :-(
>  
> I'd be willing to bet my use case is not particularly weird---there
> must have been other people encountering the same problem.
>  
> How have you guys managed it?
>  
> Cheers,
>  
> S.
>  
> 
> --
> __
> Stefano Franchi
> 
> stefano.fran...@gmail.com
> https://www.researchgate.net/profile/Stefano_Franchi
>  
> -- 
> Silvain Dupertuis
> Route de Lausanne 335
> 1293 Bellevue (Switzerland)
> tél. +41-(0)22-774.20.67
> portable +41-(0)79-604.87.52
> web: silvain-dupertuis.org
>