Re: Getting \tempo params

2021-10-21 Thread David Kastrup
Paolo Prete  writes:

> On Thu, Oct 21, 2021 at 3:04 PM David Kastrup  wrote:
>
>>
>>
>> Here's a cut of something I currently use in scores of mine for
>> doing things like accelerando, ritardando, and so on.
>>
>> tempoChange =
>> #(define-music-function (interval endscale thenscale music)
>>(ly:duration? scale? (scale? 1) ly:music?)
>>   "Make a gradual tempo change over @var{music}, essentially changing
>> speed after
>> every duration of @var{interval}, approaching a factor of speed of
>> @var{endscale}
>> compared to the start.  Afterwards, tempo is switched to @var{thenscale}
>> of the
>> original speed (default 1).  If @var{thenscale} is 0, the speed reached at
>> the
>> end is just maintained and can be overriden with an explicit @samp{\\tempo}
>> command if required."
>>(define (scaletempo oldscale newscale)
>>  (make-apply-context
>>   (lambda (ctx)
>> (set! (ly:context-property ctx 'tempoWholesPerMinute)
>>  (ly:moment-mul (ly:context-property ctx 'tempoWholesPerMinute)
>>  (ly:make-moment (/ newscale oldscale)))
>>
>>(let* ((muslen (ly:moment-main (ly:music-length music)))
>>   (intlen (ly:moment-main (ly:duration-length interval)))
>>   (steps (/ muslen intlen))
>>   (endfactor (scale->factor endscale))
>>   (thenfactor (scale->factor thenscale)))
>>  (make-simultaneous-music
>>   (list music
>> (context-spec-music
>>  (make-sequential-music
>>   (let loop ((rsteplst (iota (1+ steps) endfactor (/ (- 1
>> endfactor) steps)))
>>  (res (if (positive? thenfactor)
>>   (list (scaletempo endfactor thenfactor))
>>   (list
>> (if (null? (cdr rsteplst))
>> res
>> (loop (cdr rsteplst)
>>   (cons* (scaletempo (cadr rsteplst) (car
>> rsteplst))
>>  (make-skip-music (ly:make-duration 0 0
>> intlen))
>>  res)
>>  'Score)
>>
>> See if that helps you achieve your objective.
>>
>>
> This is interesting, thanks, but I don't understand if it fits with the
> growing beam example.
>  When that beams occur, I need three parameters:
>
> 1) the \tempo just before the beam
> 2) the \tempo at first note of the beam
> 3) the \tempo at the last note of the beam.
>
> Soon after the beam, I need that the tempo must be reset to 1)

That's the default.

> From what I see, in your code, at the end of $music the tempo is reset to
> 2) : am I wrong?

I guess so.

2) is not separately settable but determined by the requested overall
speed change (probably 1/2 or 2/1 in your case) divided by the number of
steps requested (probably 4 or 8 or so).

-- 
David Kastrup



Re: Getting \tempo params

2021-10-21 Thread Paolo Prete
On Thu, Oct 21, 2021 at 3:04 PM David Kastrup  wrote:

>
>
> Here's a cut of something I currently use in scores of mine for
> doing things like accelerando, ritardando, and so on.
>
> tempoChange =
> #(define-music-function (interval endscale thenscale music)
>(ly:duration? scale? (scale? 1) ly:music?)
>   "Make a gradual tempo change over @var{music}, essentially changing
> speed after
> every duration of @var{interval}, approaching a factor of speed of
> @var{endscale}
> compared to the start.  Afterwards, tempo is switched to @var{thenscale}
> of the
> original speed (default 1).  If @var{thenscale} is 0, the speed reached at
> the
> end is just maintained and can be overriden with an explicit @samp{\\tempo}
> command if required."
>(define (scaletempo oldscale newscale)
>  (make-apply-context
>   (lambda (ctx)
> (set! (ly:context-property ctx 'tempoWholesPerMinute)
>  (ly:moment-mul (ly:context-property ctx 'tempoWholesPerMinute)
>  (ly:make-moment (/ newscale oldscale)))
>
>(let* ((muslen (ly:moment-main (ly:music-length music)))
>   (intlen (ly:moment-main (ly:duration-length interval)))
>   (steps (/ muslen intlen))
>   (endfactor (scale->factor endscale))
>   (thenfactor (scale->factor thenscale)))
>  (make-simultaneous-music
>   (list music
> (context-spec-music
>  (make-sequential-music
>   (let loop ((rsteplst (iota (1+ steps) endfactor (/ (- 1
> endfactor) steps)))
>  (res (if (positive? thenfactor)
>   (list (scaletempo endfactor thenfactor))
>   (list
> (if (null? (cdr rsteplst))
> res
> (loop (cdr rsteplst)
>   (cons* (scaletempo (cadr rsteplst) (car
> rsteplst))
>  (make-skip-music (ly:make-duration 0 0
> intlen))
>  res)
>  'Score)
>
> See if that helps you achieve your objective.
>
>
This is interesting, thanks, but I don't understand if it fits with the
growing beam example.
 When that beams occur, I need three parameters:

1) the \tempo just before the beam
2) the \tempo at first note of the beam
3) the \tempo at the last note of the beam.

Soon after the beam, I need that the tempo must be reset to 1)

>From what I see, in your code, at the end of $music the tempo is reset to
2) : am I wrong?






> --
> David Kastrup
>


Re: Getting \tempo params

2021-10-21 Thread David Kastrup
Paolo Prete  writes:

> On Thu, Oct 21, 2021 at 2:01 PM David Kastrup  wrote:
>
>> Paolo Prete  writes:
>>
>> > On Thu, Oct 21, 2021 at 1:22 PM David Kastrup  wrote:
>> >
>> >> Paolo Prete  writes:
>> >>
>> >> > Hello,
>> >> >
>> >> > after a \tempo X = Y is set, is there a way (a scheme function or
>> >> > variable?) to get X and Y?
>> >>
>> >> What does "after" mean and "is set"?  At a later point in the source
>> >> text, at a later time in musical execution?
>> >>
>> >>
>> > yes
>>
>> Those are two different things entirely.  "yes" as an answer is not
>> suitable.
>>
>
>
> Sorry, I used a bad quote of the text. With "yes" I mean "at a later point
> in the source text".

And then you go on to give an example where clearly "at a later time in
musical execution" is desired.

>> > unfortunately this doesn't sound trivial to achieve, and I presume
>> > that tempoWholesPerMinute is not in the API.
>>
>> I have no idea what you mean by "is not in the API".  What is the API
>> according to your definition?
>>
>>
> API is the public interface exposed to the user. I assumed that
> tempoWholesPerMinute was internal stuff,


> but I just checked that it IS in the API:
> https://lilypond.org/doc/v2.22/Documentation/internals/tempo_005fperformer

Given that the manual is called "Internals", you may need to adjust your
terminology to that other LilyPond users work with.

> Anyway, I don't know if it fits what I need. More specifically, I'm
> trying to obtain in the midi output the behavior of growing beams
> (Beam.grow-direction). For example, a sort of accelerando from a fixed
> metronome (which is not the previous metronome mark).  After the beam,
> the metronome must be reset to the initial value.  For example:
>
> %%%
> {
>
> \tempo 4 = 120
>
> c'4
>
> \override Beam.grow-direction = #RIGHT
> %start from \tempo 4 = 40
> c'16[
> % \tempo 4 = 40 + 20%
> c'
> % \tempo 4 = 40 + 40%
> c'
> % \tempo 4 = 40 + 60%
> c']
>
> %reset \tempo to 4 = 120
> c'4
>
> }
> %%%
>
> I already wrote a Scheme function that increases a tempo by 20% for each
> note grouped by the beam, starting from a chosen value, but I don't know
> how to reset the tempo after the beam.

Here's a cut of something I currently use in scores of mine for
doing things like accelerando, ritardando, and so on.

tempoChange =
#(define-music-function (interval endscale thenscale music)
   (ly:duration? scale? (scale? 1) ly:music?)
  "Make a gradual tempo change over @var{music}, essentially changing speed 
after
every duration of @var{interval}, approaching a factor of speed of 
@var{endscale}
compared to the start.  Afterwards, tempo is switched to @var{thenscale} of the
original speed (default 1).  If @var{thenscale} is 0, the speed reached at the
end is just maintained and can be overriden with an explicit @samp{\\tempo}
command if required."
   (define (scaletempo oldscale newscale)
 (make-apply-context
  (lambda (ctx)
(set! (ly:context-property ctx 'tempoWholesPerMinute)
 (ly:moment-mul (ly:context-property ctx 'tempoWholesPerMinute)
 (ly:make-moment (/ newscale oldscale)))

   (let* ((muslen (ly:moment-main (ly:music-length music)))
  (intlen (ly:moment-main (ly:duration-length interval)))
  (steps (/ muslen intlen))
  (endfactor (scale->factor endscale))
  (thenfactor (scale->factor thenscale)))
 (make-simultaneous-music
  (list music
(context-spec-music
 (make-sequential-music
  (let loop ((rsteplst (iota (1+ steps) endfactor (/ (- 1 
endfactor) steps)))
 (res (if (positive? thenfactor)
  (list (scaletempo endfactor thenfactor))
  (list
(if (null? (cdr rsteplst))
res
(loop (cdr rsteplst)
  (cons* (scaletempo (cadr rsteplst) (car rsteplst))
 (make-skip-music (ly:make-duration 0 0 intlen))
 res)
 'Score)

See if that helps you achieve your objective.

-- 
David Kastrup



Re: Getting \tempo params

2021-10-21 Thread Paolo Prete
On Thu, Oct 21, 2021 at 2:01 PM David Kastrup  wrote:

> Paolo Prete  writes:
>
> > On Thu, Oct 21, 2021 at 1:22 PM David Kastrup  wrote:
> >
> >> Paolo Prete  writes:
> >>
> >> > Hello,
> >> >
> >> > after a \tempo X = Y is set, is there a way (a scheme function or
> >> > variable?) to get X and Y?
> >>
> >> What does "after" mean and "is set"?  At a later point in the source
> >> text, at a later time in musical execution?
> >>
> >>
> > yes
>
> Those are two different things entirely.  "yes" as an answer is not
> suitable.
>


Sorry, I used a bad quote of the text. With "yes" I mean "at a later point
in the source text".


>
> > unfortunately this doesn't sound trivial to achieve, and I presume that
> > tempoWholesPerMinute is not in the API.
>
> I have no idea what you mean by "is not in the API".  What is the API
> according to your definition?
>
>
API is the public interface exposed to the user. I assumed that
tempoWholesPerMinute  was internal stuff, but I just checked that it IS in
the API:
https://lilypond.org/doc/v2.22/Documentation/internals/tempo_005fperformer
Anyway, I don't know if it fits what I need. More specifically, I'm trying
to obtain in the midi output the behavior of growing beams
(Beam.grow-direction). For example, a sort of accelerando from a fixed
metronome (which is not the previous metronome mark).
After the beam, the metronome must be reset to the initial value.
For example:

%%%
{

\tempo 4 = 120

c'4

\override Beam.grow-direction = #RIGHT
%start from \tempo 4 = 40
c'16[
% \tempo 4 = 40 + 20%
c'
% \tempo 4 = 40 + 40%
c'
% \tempo 4 = 40 + 60%
c']

%reset \tempo to 4 = 120
c'4

}
%%%

I already wrote a Scheme function that increases a tempo by 20% for each
note grouped by the beam, starting from a chosen value, but I don't know
how to reset the tempo after the beam.

thanks,
P


Re: Getting \tempo params

2021-10-21 Thread David Kastrup
Paolo Prete  writes:

> On Thu, Oct 21, 2021 at 1:22 PM David Kastrup  wrote:
>
>> Paolo Prete  writes:
>>
>> > Hello,
>> >
>> > after a \tempo X = Y is set, is there a way (a scheme function or
>> > variable?) to get X and Y?
>>
>> What does "after" mean and "is set"?  At a later point in the source
>> text, at a later time in musical execution?
>>
>>
> yes

Those are two different things entirely.  "yes" as an answer is not
suitable.

>> With regard to the latter (which you could access in callbacks or
>> \applyContext) \tempo sets the context variable tempoWholesPerMinute in
>> the Score context.  How this relates to X and Y depends on the unit of
>> the beat.  A reasonable guess is it is measured in baseMoment beats,
>> possibly multipled by the gcd of the values in beatStructure (if any).
>> At least that's what Time_signature_performer tries to state.
>>
>>
> unfortunately this doesn't sound trivial to achieve, and I presume that
> tempoWholesPerMinute is not in the API.

I have no idea what you mean by "is not in the API".  What is the API
according to your definition?

> Then I wonder if it's preferable to override the \tempo function by setting
> two custom vars

Setting variables (unless you mean context properties) sounds like you
are interested in "a later point in the source text" which is quite
different from what I was writing about.

\tempo creates a music expression, and this music expression has effects
when the music is being interpreted ("iterated").  You sound like you
want to remember what \tempo does in the source text instead.  That's
kind of unusual and there are few things treated in that manner (default
durations during entry are the main exception coming to mind).  What are
you actually trying to do?

-- 
David Kastrup



Re: Getting \tempo params

2021-10-21 Thread Paolo Prete
On Thu, Oct 21, 2021 at 1:22 PM David Kastrup  wrote:

> Paolo Prete  writes:
>
> > Hello,
> >
> > after a \tempo X = Y is set, is there a way (a scheme function or
> > variable?) to get X and Y?
>
> What does "after" mean and "is set"?  At a later point in the source
> text, at a later time in musical execution?
>
>
yes

With regard to the latter (which you could access in callbacks or
> \applyContext) \tempo sets the context variable tempoWholesPerMinute in
> the Score context.  How this relates to X and Y depends on the unit of
> the beat.  A reasonable guess is it is measured in baseMoment beats,
> possibly multipled by the gcd of the values in beatStructure (if any).
> At least that's what Time_signature_performer tries to state.
>
>
unfortunately this doesn't sound trivial to achieve, and I presume that
tempoWholesPerMinute is not in the API.
Then I wonder if it's preferable to override the \tempo function by setting
two custom vars

thanks,
P



> --
> David Kastrup
>


Re: Getting \tempo params

2021-10-21 Thread David Kastrup
Paolo Prete  writes:

> Hello,
>
> after a \tempo X = Y is set, is there a way (a scheme function or
> variable?) to get X and Y?

What does "after" mean and "is set"?  At a later point in the source
text, at a later time in musical execution?

With regard to the latter (which you could access in callbacks or
\applyContext) \tempo sets the context variable tempoWholesPerMinute in
the Score context.  How this relates to X and Y depends on the unit of
the beat.  A reasonable guess is it is measured in baseMoment beats,
possibly multipled by the gcd of the values in beatStructure (if any).
At least that's what Time_signature_performer tries to state.

-- 
David Kastrup