Re: Generating music expressions from within \applyContext?

2016-07-28 Thread David Kastrup
"H. S. Teoh"  writes:

> On Tue, Jul 26, 2016 at 11:38:48PM +0200, David Kastrup wrote:
> [...]
>> But semi-continuous controller changes in Midi don't make sense to
>> require actual iteration by LilyPond.  Instead this should be made a
>> feature of the Midi backend.
>> 
>> I don't see a feasible way to do that in the current state of LilyPond
>> by mere Scheme programming.
> [...]
>
> Understood. I'm actually a C/C++ programmer by trade, and I don't mind
> hacking the C++ code in LilyPond if need be. It's just that the midi
> backend seems very scantily documented,

That's like calling skeletons "scantily clad".

> and the few times I've tried I couldn't figure out exactly how it
> works. Well, I suppose if I spent enough time on it I'd get it, but it
> would be nice if somebody who understands the organization of the code
> could provide some pointers on where things are and a quick overview
> of how various pieces connect.

I'm not really much into the Midi backend.  Heikki maybe?

-- 
David Kastrup

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


Re: Generating music expressions from within \applyContext?

2016-07-28 Thread H. S. Teoh
On Tue, Jul 26, 2016 at 11:38:48PM +0200, David Kastrup wrote:
[...]
> But semi-continuous controller changes in Midi don't make sense to
> require actual iteration by LilyPond.  Instead this should be made a
> feature of the Midi backend.
> 
> I don't see a feasible way to do that in the current state of LilyPond
> by mere Scheme programming.
[...]

Understood. I'm actually a C/C++ programmer by trade, and I don't mind
hacking the C++ code in LilyPond if need be. It's just that the midi
backend seems very scantily documented, and the few times I've tried I
couldn't figure out exactly how it works. Well, I suppose if I spent
enough time on it I'd get it, but it would be nice if somebody who
understands the organization of the code could provide some pointers on
where things are and a quick overview of how various pieces connect.

My dream is to enhance the midi backend to support single note
cresc/decresc just by setting a Staff property. (Would such a patch be
accepted into the official code base?) But right now that dream seems
still rather distant.


T

-- 
Не дорог подарок, дорога любовь.

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


Re: Generating music expressions from within \applyContext?

2016-07-28 Thread H. S. Teoh
On Wed, Jul 27, 2016 at 09:47:53AM +0300, Heikki Tauriainen wrote:
[...]
> I also gave up on my attempts to try and understand how to make use of
> \applyContext back then, after I found the crude workaround of making
> use of additional global variables to access the dynamic equalizer
> function, and the maximum and minimum expression levels from within
> the music function.  (I think the inspiration for this came from the
> implementation of the \articulate function, which uses a number of
> such variables for controlling the behavior of the function - by
> changing the values of the variables between \articulate invocations,
> the function can be made to work differently between invocations
> without the need to specify extra function arguments.)

Wow.  Thanks so much for the code!  I'll definitely take a look at it
once I finish my current project (which is at too advanced of a stage to
introducing a whole new way of writing things at this point).  The idea
of using global variables ala articulate.ly did occur to me, but I never
thought to pursue the idea.


> At the risk making a fool out of myself by letting the Scheme experts
> tear this example code to shreds, I'll attach the workaround code
> (which I've tried to clean up a bit from my local stuff without much
> testing, it could contain bugs) here.
[...]

Haha, I'm pretty sure my own Scheme code is just as atrocious, if not
more, but the important thing is that it does what it's supposed to. :-)


T

-- 
If it tastes good, it's probably bad for you.

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


Re: Generating music expressions from within \applyContext?

2016-07-26 Thread David Kastrup
"H. S. Teoh"  writes:

> On Tue, Jul 26, 2016 at 09:48:36AM +0200, David Kastrup wrote:
>> "H. S. Teoh"  writes:
> [...]
>> > The background of this is that I'm writing a Scheme function that
>> > generates single-note crescendos by emitting a series of \set
>> > Staff.midiExpression = ... events.
>> 
>> Oh, but that's perfectly manageable with \applyContext.  Don't
>> generate any events, just call ly:context-set-property! directly.  If
>> you don't want to find Staff yourself, you can just write
>> 
>> \context Staff \applyContext (lambda ...
>> 
>> and then the context passed to the applyContext function will already
>> be a Staff context.
>
> Sound good, but how do I set the property at evenly-spaced time
> intervals from inside the lambda?
>
> The main problem I'm having is that the number of intervals will differ
> depending on the volume levels of the given dynamics. Since the MIDI
> expression controller only has 127 discrete volume levels, if I'm going
> from 0 to 127 then I'd need 127 property changes, but if I'm going from
> 64 to 96 I only need 32 property changes.  But I wouldn't know this
> until the \applyContext lambda is called. How do I insert property
> changes at regularly-spaced intervals from inside the lambda?

No, this is something entirely different since you want things to happen
at more than one point of time.  SequentialMusic can generate its
elements via the elements-callback hook, but this hook only has the
SequentialMusic expression itself to work with.

But semi-continuous controller changes in Midi don't make sense to
require actual iteration by LilyPond.  Instead this should be made a
feature of the Midi backend.

I don't see a feasible way to do that in the current state of LilyPond
by mere Scheme programming.

-- 
David Kastrup

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


Re: Generating music expressions from within \applyContext?

2016-07-26 Thread H. S. Teoh
On Tue, Jul 26, 2016 at 09:48:36AM +0200, David Kastrup wrote:
> "H. S. Teoh"  writes:
[...]
> > The background of this is that I'm writing a Scheme function that
> > generates single-note crescendos by emitting a series of \set
> > Staff.midiExpression = ... events.
> 
> Oh, but that's perfectly manageable with \applyContext.  Don't
> generate any events, just call ly:context-set-property! directly.  If
> you don't want to find Staff yourself, you can just write
> 
> \context Staff \applyContext (lambda ...
> 
> and then the context passed to the applyContext function will already
> be a Staff context.

Sound good, but how do I set the property at evenly-spaced time
intervals from inside the lambda?

The main problem I'm having is that the number of intervals will differ
depending on the volume levels of the given dynamics. Since the MIDI
expression controller only has 127 discrete volume levels, if I'm going
from 0 to 127 then I'd need 127 property changes, but if I'm going from
64 to 96 I only need 32 property changes.  But I wouldn't know this
until the \applyContext lambda is called. How do I insert property
changes at regularly-spaced intervals from inside the lambda?


[...]
> So far it does not sound like you want anything returned rather than
> setting some properties.
[...]

True, so perhaps there is a way after all.  It's just that so far I've
only really worked with music expressions and grobs when it comes to
Scheme, and haven't quite figured out what happens to these objects
afterwards. :-P


T

-- 
If Java had true garbage collection, most programs would delete themselves upon 
execution. -- Robert Sewell

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


Re: Generating music expressions from within \applyContext?

2016-07-26 Thread David Kastrup
David Kastrup  writes:

> "H. S. Teoh"  writes:
>
>> I have a Scheme function that returns a music expression. Unfortunately,
>> the expression returned depends on the properties of the context it's
>> evaluated in. I.e., based on the current setting of
>> Staff.dynamicAbsoluteVolumeFunction it will return a different number of
>> events in the music expression.
>>
>> Is this possible?
>
> \applyContext works at the process-music stage.  That's actually a bit
> late to generate stream events.

Sorry, that one is actually nonsense.  I got confused between iterators
(which is what \applyContext uses) and engravers here.  So if you
actually want to generate stream events, that would be possible and
actually, for the sake of quoted music, a reasonably good idea.

So you'd use ly:make-stream-event to create suitable stream events and
broadcast them to the event-source dispatcher of the context...

Weird.  Nobody does that.  Just C++ code.  Now I'm irritated.

-- 
David Kastrup

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


Re: Generating music expressions from within \applyContext?

2016-07-26 Thread David Kastrup
"H. S. Teoh"  writes:

> I have a Scheme function that returns a music expression. Unfortunately,
> the expression returned depends on the properties of the context it's
> evaluated in. I.e., based on the current setting of
> Staff.dynamicAbsoluteVolumeFunction it will return a different number of
> events in the music expression.
>
> Is this possible?

\applyContext works at the process-music stage.  That's actually a bit
late to generate stream events.

> The background of this is that I'm writing a Scheme function that
> generates single-note crescendos by emitting a series of \set
> Staff.midiExpression = ... events.

Oh, but that's perfectly manageable with \applyContext.  Don't generate
any events, just call ly:context-set-property! directly.  If you don't
want to find Staff yourself, you can just write

\context Staff \applyContext (lambda ...

and then the context passed to the applyContext function will already be
a Staff context.

> Currently I've written a Scheme function that's able to generate these
> events; however, it requires me to specify numerical starting / ending
> values for midiExpression. I'd like to be able to specify dynamics
> instead of numerical values, and have the Scheme function
> automatically look up the numerical values based on the current volume
> function defined for the Staff.
>
> However, so far I haven't been able to figure out how to read the
> Staff properties except using \applyContext with a lambda, and AFAICT
> it's not possible to return a music expression from this lambda?

So far it does not sound like you want anything returned rather than
setting some properties.

-- 
David Kastrup

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


Re: Generating music expressions from within \applyContext?

2016-07-25 Thread Jan-Peter Voigt
Hi,

I haven't a working solution, but some thoughts:
The \applyContext is one event in time, so you can set context-properties 
*once*.
This might be a case for a midi-performer. This is an engraver inside the 
midi-block, so it should be possible to create a scheme-performer to set the 
midiExpression property inside the Staff context.
--- this is not an easier way! And I don't have a computer nearby right now, to 
test, if moving the dynamic performer into another context helps.
Another approach might be a music-function, that produces SimultaneousMusic 
with the note(s) and the dynamic midi events in separate streams. ( e.g. << { 
\music } { \dynamicevents } >> )

Just some thoughts right now.
I am quite busy right now, so if there are no helpful answers within two weeks, 
you can ask me again and I can provide some code.

Jan-Peter

Am 26. Juli 2016 00:51:49 MESZ, schrieb "H. S. Teoh" :
>Hi,
>
>I have a Scheme function that returns a music expression.
>Unfortunately,
>the expression returned depends on the properties of the context it's
>evaluated in. I.e., based on the current setting of
>Staff.dynamicAbsoluteVolumeFunction it will return a different number
>of
>events in the music expression.
>
>Is this possible?
>
>The background of this is that I'm writing a Scheme function that
>generates single-note crescendos by emitting a series of \set
>Staff.midiExpression = ... events. Currently I've written a Scheme
>function that's able to generate these events; however, it requires me
>to specify numerical starting / ending values for midiExpression. I'd
>like to be able to specify dynamics instead of numerical values, and
>have the Scheme function automatically look up the numerical values
>based on the current volume function defined for the Staff.
>
>However, so far I haven't been able to figure out how to read the Staff
>properties except using \applyContext with a lambda, and AFAICT it's
>not
>possible to return a music expression from this lambda?
>
>Or is there another (hopefully simpler?) way to achieve what I want?
>
>
>--T
>
>___
>lilypond-user mailing list
>lilypond-user@gnu.org
>https://lists.gnu.org/mailman/listinfo/lilypond-user

-- 
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Generating music expressions from within \applyContext?

2016-07-25 Thread H. S. Teoh
Hi,

I have a Scheme function that returns a music expression. Unfortunately,
the expression returned depends on the properties of the context it's
evaluated in. I.e., based on the current setting of
Staff.dynamicAbsoluteVolumeFunction it will return a different number of
events in the music expression.

Is this possible?

The background of this is that I'm writing a Scheme function that
generates single-note crescendos by emitting a series of \set
Staff.midiExpression = ... events. Currently I've written a Scheme
function that's able to generate these events; however, it requires me
to specify numerical starting / ending values for midiExpression. I'd
like to be able to specify dynamics instead of numerical values, and
have the Scheme function automatically look up the numerical values
based on the current volume function defined for the Staff.

However, so far I haven't been able to figure out how to read the Staff
properties except using \applyContext with a lambda, and AFAICT it's not
possible to return a music expression from this lambda?

Or is there another (hopefully simpler?) way to achieve what I want?


--T

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